fix(editor): the drawing stays clear of the strip while the page scrolls

The drawing column (chips, tools, canvas, add row, message line) is
pinned under the strip from 1 024 px wide and 644 px high; the canvas
box is capped in width by the window height (4:3 kept, unchanged at the
three sizes); pinned controls carry no strip margin. The rev 4 test
workarounds go; the row-click scroll was Playwright's bring-into-view.
This commit is contained in:
bchanot committed 2026-11-19 20:19:26 +01:00
1 parent da04c79d13
commit 36ed9f980b
7 files changed
+286 -31

No files matched your search

+219 -8
View File
@@ -606,6 +606,36 @@ 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.
*/
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 hit = document.elementFromPoint(
drawing.x + drawing.width / 2,
drawing.y + 2,
)
const root = document.documentElement
return {
top: box.top,
bottom: box.bottom,
canvas: { y: drawing.y, width: drawing.width, height: drawing.height },
canvasTopPainted: !!hit && canvas.contains(hit),
// Not capped: the canvas box still runs to the column's right edge.
canvasFills: Math.abs(frame.right - box.right) < 0.5,
sideways: root.scrollWidth > root.clientWidth,
}
})
}
/**
* 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.
@@ -640,6 +670,13 @@ function focusedUnderStrip(page: Page) {
})
}
/**
* A window too short for the pinned drawing column (U2 Task 17: pinned from 40.25 rem high):
* the drawing scrolls under the strip as before, and the strip's margin brings a focus out.
*/
const belowPinnedHeight = (page: Page) =>
page.setViewportSize({ width: page.viewportSize()!.width, height: 600 })
// Criterion 25: the header's « Enregistrer » and the tab row's « Défaire » and « Refaire » sit
// outside the drawing place; a keyboard focus on them, the page scrolled, never lands under the bar.
const HEADER_WIDTHS = [820, 1024, 1280]
@@ -766,9 +803,9 @@ for (const viewport of VIEWPORTS) {
window.scrollY,
selector,
)
const canvasTop = await flowTop('[data-testid="annotation-canvas"]')
const asideTop = await flowTop('[data-annotation-aside="edit"]')
const start = await stripGeometry(page)
const { canvas } = await columnGeometry(page)
expect(start.limit, 'the page must scroll').toBeGreaterThan(300)
for (let y = 0; y <= start.limit + 150; y += 150) {
@@ -783,9 +820,30 @@ for (const viewport of VIEWPORTS) {
now.innerHeight,
)
expect(now.covered, `strip painted at ${at}`).toBe(false)
// Task 17: the drawing column (chips to message line) is never under the strip
// and fits the window; the canvas keeps its size; nothing scrolls sideways.
const pinned = await columnGeometry(page)
expect(
pinned.top,
`column top below the strip at ${at}`,
).toBeGreaterThanOrEqual(now.bottom - 0.5)
// Stuck with the strip, all of it is in view (before, the page top shows its top).
if (now.top <= now.barBottom + 0.5)
expect(
pinned.bottom,
`column bottom in view at ${at}`,
).toBeLessThanOrEqual(now.innerHeight + 0.5)
expect(pinned.canvasTopPainted, `canvas top painted at ${at}`).toBe(
true,
)
expect(pinned.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
expect(pinned.canvas.height, `canvas height at ${at}`).toBe(
canvas.height,
)
expect(pinned.sideways, `no sideways scroll at ${at}`).toBe(false)
expect(pinned.canvasFills, `canvas not capped at ${at}`).toBe(true)
}
// Sticky leaves the flow alone: the canvas and the aside keep their place.
expect(await flowTop('[data-testid="annotation-canvas"]')).toBe(canvasTop)
// Sticky leaves the flow alone: the aside keeps its place.
expect(await flowTop('[data-annotation-aside="edit"]')).toBe(asideTop)
const bottom = (await stripGeometry(page)).scrollY
@@ -820,8 +878,15 @@ for (const viewport of VIEWPORTS) {
test('a focus never scrolls onto the bar or the strip, nor lands under them', async ({
page,
}) => {
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
// A marker large enough on the phone preview for its moves to be accepted.
const big = pointOf(
'pt-big',
'main',
{ cx: 500, cy: 400, r: 40 },
'Pt Big',
)
await open(page, ...manyPoints(), big)
await pickAnnotation(page, dict, 'Pt Big')
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.
@@ -837,6 +902,36 @@ for (const viewport of VIEWPORTS) {
'focus on sticky chrome',
).toBe(before)
}
// U2 Task 17: nor on the pinned column's controls (the line's « Défaire », a view
// chip, the handle, an add button, the canvas box), each below the strip. A commit
// puts « Défaire » in the message line for 6 s.
await page.getByTestId('point-handle').focus()
await page.keyboard.press('ArrowRight')
await page.keyboard.press('Enter')
const line = page.getByTestId('gesture-line')
const undo = line.getByRole('button', {
name: dict['editor.history.undo_title'],
})
await expect(undo).toBeVisible()
for (const target of [
undo,
viewChip(page, 'Vue principale'),
page.getByTestId('point-handle'),
page.locator('[data-add-kind="point"]'),
page.getByTestId('annotation-canvas'),
]) {
await target.focus()
const label = await target.evaluate(
(el) => el.getAttribute('aria-label') ?? el.textContent,
)
expect((await stripGeometry(page)).scrollY, `focus on ${label}`).toBe(
before,
)
expect(
(await target.boundingBox())!.y,
`${label} below the strip`,
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom - 0.5)
}
// A row hidden under the strip comes out below it, not under it. The row sits low in the
// page: a short window lets the page scroll far enough to put it under the strip.
await page.setViewportSize({
@@ -864,9 +959,10 @@ for (const viewport of VIEWPORTS) {
)
})
test('a vertex handle (SVG) focused under the strip ends below it', async ({
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',
@@ -901,9 +997,10 @@ for (const viewport of VIEWPORTS) {
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
})
test("Tab and Shift+Tab onto the drawing place's native controls land below the strip", async ({
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.
@@ -934,9 +1031,10 @@ for (const viewport of VIEWPORTS) {
}
})
test('Delete from the keyboard focuses the next vertex below the strip', async ({
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',
@@ -975,6 +1073,73 @@ for (const viewport of VIEWPORTS) {
)
})
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,
}) => {
await open(page, ...manyPoints())
for (const name of ['Pt 3', 'Pt 4']) {
const row = annotationList(page, dict).getByRole('button', { name })
// The row at mid-window, the page scrolled past the point where the column sticks.
await row.evaluate((el) => {
const top = el.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, top - window.innerHeight / 2)
})
expect((await stripGeometry(page)).scrollY).toBeGreaterThan(300)
const box = (await row.boundingBox())!
const strip = await stripGeometry(page)
expect(box.y, `precondition: ${name} in view`).toBeGreaterThan(
strip.bottom,
)
expect(box.y + box.height).toBeLessThan(strip.innerHeight)
const before = await columnGeometry(page)
// A real pointer press on the visible row: no bring-into-view scroll.
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2)
await expect(selectionTag(page)).toContainText(name)
expect((await stripGeometry(page)).scrollY, name).toBe(strip.scrollY)
expect((await columnGeometry(page)).canvas, name).toEqual(before.canvas)
}
})
test('with the strip hidden only the bar offset is applied', async ({
page,
}) => {
@@ -1001,3 +1166,49 @@ for (const viewport of VIEWPORTS) {
})
})
}
// U2 Task 17 at shorter windows: 1 180 x 700 pins a capped canvas (its size set by the window,
// never by the scroll); 1 024 x 600 is below the pinned height (nothing pinned or capped).
const SHORT_WINDOWS = [
{ width: 1180, height: 700, pinned: true },
{ width: 1024, height: 600, pinned: false },
]
for (const { pinned, ...viewport } of SHORT_WINDOWS) {
test.describe(`the drawing column at ${viewport.width} x ${viewport.height} (U2 Task 17)`, () => {
test.use({ locale: 'fr-FR', actionTimeout: 15_000, viewport })
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('no sideways scroll at any scroll step; pinned, the column fits the window', async ({
page,
}) => {
await open(page, ...manyPoints())
const start = await stripGeometry(page)
const { canvas, canvasFills } = await columnGeometry(page)
expect(canvasFills, 'the canvas is capped only when pinned').toBe(!pinned)
for (let y = 0; y <= start.limit + 150; y += 150) {
await page.evaluate((to) => window.scrollTo(0, to), y)
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(now.canvas.width, `canvas width at ${at}`).toBe(canvas.width)
if (!pinned) continue
expect(
now.top,
`column below the strip at ${at}`,
).toBeGreaterThanOrEqual(strip.bottom - 0.5)
if (strip.top <= strip.barBottom + 0.5)
expect(now.bottom, `column in view at ${at}`).toBeLessThanOrEqual(
strip.innerHeight + 0.5,
)
}
})
})
}