Skip to content

PR 1: Add Vitest test infrastructure for frontend#409

Merged
payamnj merged 2 commits intomasterfrom
copilot/create-tests-frontend-jsx-files
May 5, 2026
Merged

PR 1: Add Vitest test infrastructure for frontend#409
payamnj merged 2 commits intomasterfrom
copilot/create-tests-frontend-jsx-files

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

No test runner or tooling existed for the React frontend. This PR bootstraps the full test infrastructure that all subsequent component test PRs depend on.

Changes

Dependencies

  • Added vitest, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, jsdom as devDependencies
  • Added test and test:watch scripts to package.json

vitest.config.js

  • jsdom environment, Vitest globals enabled, points to setup file

src/test/setup.js

  • Global mocks: fetch, localStorage, window.matchMedia, document.cookie, logo PNG asset imports (required by MUI + MenuBar)
  • Resets all mocks in beforeEach

src/test/test-utils.jsx

  • renderWithProviders(ui, options) — wraps any component with ThemeContextProvider + AppContext, with sensible defaults matching the production shape
  • useAppContext re-exported for use in test probes without triggering createRoot side-effects from render.jsx

src/test/smoke.test.jsx

  • 4 sanity tests confirming rendering, context access, localStorage mock, and fetch mock all work end-to-end

.github/workflows/pr-check.yml

  • Added a frontend-test job that runs on every PR using Node 20, installs dependencies with npm ci, and executes npm test (Vitest)
  • Scoped to contents: read permissions
// Example usage in component tests
import { renderWithProviders } from '../test/test-utils';

renderWithProviders(<MyComponent />, {
  appContext: { direction: 'rtl', isPlatformAdmin: true },
});

@payamnj
Copy link
Copy Markdown
Contributor

payamnj commented May 5, 2026

@copilot can you also add running these frontend tests in the .github/workflows/pr-check?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot can you also add running these frontend tests in the .github/workflows/pr-check?

Done in e133c74. Added a frontend-test job to .github/workflows/pr-check.yml that runs on every PR:

  • Sets up Node 20 with npm cache keyed to frontend/package-lock.json
  • Installs deps with npm ci
  • Runs npm test (Vitest)
  • Scoped to contents: read permissions

Copilot AI requested a review from payamnj May 5, 2026 11:43
Copilot finished work on behalf of payamnj May 5, 2026 11:43
@payamnj payamnj marked this pull request as ready for review May 5, 2026 11:44
@payamnj payamnj merged commit 956b0ad into master May 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants