src/
├── Components/
│ └── DnDLayout/
│ ├── GridLayout.test.tsx # Component unit tests
│ └── __snapshots__/ # Jest snapshots
├── hooks/
│ └── tests/
│ ├── useDashboardConfig.test.ts
│ ├── useDashboardTemplate.test.ts
│ ├── useGetDashboards.test.ts
│ └── ... # One test file per hook
playwright/
├── widget-layout.spec.ts # E2E tests
└── README.md
- Jest 27 with
jest-environment-jsdom - React Testing Library (
@testing-library/react) @testing-library/jest-domextended matchers (viaconfig/jest.setup.js)- CSS/SCSS/SVG mocked via
identity-obj-proxy - Coverage collected from
src/**/*.js
Every test file must mock these Chrome shell dependencies:
// Mock useChrome hook
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
__esModule: true,
default: () => ({
auth: { getUser: jest.fn().mockResolvedValue({ identity: { user: { username: 'test-user' } } }) },
analytics: { track: jest.fn() },
}),
}));
// Mock Scalprum for federated widgets
jest.mock('@scalprum/react-core', () => ({
ScalprumComponent: ({ scope, module }: { scope: string; module: string }) => (
<div data-testid={`scalprum-${scope}-${module}`}>ScalprumWidget</div>
),
}));Use createStore + Provider to inject atom values:
import { Provider, createStore } from 'jotai';
function renderWithStore(ui: React.ReactElement, overrides?: Record<string, unknown>) {
const store = createStore();
if (overrides?.widgetMapping) store.set(widgetMappingAtom, overrides.widgetMapping);
if (overrides?.layoutVariant) store.set(layoutVariantAtom, overrides.layoutVariant);
return render(<Provider store={store}>{ui}</Provider>);
}crypto.randomUUID is not available in jsdom — polyfill at the top of test files that use widget ID generation:
Object.defineProperty(global, 'crypto', {
value: { randomUUID: () => 'test-uuid-1234' },
});Mock fetch or individual API functions from src/api/dashboard-templates.ts:
jest.mock('../../api/dashboard-templates', () => ({
...jest.requireActual('../../api/dashboard-templates'),
getDashboardTemplates: jest.fn(),
patchDashboardTemplate: jest.fn(),
}));Snapshot tests exist for component rendering states. Update snapshots with:
npm test -- -uReview snapshot diffs carefully — they catch unintended UI regressions.
- Config:
playwright.config.tsat repo root - Tests:
playwright/widget-layout.spec.ts - Auth: Uses
@redhat-cloud-services/playwright-test-authfor HCC authentication - Run:
npm run test:playwright
npm test # Unit tests only
npm run test:playwright # E2E tests
npm run verify # Build + lint + test (full CI equivalent)