mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 15:36:18 -05:00
ui: test the last four components, and put the last four in the gallery
Closes the tail of the library: `Loader`, `Loading`, `Placeholder` and `Checkbox` had no test of their own, and `IconStack`, `MediaFilterToggle`, `MultiSelect` and `NumberInput` were not in the gallery, which the project rule says every component must be. Putting them in the gallery is what found the rest of this. An IconStack's corner glyph paints a disc of the surface behind itself so the two sets of strokes do not cross, and that surface was hardcoded to the page background. It is right in exactly one of the three places a stack appears. The nav bar showed a white disc on the red bar, and the file browser's "New Folder" button showed one punched through the blue fill. It is now `--icon-stack-bg`, defaulting to the page: the file browser passes the button's fill, and the nav bar sets it on the <nav> beside the colour it already writes there, so it inherits -- the bar's colour is a user setting and cannot be named by a token. A MultiSelect's chosen options are Mantine Pills, and Pill is the one component that ignores the radius theme: it writes `--pill-radius: rem(1000)` onto the element, which zeroing `--mantine-radius-xl` cannot reach. They were lozenges on a page of square boxes. Twelve jest tests and sixteen browser tests. The browser half covers what jsdom cannot judge: that a Skeleton is a different colour from the panel it covers in all four themes (its greys are remapped to our tokens, and neither `--border` nor `--bg` was picked with a panel behind it), that the loader colour resolves through the token, and that the corner disc matches its surface. Every one was checked red against a planted regression first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ac7012c51d
commit
048ed6c8e2
7 changed files with 392 additions and 13 deletions
|
|
@ -13,10 +13,14 @@ import {
|
|||
Button,
|
||||
Card,
|
||||
CardGroup,
|
||||
Checkbox,
|
||||
Confirm,
|
||||
Header,
|
||||
Icon,
|
||||
IconStack,
|
||||
Loader,
|
||||
Loading,
|
||||
Placeholder,
|
||||
Pagination,
|
||||
SearchBox,
|
||||
TabBar,
|
||||
|
|
@ -880,6 +884,119 @@ describe('Toggle', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Checkbox', () => {
|
||||
it('reports and changes its state', async () => {
|
||||
const onChange = jest.fn();
|
||||
renderUI(<Checkbox label='Download comments' checked={false} onChange={onChange}/>);
|
||||
|
||||
const box = screen.getByRole('checkbox', {name: 'Download comments'});
|
||||
expect(box).not.toBeChecked();
|
||||
await userEvent.click(box);
|
||||
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('points Mantine\'s own variables at tokens', () => {
|
||||
/*
|
||||
* The only reason this wrapper exists. Mantine draws the box and the tick from
|
||||
* --checkbox-color and --checkbox-icon-color; left alone they are Mantine's blue and
|
||||
* a literal white, and a white tick is exactly the pixel night mode forbids.
|
||||
*/
|
||||
const {container} = renderUI(<Checkbox label='Download comments'/>);
|
||||
|
||||
const root = container.querySelector('.mantine-Checkbox-root');
|
||||
expect(root.style.getPropertyValue('--checkbox-color')).toBe('var(--blue)');
|
||||
expect(root.style.getPropertyValue('--checkbox-icon-color')).toBe('var(--btn-text)');
|
||||
});
|
||||
|
||||
it('keeps those variables when the caller brings a style of its own', () => {
|
||||
// `style={style}` instead of `style={{...checkboxStyles, ...style}}` would drop the
|
||||
// tokens for any call site that sets so much as a margin, and only in that one place.
|
||||
const {container} = renderUI(<Checkbox label='Download comments' style={{marginTop: 4}}/>);
|
||||
|
||||
const root = container.querySelector('.mantine-Checkbox-root');
|
||||
expect(root.style.marginTop).toBe('4px');
|
||||
expect(root.style.getPropertyValue('--checkbox-color')).toBe('var(--blue)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loader', () => {
|
||||
it('has an accessible name, because a spinner with no name is silence', () => {
|
||||
renderUI(<Loader/>);
|
||||
|
||||
expect(screen.getByLabelText('Loading')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('says what is being waited on when the caller knows', () => {
|
||||
renderUI(<Loader label='Fetching channels'/>);
|
||||
|
||||
expect(screen.getByLabelText('Fetching channels')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('takes its colour from a token rather than a fixed value', () => {
|
||||
// A hex here would be one colour in all four themes, and a blue one in night mode.
|
||||
const {container} = renderUI(<Loader/>);
|
||||
|
||||
expect(container.querySelector('.mantine-Loader-root').style.getPropertyValue('--loader-color'))
|
||||
.toBe('var(--blue)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loading', () => {
|
||||
it('names the spinner after the caption, so the wait is announced', () => {
|
||||
renderUI(<Loading>Loading backups…</Loading>);
|
||||
|
||||
expect(screen.getByLabelText('Loading backups…')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('falls back to a generic name when the caption is not text', () => {
|
||||
// aria-label takes a string; handing it a React element yields "[object Object]".
|
||||
renderUI(<Loading><strong>Loading backups…</strong></Loading>);
|
||||
|
||||
expect(screen.getByLabelText('Loading')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Placeholder', () => {
|
||||
const lineWidths = (container) =>
|
||||
[...container.querySelectorAll('.mantine-Skeleton-root')]
|
||||
.map(line => line.style.getPropertyValue('--skeleton-width'));
|
||||
|
||||
it('stands in for three lines by default', () => {
|
||||
const {container} = renderUI(<Placeholder/>);
|
||||
|
||||
expect(lineWidths(container)).toHaveLength(3);
|
||||
});
|
||||
|
||||
it('honours the number of lines asked for', () => {
|
||||
const {container} = renderUI(<Placeholder lines={5}/>);
|
||||
|
||||
expect(lineWidths(container)).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('ends ragged, so it reads as text rather than a block', () => {
|
||||
const {container} = renderUI(<Placeholder lines={4}/>);
|
||||
|
||||
expect(lineWidths(container)).toEqual(['100%', '100%', '100%', '60%']);
|
||||
});
|
||||
|
||||
it('leaves a single line short as well', () => {
|
||||
// lines={1} makes the first line the last one; an off-by-one here would render one
|
||||
// full-width bar, which is a block and not a line of text.
|
||||
const {container} = renderUI(<Placeholder lines={1}/>);
|
||||
|
||||
expect(lineWidths(container)).toEqual(['60%']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ThemePicker', () => {
|
||||
const renderPicker = (themeContext = {}) => {
|
||||
const setTheme = jest.fn();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue