fix(editor): state the pinned column's window bounds; tidy its tests

The canvas is unchanged for browser windows of the three sizes, smaller
in shorter ones; below 644 px of window height nothing is pinned (CSS
comment, rendering doc, owner trial step 18). A page-top focus on the add
row reveals it below the strip; the geometry helper is split, long test
titles wrapped.
This commit is contained in:
bchanot committed 2026-11-19 20:40:02 +01:00
1 parent 5e6d74428f
commit 031826dced
4 files changed
+220 -174

No files matched your search

+201 -165
View File
@@ -608,38 +608,43 @@ function stripGeometry(page: Page) {
/**
* The pinned drawing column (U2 Task 17): its box, the canvas box, what is painted at the
* canvas's top centre, and whether the page scrolls sideways.
* canvas's top centre.
*/
function columnGeometry(page: Page) {
return page.evaluate(() => {
const column = document.querySelector('[data-drawing-column]')!
const canvas = document.querySelector('[data-testid="annotation-canvas"]')!
const box = column.getBoundingClientRect()
const drawing = canvas.getBoundingClientRect()
const frame = document
.querySelector('[data-canvas-box]')!
.getBoundingClientRect()
const rect = (css: string) =>
document.querySelector(css)!.getBoundingClientRect()
const box = rect('[data-drawing-column]')
const drawing = rect('[data-testid="annotation-canvas"]')
const hit = document.elementFromPoint(
drawing.x + drawing.width / 2,
drawing.y + 2,
)
// A sideways scroll attempt moves the page only if something overflows (scrollWidth
// against clientWidth hides up to the scrollbar gutter's width).
window.scrollTo(100, window.scrollY)
const sideways = window.scrollX > 0
window.scrollTo(0, window.scrollY)
return {
top: box.top,
bottom: box.bottom,
canvas: { y: drawing.y, width: drawing.width, height: drawing.height },
canvasTopPainted: !!hit && canvas.contains(hit),
canvasTopPainted: !!hit?.closest('[data-testid="annotation-canvas"]'),
// Not capped: the canvas box still runs to the column's right edge.
canvasFills: Math.abs(frame.right - box.right) < 0.5,
sideways,
canvasFills: Math.abs(rect('[data-canvas-box]').right - box.right) < 0.5,
}
})
}
/**
* Whether the page scrolls sideways: a scroll attempt moves it only if something overflows
* (scrollWidth against clientWidth hides up to the scrollbar gutter's width). It scrolls the
* page sideways and back, so it fires scroll events.
*/
function scrollsSideways(page: Page) {
return page.evaluate(() => {
window.scrollTo(100, window.scrollY)
const moved = window.scrollX > 0
window.scrollTo(0, window.scrollY)
return moved
})
}
/**
* The focused element's top against the bottom of what covers it (the strip in the drawing
* place, else the bar); null on the sticky chrome itself, whose focus never scrolls the page.
@@ -844,7 +849,9 @@ for (const viewport of VIEWPORTS) {
expect(pinned.canvas.height, `canvas height at ${at}`).toBe(
canvas.height,
)
expect(pinned.sideways, `no sideways scroll at ${at}`).toBe(false)
expect(await scrollsSideways(page), `no sideways scroll at ${at}`).toBe(
false,
)
expect(pinned.canvasFills, `canvas not capped at ${at}`).toBe(true)
}
// Sticky leaves the flow alone: the aside keeps its place.
@@ -891,6 +898,22 @@ for (const viewport of VIEWPORTS) {
)
await open(page, ...manyPoints(), big)
await pickAnnotation(page, dict, 'Pt Big')
// At the page top the add row is below the fold: its focus reveals it with the least
// scroll, never onto the bar or the strip, and the column stays below the strip.
await page.evaluate(() => window.scrollTo(0, 0))
const add = page.locator('[data-add-kind="point"]')
await add.focus()
const revealed = await stripGeometry(page)
const addBox = (await add.boundingBox())!
expect(addBox.y, 'the add button below the strip').toBeGreaterThanOrEqual(
revealed.bottom - 0.5,
)
expect(addBox.y + addBox.height).toBeLessThanOrEqual(
revealed.innerHeight + 0.5,
)
expect((await columnGeometry(page)).top).toBeGreaterThanOrEqual(
revealed.bottom - 0.5,
)
await page.evaluate(() => window.scrollTo(0, 300))
const before = (await stripGeometry(page)).scrollY
// The keyboard's focus move on the strip's command and on the bar's first control.
@@ -963,159 +986,170 @@ for (const viewport of VIEWPORTS) {
)
})
test('a vertex handle (SVG) focused under the strip ends below it (window below the pinned height)', async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-v', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone V'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 200],
[600, 200],
[600, 500],
[300, 500],
],
},
})
await pickAnnotation(page, dict, 'Zone V')
const vertex = page.locator('[data-vertex="0"]')
await expect(vertex).toBeVisible()
await page.evaluate(() => {
const el = document.querySelector('[data-vertex="0"]')!
window.scrollTo(0, el.getBoundingClientRect().top + window.scrollY - 80)
})
const strip = await stripGeometry(page)
const before = (await vertex.boundingBox())!
expect(
before.y,
'precondition: the handle starts under the strip',
).toBeLessThan(strip.bottom)
await vertex.focus()
const after = (await vertex.boundingBox())!
expect(
after.y,
'the focused handle is below the strip',
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
})
test("Tab and Shift+Tab onto the drawing place's native controls land below the strip (window below the pinned height)", async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
// A commit puts « Défaire » in the message line under the drawing.
await page.getByTestId('point-handle').focus()
await page.keyboard.press('ArrowRight')
await page.keyboard.press('Enter')
await expect(page.getByTestId('gesture-message')).toBeVisible()
// Each walk starts on the canvas box, the page scrolled so the canvas top and the
// aside's top sit under the strip; the focus starts there without a scroll.
for (const key of ['Shift+Tab', 'Tab']) {
await page.evaluate(() => {
const canvas = document.querySelector<HTMLElement>(
'[data-testid="annotation-canvas"]',
)!
const top = canvas.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, top - 100)
canvas.focus({ preventScroll: true })
test(
'a vertex handle (SVG) focused under the strip ends below it ' +
'(window below the pinned height)',
async ({ page }) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-v', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone V'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 200],
[600, 200],
[600, 500],
[300, 500],
],
},
})
for (let step = 0; step < 40; step++) {
await pickAnnotation(page, dict, 'Zone V')
const vertex = page.locator('[data-vertex="0"]')
await expect(vertex).toBeVisible()
await page.evaluate(() => {
const el = document.querySelector('[data-vertex="0"]')!
window.scrollTo(
0,
el.getBoundingClientRect().top + window.scrollY - 80,
)
})
const strip = await stripGeometry(page)
const before = (await vertex.boundingBox())!
expect(
before.y,
'precondition: the handle starts under the strip',
).toBeLessThan(strip.bottom)
await vertex.focus()
const after = (await vertex.boundingBox())!
expect(
after.y,
'the focused handle is below the strip',
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
},
)
test(
"Tab and Shift+Tab onto the drawing place's native controls land below the strip " +
'(window below the pinned height)',
async ({ page }) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
// A commit puts « Défaire » in the message line under the drawing.
await page.getByTestId('point-handle').focus()
await page.keyboard.press('ArrowRight')
await page.keyboard.press('Enter')
await expect(page.getByTestId('gesture-message')).toBeVisible()
// Each walk starts on the canvas box, the page scrolled so the canvas top and the
// aside's top sit under the strip; the focus starts there without a scroll.
for (const key of ['Shift+Tab', 'Tab']) {
await page.evaluate(() => {
const canvas = document.querySelector<HTMLElement>(
'[data-testid="annotation-canvas"]',
)!
const top = canvas.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, top - 100)
canvas.focus({ preventScroll: true })
})
for (let step = 0; step < 40; step++) {
await page.keyboard.press(key)
const at = await focusedUnderStrip(page)
if (at.limit === null) continue
expect(
at.top,
`${key} ${step + 1}: ${at.name} below the strip or the bar`,
).toBeGreaterThanOrEqual(at.limit - 0.5)
}
}
},
)
test(
'Delete from the keyboard focuses the next vertex below the strip ' +
'(window below the pinned height)',
async ({ page }) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 600],
[300, 150],
[600, 150],
[600, 600],
],
},
})
await pickAnnotation(page, dict, 'Zone K')
// The next vertex (drawn higher) starts under the strip, the focused one below it.
const top = await page.evaluate(() => {
const next = document.querySelector('[data-vertex="1"]')!
const y = next.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, y - 90)
document
.querySelector<SVGElement>('[data-vertex="0"]')!
.focus({ preventScroll: true })
return next.getBoundingClientRect().top
})
const strip = await stripGeometry(page)
expect(
top,
'precondition: the next vertex is under the strip',
).toBeLessThan(strip.bottom)
await page.keyboard.press('Delete')
await expect(page.locator('[data-vertex="3"]')).toHaveCount(0)
const at = await focusedUnderStrip(page)
expect(at.name).toContain('Sommet')
expect(at.top, `${at.name} below the strip`).toBeGreaterThanOrEqual(
(await stripGeometry(page)).bottom - 0.5,
)
},
)
test(
'pinned: Delete and Insert from the keyboard keep the page still, ' +
'the vertex below the strip',
async ({ page }) => {
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 600],
[300, 150],
[600, 150],
[600, 600],
],
},
})
await pickAnnotation(page, dict, 'Zone K')
await page.evaluate(() => window.scrollTo(0, 400))
// A pinned handle carries no strip margin: its focus does not scroll the page.
await page.locator('[data-vertex="0"]').focus()
const before = (await stripGeometry(page)).scrollY
expect(before, 'the focus on a pinned handle').toBe(400)
for (const [key, last] of [
['Delete', 0],
['Insert', 1],
] as const) {
await page.keyboard.press(key)
await expect(page.locator('[data-vertex="3"]')).toHaveCount(last)
const at = await focusedUnderStrip(page)
if (at.limit === null) continue
expect(at.name, key).toContain('Sommet')
expect(
at.top,
`${key} ${step + 1}: ${at.name} below the strip or the bar`,
).toBeGreaterThanOrEqual(at.limit - 0.5)
`${key}: ${at.name} below the strip`,
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
expect((await stripGeometry(page)).scrollY, `${key}: the page`).toBe(
before,
)
}
}
})
test('Delete from the keyboard focuses the next vertex below the strip (window below the pinned height)', async ({
page,
}) => {
await belowPinnedHeight(page)
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 600],
[300, 150],
[600, 150],
[600, 600],
],
},
})
await pickAnnotation(page, dict, 'Zone K')
// The next vertex (drawn higher) starts under the strip, the focused one below it.
const top = await page.evaluate(() => {
const next = document.querySelector('[data-vertex="1"]')!
const y = next.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, y - 90)
document
.querySelector<SVGElement>('[data-vertex="0"]')!
.focus({ preventScroll: true })
return next.getBoundingClientRect().top
})
const strip = await stripGeometry(page)
expect(
top,
'precondition: the next vertex is under the strip',
).toBeLessThan(strip.bottom)
await page.keyboard.press('Delete')
await expect(page.locator('[data-vertex="3"]')).toHaveCount(0)
const at = await focusedUnderStrip(page)
expect(at.name).toContain('Sommet')
expect(at.top, `${at.name} below the strip`).toBeGreaterThanOrEqual(
(await stripGeometry(page)).bottom - 0.5,
)
})
test('pinned: Delete and Insert from the keyboard keep the page still, the vertex below the strip', async ({
page,
}) => {
await open(page, ...manyPoints(), {
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
kind: 'zone',
geometry: {
type: 'polygon',
points: [
[300, 600],
[300, 150],
[600, 150],
[600, 600],
],
},
})
await pickAnnotation(page, dict, 'Zone K')
await page.evaluate(() => window.scrollTo(0, 400))
// A pinned handle carries no strip margin: its focus does not scroll the page.
await page.locator('[data-vertex="0"]').focus()
const before = (await stripGeometry(page)).scrollY
expect(before, 'the focus on a pinned handle').toBe(400)
for (const [key, last] of [
['Delete', 0],
['Insert', 1],
] as const) {
await page.keyboard.press(key)
await expect(page.locator('[data-vertex="3"]')).toHaveCount(last)
const at = await focusedUnderStrip(page)
expect(at.name, key).toContain('Sommet')
expect(
at.top,
`${key}: ${at.name} below the strip`,
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
expect((await stripGeometry(page)).scrollY, `${key}: the page`).toBe(
before,
)
}
})
},
)
test('pinned: a row selection moves neither the page nor the drawing on screen', async ({
page,
@@ -1201,7 +1235,9 @@ for (const { pinned, ...viewport } of SHORT_WINDOWS) {
const strip = await stripGeometry(page)
const now = await columnGeometry(page)
const at = `scrollY ${strip.scrollY}`
expect(now.sideways, `no sideways scroll at ${at}`).toBe(false)
expect(await scrollsSideways(page), `no sideways scroll at ${at}`).toBe(
false,
)
expect(now.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
if (!pinned) continue
expect(
+5 -3
View File
@@ -63,8 +63,8 @@ body,
}
/* The drawing column (chips, tools, canvas, add row, message line) is pinned under the
strip, so no part of the drawing is ever under it while the side panel scrolls (U2 Task
17). Only where the column fits: below 40.25rem high the 365 px tool column beside a
capped canvas does not, and nothing here applies. The negative bottom margin lets the
17). Only where the column fits: below 40.25rem (644 px) of window height the 365 px tool
column beside a capped canvas does not, nothing here applies and nothing is pinned. The negative bottom margin lets the
pinned travel run into the page's bottom space (workspace gap + main padding): without
it, the page's end pushed the column's top under the strip at 1 180 x 820. */
@media (min-width: 1024px) and (min-height: 40.25rem) {
@@ -77,7 +77,9 @@ body,
/* The column fits the window: the 4:3 box's width is capped by the small viewport height
less the pinned top and the column's other parts (one row of chips, the add row, the
line, the gaps: 9.25rem), plus its 2 px border. svh: a toolbar collapsing during a
scroll never resizes the box. Unchanged at 1 024 x 768, 1 180 x 820, 1 280 x 800. */
scroll never resizes the box. Unchanged when the browser window (not the screen) is
1 024 x 768, 1 180 x 820 or 1 280 x 800; smaller in shorter windows (capped below
672, 789 and 672 px of window height). */
[data-drawing-column] [data-canvas-box] {
max-width: calc((100svh - var(--edit-pinned-top) - 9.25rem) * 4 / 3 + 2px);
}
+11 -6
View File
@@ -255,13 +255,18 @@ always fits the window, the canvas box (`data-canvas-box`) is capped in width at
`(100svh − --edit-pinned-top − 9.25 rem) × 4/3 + 2 px` (9.25 rem: one row of
chips, one add row, the line and the gaps; 2 px: the box's border), keeping its
4:3 ratio: the cap follows the window's small viewport height, never the
scroll nor a collapsing browser toolbar, and leaves the box unchanged at
1 024 × 768, 1 180 × 820 and 1 280 × 800; a capped box sits left, with spare
width on its right. Its focusables carry only the bar's margin there (the
scroll nor a collapsing browser toolbar. The box is unchanged when the browser
window (not the screen) is 1 024 × 768, 1 180 × 820 or 1 280 × 800, and smaller
in shorter windows (capped below 672, 789 and 672 px of window height at those
widths; a tablet's browser toolbars take their height off the screen's); a
capped box sits left, with spare width on its right. The 9.25 rem assumes one
row of view chips: a sheet whose chips wrap to a second row makes the column
about 38 px taller than the cap allows, so where the cap binds the column's
top goes under the strip at the end of the page. Its focusables carry only the bar's margin there (the
strip's margin, larger than the pinned top, would scroll the page on a focus of
a pinned control). Below 644 px high the tool column (365 px) no longer fits
beside a capped box: nothing is pinned or capped, and the drawing scrolls under
the strip as before, with the strip's margin on its focusables.
a pinned control). Below 644 px of window height the tool column (365 px) no
longer fits beside a capped box: nothing is pinned or capped, and the drawing
scrolls under the strip as before, with the strip's margin on its focusables.
The editor page's other focusables (criterion 25: the header's « Enregistrer », the
tab row, « Défaire » and « Refaire », the notices' controls) carry a smaller margin,
+3
View File
@@ -790,6 +790,9 @@ Tablette en paysage (au moins 1 024 px de large ; en dessous, l'éditeur est en
18. Tablette et fenêtres de 1 024, 1 180 et 1 280 px : la bande qui reste en haut. Action : faites défiler la page
avec une annotation sélectionnée. Attendu : la bande reste entière sous la barre du haut, rien ne bouge et rien
n'est caché derrière. Un Tab sur une commande de la bande ou sur un lien de la barre ne fait pas défiler la page.
Sur la tablette, faites défiler la page des annotations jusqu'à la fin : aucune partie du dessin, de ses boutons
de vue, de la rangée d'ajout ou de la ligne de message ne passe sous la bande. Si une partie y passe, notez-le :
la fenêtre fait alors moins de 644 px de haut.
19. Refaire retenu. Préparez quelque chose à défaire et à refaire : créez un point, déplacez-le d'un pas aux flèches
validé par Entrée, puis « Défaire ». Action : outil « Zone », posez un sommet (la boîte de « Point » s'ouvre tout
de suite et cache l'en-tête : prenez « Zone »), puis donnez le focus à « Refaire » puis à « Défaire » : un lecteur