From 1f9ed523fbfd80feb13252d2a148accfaf5cc82d Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 20 Nov 2026 15:11:34 +0100 Subject: [PATCH] test(tests): browser journeys for the add buttons and the open-side bubble --- apps/app/e2e/shell/editor-annotations.spec.ts | 110 ++++++++++ apps/app/e2e/shell/editor-geometry.spec.ts | 95 ++++++++ .../e2e/shell/editor-shell-crossing.spec.ts | 9 +- apps/app/e2e/shell/editor-touch.spec.ts | 202 ++++++++++++++++++ 4 files changed, 413 insertions(+), 3 deletions(-) diff --git a/apps/app/e2e/shell/editor-annotations.spec.ts b/apps/app/e2e/shell/editor-annotations.spec.ts index 45f1fef8..ec39f2a1 100644 --- a/apps/app/e2e/shell/editor-annotations.spec.ts +++ b/apps/app/e2e/shell/editor-annotations.spec.ts @@ -1055,4 +1055,114 @@ test.describe('editor annotations (A3)', () => { await historyButton(page, dict, 'undo').click() await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(0) }) + + // U2 trial adjustments (C7): « Ajouter … » arms its tool on a mouse click; the drawing + // places the element where it is clicked; a double click leaves the tool armed. + test.describe('the add buttons arm their tool (U2 trial)', () => { + const ADD_KINDS = ['point', 'zone', 'detail_trigger'] as const + const add = (page: Page, kind: string) => + page.locator(`[data-add-kind="${kind}"]`) + + const sizes = async (page: Page) => + Promise.all( + ADD_KINDS.map(async (kind) => { + const box = (await add(page, kind).boundingBox())! + return { width: box.width, height: box.height } + }), + ) + + /** The colour once the button's transition is over (two equal reads in a row). */ + async function settledColour(button: Locator): Promise { + let last = '' + await expect + .poll( + async () => { + const now = await button.evaluate( + (element) => getComputedStyle(element).backgroundColor, + ) + const settled = now === last + last = now + return settled + }, + { intervals: [250] }, + ) + .toBe(true) + return last + } + + for (const width of [1024, 1180, 1280]) { + test(`at ${width} px: a click arms « Ajouter un point », pressed like the tool, nothing moves`, async ({ + page, + requests, + }) => { + await page.setViewportSize({ width, height: 800 }) + const { actor } = await openAnnotations(page) + requests.forbid(actor.account.email, actor.account.password) + // In view first: a click scrolls an offscreen button, which the probe reads as a move. + await add(page, 'point').scrollIntoViewIfNeeded() + const before = await sizes(page) + await expectNoShift(page, async () => { + await add(page, 'point').click() + await expect( + page.getByRole('dialog', { name: /./ }), + 'a click only arms: no dialog', + ).toHaveCount(0) + await expect(add(page, 'point')).toHaveAttribute('data-armed', '') + }) + await expect(tool(page, 'point')).toHaveAttribute( + 'aria-pressed', + 'true', + ) + // Button has a transition: the add button reaches the tool's pressed colour. + const pressed = await settledColour(tool(page, 'point')) + await expect(add(page, 'point')).toHaveCSS('background-color', pressed) + expect(await sizes(page)).toEqual(before) + + if (width !== 1280) return + // The click in the drawing places the point there: the ghost's centre is the click. + const canvas = (await page + .getByTestId('annotation-canvas') + .boundingBox())! + const click = { + x: canvas.x + canvas.width * 0.3, + y: canvas.y + canvas.height * 0.4, + } + await page.mouse.click(click.x, click.y) + await expect(creationDialog(page, 'point')).toBeVisible() + const ghost = (await page + .getByTestId('overlay-ghost') + .locator('circle') + .first() + .boundingBox())! + expect( + Math.abs(ghost.x + ghost.width / 2 - click.x), + 'ghost centre x', + ).toBeLessThanOrEqual(3) + expect( + Math.abs(ghost.y + ghost.height / 2 - click.y), + 'ghost centre y', + ).toBeLessThanOrEqual(3) + // « Abandonner », confirmed: the focus comes back to the button that armed it. + await creationDialog(page, 'point') + .getByRole('button', { + name: dict['editor.annotations.creation.discard'], + }) + .click() + await creationDialog(page, 'point') + .getByRole('group', { + name: dict['editor.annotations.guard.creation'], + }) + .getByRole('button', { + name: dict['editor.annotations.guard.discard'], + }) + .click() + await expect(creationDialog(page, 'point')).toHaveCount(0) + await expect(add(page, 'point')).toBeFocused() + // A double click presses twice: the second press (detail 2) does not disarm it. + await add(page, 'zone').dblclick() + await expect(add(page, 'zone')).toHaveAttribute('data-armed', '') + await expect(tool(page, 'zone')).toHaveAttribute('aria-pressed', 'true') + }) + } + }) }) diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index 20777e30..47d8d640 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -1258,3 +1258,98 @@ for (const { pinned, ...viewport } of SHORT_WINDOWS) { }) }) } + +// U2 criterion 32 on the final code (owner 2026-11-20): with enough detail views for the view +// chips to wrap onto several rows, the pinned column still sits below the strip, fits the +// window when stuck, keeps its canvas size and never scrolls sideways. +const CHIP_WINDOWS = [ + { width: 1024, height: 768 }, + { width: 1180, height: 820 }, + { width: 1180, height: 700 }, + { width: 1280, height: 800 }, +] + +/** The standard shape, many points, and eight detail views with long names. */ +function chipRowsShape(document: Record) { + shapeWith(...manyPoints())(document) + for (let n = 1; n <= 8; n++) + (document.views as unknown[]).push({ + id: `detail-long-${n}`, + kind: 'detail', + name: { + fr: `Détail de la région thoracique ${n}`, + en: `Thoracic region detail ${n}`, + }, + svg_asset_id: null, + view_box: { min_x: 100, min_y: 100, width: 300, height: 240 }, + parent_view_id: 'main', + }) +} + +for (const viewport of CHIP_WINDOWS) { + test.describe(`the column with the view chips on several rows at ${viewport.width} x ${viewport.height} (U2 criterion 32)`, () => { + 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) + }) + + // owner decision pending (criterion 32, chips on several rows): the budget counts one row + // of chips; measured with eight long names, the stuck column's bottom ends past the + // window bottom (3 to 5 rows of chips). Never made to pass by changing the layout. + test.fixme('the chips take two rows or more; the column keeps below the strip and inside the window', async ({ + page, + }) => { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { shape: chipRowsShape }) + await openEditor(page, dict, actor, seed.sheetId) + await expect(tool(page, 'point')).toBeEnabled() + const rows = await page + .getByRole('group', { name: dict['editor.annotations.views'] }) + .getByRole('button') + .evaluateAll( + (chips) => + new Set(chips.map((c) => Math.round(c.getBoundingClientRect().top))) + .size, + ) + expect( + rows, + 'the view chips wrap onto several rows', + ).toBeGreaterThanOrEqual(2) + + const start = await stripGeometry(page) + const { canvas } = await columnGeometry(page) + expect(start.limit, 'the page must scroll').toBeGreaterThan(300) + const overflow: string[] = [] + 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 + .soft(now.top, `column top below the strip at ${at}`) + .toBeGreaterThanOrEqual(strip.bottom - 0.5) + if (strip.top <= strip.barBottom + 0.5) { + const past = now.bottom - strip.innerHeight + if (past > 0.5) overflow.push(`${at}: ${past.toFixed(1)} px`) + } + expect + .soft(now.canvas.width, `canvas width at ${at}`) + .toBe(canvas.width) + expect + .soft(now.canvas.height, `canvas height at ${at}`) + .toBe(canvas.height) + expect + .soft(await scrollsSideways(page), `no sideways scroll at ${at}`) + .toBe(false) + } + expect( + overflow, + `column bottom past the window bottom when stuck (${rows} rows)`, + ).toEqual([]) + }) + }) +} diff --git a/apps/app/e2e/shell/editor-shell-crossing.spec.ts b/apps/app/e2e/shell/editor-shell-crossing.spec.ts index 8e1d6622..83dfff14 100644 --- a/apps/app/e2e/shell/editor-shell-crossing.spec.ts +++ b/apps/app/e2e/shell/editor-shell-crossing.spec.ts @@ -265,9 +265,12 @@ test.describe('editor shell, width crossing (H)', () => { }) await expect(zone).toBeEnabled() await zone.click() - await page - .getByRole('button', { name: dict['editor.annotations.add.point'] }) - .click() + // A click now only arms the tool; Enter on the button is the centre placement. + const addPoint = page.getByRole('button', { + name: dict['editor.annotations.add.point'], + }) + await addPoint.focus() + await page.keyboard.press('Enter') const dialog = page.getByRole('dialog', { name: dict['editor.annotations.new.point'], }) diff --git a/apps/app/e2e/shell/editor-touch.spec.ts b/apps/app/e2e/shell/editor-touch.spec.ts index f18bb935..b69d90b2 100644 --- a/apps/app/e2e/shell/editor-touch.spec.ts +++ b/apps/app/e2e/shell/editor-touch.spec.ts @@ -7,6 +7,8 @@ import { clientOf, creationPanel, editorActor, + equineDrawing, + equineShape, historyButton, openEditor, pickAnnotation, @@ -556,3 +558,203 @@ test.describe('a resumed trace by finger at 1 180 px (rev 4)', () => { await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(0) }) }) + +// U2 trial adjustments (C7, R-9, LRN-105): the add buttons and the handles' marks by finger +// at 1 180 px, on the run's own equine draft for the handles. +test.describe('the add buttons and the handles by finger at 1 180 px (U2 trial)', () => { + test.use({ + locale: 'fr-FR', + actionTimeout: 15_000, + hasTouch: true, + viewport: { width: 1180, height: 800 }, + }) + 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) + }) + + const centreOfBox = (box: { + x: number + y: number + width: number + height: number + }) => ({ + x: box.x + box.width / 2, + y: box.y + box.height / 2, + }) + + test('a tap on « Ajouter un point » arms it, a tap in the drawing opens the dialog; the button is 44 px tall', async ({ + page, + context, + requests, + }) => { + const { actor } = await open(page) + requests.forbid(actor.account.email, actor.account.password) + const cdp = await context.newCDPSession(page) + const add = page.locator('[data-add-kind="point"]') + await add.scrollIntoViewIfNeeded() + const box = (await add.boundingBox())! + expect(box.height).toBeGreaterThanOrEqual(43.5) + await tap(cdp, centreOfBox(box)) + await expect(add).toHaveAttribute('data-armed', '') + await canvas(page).scrollIntoViewIfNeeded() + await tap(cdp, await clientOf(page, 800, 150)) + await expect(creationPanel(page)).toBeVisible() + }) + + /** Every handle box of the layer, read in the page, plus the visible marks. */ + async function readHandles(page: Page) { + return page.getByTestId('handle-layer').evaluate((layer) => { + const rect = (el: Element) => { + const { x, y, width, height } = el.getBoundingClientRect() + return { x, y, width, height } + } + const handles = [...layer.querySelectorAll('[data-handle]')].map( + (el) => ({ + kind: JSON.parse(el.getAttribute('data-handle')!).kind as string, + index: JSON.parse(el.getAttribute('data-handle')!) as { + index?: number + after?: number + }, + box: rect(el), + }), + ) + const mark = layer.querySelector( + 'g[aria-label^="Retirer"] rect:not([data-handle])[rx]', + ) + const vertices = [...layer.querySelectorAll('[data-vertex]')].map( + (g) => ({ + index: Number(g.getAttribute('data-vertex')), + chosen: g.getAttribute('aria-pressed') === 'true', + dot: rect(g.querySelector('circle[stroke="var(--color-ink)"]')!), + }), + ) + return { handles, mark: mark ? rect(mark) : null, vertices } + }) + } + + test('« Vertèbres thoraciques » zoomed: every chosen vertex keeps its bubble clear, on screen and light; a tap on « + » adds, « Défaire » restores', async ({ + page, + context, + requests, + }) => { + const actor = await editorActor('fr') + const seed = await seedDraft(actor, { + drawing: equineDrawing(), + shape: equineShape, + }) + await openEditor(page, dict, actor, seed.sheetId) + await expect(toolButton(page, dict, 'point')).toBeEnabled() + requests.forbid(actor.account.email, actor.account.password) + const cdp = await context.newCDPSession(page) + await select(page, 'Vertèbres thoraciques') + for (let step = 0; step < 2; step++) + await button(page, 'catalogue.zoom.in').click() + await canvas(page).scrollIntoViewIfNeeded() + const box = (await canvas(page).boundingBox())! + const inside = ( + b: { x: number; y: number; width: number; height: number }, + slack = 0, + ) => + b.x >= box.x - slack && + b.y >= box.y - slack && + b.x + b.width <= box.x + box.width + slack && + b.y + b.height <= box.y + box.height + slack + + const vertexBoxes = await page + .locator('[data-vertex] [data-handle]') + .evaluateAll((els) => + els.map((el) => { + const { x, y, width, height } = el.getBoundingClientRect() + return { x, y, width, height } + }), + ) + const shown = vertexBoxes + .map((b, index) => ({ b, index })) + .filter(({ b }) => + inside({ + ...b, + x: b.x + b.width / 2, + y: b.y + b.height / 2, + width: 0, + height: 0, + }), + ) + expect(shown.length, 'vertices on screen after the zoom').toBeGreaterThan(0) + + for (const { index } of shown) { + await page + .locator(`[data-vertex="${index}"]`) + .evaluate((el) => (el as SVGElement).focus({ preventScroll: true })) + await expect(page.locator(`[data-vertex="${index}"]`)).toHaveAttribute( + 'aria-pressed', + 'true', + ) + expect( + await canvas(page).evaluate((el) => [el.scrollLeft, el.scrollTop]), + ).toEqual([0, 0]) + const read = await readHandles(page) + const remove = read.handles.find((h) => h.kind === 'remove')! + for (const insert of read.handles.filter((h) => h.kind === 'insert')) { + const r = insert.box.width / 2 + const c = centreOfBox(insert.box) + const nearX = Math.max( + remove.box.x, + Math.min(c.x, remove.box.x + remove.box.width), + ) + const nearY = Math.max( + remove.box.y, + Math.min(c.y, remove.box.y + remove.box.height), + ) + expect( + Math.hypot(c.x - nearX, c.y - nearY) - r, + `vertex ${index}: « − » vs the « + » after ${insert.index.after}`, + ).toBeGreaterThanOrEqual(-1.5) + } + expect( + inside(remove.box, 1.5), + `vertex ${index}: « − » on the canvas`, + ).toBe(true) + for (const vertex of read.vertices) { + expect( + Math.abs(vertex.dot.width - (vertex.chosen ? 18 : 14)), + ).toBeLessThanOrEqual(1.5) + } + expect(read.mark, `vertex ${index}: the « − » mark`).not.toBeNull() + expect(Math.abs(read.mark!.width - 32)).toBeLessThanOrEqual(1.5) + expect(Math.abs(read.mark!.height - 26)).toBeLessThanOrEqual(1.5) + await expectFingerSizedHandles(page) + } + + // A real tap chooses a vertex, a tap on its « + » adds one; « Défaire » restores. + const count = () => page.locator('[data-vertex]').count() + const before = await count() + const read = await readHandles(page) + const target = shown + .map(({ index }) => ({ + index, + vertex: centreOfBox(vertexBoxes[index]), + insert: read.handles.find( + (h) => h.kind === 'insert' && h.index.after === index, + ), + })) + .find(({ insert }) => insert && inside(insert.box)) + expect(target, 'a vertex with its « + » on screen').toBeDefined() + await tap(cdp, target!.vertex) + await expect( + page.locator(`[data-vertex="${target!.index}"]`), + ).toHaveAttribute('aria-pressed', 'true') + const insertAt = centreOfBox( + (await readHandles(page)).handles.find( + (h) => h.kind === 'insert' && h.index.after === target!.index, + )!.box, + ) + await tap(cdp, insertAt) + await expect.poll(count).toBe(before + 1) + await historyButton(page, dict, 'undo').click() + await expect.poll(count).toBe(before) + }) +})