Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('ClusterGrid.common utilities', () => {
const event = new KeyboardEvent('keydown', { key: 'Enter' })
Object.defineProperty(event, 'preventDefault', { value: vi.fn() })

handler(event as any)
handler(event as unknown as React.KeyboardEvent<HTMLDivElement>)
expect(callback).toHaveBeenCalledTimes(1)
expect(event.preventDefault).toHaveBeenCalled()
})
Expand All @@ -141,7 +141,7 @@ describe('ClusterGrid.common utilities', () => {
const event = new KeyboardEvent('keydown', { key: ' ' })
Object.defineProperty(event, 'preventDefault', { value: vi.fn() })

handler(event as any)
handler(event as unknown as React.KeyboardEvent<HTMLDivElement>)
expect(callback).toHaveBeenCalledTimes(1)
expect(event.preventDefault).toHaveBeenCalled()
})
Expand All @@ -152,7 +152,7 @@ describe('ClusterGrid.common utilities', () => {
const event = new KeyboardEvent('keydown', { key: 'a' })
Object.defineProperty(event, 'preventDefault', { value: vi.fn() })

handler(event as any)
handler(event as unknown as React.KeyboardEvent<HTMLDivElement>)
expect(callback).not.toHaveBeenCalled()
expect(event.preventDefault).not.toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,36 @@ vi.mock('react-i18next', () => ({
}),
}))

interface MockModalHeaderProps {
title: string
onClose: () => void
disabled?: boolean
}

interface MockModalFooterProps {
children: React.ReactNode
disabled?: boolean
loading?: boolean
}

