514de78ba7
- Fix ExemptionManager apiVersion bug (apps/batch resources used wrong API path) - Replace resource: any with proper KubeResource interface (strict TypeScript) - Replace all var(--mui-palette-*) CSS variables with useTheme() + theme.palette.* - Replace custom drawer with MUI Drawer component (proper a11y and theming) - Replace alert() calls with StatusLabel-based inline feedback - Add PolarisErrorBoundary wrapping all registered plugin components - Export getPolarisApiPath/isFullUrl from polaris.ts, deduplicate in PolarisSettings - Fix PolarisDataContext test mock missing triggerRefresh - Fix DashboardView test SimpleTable mock using any - Remove dead NamespaceDetailView (replaced by drawer), unused MockPolarisProvider, unused getSeverityColor export - Add tests for InlineAuditSection, AppBarScoreBadge, topIssues, checkMapping (32 new) - Update CLAUDE.md, CHANGELOG.md, README.md for v0.6.0 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { renderHook } from '@testing-library/react';
|
|
import React from 'react';
|
|
import { describe, expect, it, vi } from 'vitest';
|
|
import { makeAuditData, makeResult } from '../test-utils';
|
|
|
|
vi.mock('@kinvolk/headlamp-plugin/lib', () => ({
|
|
ApiProxy: { request: vi.fn() },
|
|
}));
|
|
|
|
// Mock usePolarisData so PolarisDataProvider doesn't make real API calls
|
|
vi.mock('./polaris', async importOriginal => {
|
|
const actual = await importOriginal<typeof import('./polaris')>();
|
|
return {
|
|
...actual,
|
|
usePolarisData: vi.fn(() => ({
|
|
data: makeAuditData([makeResult()]),
|
|
loading: false,
|
|
error: null,
|
|
triggerRefresh: vi.fn(),
|
|
})),
|
|
};
|
|
});
|
|
|
|
import { PolarisDataProvider, usePolarisDataContext } from './PolarisDataContext';
|
|
|
|
describe('usePolarisDataContext', () => {
|
|
it('throws when used outside PolarisDataProvider', () => {
|
|
// Suppress console.error from React during expected error
|
|
const spy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
expect(() => {
|
|
renderHook(() => usePolarisDataContext());
|
|
}).toThrow('usePolarisDataContext must be used within a PolarisDataProvider');
|
|
|
|
spy.mockRestore();
|
|
});
|
|
|
|
it('returns context value when inside PolarisDataProvider', () => {
|
|
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
<PolarisDataProvider>{children}</PolarisDataProvider>
|
|
);
|
|
|
|
const { result } = renderHook(() => usePolarisDataContext(), { wrapper });
|
|
|
|
expect(result.current.data).not.toBeNull();
|
|
expect(result.current.loading).toBe(false);
|
|
expect(result.current.error).toBeNull();
|
|
expect(result.current.refresh).toBeDefined();
|
|
});
|
|
});
|