test(tests): view row checks that can fail; reversal, double click, hygiene

This commit is contained in:
bchanot committed 2026-11-21 22:55:47 +01:00
1 parent bc82cd63b6
commit 411bdb0104
1 file changed
+150 -41
+150 -41
View File
@@ -1386,6 +1386,8 @@ const chevronOf = (page: Page, side: 'start' | 'end') =>
hintOf(page, side).locator('[title]')
const pressedChip = (page: Page) => rowOf(page).locator('[aria-pressed="true"]')
const LAST_VIEW = 'detail-long-8'
/** viewRow.ts OPENING_MS plus a margin: the reveals of the opening are instant. */
const OPENING_WINDOW_MS = 700
/** The shape of the criterion 32 test plus an annotation on the last view. */
function viewRowShape(document: Record<string, unknown>) {
@@ -1453,6 +1455,75 @@ async function expectScrollLeft(page: Page, expected: number, tolerance = 4) {
.toBeLessThanOrEqual(tolerance)
}
/** Resolves on the first frame the chip is clear of both fades, the row still moving. */
function waitClearInFlight(page: Page, id: string) {
return chipById(page, id).evaluate(
(chip, clear) =>
new Promise<void>((resolve, reject) => {
const row = chip.closest('[data-view-row]') as HTMLElement
const deadline = performance.now() + 3_000
const tick = () => {
const box = chip.getBoundingClientRect()
const rowBox = row.getBoundingClientRect()
if (
box.left >= rowBox.left + clear &&
box.right <= rowBox.right - clear
)
resolve()
else if (performance.now() > deadline)
reject(new Error('the chip never lay clear while the row moved'))
else requestAnimationFrame(tick)
}
tick()
}),
HINT_CLEAR,
)
}
/**
* Counts the `scroll` events of every view row from now on, a row mounted later included
* (the read-only twin mounts at the flip): a capture listener on the document sees them.
*/
function countRowScrolls(page: Page) {
return page.evaluate(() => {
const scope = window as unknown as { __scrolls: number }
scope.__scrolls = 0
document.addEventListener(
'scroll',
(event) => {
if ((event.target as Element).matches?.('[data-view-row]'))
scope.__scrolls++
},
true,
)
})
}
const rowScrolls = (page: Page) =>
page.evaluate(() => (window as unknown as { __scrolls: number }).__scrolls)
/** A smooth scroll is over when `scrollLeft` keeps one value over several frames. */
async function expectSettled(page: Page) {
await expect
.poll(
() =>
rowOf(page).evaluate(
(row) =>
new Promise<boolean>((resolve) => {
const start = row.scrollLeft
let frames = 0
const tick = () =>
++frames < 8
? requestAnimationFrame(tick)
: resolve(row.scrollLeft === start)
requestAnimationFrame(tick)
}),
),
{ timeout: 4_000, message: 'the row stops scrolling' },
)
.toBe(true)
}
/**
* How far the chip is from « visible and pressable »: its overshoot into a fade (the first and
* the last chip at the clamp excepted) and 100 when what is painted at its centre is not it.
@@ -1614,22 +1685,46 @@ test.describe('the view row (criterion 32)', () => {
'data-view-chip',
'detail-long-3',
)
// Not expectNoShift: the check mark widens the active chip, inside the row.
await page.evaluate(
() =>
new Promise((done) =>
requestAnimationFrame(() => requestAnimationFrame(done)),
),
)
const after = await columnBoxes(page)
// Not expectNoShift: the check mark widens the active chip, inside the row. The boxes
// are polled toward their values before the activation.
for (const part of ['canvas', 'strip', 'line'] as const)
for (let i = 0; i < 4; i++)
expect
.soft(after[part]?.[i], `${part} box [${i}] across the activation`)
await expect
.poll(async () => (await columnBoxes(page))[part]?.[i], {
message: `${part} box [${i}] across the activation`,
})
.toBeCloseTo(before[part]![i], 0)
expect(await scrollY(page)).toBe(top)
})
test('a reversed arrow mid-slide: the chip reached last is clear of the fades once the row settles', async ({
page,
}) => {
await openRow(page)
// Past the opening window, where every reveal is instant.
await page.waitForTimeout(OPENING_WINDOW_MS)
await chipById(page, 'main').focus()
for (let n = 0; n < 4; n++) await page.keyboard.press('ArrowRight')
// In flight toward the fourth chip, once the third is clear of both fades: the arrow
// back must not leave the row to its old target.
await waitClearInFlight(page, 'detail-long-2')
await page.keyboard.press('ArrowLeft')
await expect(chipById(page, 'detail-long-2')).toBeFocused()
await expectSettled(page)
await expectRevealed(page, 'detail-long-2', 'ArrowLeft in mid-slide')
})
test('a chevron page in flight then an arrow: the chip focused is clear of the fades once the row settles', async ({
page,
}) => {
await openRow(page)
await chipById(page, 'main').focus()
await chevronOf(page, 'end').click()
await page.keyboard.press('ArrowRight')
await expectSettled(page)
await expectRevealed(page, 'detail-a', 'ArrowRight after a chevron page')
})
test('End and Home reveal the last and the first chip, pressable at the clamp', async ({
page,
}) => {
@@ -1741,7 +1836,9 @@ test.describe('the view row (criterion 32)', () => {
await page.evaluate(
() =>
new Promise((resolve) =>
requestAnimationFrame(() => requestAnimationFrame(() => resolve(null))),
requestAnimationFrame(() =>
requestAnimationFrame(() => resolve(null)),
),
),
)
expect((await rowGeometry(page)).scrollLeft).toBeCloseTo(before, 0)
@@ -1752,6 +1849,33 @@ test.describe('the view row (criterion 32)', () => {
)
})
test('no click misdirected: a double click on a chip half under the end fade presses only that chip', async ({
page,
}) => {
await openRow(page)
const { clientWidth } = await rowGeometry(page)
await setRowScroll(
page,
await scrollLeftFor(page, 'detail-long-3', clientWidth - 90),
)
const at = await chipById(page, 'detail-long-3').evaluate((chip, clear) => {
const row = chip.closest('[data-view-row]')!.getBoundingClientRect()
const box = chip.getBoundingClientRect()
return { x: row.right - clear + 12, y: box.top + box.height / 2 }
}, HINT_CLEAR)
await page.mouse.dblclick(at.x, at.y)
await expectSettled(page)
await expect(pressedChip(page)).toHaveAttribute(
'data-view-chip',
'detail-long-3',
)
await expect(pressedChip(page)).toHaveCount(1)
await expect(chipById(page, 'detail-long-4')).toHaveAttribute(
'aria-pressed',
'false',
)
})
test('the dot: the active chip scrolled out of sight shows a dot on the chevron, a click brings it back', async ({
page,
}) => {
@@ -1833,17 +1957,13 @@ test.describe('the view row (criterion 32)', () => {
await expect(pressedChip(page)).toHaveAttribute('data-view-chip', LAST_VIEW)
await page.setViewportSize({ width: 1023, height: 768 })
await expect(page.getByTestId('edit-strip')).toBeHidden()
await page.evaluate(() => {
const scope = window as unknown as { __scrolls: number }
scope.__scrolls = 0
for (const row of document.querySelectorAll('[data-view-row]'))
row.addEventListener('scroll', () => scope.__scrolls++)
})
await countRowScrolls(page)
await page.setViewportSize({ width: 1024, height: 768 })
await expect(page.getByTestId('edit-strip')).toBeVisible()
await expectRevealed(page, LAST_VIEW, 'the edit body is shown again')
const scrolls = await page.evaluate(
() => (window as unknown as { __scrolls: number }).__scrolls,
const scrolls = await rowScrolls(page)
expect(scrolls, 'positive control: the placement is seen').toBeGreaterThan(
0,
)
expect(
scrolls,
@@ -1861,18 +1981,14 @@ test.describe('the view row (criterion 32)', () => {
await expect(pressedChip(page)).toHaveAttribute('data-view-chip', LAST_VIEW)
await pickAnnotation(page, dict, /Pt dernier/)
await openProperties(page, dict)
await page.evaluate(() => {
const scope = window as unknown as { __scrolls: number }
scope.__scrolls = 0
for (const row of document.querySelectorAll('[data-view-row]'))
row.addEventListener('scroll', () => scope.__scrolls++)
})
await countRowScrolls(page)
await page.setViewportSize({ width: 1023, height: 768 })
await expect(page.getByTestId('edit-strip')).toBeHidden()
await expect(pressedChip(page)).toHaveAttribute('data-view-chip', LAST_VIEW)
await expectRevealed(page, LAST_VIEW, 'the twin is shown', false)
const scrolls = await page.evaluate(
() => (window as unknown as { __scrolls: number }).__scrolls,
const scrolls = await rowScrolls(page)
expect(scrolls, 'positive control: the placement is seen').toBeGreaterThan(
0,
)
expect(
scrolls,
@@ -1927,7 +2043,9 @@ test.describe('the view row (criterion 32)', () => {
await page.keyboard.press('Enter')
await expect(pressedChip(page)).toHaveAttribute('data-view-chip', LAST_VIEW)
await expectRevealed(page, LAST_VIEW, 'the view change')
expect(await canvasTop(), 'after a view change').toBeCloseTo(top, 0)
await expect
.poll(canvasTop, { message: 'after a view change' })
.toBeCloseTo(top, 0)
await page
.getByRole('button', { name: dict['lang.switch_to_en'], exact: true })
.first()
@@ -2105,22 +2223,13 @@ test.describe('the view row under a touch drag (criterion 32)', () => {
row.right - HINT_CLEAR,
)
await touchDrag(page, context, from, { x: from.x - 200, y: from.y })
// Chromium's touch emulation may not pan an overflow container (LRN-135).
const moved = await expect
// The gain depends on the load (LRN-135): a lower bound well under the 200 px drag.
await expect
.poll(async () => (await rowGeometry(page)).scrollLeft, {
timeout: 2_000,
message: 'the row panned under the finger',
})
.toBeGreaterThan(100)
.then(
() => true,
() => false,
)
if (!moved)
test.info().annotations.push({
type: 'limit',
description:
'emulated touch did not pan the row (LRN-135): trial on the tablet',
})
.toBeGreaterThan(20)
expect(await scrollY(page), 'the page did not scroll').toBe(0)
await expect(pressedChip(page)).toHaveAttribute('data-view-chip', 'main')
})