diff --git a/apps/app/e2e/shell/editor-deselect.spec.ts b/apps/app/e2e/shell/editor-deselect.spec.ts index 99dd6ac6..a07e7c9a 100644 --- a/apps/app/e2e/shell/editor-deselect.spec.ts +++ b/apps/app/e2e/shell/editor-deselect.spec.ts @@ -20,7 +20,6 @@ import { reloadAccepting, revisionText, saveLine, - scrollToTop, seedDraft, selectionTag, selectTab, @@ -141,18 +140,6 @@ async function expectDeselected(page: Page) { await expect(overview(page)).toBeVisible() } -/** The client point hits the canvas box, not the sticky strip or bar over it. */ -async function expectOnDrawing(page: Page, at: { x: number; y: number }) { - const hit = await page.evaluate( - ({ x, y }) => - document - .elementFromPoint(x, y) - ?.closest('[data-testid="annotation-canvas"]') != null, - at, - ) - expect(hit, `${at.x}, ${at.y} lands on the drawing`).toBe(true) -} - /** A negative check: the state is still there after two animation frames. */ async function expectKept(page: Page, name: string) { await frames(page) @@ -305,9 +292,6 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => { requests.forbid(actor.account.email, actor.account.password) await select(page, POINT) for (const at of [IN_CIRCLE, IN_RECT, IN_ROOT]) { - // The row click scrolled the page: the drawing's top band is under the sticky strip. - await scrollToTop(page) - await expectOnDrawing(page, await clientOf(page, at.x, at.y)) await clickAt(page, at) await expectDeselected(page) await select(page, POINT) @@ -640,11 +624,9 @@ test.describe('deselect and D6b (touch, editor at 1 280 px)', () => { // b. Empty drawing, a zone about 40 px below the tap. await select(page, POINT) - await scrollToTop(page) await takeRecord(page) const top = await clientOf(page, 175, 100) const above = { x: top.x, y: top.y - 40 } - await expectOnDrawing(page, above) expect(await annotationUnder(page, above)).toBeNull() await tap(cdp, above) await expectDeselected(page) diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index 1e7d36a2..141177ba 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -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, + ) + } + }) + }) +} diff --git a/apps/app/e2e/shell/editor-journey.spec.ts b/apps/app/e2e/shell/editor-journey.spec.ts index b251bc97..d8860cd8 100644 --- a/apps/app/e2e/shell/editor-journey.spec.ts +++ b/apps/app/e2e/shell/editor-journey.spec.ts @@ -256,8 +256,6 @@ async function modifyAnnotations(page: Page) { */ async function repairGeometry(page: Page) { await toolButton(page, dict, 'point').click() - // The last row click scrolled the page: the drawing's top edge is under the sticky strip. - await scrollToTop(page) // On this 200 x 150 drawing the core keeps a shrunk marker at 1 unit from the edge: the // proposal of a corrected position needs a click on the edge itself (editor-geometry // covers it on a 1 000-unit drawing). Here the click is placed at once. @@ -337,7 +335,8 @@ test.describe('editor journey (owner trial steps)', () => { await historyButton(page, dict, 'undo').click() await historyButton(page, dict, 'redo').click() const modified = await modifyAnnotations(page) - // At rest: scrolled, the stuck strip covers part of the aside's targets (axe target-size). + // Scrolled, the side panel still passes under the strip (only the drawing column is + // pinned): a row under it fails axe's target-size. The scan runs at rest, at the top. await scrollToTop(page) await expectAccessible(page, 'the editor with annotations') await saveDraft(page, dict, 1) diff --git a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx index f29a90a6..ee5df696 100644 --- a/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx +++ b/apps/app/src/components/editor/annotations/AnnotationCanvas.tsx @@ -181,7 +181,7 @@ function CanvasBox({ const root = build.root?.viewId === viewId ? build.root : null const cursor = tool === 'select' ? 'cursor-grab' : 'cursor-crosshair' return ( -
+
+