test(ui): consolidate console test infrastructure - #6887
Merged
Conversation
Merge `src/test/` and `src/test-utils/` into a single `src/tests/` directory and delete the unused `createAxiosError` helper. `src/__mocks__/env.ts` stays in place because Vitest's manual mock resolution requires the `__mocks__/` directory to be a sibling of the module it replaces.
The hook is a jsdom workaround needed by every dialog/drawer test. A global `vi.mock` in `setup.ts` paired with `hooks/__mocks__/useFocusTrap.ts` replaces 12 identical inline mocks. The two files that test the real hook (`useFocusTrap.test`, `Drawer.test`) opt out with `vi.unmock`.
Promote the Drawer mock from `admin/users/__tests__/mocks.tsx` to
`src/tests/mocks.tsx` and replace 9 inline copies. The shared mock
renders `role="dialog"` with `aria-label={title}`, which required
tightening two `/private key/i` label queries in the vault
`KeyDrawer` tests to `^private key$` so they don't collide with
the drawer title.
Add `MockConfirmDialog` to `src/tests/mocks.tsx` and replace 8 identical inline ConfirmDialog mocks.
Add `MockCopyButton` to `src/tests/mocks.tsx` and replace 10 inline CopyButton mocks.
Add `MockBaseDialog` to `src/tests/mocks.tsx` and replace 5 inline BaseDialog mocks.
`setup.ts` already calls `afterEach(cleanup)` and stubs `HTMLDialogElement.prototype.showModal`/`.close` globally, so the per-file copies were redundant.
|
Claude finished @luizhf42's task in 2m 3s —— View job Code Review CompleteReviewed 81 files across code quality, security, testing, language patterns, and architecture — no new issues found. The code looks good as-is. I verified the higher-risk areas of this refactor directly:
If you push additional changes and want a new review, tag |
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.
What
Unified scattered test utilities (
src/test/,src/test-utils/,src/__mocks__/) into a singlesrc/tests/directory, replaced ~44 inline component mocks with 4 shared mocks + 1 auto-mock, and removed per-fileafterEach(cleanup)andHTMLDialogElementstubs thatsetup.tsalready provides globally.Why
Test infrastructure was duplicated across three directories and dozens of files. The same
Drawer,ConfirmDialog,CopyButton, andBaseDialogmocks were copy-pasted into every consumer, drifting slightly between copies.afterEach(cleanup)appeared in 38 files despite being in the global setup. This made adding new tests slower and existing tests harder to maintain.Changes
src/tests/: new canonical home for test utilities — movedsetup.ts,decodeB64url.ts,renderHookWithRouter.tsx, and their test from the old scattered locations. Deletedsrc/test/createAxiosError.ts(zero consumers).src/tests/mocks.tsx: single source forMockDrawer,MockConfirmDialog,MockCopyButton, andMockBaseDialog— minimal DOM structure exposingrole="dialog", ARIA attributes, and interactive elements that consumer tests query against.src/hooks/__mocks__/useFocusTrap.ts: Vitest auto-mock (sibling__mocks__/convention), activated globally viavi.mock("@/hooks/useFocusTrap")insetup.ts. Test files for the real hook andDraweropt out withvi.unmock().setup.ts: added globaluseFocusTrapmock alongside the existing@/envmock.afterEach(cleanup)(38 files),HTMLDialogElement.prototype.showModal/.closestubs (2 files), and unused imports left behind.useDeviceChooser.test.ts: fixed../../client/→@/client/import (pre-existing convention violation caught during this cleanup).Testing
All 211 test files (3024 tests) pass. Key areas to verify: files that
vi.unmock("@/hooks/useFocusTrap")(useFocusTrap.test.tsx,Drawer.test.tsx) — these test the real implementation and must not pick up the global mock.