fix(editor): the strip stays below the top bar on scroll

This commit is contained in:
bchanot committed 2026-11-19 12:15:52 +01:00
1 parent 62b400e876
commit f2809f20ca
6 files changed
+153 -3

No files matched your search

+121
View File
@@ -563,3 +563,124 @@ test.describe('editor touch path (real browser)', () => {
expect(Math.abs((await shownNumber(page, 'cx')) - 620)).toBeLessThan(3)
})
})
// U2 Task 14 (owner point 1): on the editable layout the strip stays right under the sticky
// top bar at every scroll position, without moving anything in the flow.
const VIEWPORTS = [
{ width: 1024, height: 768 },
{ width: 1180, height: 820 },
{ width: 1280, height: 800 },
]
/** Enough annotations for the overview to grow the page well past one screen. */
const manyPoints = () =>
Array.from({ length: 14 }, (_, i) =>
pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`),
)
/** The strip's and the bar's boxes, and what is painted at the strip's centre. */
function stripGeometry(page: Page) {
return page.evaluate(() => {
const strip = document.querySelector('[data-testid="edit-strip"]')!
const bar = document.querySelector(
'header:has([data-testid="topbar-account"])',
)!
const box = strip.getBoundingClientRect()
const hit = document.elementFromPoint(
box.x + box.width / 2,
box.y + box.height / 2,
)
return {
barBottom: bar.getBoundingClientRect().bottom,
top: box.top,
bottom: box.bottom,
covered: !hit || !strip.contains(hit),
scrollY: window.scrollY,
limit: document.documentElement.scrollHeight - window.innerHeight,
innerHeight: window.innerHeight,
}
})
}
for (const viewport of VIEWPORTS) {
test.describe(`the strip under the top bar at ${viewport.width} px (U2 Task 14)`, () => {
test.use({
locale: 'fr-FR',
actionTimeout: 15_000,
hasTouch: true,
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('at every scroll step the strip is below the bar and visible; nothing shifts', async ({
page,
context,
}) => {
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
await expect(selectionTag(page)).toContainText('Pt 0')
const flowTop = (selector: string) =>
page.evaluate(
(css) =>
document.querySelector(css)!.getBoundingClientRect().top +
window.scrollY,
selector,
)
const canvasTop = await flowTop('[data-testid="annotation-canvas"]')
const asideTop = await flowTop('[data-annotation-aside="edit"]')
const start = await stripGeometry(page)
expect(start.limit, 'the page must scroll').toBeGreaterThan(300)
for (let y = 0; y <= start.limit + 150; y += 150) {
await page.evaluate((to) => window.scrollTo(0, to), y)
const now = await stripGeometry(page)
const at = `scrollY ${now.scrollY}`
expect(
now.top,
`strip top below the bar at ${at}`,
).toBeGreaterThanOrEqual(now.barBottom - 0.5)
expect(now.bottom, `strip bottom in view at ${at}`).toBeLessThanOrEqual(
now.innerHeight,
)
expect(now.covered, `strip painted at ${at}`).toBe(false)
}
// Sticky leaves the flow alone: the canvas and the aside keep their place.
expect(await flowTop('[data-testid="annotation-canvas"]')).toBe(canvasTop)
expect(await flowTop('[data-annotation-aside="edit"]')).toBe(asideTop)
const bottom = (await stripGeometry(page)).scrollY
const command = page
.getByTestId('edit-strip')
.getByRole('button', { name: dict['editor.annotations.properties'] })
// A finger on a strip command after the scroll hits it (a hit check that had to
// scroll again would move the page), and no box moves.
const cdp = await context.newCDPSession(page)
const box = (await command.boundingBox())!
expect(
box.y,
'the command is in view, under the bar',
).toBeGreaterThanOrEqual((await stripGeometry(page)).barBottom)
await expectNoShift(page, async () => {
const at = { x: box.x + box.width / 2, y: box.y + box.height / 2 }
await cdp.send('Input.dispatchTouchEvent', {
type: 'touchStart',
touchPoints: [at],
})
await cdp.send('Input.dispatchTouchEvent', {
type: 'touchEnd',
touchPoints: [],
})
await expect(page.getByRole('dialog')).toBeVisible()
await page.keyboard.press('Escape')
await expect(page.getByRole('dialog')).toHaveCount(0)
})
expect((await stripGeometry(page)).scrollY).toBe(bottom)
})
})
}