mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 04:46:18 -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
affe5869f5
commit
b15a9408f1
4 changed files with 113 additions and 30 deletions
|
|
@ -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