vi.mock('../../../lib/modals', () => ({
BaseModal: Object.assign(
({ children, isOpen }: { children: React.ReactNode; isOpen: boolean }) => {
if (!isOpen) return null
return <div data-testid="base-modal">{children}</div>
},
{
Header: ({ title, onClose, ...rest }: { title: string; onClose: () => void; [key: string]: unknown }) => (
Header: ({ title, onClose, disabled }: MockModalHeaderProps) => (
<div data-testid="modal-header">
<span>{title}</span>
<button onClick={onClose} data-testid="close-button" disabled={(rest as any).disabled}>Close</button>
<button onClick={onClose} data-testid="close-button" disabled={disabled}>Close</button>
</div>
),
Content: ({ children }: { children: React.ReactNode }) => (
<div data-testid="modal-content">{children}</div>
),
Footer: ({ children, ...rest }: { children: React.ReactNode; [key: string]: unknown }) => (
<div data-testid="modal-footer" data-disabled={(rest as any).disabled} data-loading={(rest as any).loading}>{children}</div>
Footer: ({ children, disabled, loading }: MockModalFooterProps) => (
<div data-testid="modal-footer" data-disabled={disabled} data-loading={loading}>{children}</div>
),
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ vi.mock('../../dashboard/FloatingDashboardActions', () => ({
<button onClick={onOpenCustomizer}>Open studio</button>
),
}))
interface MockDashboardCustomizerProps {
existingCardTypes: string[]
onAddCards: (cards: Array<{ type: string; title: string; config: Record<string, unknown> }>) => void
isOpen: boolean
}

vi.mock('../../dashboard/customizer/DashboardCustomizer', () => ({
DashboardCustomizer: ({ existingCardTypes, onAddCards, isOpen }: any) => (
DashboardCustomizer: ({ existingCardTypes, onAddCards, isOpen }: MockDashboardCustomizerProps) => (
<div>
<div data-testid="customizer-open">{String(isOpen)}</div>
<div data-testid="existing-cards">{existingCardTypes.join(',')}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'

const mockOpenAddCardModal = vi.fn()

interface MockSidebarShellProps {
navSections: Array<{ items: Array<{ id: string; href: string; label: string }> }>
branding: { title: string; subtitle: string }
onAddCard: () => void
onAddMore: () => void
}

vi.mock('../../layout/SidebarShell', () => ({
SidebarShell: ({ navSections, branding, onAddCard, onAddMore }: any) => (
SidebarShell: ({ navSections, branding, onAddCard, onAddMore }: MockSidebarShellProps) => (
<div>
<h1>{branding.title}</h1>
<p>{branding.subtitle}</p>
{navSections.flatMap((section: any) => section.items).map((item: any) => (
{navSections.flatMap((section) => section.items).map((item) => (
<a key={item.id} href={item.href}>{item.label}</a>
))}
<button onClick={onAddCard}>Add card</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ describe('ClusterReadinessCard', () => {
projectNames: ['falco'],
readiness: { overallScore: 85, cpuHeadroomPercent: 75, memHeadroomPercent: 75, storageHeadroomPercent: 100 },
warnings: []
} as unknown as any}
}}
/>
)

Expand All @@ -245,7 +245,7 @@ describe('ClusterReadinessCard', () => {
projectNames: [],
readiness: { overallScore: 85 },
warnings: []
} as unknown as any}
}}
/>
)

Expand Down Expand Up @@ -393,7 +393,7 @@ describe('FixerDefinitionPanel', () => {
onRemoveProject={vi.fn()}
onUpdatePriority={vi.fn()}
aiStreaming={true}
planningMission={{ status: 'running', messages: [] } as unknown as any}
planningMission={{ status: 'running', messages: [] }}
/>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function getVClusterActionMessage(feedback: VClusterActionFeedback, t: TFunction
if (feedback.state === 'error') {
return feedback.message
? friendlyErrorMessage(feedback.message)
// Dynamic i18n keys require type assertion — the key is built at runtime
// eslint-disable-next-line @typescript-eslint/no-explicit-any
: String(t(`${keyBase}Fallback` as any, { name: feedback.name, namespace: feedback.namespace }))
}
Expand Down
51 changes: 39 additions & 12 deletions web/src/components/workloads/__tests__/WorkloadsExtended.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,37 @@ vi.mock('../../../lib/dashboards/DashboardPage', () => ({
),
}))

let mockPodIssues: any[] = []
let mockDeploymentIssues: any[] = []
let mockDeployments: any[] = []
const mockClusters: any[] = []
interface MockPodIssue {
name: string
namespace: string
cluster: string
reason: string
}

interface MockDeploymentIssue {
name: string
namespace: string
cluster: string
reason?: string
}

interface MockDeployment {
name: string
namespace: string
cluster: string
status: string
replicas: number
readyReplicas: number
}

interface MockCluster {
name: string
}

let mockPodIssues: MockPodIssue[] = []
let mockDeploymentIssues: MockDeploymentIssue[] = []
let mockDeployments: MockDeployment[] = []
const mockClusters: MockCluster[] = []
let mockIsLoading = false
let mockIsDemoMode = true

Expand All @@ -65,7 +92,7 @@ vi.mock('../../../hooks/useGlobalFilters', () => ({
selectedClusters: [],
isAllClustersSelected: true,
customFilter: '',
filterByCluster: (items: any[]) => items,
filterByCluster: <T,>(items: T[]) => items,
})),
}))

Expand Down Expand Up @@ -115,7 +142,7 @@ vi.mock('../../ui/Toast', () => ({
const kubectlExecSpy = vi.fn().mockResolvedValue({ output: 'deployment.apps/test restarted', exitCode: 0 })
vi.mock('../../../lib/kubectlProxy', () => ({
kubectlProxy: {
exec: (...args: any[]) => kubectlExecSpy(...args),
exec: (...args: unknown[]) => kubectlExecSpy(...args),
},
}))

Expand All @@ -141,8 +168,8 @@ const setupDeploymentView = () => {
selectedClusters: [],
isAllClustersSelected: true,
customFilter: 'nginx',
filterByCluster: (items: any[]) => items,
} as any)
filterByCluster: <T,>(items: T[]) => items,
})

mockDeployments = [
{ name: 'nginx-web', namespace: 'production', cluster: 'ctx/prod-east', status: 'running', replicas: 3, readyReplicas: 3 },
Expand Down Expand Up @@ -228,8 +255,8 @@ describe('Namespace-grouped view (#12479)', () => {
selectedClusters: [],
isAllClustersSelected: true,
customFilter: '',
filterByCluster: (items: any[]) => items,
} as any)
filterByCluster: <T,>(items: T[]) => items,
})
})

it('groups deployments by namespace/cluster when no filter is applied', () => {
Expand Down Expand Up @@ -435,8 +462,8 @@ describe('Loading skeleton and agent-offline states (#12481)', () => {
selectedClusters: [],
isAllClustersSelected: true,
customFilter: '',
filterByCluster: (items: any[]) => items,
} as any)
filterByCluster: <T,>(items: T[]) => items,
})
})

it('shows loading skeletons when data is loading and no data exists', () => {
Expand Down
Loading