mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
test: act on review — a test that could not pass with Reduce Motion on
The indeterminate test read the band's position out of a running animation and asserted it had left the box. Two problems, and the second is the serious one: it samples a moving target, and under `prefers-reduced-motion` the slide is replaced by `width: 100%` with no negative margin, so the band never leaves the box and the assertion is permanently false. Anyone with Reduce Motion turned on -- or a CI host with it set -- gets a hard failure on a correct build. Reproduced it rather than taking it on faith: forcing the reduced-motion branch for the whole run fails the old form and passes the new one. The band is pinned now, to where the animation's first keyframe puts it, and the assertion is on the clip plus that escape. Deterministic, and true on any machine. Added the other branch too: with motion suppressed the bar fills instead of sliding, and a band that never moves must never leave the box. `text-overflow: ellipsis` on the label. `nowrap` alone stopped it wrapping and being bisected by the clip, but left a hard mid-glyph cut, and the call sites that feed this are exactly the ones with long strings -- Upload.js and FileBrowser.js label with a filename, Files.js with the error string. The one-line test was close to circular: with `nowrap` applied, one line box is almost a restatement of the rule. It now also asserts the computed `nowrap` and `ellipsis`, and that the line is genuinely WIDER than the space it has -- without that, a label that simply fits would satisfy it. Dropped a dead ternary from the air-around-label test; it built a rect nothing used and made it look as though the measurement came from somewhere it did not. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e57545add3
commit
1dc75896a9
2 changed files with 67 additions and 16 deletions
|
|
@ -521,17 +521,14 @@ describe('a progress bar has room for the label inside it', () => {
|
|||
|
||||
cy.get('.wrolpi-progress').should(($bar) => {
|
||||
const box = $bar[0].getBoundingClientRect();
|
||||
const text = $bar[0].querySelector('.wrolpi-progress-text')
|
||||
.firstChild.getBoundingClientRect
|
||||
? $bar[0].querySelector('.wrolpi-progress-text').getBoundingClientRect()
|
||||
: null;
|
||||
expect(box.height, 'bar height').to.be.at.least(20);
|
||||
|
||||
// The line box, measured from the text node itself rather than its stretched
|
||||
// flex container, which is inset:0 and therefore always the bar's height.
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents($bar[0].querySelector('.wrolpi-progress-text'));
|
||||
const line = range.getBoundingClientRect();
|
||||
expect(box.height - line.height, 'air around the label').to.be.at.least(4);
|
||||
expect(box.height - range.getBoundingClientRect().height, 'air around the label')
|
||||
.to.be.at.least(4);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -551,10 +548,21 @@ describe('a progress bar has room for the label inside it', () => {
|
|||
);
|
||||
|
||||
cy.get('.wrolpi-progress-text').should(($text) => {
|
||||
const style = getComputedStyle($text[0]);
|
||||
expect(style.whiteSpace, 'label does not wrap').to.equal('nowrap');
|
||||
expect(style.textOverflow, 'and is cut with an ellipsis, not mid-glyph')
|
||||
.to.equal('ellipsis');
|
||||
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents($text[0]);
|
||||
const lines = range.getClientRects().length;
|
||||
expect(lines, 'the label occupies one line box').to.equal(1);
|
||||
expect(range.getClientRects().length, 'one line box').to.equal(1);
|
||||
/*
|
||||
* And that one line is genuinely wider than the space it has -- otherwise the
|
||||
* test proves nothing, since a label that fits occupies one line either way.
|
||||
* This is the case that used to wrap and get bisected by the clip.
|
||||
*/
|
||||
expect(range.getBoundingClientRect().width, 'the label really is too long')
|
||||
.to.be.greaterThan($text[0].getBoundingClientRect().width);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -619,11 +627,15 @@ describe('a progress bar has room for the label inside it', () => {
|
|||
|
||||
it('keeps the indeterminate band inside the bar', () => {
|
||||
/*
|
||||
* The band slides on `margin-left`, from -35% to 100%. Those are its real layout
|
||||
* positions -- it genuinely does extend past both edges, and `getBoundingClientRect`
|
||||
* reports that whether or not it is visible. So the assertion is on the clip, plus
|
||||
* the fact that the band escapes without one: together they show the clip is doing
|
||||
* work rather than being decoration.
|
||||
* The band slides on `margin-left` from -35% to 100%, so it genuinely does extend
|
||||
* past both edges and `getBoundingClientRect` reports that whether or not it is
|
||||
* painted. The clip is what keeps it out of sight.
|
||||
*
|
||||
* The band is PINNED here rather than sampled mid-animation. Reading a running
|
||||
* animation made this both flaky and, worse, permanently false for anyone with
|
||||
* Reduce Motion turned on: `prefers-reduced-motion` replaces the slide with
|
||||
* `width: 100%` and no negative margin, so the band never leaves the box and an
|
||||
* assertion that it does could not pass on that machine at all.
|
||||
*/
|
||||
cy.mountUI(bar({indeterminate: true, label: 'Uploading…'}), {theme: 'light'});
|
||||
|
||||
|
|
@ -631,10 +643,42 @@ describe('a progress bar has room for the label inside it', () => {
|
|||
expect(getComputedStyle($bar[0]).overflow, 'the bar clips its contents')
|
||||
.to.equal('hidden');
|
||||
|
||||
const fill = $bar[0].querySelector('.wrolpi-progress-fill');
|
||||
// Where the animation's first keyframe puts it, held still.
|
||||
fill.style.animation = 'none';
|
||||
fill.style.width = '35%';
|
||||
fill.style.marginLeft = '-35%';
|
||||
|
||||
const box = $bar[0].getBoundingClientRect();
|
||||
const band = fill.getBoundingClientRect();
|
||||
expect(band.left, 'the band does leave the box, so the clip is load-bearing')
|
||||
.to.be.lessThan(box.left - 1);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not move the band at all when motion is suppressed', () => {
|
||||
/*
|
||||
* The other branch, and the reason the test above pins rather than samples: with
|
||||
* Reduce Motion the bar fills instead of sliding, because motion was the only signal
|
||||
* it had. A band that never moves must also never leave the box.
|
||||
*/
|
||||
cy.mountUI(bar({indeterminate: true}), {theme: 'light'});
|
||||
cy.get('.wrolpi-progress-fill').should('exist');
|
||||
|
||||
cy.document().then((doc) => {
|
||||
const probe = doc.createElement('style');
|
||||
probe.textContent = `
|
||||
.wrolpi-progress-indeterminate .wrolpi-progress-fill {
|
||||
animation: none; width: 100%; opacity: 0.5;
|
||||
}`;
|
||||
doc.head.appendChild(probe);
|
||||
});
|
||||
|
||||
cy.get('.wrolpi-progress-indeterminate').should(($bar) => {
|
||||
const box = $bar[0].getBoundingClientRect();
|
||||
const band = $bar[0].querySelector('.wrolpi-progress-fill').getBoundingClientRect();
|
||||
expect(band.left < box.left - 1 || band.right > box.right + 1,
|
||||
'the band does leave the box, so the clip is load-bearing').to.equal(true);
|
||||
expect(band.left, 'band starts at the bar').to.be.closeTo(box.left, 2);
|
||||
expect(band.right, 'band ends at the bar').to.be.closeTo(box.right, 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1057,10 +1057,17 @@ html .mantine-Notification-closeButton:hover {
|
|||
font-weight: 700;
|
||||
color: var(--text);
|
||||
font-variant-numeric: tabular-nums;
|
||||
/* A long label must not push the bar wider than the column it was given. */
|
||||
/*
|
||||
* A long label is a real case, not a hypothetical: uploads label with a filename
|
||||
* (Upload.js, FileBrowser.js) and a failed refresh labels with the error string.
|
||||
* Without `nowrap` it wraps to a second line inside a 22px bar and the clip bisects
|
||||
* it; with a hard clip and no ellipsis, `Complete: very-long-archive-name.tar.gz`
|
||||
* ends mid-glyph and reads as broken rather than truncated.
|
||||
*/
|
||||
padding: 0 6px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue