Frontend Test Infrastructure Setup - Complete¶
Date: 5 February 2026 Status: ✅ Complete and Working
Summary¶
Comprehensive test infrastructure has been set up for the Quill Medical frontend to support writing unit and integration tests for React components, hooks, and utilities.
What Was Created¶
Configuration Files¶
frontend/vitest.config.ts- Vitest test runner configuration- Enables jsdom environment for DOM testing
- Configures test setup file
- Sets up coverage reporting (v8 provider)
-
Excludes appropriate files from coverage
-
frontend/src/test/setup.ts- Global test setup - Imports jest-dom matchers for Vitest
- Configures automatic cleanup after each test
- Mocks browser APIs (matchMedia, IntersectionObserver, ResizeObserver)
-
Ensures consistent test environment
-
frontend/src/test/test-utils.tsx- Custom testing utilities renderWithMantine()- Render components with Mantine providerrenderWithRouter()- Render components with Router and MantinecreateMockResponse()- Helper for mocking fetch responses-
waitForCondition()- Flexible async waiting utility -
frontend/src/test/infrastructure.test.tsx- Verification tests - 9 tests that verify the infrastructure works correctly
- Tests jest-dom matchers, render utilities, user-event, and mock helpers
-
Serves as examples for writing new tests
-
frontend/src/test/README.md- Comprehensive testing guide - Documentation on how to write tests
- Examples for common testing scenarios
- Best practices and troubleshooting
-
Coverage configuration
-
frontend/package.json- Added coverage script yarn unit-test:coveragecommand for coverage reports
Test Results¶
✓ .storybook/utils/useBreakPoint.test.tsx (5 tests)
✓ src/test/infrastructure.test.tsx (9 tests)
Test Files: 2 passed (2)
Tests: 14 passed (14)
Duration: ~2s
Features Enabled¶
Jest-DOM Matchers¶
All matchers from @testing-library/jest-dom are now available:
expect(element).toBeInTheDocument();
expect(element).toBeVisible();
expect(element).toBeDisabled();
expect(element).toHaveTextContent("text");
// ... and many more
User Event Testing¶
User interactions can be tested realistically:
const user = userEvent.setup();
await user.click(button);
await user.type(input, "text");
Custom Render Functions¶
Components can be rendered with required providers:
// For Mantine components
renderWithMantine(<MyComponent />);
// For components using routing
renderWithRouter(<LoginPage />);
Mock Helpers¶
Easy creation of mock responses:
global.fetch = vi.fn().mockResolvedValue(createMockResponse({ data: "test" }));
Dependencies Already Installed¶
All necessary testing libraries were already in package.json:
- ✅
vitest- Test runner - ✅
@testing-library/react- React testing utilities - ✅
@testing-library/jest-dom- DOM matchers - ✅
@testing-library/user-event- User interaction simulation - ✅
jsdom- Browser environment simulation
No additional packages needed to be installed.
Usage¶
Run Tests¶
# Interactive watch mode
yarn unit-test
# CI mode (run once)
yarn unit-test:run
# With coverage
yarn unit-test:coverage
# Via Justfile (in Docker)
just unit-tests-frontend
Write a Test¶
import { describe, it, expect } from "vitest";
import { screen } from "@testing-library/react";
import { renderWithMantine } from "@/test/test-utils";
import MyComponent from "./MyComponent";
describe("MyComponent", () => {
it("renders correctly", () => {
renderWithMantine(<MyComponent />);
expect(screen.getByText("Hello")).toBeInTheDocument();
});
});
Next Steps¶
Now that the test infrastructure is complete, you can:
- Write tests for critical components:
- API client (
src/lib/api.ts) - Auth context (
src/auth/AuthContext.tsx) - Login page (
src/pages/LoginPage.tsx) -
Patient management components
-
Run tests regularly:
- During development:
yarn unit-test(watch mode) - Before commits:
just unit-tests-frontend -
Check coverage:
yarn unit-test:coverage -
Follow the testing guide:
- See
frontend/src/test/README.mdfor examples - Look at
infrastructure.test.tsxfor patterns - Use semantic queries (getByRole, getByLabelText)
Files Modified¶
- ✅ Created:
frontend/vitest.config.ts - ✅ Created:
frontend/src/test/setup.ts - ✅ Created:
frontend/src/test/test-utils.tsx - ✅ Created:
frontend/src/test/infrastructure.test.tsx - ✅ Created:
frontend/src/test/README.md - ✅ Modified:
frontend/package.json(added coverage script)
Verification¶
All tests passing:
- ✅ 5 existing tests (useBreakPoint)
- ✅ 9 new infrastructure tests
- ✅ Total: 14 tests passing
The test infrastructure is now ready for comprehensive test coverage development.