mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 07:26:18 -05:00
ui: Statistic and StatisticGroup, and the four defects they had
These three exports had no test of their own. Statistic had already been
caught out once -- it relied on Semantic's `Statistic.Group` for its
spacing, so it broke silently when that was uninstalled -- and they are
on the Status, Dashboard, Apps, Docs, Videos, Archive and Channels pages.
Four defects, each with a test that goes red without the fix:
* StatisticGroup ruled between columns only, with a `border-right` on
every cell but the last. `auto-fit` wraps, so the seven statistics on
the Docs page became four rows on a phone with no rule between them,
and the cell ending each earlier row drew its border straight onto the
group's outer one, making that edge 2px on the right and 1px on the
left. The hairlines are now a 1px grid gap filled by an outline on
each cell, which rules both axes however the tracks fall.
Ruling the gaps with a border-coloured background behind the grid --
which is where this went first -- has the same reach but paints every
track no cell landed in: an odd count left the last slot a solid grey
block. An outline is drawn only where a cell is. Both of these are
guarded, because the second was introduced while fixing the first.
* A statistic that renders nothing left a padded cell and a stray
hairline mid-row. FanRPMStatistic returns null on a device with no fan
connector, which is most of them, so this was the Status page's normal
appearance. The group cannot render a child to find out, so the cell
is still emitted and `:empty` takes it out of the grid -- which is why
the cells carry no inline style for that rule to have to outrank.
* Statistic destructured five props and dropped the rest. LoadStatistic
and the four Status wrappers all end in `{...props}`, so anything
passed through a wrapper vanished with no error anywhere.
* VideosStatistics passed `style={{margin: '2em'}}` to every statistic,
Semantic-era spacing that the grid now provides. It beat the group's
own rule, being inline, and made that one page's statistics sit
differently from the six others.
CardGroup was the only component in the library with no class of its own,
which left nothing to assert against -- `container.firstChild` in jsdom
is Mantine's injected <style> element. It has one now, and takes
className/style/rest like its siblings.
The gallery grows a seventh statistic, so the group wraps at a normal
window width where the row hairlines can be seen, and a second group of
coloured readings as Status renders them.
Geometry, hairlines and per-theme token resolution are in ui-layout.cy.js
rather than jest: jsdom returns zeros from getBoundingClientRect and
never resolves a var(), so it cannot judge any of it.
This commit is contained in:
parent
9d24d67f59
commit
a2aa1352fb
6 changed files with 376 additions and 35 deletions
|
|
@ -151,12 +151,28 @@ export function ThemeSamplePage() {
|
|||
</Section>
|
||||
|
||||
<Section label='Statistics'>
|
||||
{/*
|
||||
* Seven, deliberately: enough to wrap on a narrow window, which is where the row
|
||||
* hairlines are worth looking at. The group rules both axes from --border, so the
|
||||
* grid holds together however the tracks fall.
|
||||
*/}
|
||||
<StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Statistic value='896' label='Archives'/>
|
||||
<Statistic value='12,904' label='Files'/>
|
||||
<Statistic value='87.4 GiB' label='Free space'/>
|
||||
<Statistic value='14' label='Zim files'/>
|
||||
<Statistic value='312' label='eBooks'/>
|
||||
<Statistic value={0} label='Downloading'/>
|
||||
</StatisticGroup>
|
||||
|
||||
{/* Status colours a reading that carries meaning. Check these in night, where
|
||||
there is no hue to spend and the value has to read by brightness. */}
|
||||
<StatisticGroup style={{marginTop: 14}}>
|
||||
<Statistic value='0.4' label='1 Min. Load'/>
|
||||
<Statistic value='2.6' label='5 Min. Load' color='orange'/>
|
||||
<Statistic value='4.1' label='15 Min. Load' color='red'/>
|
||||
<Statistic value='48' label='Temp C°'/>
|
||||
</StatisticGroup>
|
||||
</Section>
|
||||
|
||||
|
|
|
|||
|
|
@ -795,7 +795,7 @@ export function VideosStatistics() {
|
|||
<StatisticGroup>
|
||||
{names.map(
|
||||
({key, label}) =>
|
||||
<Statistic key={key} value={stats[key]} label={label} style={{margin: '2em'}}/>
|
||||
<Statistic key={key} value={stats[key]} label={label}/>
|
||||
)}
|
||||
</StatisticGroup>
|
||||
</Panel>
|
||||
|
|
|
|||
|
|
@ -76,16 +76,21 @@ export function Panel({danger, className, children, ...props}: PanelProps) {
|
|||
|
||||
// ---------------------------------------------------------------- Statistics
|
||||
|
||||
export interface StatisticProps {
|
||||
export interface StatisticProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'color'> {
|
||||
/** The number. Rendered as given, so `0` shows as a zero rather than nothing. */
|
||||
value: React.ReactNode;
|
||||
label: React.ReactNode;
|
||||
/** A token colour name, for a reading that carries meaning: load, temperature, IO wait. */
|
||||
color?: string;
|
||||
className?: string;
|
||||
style?: React.CSSProperties;
|
||||
}
|
||||
|
||||
export function Statistic({value, label, color, className, style}: StatisticProps) {
|
||||
return <div className={['wrolpi-statistic', className].filter(Boolean).join(' ')} style={style}>
|
||||
/**
|
||||
* One figure and its label. The rest of the props reach the outer element, because
|
||||
* `LoadStatistic` and the four Status wrappers all end in `{...props}` and used to have
|
||||
* everything past the named five silently dropped.
|
||||
*/
|
||||
export function Statistic({value, label, color, className, ...props}: StatisticProps) {
|
||||
return <div className={['wrolpi-statistic', className].filter(Boolean).join(' ')} {...props}>
|
||||
<div className='wrolpi-statistic-value' style={{color: color ? `var(--${color})` : undefined}}>
|
||||
{value}
|
||||
</div>
|
||||
|
|
@ -93,25 +98,16 @@ export function Statistic({value, label, color, className, style}: StatisticProp
|
|||
</div>
|
||||
}
|
||||
|
||||
/** A row of statistics separated by hairlines, sharing one outer border. */
|
||||
export function StatisticGroup({children}: {children: React.ReactNode}) {
|
||||
const items = React.Children.toArray(children);
|
||||
return <div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: `repeat(auto-fit, minmax(150px, 1fr))`,
|
||||
border: '1px solid var(--border)',
|
||||
}}>
|
||||
{items.map((child, index) => <div
|
||||
key={index}
|
||||
className='wrolpi-statistic-cell'
|
||||
style={{
|
||||
background: 'var(--panel)',
|
||||
padding: '14px 16px',
|
||||
borderRight: index === items.length - 1 ? undefined : '1px solid var(--border)',
|
||||
}}
|
||||
>
|
||||
{child}
|
||||
</div>)}
|
||||
/**
|
||||
* A row of statistics separated by hairlines, sharing one outer border. The cells carry
|
||||
* no inline style of their own so that `.wrolpi-statistic-cell:empty` can hide the ones
|
||||
* whose statistic rendered nothing — Status omits the fan reading on the devices, most of
|
||||
* them, with no fan connector.
|
||||
*/
|
||||
export function StatisticGroup({children, className, ...props}: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div className={['wrolpi-statistic-group', className].filter(Boolean).join(' ')} {...props}>
|
||||
{React.Children.toArray(children).map((child, index) =>
|
||||
<div key={index} className='wrolpi-statistic-cell'>{child}</div>)}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
|
@ -161,12 +157,26 @@ export function Card({media, title, meta, children, onClick, color, className}:
|
|||
</MCard>
|
||||
}
|
||||
|
||||
export function CardGroup({children, minWidth = 200}: {children: React.ReactNode; minWidth?: number}) {
|
||||
return <div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, 1fr))`,
|
||||
gap: 14,
|
||||
}}>
|
||||
export interface CardGroupProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
/**
|
||||
* The narrowest a card may be laid out. `auto-fill` rather than `auto-fit`, so a group
|
||||
* of two cards in a wide column keeps them card-sized instead of stretching each to half
|
||||
* the page.
|
||||
*/
|
||||
minWidth?: number;
|
||||
}
|
||||
|
||||
export function CardGroup({children, minWidth = 200, className, style, ...props}: CardGroupProps) {
|
||||
return <div
|
||||
className={['wrolpi-card-group', className].filter(Boolean).join(' ')}
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: `repeat(auto-fill, minmax(${minWidth}px, 1fr))`,
|
||||
gap: 14,
|
||||
...style,
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import {ActionInput, Button, PathInput, TextInput} from './index';
|
||||
import {ActionInput, Button, PathInput, Statistic, StatisticGroup, TextInput} from './index';
|
||||
import {themeNames} from '../../themes/names';
|
||||
|
||||
/*
|
||||
|
|
@ -133,6 +133,171 @@ describe('ActionInput', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('StatisticGroup rules every row it ends up with', () => {
|
||||
/*
|
||||
* The group wraps: `auto-fit` with a 150px minimum gives seven statistics one row on a
|
||||
* desktop and four on a phone, and how many rows there are is decided by the viewport at
|
||||
* paint time. Only a browser can say -- jsdom has no tracks, no rows and no widths -- so
|
||||
* the row-separator claims live here.
|
||||
*/
|
||||
|
||||
// Narrow enough that six statistics cannot fit on one row at a 150px minimum.
|
||||
const inNarrowColumn = (children) => <div style={{width: 340}}>{children}</div>;
|
||||
|
||||
const sixStatistics = <StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Statistic value='896' label='Archives'/>
|
||||
<Statistic value='12,904' label='Files'/>
|
||||
<Statistic value='87.4 GiB' label='Free space'/>
|
||||
<Statistic value='14' label='Zim files'/>
|
||||
<Statistic value='312' label='eBooks'/>
|
||||
</StatisticGroup>;
|
||||
|
||||
const rowTops = (cells) => [...new Set(
|
||||
[...cells].map((cell) => Math.round(cell.getBoundingClientRect().top))
|
||||
)].sort((a, b) => a - b);
|
||||
|
||||
it('wraps into rows at this width, so the rest of these tests mean something', () => {
|
||||
cy.mountUI(inNarrowColumn(sixStatistics));
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').should(($cells) =>
|
||||
expect(rowTops($cells).length, 'rows the group wrapped into').to.be.greaterThan(1));
|
||||
});
|
||||
|
||||
it('draws a hairline between wrapped rows', () => {
|
||||
/*
|
||||
* This is the defect: the old group put a `border-right` on every cell but the last,
|
||||
* which rules between columns and says nothing about rows. Wrapped rows sat flush
|
||||
* against each other, so the Docs page's seven statistics ran together into one block
|
||||
* on a phone. A row boundary must be a visible 1px of border colour.
|
||||
*/
|
||||
cy.mountUI(inNarrowColumn(sixStatistics));
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').should(($cells) => {
|
||||
const cells = [...$cells].map((cell) => cell.getBoundingClientRect());
|
||||
const tops = rowTops($cells);
|
||||
|
||||
for (let row = 1; row < tops.length; row++) {
|
||||
const previousRowBottom = Math.max(...cells
|
||||
.filter((rect) => Math.round(rect.top) === tops[row - 1])
|
||||
.map((rect) => rect.bottom));
|
||||
const separation = tops[row] - previousRowBottom;
|
||||
expect(separation, `hairline above row ${row + 1}`).to.be.closeTo(1, 0.6);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('draws a hairline between columns too', () => {
|
||||
cy.mountUI(inNarrowColumn(sixStatistics));
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').should(($cells) => {
|
||||
const cells = [...$cells].map((cell) => cell.getBoundingClientRect());
|
||||
const firstRowTop = rowTops($cells)[0];
|
||||
const firstRow = cells
|
||||
.filter((rect) => Math.round(rect.top) === firstRowTop)
|
||||
.sort((a, b) => a.left - b.left);
|
||||
|
||||
expect(firstRow.length, 'columns in the first row').to.be.greaterThan(1);
|
||||
for (let column = 1; column < firstRow.length; column++) {
|
||||
expect(firstRow[column].left - firstRow[column - 1].right, 'hairline between columns')
|
||||
.to.be.closeTo(1, 0.6);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('does not double the outer border where a row ends', () => {
|
||||
/*
|
||||
* The old code suppressed `border-right` on the last child only, so the cell ending
|
||||
* every earlier row -- there is one per wrap -- drew its own hairline directly onto the
|
||||
* group's outer border, giving a 2px edge on the right and a 1px edge on the left.
|
||||
* Now no cell has a border at all and the single outer one is the edge.
|
||||
*/
|
||||
cy.mountUI(inNarrowColumn(sixStatistics));
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').each(($cell) =>
|
||||
expect(getComputedStyle($cell[0]).borderRightWidth, 'cell draws no border of its own')
|
||||
.to.equal('0px'));
|
||||
cy.get('.wrolpi-statistic-group').should(($group) =>
|
||||
expect(getComputedStyle($group[0]).borderRightWidth, 'one outer hairline').to.equal('1px'));
|
||||
});
|
||||
|
||||
it('leaves no painted block in a track no statistic landed in', () => {
|
||||
/*
|
||||
* An odd count leaves the last row short: seven statistics in two columns fill the
|
||||
* eighth slot with nothing. Ruling the gaps with a border-coloured background behind
|
||||
* the grid -- the obvious way to do it -- painted that empty slot a solid block of
|
||||
* border grey, which read as a broken cell. The hairlines are outlines on the cells
|
||||
* instead, so a track with no cell in it is just surface.
|
||||
*/
|
||||
cy.mountUI(inNarrowColumn(<StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Statistic value='896' label='Archives'/>
|
||||
<Statistic value='12,904' label='Files'/>
|
||||
<Statistic value='87.4 GiB' label='Free space'/>
|
||||
<Statistic value='14' label='Zim files'/>
|
||||
<Statistic value='312' label='eBooks'/>
|
||||
<Statistic value={0} label='Downloading'/>
|
||||
</StatisticGroup>));
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').should(($cells) => {
|
||||
// An odd number of cells over an even number of columns, or this proves nothing.
|
||||
expect($cells.length % 2, 'a short last row').to.equal(1);
|
||||
});
|
||||
cy.get('.wrolpi-statistic-group').should(($group) => {
|
||||
const group = getComputedStyle($group[0]);
|
||||
expect(group.backgroundColor, 'the empty track shows surface, not hairline')
|
||||
.to.not.equal(group.borderRightColor);
|
||||
});
|
||||
});
|
||||
|
||||
it('hides the cell of a statistic that rendered nothing', () => {
|
||||
/*
|
||||
* Status omits the fan reading on a device with no fan connector -- most of them --
|
||||
* by returning null from FanRPMStatistic. The group still emits its cell, because it
|
||||
* cannot render a child to find out, so `:empty` has to take the cell out of the grid.
|
||||
* Left in, it was a blank padded panel and a stray hairline in the middle of the row.
|
||||
*/
|
||||
const NoFanFitted = () => null;
|
||||
cy.mountUI(<StatisticGroup>
|
||||
<Statistic value='0.4' label='1 Min. Load'/>
|
||||
<NoFanFitted/>
|
||||
<Statistic value='48' label='Temp C°'/>
|
||||
</StatisticGroup>);
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').should('have.length', 3);
|
||||
cy.get('.wrolpi-statistic-cell').filter(':empty').should('not.be.visible');
|
||||
cy.get('.wrolpi-statistic-cell').filter(':empty').should(($cell) =>
|
||||
expect($cell[0].getBoundingClientRect().width, 'the empty cell takes no track').to.equal(0));
|
||||
});
|
||||
|
||||
themeNames.forEach((theme) => {
|
||||
it(`takes its hairline and surface from ${theme}'s tokens`, () => {
|
||||
// Drawn from --border and --panel rather than a fixed grey, which is what lets the
|
||||
// group survive night mode without putting a non-red pixel on the screen.
|
||||
cy.mountUI(inNarrowColumn(sixStatistics), {theme});
|
||||
|
||||
cy.get('.wrolpi-statistic-group').then(($group) => {
|
||||
const group = getComputedStyle($group[0]);
|
||||
|
||||
cy.get('.wrolpi-statistic-cell').first().should(($cell) => {
|
||||
const cell = getComputedStyle($cell[0]);
|
||||
|
||||
// The inner hairlines are the cells' outlines and the outer one is the
|
||||
// group's border; they meet at every edge, so a theme that resolved them
|
||||
// to different values would show a two-tone frame.
|
||||
expect(cell.outlineColor, 'inner hairline matches the outer')
|
||||
.to.equal(group.borderRightColor);
|
||||
// And the hairline has to be visible against the surface it sits on --
|
||||
// both resolved from tokens, so a theme that forgot one shows up here.
|
||||
expect(cell.outlineColor, 'hairline is not the surface colour')
|
||||
.to.not.equal(cell.backgroundColor);
|
||||
expect(cell.backgroundColor, 'cell has a surface').to.not.equal('rgba(0, 0, 0, 0)');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('theme tokens actually resolve', () => {
|
||||
themeNames.forEach((theme) => {
|
||||
it(`paints text and borders from ${theme}'s table`, () => {
|
||||
|
|
|
|||
|
|
@ -852,9 +852,10 @@ html[data-theme="amber"] .wrolpi-card-tag {
|
|||
/* ------------------------------------------------------------- Statistics */
|
||||
/*
|
||||
* A statistic carries its own spacing rather than relying on a parent to supply
|
||||
* it: unmigrated pages still drop these inside Semantic's `Statistic.Group`,
|
||||
* whose CSS only spaces elements carrying Semantic's own classes, and without
|
||||
* this the labels run together into one unreadable line.
|
||||
* it, so that one dropped on a page by itself still sits clear of its
|
||||
* neighbours. Semantic's `Statistic.Group` only spaced elements carrying
|
||||
* Semantic's own classes, so without this the labels ran together into one
|
||||
* unreadable line.
|
||||
*/
|
||||
|
||||
.wrolpi-statistic {
|
||||
|
|
@ -863,6 +864,44 @@ html[data-theme="amber"] .wrolpi-card-tag {
|
|||
margin: 0 26px 10px 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* The group's hairlines are an outline on each cell, drawn into a 1px grid gap.
|
||||
*
|
||||
* Not a border per cell: a border can only separate the siblings the author can
|
||||
* count -- the old code suppressed `border-right` on the last child -- and
|
||||
* `auto-fit` wraps, so the seven statistics on the Docs page became four rows on
|
||||
* a phone with no rule between them, while the cell ending each earlier row drew
|
||||
* its border straight onto the outer one.
|
||||
*
|
||||
* Nor a border-coloured background behind the gaps, which rules both axes but
|
||||
* also paints every track no cell landed in: seven statistics in two columns
|
||||
* left the eighth slot a solid grey block. An outline is drawn outside the
|
||||
* cell, so it appears only where a cell actually is. Adjacent outlines meet in
|
||||
* the same 1px of gap, and the outer ones land on the group's own border, all in
|
||||
* the same colour, so every rule reads as a single hairline.
|
||||
*/
|
||||
.wrolpi-statistic-group {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 1px;
|
||||
background-color: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.wrolpi-statistic-cell {
|
||||
background-color: var(--panel);
|
||||
outline: 1px solid var(--border);
|
||||
padding: 14px 16px;
|
||||
}
|
||||
|
||||
/*
|
||||
* A statistic that renders nothing -- Status omits the fan reading on a device
|
||||
* with no fan connector -- must not leave a padded cell and a hairline behind.
|
||||
*/
|
||||
.wrolpi-statistic-cell:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Inside our own group the grid does the spacing, so the intrinsic margin goes. */
|
||||
.wrolpi-statistic-cell .wrolpi-statistic {
|
||||
display: block;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
ActionInput,
|
||||
Button,
|
||||
Card,
|
||||
CardGroup,
|
||||
Confirm,
|
||||
Header,
|
||||
Icon,
|
||||
|
|
@ -28,6 +29,8 @@ import {
|
|||
PathInput,
|
||||
Progress,
|
||||
resolveIconName,
|
||||
Statistic,
|
||||
StatisticGroup,
|
||||
Status,
|
||||
Table,
|
||||
ThemePicker,
|
||||
|
|
@ -645,6 +648,114 @@ describe('Card', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('CardGroup', () => {
|
||||
it('renders every card it is given', () => {
|
||||
renderUI(<CardGroup>
|
||||
<Card title='One'/>
|
||||
<Card title='Two'/>
|
||||
<Card title='Three'/>
|
||||
</CardGroup>);
|
||||
|
||||
expect(screen.getByText('One')).toBeInTheDocument();
|
||||
expect(screen.getByText('Two')).toBeInTheDocument();
|
||||
expect(screen.getByText('Three')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lays cards out on a track no narrower than minWidth', () => {
|
||||
// The default suits file results; a group of wide cards raises it. If the value were
|
||||
// dropped the grid would fall back to one column, which is how a card wall becomes a
|
||||
// list on a desktop.
|
||||
const {container} = renderUI(<CardGroup minWidth={320}><Card title='One'/></CardGroup>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-card-group'))
|
||||
.toHaveStyle({gridTemplateColumns: 'repeat(auto-fill, minmax(320px, 1fr))'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Statistic', () => {
|
||||
it('shows the value and its label', () => {
|
||||
renderUI(<Statistic value='87.4 GiB' label='Free space'/>);
|
||||
|
||||
expect(screen.getByText('87.4 GiB')).toBeInTheDocument();
|
||||
expect(screen.getByText('Free space')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('colours the value from a token, not a hex', () => {
|
||||
// Status turns load, temperature and IO wait red or orange. A hex here would not
|
||||
// remap in night mode, putting a green or orange pixel on a red-only screen.
|
||||
const {container} = renderUI(<Statistic value='3.9' label='1 Min. Load' color='red'/>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-statistic-value')).toHaveStyle({color: 'var(--red)'});
|
||||
});
|
||||
|
||||
it('leaves the value in body text when no colour is given', () => {
|
||||
const {container} = renderUI(<Statistic value='0.4' label='1 Min. Load'/>);
|
||||
|
||||
expect(container.querySelector('.wrolpi-statistic-value').style.color).toBe('');
|
||||
});
|
||||
|
||||
it('renders a zero rather than nothing', () => {
|
||||
// `pending_downloads` is 0 on an idle WROLPi, and a falsy check would blank the cell.
|
||||
renderUI(<Statistic value={0} label='Downloading'/>);
|
||||
|
||||
expect(screen.getByText('0')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('forwards the props its wrappers spread onto it', () => {
|
||||
// `LoadStatistic` and the four Status wrappers (`CPUTemperatureStatistic`,
|
||||
// `FanRPMStatistic`, `IOWaitStatistic`, `UptimeStatistic`) all end in `{...props}`.
|
||||
// Statistic destructured a fixed five and dropped the rest on the floor, so anything
|
||||
// a caller passed through a wrapper vanished with no error anywhere.
|
||||
renderUI(<Statistic value='42' label='Fan RPM' title='Reported by the fan connector'/>);
|
||||
|
||||
expect(screen.getByTitle('Reported by the fan connector')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('StatisticGroup', () => {
|
||||
it('gives each statistic its own cell', () => {
|
||||
const {container} = renderUI(<StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Statistic value='896' label='Archives'/>
|
||||
</StatisticGroup>);
|
||||
|
||||
expect(container.querySelectorAll('.wrolpi-statistic-cell')).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('leaves a cell empty when its statistic renders nothing', () => {
|
||||
// `FanRPMStatistic` returns null on a device with no fan connector, which is most of
|
||||
// them. The group cannot know that in advance, so the cell is still emitted and
|
||||
// `.wrolpi-statistic-cell:empty` hides it -- which only works while the cell has no
|
||||
// padding or background of its own inline for that rule to have to outrank.
|
||||
const Nothing = () => null;
|
||||
const {container} = renderUI(<StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Nothing/>
|
||||
</StatisticGroup>);
|
||||
|
||||
const cells = container.querySelectorAll('.wrolpi-statistic-cell');
|
||||
expect(cells[1].childNodes).toHaveLength(0);
|
||||
expect(cells[1].getAttribute('style')).toBeNull();
|
||||
});
|
||||
|
||||
it('draws its hairlines with the grid, not a border per cell', () => {
|
||||
// A per-cell border can only separate siblings the author can count -- the old code
|
||||
// suppressed `borderRight` on the last child -- and `auto-fit` wraps. Seven
|
||||
// statistics on a phone became four rows with no rule between them, while the cell
|
||||
// ending each earlier row drew its border straight onto the outer one. A 1px gap
|
||||
// over a border-coloured background rules both axes however the tracks fall.
|
||||
const {container} = renderUI(<StatisticGroup>
|
||||
<Statistic value='1,432' label='Videos'/>
|
||||
<Statistic value='896' label='Archives'/>
|
||||
</StatisticGroup>);
|
||||
|
||||
for (const cell of container.querySelectorAll('.wrolpi-statistic-cell')) {
|
||||
expect(cell.style.borderRight).toBe('');
|
||||
}
|
||||
expect(container.querySelector('.wrolpi-statistic-group')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Panel', () => {
|
||||
it('marks danger zones', () => {
|
||||
const {container} = renderUI(<Panel danger>Destructive actions</Panel>);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue