test: the theme drives the colour scheme, and mockModule takes the module

Both of Greptile's findings on #591 were real, and the first was a plain miss:
mockModule shipped with no caller, so its documented usage had never once been
executed and could not have worked.  It called jest.requireActual on a path
passed in by the spec, which resolves relative to test-utils.js rather than to
the caller -- for any spec in a subdirectory the documented
'../hooks/customHooks' pointed outside src altogether.  It now takes the module
the spec has already resolved, and throws on a string rather than quietly
resolving to the wrong one, which was the original failure.

It also has a caller now.  FileBrowser.test.js listed six hooks in a hand-written
factory and returned only those, so every other export of customHooks was
undefined for anything it rendered -- the exact landmine the helper exists to
remove.

The second: `inverted` drove Mantine's colour scheme on its own, so asking for
night or amber through the new theme option produced a tree that reported a dark
theme while Mantine rendered its light one.  Production cannot reach that
combination, and a harness that invents states the app never has is worse than
one that is merely incomplete -- what a test proves about such a tree is true of
nothing.  The scheme is now derived from the theme name via isDarkTheme, and
data-theme is stamped on <html>, without which a component test cannot exercise
any token table or the night-mode treatment at all.  isDark remains overridable
so a spec can still make the two disagree deliberately.

test-utils.test.js covers the harness itself, which had none.  Eight of its
twelve assertions were red against the code above.

986 jest, 46 e2e, clean cache-busted build, tsc clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-30 16:39:30 -06:00
parent 17d658fc0b
commit 40a3886eaf
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 156 additions and 21 deletions

View file

@ -28,14 +28,23 @@ const mockUseUploadFile = {
inProgress: false,
};
jest.mock('../hooks/customHooks', () => ({
useBrowseFiles: jest.fn(),
useMediaDirectory: jest.fn(() => '/media/wrolpi'),
useWROLMode: jest.fn(() => false),
useStatusFlag: jest.fn(() => false),
useUploadFile: () => mockUseUploadFile,
useElementWidth: jest.fn(() => [() => {}, 0]),
}));
/*
* Every other export of customHooks used to be dropped here -- the factory listed six hooks and
* returned only those, so the rest of the module was undefined for anything this spec rendered.
* mockModule spreads the real module first, so the next hook a component reaches for still
* exists.
*/
jest.mock('../hooks/customHooks', () => require('../test-utils').mockModule(
jest.requireActual('../hooks/customHooks'),
{
useBrowseFiles: jest.fn(),
useMediaDirectory: jest.fn(() => '/media/wrolpi'),
useWROLMode: jest.fn(() => false),
useStatusFlag: jest.fn(() => false),
useUploadFile: () => mockUseUploadFile,
useElementWidth: jest.fn(() => [() => {}, 0]),
},
));
// Mock react-dropzone
jest.mock('react-dropzone', () => ({