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(