test: bootstrap frontend Jest and strengthen view-only org inventory spec#293
Open
GitAddRemote wants to merge 1 commit into
Open
test: bootstrap frontend Jest and strengthen view-only org inventory spec#293GitAddRemote wants to merge 1 commit into
GitAddRemote wants to merge 1 commit into
Conversation
- Add jest.config.ts, tsconfig.jest.json, jest.setup.ts for frontend test infrastructure (ts-jest, jsdom, moduleNameMapper for import.meta.env) - Add src/__mocks__/config/api.ts to stub Vite-only VITE_API_URL construct - Add jest/ts-jest/jest-environment-jsdom devDependencies and test script - Fix Inventory.editor-mode.test.tsx: use wrapper fns so jest.resetAllMocks() doesn't wipe module-mock implementations; add orgExclusiveItem to view-only test and correct getOrgInventory call signature assertion (orgId is first arg, not inside params object)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces Jest-based unit testing infrastructure for the frontend (ts-jest + JSDOM) and strengthens the “view-only org inventory” regression test to ensure org inventory is actually fetched/rendered and that getOrgInventory is called with the correct orgId.
Changes:
- Add frontend Jest configuration (
jest.config.ts,jest.setup.ts,tsconfig.jest.json) and wire up apnpm --filter frontend testscript. - Add a Jest mock for the API URL module and update module mocking patterns to survive
jest.resetAllMocks(). - Strengthen
Inventory.editor-mode.test.tsxview-only org inventory test with a distinct org-only item and correctedgetOrgInventorycall assertion.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Adds Jest-related dependencies; currently reflects mixed Jest v29/v30 resolution. |
| frontend/package.json | Adds Jest/ts-jest and a test script for the frontend package. |
| frontend/jest.config.ts | Introduces ts-jest + jsdom Jest config and module mapping for frontend tests. |
| frontend/jest.setup.ts | Adds Testing Library setup and per-test cleanup hooks. |
| frontend/tsconfig.jest.json | Adds a Jest-specific TS config for CommonJS transpilation. |
| frontend/src/mocks/config/api.ts | Provides a test-time API URL export intended to avoid Vite import.meta.env usage. |
| frontend/src/pages/Inventory.editor-mode.test.tsx | Fixes mock reset behavior and strengthens the view-only org inventory test assertions. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
+19
| moduleNameMapper: { | ||
| '^@/(.*)$': '<rootDir>/$1', | ||
| 'config/api': '<rootDir>/__mocks__/config/api.ts', | ||
| }, |
Comment on lines
+40
to
+42
| "jest": "^29.7.0", | ||
| "jest-environment-jsdom": "^30.4.1", | ||
| "ts-jest": "^29.4.5", |
Comment on lines
225
to
+227
| ts-jest: | ||
| specifier: ^29.1.4 | ||
| version: 29.4.5(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@29.7.0)(jest@29.7.0(@types/node@20.19.25)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.19.25)(typescript@5.9.3)))(typescript@5.9.3) | ||
| version: 29.4.5(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@30.4.1)(babel-jest@29.7.0(@babel/core@7.28.5))(jest-util@30.4.1)(jest@29.7.0(@types/node@20.19.25)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.19.25)(typescript@5.9.3)))(typescript@5.9.3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
jest.config.ts,tsconfig.jest.json,jest.setup.ts, and animport.meta.envmock so ts-jest can run Vite-based source files in JSDOMInventory.editor-mode.test.tsx: wrap module mock methods in arrow fns sojest.resetAllMocks()doesn't wipe implementations; add a distinctorgExclusiveItemto the view-only test; correctgetOrgInventorycall-signature assertion (orgIdis the first positional argument, not a field inside the params object)Test plan
pnpm --filter frontend test— all Jest tests passhides the add button for view-only org users but still shows org inventory) passesCloses #167