mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 09:26:17 -05:00
ui: a browser layer for the library, and the .media reset that never applied
The PathInput overlap could not have been caught by jest -- jsdom computes no layout -- so the only guard was a grep for one spelling of one mistake. This adds the layer that can actually see it, and it found a real bug immediately. ui-layout.cy.js mounts library components in a real browser through a new cy.mountUI(), which supplies Mantine's provider and a stamped data-theme and nothing else. That spartan setup is the point: these components read no ambient state, so a spec can assert what jsdom cannot compute -- real geometry, resolved custom properties, applied filters -- across all four themes. It reproduces the leftSectionWidth='auto' overlap on purpose and asserts it still overlaps, because a geometry check that has never gone red is indistinguishable from one that cannot fail. The bug it found: the rule resetting `filter` on leaf media inside a `.media` wrapper scored (0,2,2) against the (0,3,1) rule it was correcting, so it lost every time and never applied to anything. Every image inside a filtered wrapper has been through the luminance matrix twice since that rule landed -- markedly darker than its surroundings, which is exactly what it was written to prevent. tokens.test.js asserted only that the rule's text was present, and so stayed green throughout; it now compares the two selectors' specificity, which is computable without a browser and goes red on the old selector. Three guards in ui.test.js keep the library mock-free by construction rather than by habit: no jest.mock in its own tests, no fetch in any library file, and no useContext outside the theme controls, whose job is to read the theme. All three were verified red against planted violations. 959 jest tests, 14 new browser tests, clean cache-busted build. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c534cbfe23
commit
c100ffb378
5 changed files with 338 additions and 7 deletions
|
|
@ -366,7 +366,10 @@ describe('no input reserves space for a section it cannot measure', () => {
|
|||
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) walk(full);
|
||||
else if (/\.(js|jsx|tsx)$/.test(entry.name) && !/\.test\./.test(entry.name)) {
|
||||
// Specs are exempt: ui-layout.cy.js reproduces this exact mistake on
|
||||
// purpose, to prove its overlap check can still detect it.
|
||||
else if (/\.(js|jsx|tsx)$/.test(entry.name)
|
||||
&& !/\.test\.|\.cy\./.test(entry.name)) {
|
||||
// Comments are stripped first: the component that replaced this
|
||||
// pattern documents it by name, and prose about a mistake is not the
|
||||
// mistake.
|
||||
|
|
@ -386,6 +389,56 @@ describe('no input reserves space for a section it cannot measure', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('the library stays mockable-free', () => {
|
||||
/*
|
||||
* The whole reason these 80-odd tests need no setup is that a library component takes
|
||||
* props and reaches for nothing else -- no module-level fetch, no API helper, no
|
||||
* ambient state it has to be lied to about. Pages are the opposite: DomainEditPage
|
||||
* needs seven jest.mock calls before it will render at all, which is precisely why the
|
||||
* inputs on the Settings page had no test when they broke.
|
||||
*
|
||||
* That property is worth asserting rather than hoping for. The day a library
|
||||
* component grows a fetch, the mock somebody has to add to keep this file passing
|
||||
* trips the first check, and the import trips the second.
|
||||
*/
|
||||
|
||||
const libraryFiles = () => fs.readdirSync(__dirname)
|
||||
.filter(name => /\.(ts|tsx)$/.test(name) && !/\.test\./.test(name))
|
||||
.map(name => [name, fs.readFileSync(path.join(__dirname, name), 'utf8')]);
|
||||
|
||||
it('needs no module mocked to render any of it', () => {
|
||||
const source = fs.readFileSync(path.join(__dirname, 'ui.test.js'), 'utf8')
|
||||
.replace(/\/\*[\s\S]*?\*\//g, '')
|
||||
.replace(/^\s*\/\/.*$/gm, '');
|
||||
|
||||
expect(source).not.toMatch(/jest\.mock\s*\(/);
|
||||
});
|
||||
|
||||
it('asks the network for nothing', () => {
|
||||
const offenders = libraryFiles()
|
||||
.filter(([, source]) => /\bfetch\s*\(|\bapiCall\b|\baxios\b/
|
||||
.test(source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^\s*\/\/.*$/gm, '')))
|
||||
.map(([name]) => name);
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
|
||||
it('reads ambient state only in the theme controls', () => {
|
||||
/*
|
||||
* ThemePicker and MediaFilterToggle are the deliberate exception -- a control whose
|
||||
* entire job is to show and change the current theme has to know it. Their tests
|
||||
* pass a real ThemeContext.Provider holding plain values, which is supplying data,
|
||||
* not mocking a module. Everything else takes props.
|
||||
*/
|
||||
const offenders = libraryFiles()
|
||||
.filter(([name]) => name !== 'ThemePicker.tsx')
|
||||
.filter(([, source]) => /useContext\s*\(/.test(source))
|
||||
.map(([name]) => name);
|
||||
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ActionInput', () => {
|
||||
it('joins the input and its action into one control', () => {
|
||||
const {container} = renderUI(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue