mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 23:16:17 -05:00
test: act on review — the skeleton guard was reading the wrong layer
The "separates the skeleton from the panel" cases could not fail. A Skeleton
is three layers: the element paints nothing, ::before paints
--mantine-color-body (`--bg`) at z-index 10, and ::after paints the bar the
user actually sees (`--head` in light, `--border` in dark) at z-index 11, on
top. `paintedBackground` walked outward from the element and returned the
first paint, which is ::before -- so all four cases compared the page
background to the panel. Those differ by design in every theme, so the bars
could have collapsed into the panel entirely and every assertion stayed green.
My planted regression did not catch it because the plant was broader than the
claim: it forced all three layers to the panel colour, so the test went red
for a reason the fix did not depend on. The plant now sets only ::after, and
a second plant sets only ::before and must stay GREEN.
The layer order is now the caller's argument, since "the background" is
ambiguous once pseudo-elements are involved and guessing makes a test vacuous
rather than wrong.
Also from review:
The disc on a filled button was pinned to `--blue` at the call site, but WROL
mode disables that button and Mantine repaints it `--mantine-color-disabled`
-- a blue chip on a grey button, the original hole inverted. The surface now
comes from the cascade (`--button-bg`, and the disabled colour for any
variant), so the call site says nothing at all and cannot be wrong about a
state it does not control. Keying on `[data-variant="filled"]` alone matched
none of our buttons: Mantine omits the attribute when a call site names a
colour but no variant, which is how every filled button here is written.
The Checkbox behaviour test asserted only that a handler fired, against a box
held at `checked={false}` that could never change. It is now uncontrolled and
asserts the box is checked, plus a second test that the handler sees the new
state -- read inside the handler, because `currentTarget` is null by the time
a mock is inspected.
The empty-caption test counted every div in the container; it counts the
loader's siblings now. Two comments corrected: Pill emits no `--pill-radius`
at all and its own stylesheet falls back to `1000rem`, and the nav bar no
longer relies on the default surface.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
048ed6c8e2
commit
ab58019550
4 changed files with 113 additions and 30 deletions
|
|
@ -437,10 +437,9 @@ export function FileBrowser() {
|
|||
disabled={wrolModeEnabled}
|
||||
style={{paddingLeft: '1em', paddingRight: showLabels ? '1em' : '0.8em'}}
|
||||
>
|
||||
{/* On a filled button, so the corner disc must be the button's fill and not
|
||||
the page background, which would read as a hole punched in the button. */}
|
||||
<IconStack corner={<Icon name='add'/>} label='New folder'
|
||||
style={{'--icon-stack-bg': 'var(--blue)'}}>
|
||||
{/* The corner disc follows the button's fill on its own -- including when WROL
|
||||
mode disables it and Mantine repaints it grey. See ui.css. */}
|
||||
<IconStack corner={<Icon name='add'/>} label='New folder'>
|
||||
<Icon name='folder'/>
|
||||
</IconStack>
|
||||
{showLabels ? <> New Folder</> : null}
|
||||
|
|
|
|||
|
|
@ -621,12 +621,19 @@ describe('a toast is readable in every theme', () => {
|
|||
});
|
||||
|
||||
/*
|
||||
* The colour a box actually shows: its own background, or the first pseudo-element that
|
||||
* paints one. Mantine's Skeleton draws itself entirely from ::before and ::after, so
|
||||
* reading the root alone reports `rgba(0, 0, 0, 0)` and any test built on it is vacuous.
|
||||
* The colour a box actually shows, looking through the layers in the order given.
|
||||
*
|
||||
* The order is the caller's business, because "the background" is ambiguous once
|
||||
* pseudo-elements are involved and picking wrong makes a test vacuous rather than wrong.
|
||||
* A Skeleton is three layers: the element paints nothing, ::before paints
|
||||
* --mantine-color-body (our `--bg`) at z-index 10, and ::after paints the bar the user
|
||||
* actually sees -- --mantine-color-gray-3 in light, --mantine-color-dark-4 in dark, which
|
||||
* themes/mantine.ts maps to `--head` and `--border` -- at z-index 11, on top. Walk from
|
||||
* the element outward and you get `--bg` and compare the page background to the panel,
|
||||
* which differ by design in every theme, so the bars could vanish and nothing would fail.
|
||||
*/
|
||||
const paintedBackground = (el) => {
|
||||
for (const pseudo of [null, '::before', '::after']) {
|
||||
const paintedBackground = (el, order = [null, '::before', '::after']) => {
|
||||
for (const pseudo of order) {
|
||||
const colour = getComputedStyle(el, pseudo).backgroundColor;
|
||||
if (colour && !/^rgba\(.*,\s*0(\.0+)?\)$/.test(colour) && colour !== 'transparent') {
|
||||
return colour;
|
||||
|
|
@ -639,19 +646,18 @@ describe('a loading placeholder is visible on the surface it covers', () => {
|
|||
themeNames.forEach((theme) => {
|
||||
it(`separates the skeleton from the panel in ${theme}`, () => {
|
||||
/*
|
||||
* A Skeleton is Mantine's, and Mantine draws it from --mantine-color-gray-1 or
|
||||
* --mantine-color-dark-4. Those are remapped to our tokens in themes/mantine.ts,
|
||||
* which is exactly what makes this worth checking: `dark-4` is `--border` and
|
||||
* `gray-1` is `--bg`, and neither was chosen with a panel behind it in mind. If
|
||||
* the bars come out the same colour as the panel there is no placeholder at all,
|
||||
* only an empty box, and nothing in jsdom can see that.
|
||||
* `--head` and `--border` are what the bars come out as, and neither was chosen
|
||||
* with a panel behind it in mind. If they land on the panel's own colour there
|
||||
* is no placeholder at all, only an empty box, and jsdom cannot see that.
|
||||
*/
|
||||
cy.mountUI(<Panel><Placeholder lines={3}/></Panel>, {theme});
|
||||
|
||||
cy.get('.mantine-Skeleton-root').first().should(($line) => {
|
||||
const line = paintedBackground($line[0]);
|
||||
const panel = paintedBackground($line[0].closest('.wrolpi-panel'));
|
||||
// Topmost layer first for the bar; the panel paints on the element itself.
|
||||
const line = paintedBackground($line[0], ['::after', '::before', null]);
|
||||
const panel = paintedBackground($line[0].closest('.wrolpi-panel'), [null]);
|
||||
expect(line, 'the skeleton paints something').to.not.equal(null);
|
||||
expect(panel, 'the panel paints something').to.not.equal(null);
|
||||
expect(line, 'the skeleton is not the panel it sits on').to.not.equal(panel);
|
||||
});
|
||||
});
|
||||
|
|
@ -703,8 +709,10 @@ describe('an icon stack carries the surface it was placed on', () => {
|
|||
it(`matches a filled button in ${theme}`, () => {
|
||||
cy.mountUI(
|
||||
<Button color='blue'>
|
||||
<IconStack corner={<Icon name='add'/>} label='New folder'
|
||||
style={{'--icon-stack-bg': 'var(--blue)'}}>
|
||||
{/* No style: a filled button supplies the surface through the cascade,
|
||||
which is the point -- the call site cannot know it is about to be
|
||||
disabled and repainted. */}
|
||||
<IconStack corner={<Icon name='add'/>} label='New folder'>
|
||||
<Icon name='folder'/>
|
||||
</IconStack>
|
||||
</Button>,
|
||||
|
|
@ -719,6 +727,29 @@ describe('an icon stack carries the surface it was placed on', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('follows a filled button when it is disabled', () => {
|
||||
/*
|
||||
* The file browser's New Folder button is disabled in WROL mode, and Mantine swaps a
|
||||
* disabled button's fill for --mantine-color-disabled. A disc pinned to `--blue`
|
||||
* then becomes a blue chip on a grey surface -- the same defect as the original
|
||||
* hole, inverted. The disc has to follow the button, not the button's enabled fill.
|
||||
*/
|
||||
cy.mountUI(
|
||||
<Button color='blue' disabled>
|
||||
<IconStack corner={<Icon name='add'/>} label='New folder'>
|
||||
<Icon name='folder'/>
|
||||
</IconStack>
|
||||
</Button>,
|
||||
{theme: 'light'},
|
||||
);
|
||||
|
||||
cy.get('.wrolpi-icon-stack-corner').should(($corner) => {
|
||||
const disc = getComputedStyle($corner[0]).backgroundColor;
|
||||
const button = getComputedStyle($corner[0].closest('button')).backgroundColor;
|
||||
expect(disc, 'the disc is the disabled fill').to.equal(button);
|
||||
});
|
||||
});
|
||||
|
||||
it('takes the surface from an ancestor, which is how the nav bar sets it', () => {
|
||||
/*
|
||||
* The nav bar's colour is a user setting written inline on the <nav>, so the stack
|
||||
|
|
@ -742,8 +773,10 @@ describe('an icon stack carries the surface it was placed on', () => {
|
|||
});
|
||||
|
||||
it('defaults to the page background when nothing says otherwise', () => {
|
||||
// The other half of the claim: the default still has to be right for the nav bar,
|
||||
// which is where every other stack in the app lives.
|
||||
// The fallback, for a stack standing on the page rather than under something that
|
||||
// sets a surface. Both stacks in the app are covered by the two tests above -- the
|
||||
// nav bar by inheritance, the file browser by the button cascade -- so this one
|
||||
// guards the default that everything else is defined against.
|
||||
cy.mountUI(
|
||||
<IconStack corner={<Icon name='question'/>} label='WiFi status unknown'>
|
||||
<Icon name='wifi'/>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,30 @@
|
|||
padding: 1px;
|
||||
}
|
||||
|
||||
/*
|
||||
* A stack inside a button is the one case the call site should not have to describe,
|
||||
* because the surface changes underneath it: Mantine paints a filled button from
|
||||
* `--button-bg` but a disabled one from `--mantine-color-disabled`, whatever its variant.
|
||||
* The file browser's New Folder button is disabled in WROL mode, so a disc pinned to the
|
||||
* enabled fill would be a blue chip on a grey button -- the original hole, inverted.
|
||||
*
|
||||
* Only `filled` gets the first rule: an outline or subtle button sets `--button-bg` to
|
||||
* `transparent`, and there the surface behind the button is still the right answer.
|
||||
* `:not([data-variant])` is that same case -- Mantine omits the attribute entirely when a
|
||||
* call site names a colour but no variant, which is how every filled button here is
|
||||
* written, and keying on the attribute alone matched none of them. `--button-bg` itself
|
||||
* is absent when a button names neither, hence the fallback chain.
|
||||
*/
|
||||
.mantine-Button-root:not([data-variant]) .wrolpi-icon-stack-corner,
|
||||
.mantine-Button-root[data-variant="filled"] .wrolpi-icon-stack-corner {
|
||||
background: var(--button-bg, var(--icon-stack-bg, var(--bg)));
|
||||
}
|
||||
|
||||
.mantine-Button-root:disabled .wrolpi-icon-stack-corner,
|
||||
.mantine-Button-root[data-disabled] .wrolpi-icon-stack-corner {
|
||||
background: var(--mantine-color-disabled);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- Buttons */
|
||||
/*
|
||||
* Dashed borders mean "destructive or failed", and nothing else may use them.
|
||||
|
|
@ -364,9 +388,11 @@ html[data-theme="amber"] .wrolpi-searchbox-control:focus-within {
|
|||
/* ------------------------------------------------------------- Form fields */
|
||||
/*
|
||||
* A Pill is what MultiSelect renders for each chosen option, and it is the one place
|
||||
* Mantine does not honour the radius theme: `Pill` writes `--pill-radius: rem(1000)`
|
||||
* on the element itself, which no amount of zeroing `--mantine-radius-xl` can reach.
|
||||
* Everything else in the library has hard corners, so these do too.
|
||||
* Mantine does not honour the radius theme. MultiSelect leaves `radius` undefined, so
|
||||
* Pill emits no `--pill-radius` at all and its stylesheet falls back to
|
||||
* `border-radius: var(--pill-radius, 1000rem)` -- a literal in Mantine's own CSS, which
|
||||
* zeroing `--mantine-radius-xl` never touches. Defining the variable is what stops the
|
||||
* fallback from ever applying. Everything else in the library has hard corners.
|
||||
*/
|
||||
.mantine-Pill-root {
|
||||
--pill-radius: 0;
|
||||
|
|
|
|||
|
|
@ -886,14 +886,34 @@ describe('Toggle', () => {
|
|||
|
||||
describe('Checkbox', () => {
|
||||
it('reports and changes its state', async () => {
|
||||
const onChange = jest.fn();
|
||||
renderUI(<Checkbox label='Download comments' checked={false} onChange={onChange}/>);
|
||||
// Uncontrolled, so the box actually has to become checked. Held at `checked={false}`
|
||||
// it never can, and the test could only ever say "a handler fired".
|
||||
renderUI(<Checkbox label='Download comments' defaultChecked={false}/>);
|
||||
|
||||
const box = screen.getByRole('checkbox', {name: 'Download comments'});
|
||||
expect(box).not.toBeChecked();
|
||||
await userEvent.click(box);
|
||||
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
expect(box).toBeChecked();
|
||||
});
|
||||
|
||||
it('hands the caller the new state', async () => {
|
||||
/*
|
||||
* Read inside the handler, as every call site does: `currentTarget` is only set
|
||||
* while the event is being dispatched and is null by the time the mock is inspected.
|
||||
* The claim is that the handler sees the state the user just asked for -- fire it
|
||||
* with the old value and each call site writes the state back unchanged.
|
||||
*/
|
||||
let checkedWhenCalled;
|
||||
const onChange = jest.fn(event => {
|
||||
checkedWhenCalled = event.currentTarget.checked;
|
||||
});
|
||||
renderUI(<Checkbox label='Download comments' checked={false} onChange={onChange}/>);
|
||||
|
||||
await userEvent.click(screen.getByRole('checkbox', {name: 'Download comments'}));
|
||||
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
expect(checkedWhenCalled).toBe(true);
|
||||
});
|
||||
|
||||
it('points Mantine\'s own variables at tokens', () => {
|
||||
|
|
@ -959,9 +979,14 @@ describe('Loading', () => {
|
|||
it('renders no caption when there is nothing to say', () => {
|
||||
const {container} = renderUI(<Loading/>);
|
||||
|
||||
expect(container.querySelector('.mantine-Loader-root')).toBeInTheDocument();
|
||||
// An empty caption div would still take its line-height, moving the spinner off centre.
|
||||
expect(container.querySelectorAll('div').length).toBe(1);
|
||||
const loader = container.querySelector('.mantine-Loader-root');
|
||||
expect(loader).toBeInTheDocument();
|
||||
/*
|
||||
* An empty caption div would still take its line-height and push the spinner off
|
||||
* centre. Counted against the loader's own parent rather than the container: the
|
||||
* provider is free to add wrappers, and a global count would fail on that instead.
|
||||
*/
|
||||
expect(loader.parentElement.children).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue