diff --git a/apps/app/e2e/shell/editor-annotations.spec.ts b/apps/app/e2e/shell/editor-annotations.spec.ts index 2e267843..ef9919dd 100644 --- a/apps/app/e2e/shell/editor-annotations.spec.ts +++ b/apps/app/e2e/shell/editor-annotations.spec.ts @@ -746,4 +746,118 @@ test.describe('editor annotations (A3)', () => { expect(await gutter()).toBe('auto') }) }) + + // Rev 4 point 3 (board 04 C, criterion 27): « Reprendre le tracé » edits the closed shape + // with its handles; the document and the history wait for « Créer ». + test('a resumed trace is edited with its handles, then created in one step', async ({ + page, + requests, + }) => { + await page.setViewportSize({ width: 1280, height: 800 }) + const { actor } = await openAnnotations(page) + requests.forbid(actor.account.email, actor.account.password) + const line = page.getByTestId('gesture-line') + const strip = page.getByTestId('edit-strip') + const ghostPoints = async () => + ( + (await page + .getByTestId('overlay-ghost') + .locator('polygon') + .first() + .getAttribute('points')) ?? '' + ) + .trim() + .split(/\s+/) + .map((pair) => pair.split(',').map(Number)) + const handle = (name: string) => + page.getByRole('button', { name, exact: true }) + const button = (_page: Page, key: string) => handle(dict[key]) + const pressHandle = async (name: string) => { + const box = (await handle(name).locator('[data-handle]').boundingBox())! + await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2) + } + + await tool(page, 'zone').click() + for (const [x, y] of [ + [200, 150], + [450, 150], + [500, 350], + [350, 450], + [150, 350], + ]) + await clickDrawing(page, x, y) + await button(page, 'editor.annotations.trace_close').click() + await expect(creationDialog(page, 'zone')).toBeVisible() + await creation(page) + .getByLabel(dict['editor.annotations.name_fr']) + .fill('Tibia') + const saved = await saveLine(page).textContent() + await expectNoShift(page, async () => { + await creationDialog(page, 'zone') + .getByRole('button', { + name: dict['editor.annotations.creation.resume'], + }) + .click() + await expect(creationDialog(page, 'zone')).toHaveCount(0) + await expect(handle('Sommet 1 de Tibia')).toBeAttached() + }) + await expect(strip).toContainText(dict['editor.annotations.strip.resumed']) + await expect( + strip.getByRole('button', { name: dict['editor.annotations.trace_pop'] }), + ).toHaveCount(0) + await expect( + page.getByRole('group', { name: 'Sommets de Tibia', exact: true }), + ).toBeAttached() + await expectAccessible(page, 'a resumed trace with its handles') + + // A vertex dragged: the ghost changes, said without « Défaire »; nothing else moves. + const from = await clientOf(page, 450, 150) + const to = await clientOf(page, 480, 110) + await page.mouse.move(from.x, from.y) + await page.mouse.down() + await page.mouse.move(to.x, to.y, { steps: 6 }) + await page.mouse.up() + await expect(line).toContainText( + dict['editor.annotations.message.vertex_moved'], + ) + await expect( + line.getByRole('button', { name: dict['editor.history.undo_title'] }), + ).toHaveCount(0) + const [, moved] = await ghostPoints() + expect(Math.abs(moved[0] - 480)).toBeLessThan(3) + expect(Math.abs(moved[1] - 110)).toBeLessThan(3) + + // « + » then « − »: six vertices, then five again; the document never changed. + await pressHandle('Ajouter un sommet après le sommet 1 de Tibia') + await expect.poll(async () => (await ghostPoints()).length).toBe(6) + await expect(line).toContainText( + dict['editor.annotations.message.vertex_added'], + ) + await pressHandle('Sommet 4 de Tibia') + await pressHandle('Retirer le sommet 4 de Tibia') + await expect.poll(async () => (await ghostPoints()).length).toBe(5) + await expect(saveLine(page)).toHaveText(saved ?? '') + await expect(historyButton(page, dict, 'undo')).toHaveAttribute( + 'aria-disabled', + 'true', + ) + const edited = await ghostPoints() + + await expectNoShift(page, async () => { + await button(page, 'editor.annotations.back_to_properties').click() + await expect(creationDialog(page, 'zone')).toBeVisible() + }) + await expect( + creation(page).getByLabel(dict['editor.annotations.name_fr']), + ).toHaveValue('Tibia') + await fillCreation(page, { fr: 'Tibia', en: 'Tibia' }) + await createFromPanel(page) + await expect(selectionTag(page)).toContainText('Tibia') + expect(await shownPoints(page)).toEqual(edited) + // One step: a single undo removes the whole new zone. + const rows = list(page).getByRole('button') + await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(1) + await historyButton(page, dict, 'undo').click() + await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(0) + }) }) diff --git a/apps/app/e2e/shell/editor-touch.spec.ts b/apps/app/e2e/shell/editor-touch.spec.ts index 2aeebcd1..9582f8af 100644 --- a/apps/app/e2e/shell/editor-touch.spec.ts +++ b/apps/app/e2e/shell/editor-touch.spec.ts @@ -3,6 +3,7 @@ import type { CDPSession, Page, TestInfo } from '@playwright/test' import { expect, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { + annotationList, clientOf, creationPanel, editorActor, @@ -438,3 +439,115 @@ for (const width of WIDTHS) { }) }) } + +// Rev 4 point 3 (board 04 C, criterion 27): a resumed trace edited by finger at 1 180 px. +test.describe('a resumed trace by finger at 1 180 px (rev 4)', () => { + 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 ghostPoints = async (page: Page) => + ( + (await page + .getByTestId('overlay-ghost') + .locator('polygon') + .first() + .getAttribute('points')) ?? '' + ) + .trim() + .split(/\s+/) + .map((pair) => pair.split(',').map(Number)) + const centreOf = async (page: Page, name: string) => { + const hit = page + .getByRole('button', { name, exact: true }) + .locator('[data-handle]') + const box = (await hit.boundingBox())! + return { x: box.x + box.width / 2, y: box.y + box.height / 2 } + } + + test('drag with the loupe, « + », « − », back, « Créer »: one undo removes it', async ({ + page, + context, + requests, + }) => { + const { actor } = await open(page) + requests.forbid(actor.account.email, actor.account.password) + const cdp = await context.newCDPSession(page) + await toolButton(page, dict, 'zone').click() + await canvas(page).scrollIntoViewIfNeeded() + // Quick taps, each within the absorber's 400 ms of the last: each one places. + for (const [x, y] of [ + [100, 100], + [260, 90], + [270, 250], + [180, 300], + [80, 230], + ]) + await tap(cdp, await clientOf(page, x, y)) + await button(page, 'editor.annotations.trace_close').click() + await expect(creationPanel(page)).toBeVisible() + await creationPanel(page) + .getByLabel(dict['editor.annotations.name_fr']) + .fill('Tibia') + await expectNoShift(page, async () => { + await button(page, 'editor.annotations.creation.resume').click() + await expect(creationPanel(page)).toHaveCount(0) + }) + await expectFingerSizedHandles(page) + const undoHeld = historyButton(page, dict, 'undo') + await expect(undoHeld).toHaveAttribute('aria-disabled', 'true') + + await canvas(page).scrollIntoViewIfNeeded() + const from = await clientOf(page, 260, 90) + await dragWithLoupe(page, cdp, from, { x: from.x + 30, y: from.y + 30 }) + await expect(message(page)).toContainText( + dict['editor.annotations.message.vertex_moved'], + ) + expect((await ghostPoints(page))[1]).not.toEqual([260, 90]) + + await tap( + cdp, + await centreOf(page, 'Ajouter un sommet après le sommet 1 de Tibia'), + ) + await expect.poll(async () => (await ghostPoints(page)).length).toBe(6) + await tap(cdp, await centreOf(page, 'Sommet 4 de Tibia')) + await tap(cdp, await centreOf(page, 'Retirer le sommet 4 de Tibia')) + await expect.poll(async () => (await ghostPoints(page)).length).toBe(5) + await expect(undoHeld).toHaveAttribute('aria-disabled', 'true') + const edited = await ghostPoints(page) + + await expectNoShift(page, async () => { + await button(page, 'editor.annotations.back_to_properties').click() + await expect(creationPanel(page)).toBeVisible() + }) + const panel = creationPanel(page) + await expect( + panel.getByLabel(dict['editor.annotations.name_fr']), + ).toHaveValue('Tibia') + await panel.getByLabel(dict['editor.annotations.name_en']).fill('Tibia') + await panel + .getByLabel(dict['editor.annotations.laterality']) + .selectOption('unpaired') + await panel + .getByRole('button', { name: dict['editor.annotations.create'] }) + .click() + await expect(creationPanel(page)).toHaveCount(0) + await expect(selectionTag(page)).toContainText('Tibia') + expect(await shownPoints(page)).toEqual(edited) + // One step: a single undo removes the whole new zone. + const rows = annotationList(page, dict).getByRole('button') + await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(1) + await historyButton(page, dict, 'undo').click() + await expect(rows.filter({ hasText: 'Tibia' })).toHaveCount(0) + }) +}) diff --git a/apps/app/src/components/editor/annotations/CreationCommands.tsx b/apps/app/src/components/editor/annotations/CreationCommands.tsx index 4b003529..b964e0b8 100644 --- a/apps/app/src/components/editor/annotations/CreationCommands.tsx +++ b/apps/app/src/components/editor/annotations/CreationCommands.tsx @@ -1,26 +1,18 @@ import Button from '@/components/ui/Button' import { askCreation } from '@/editor/annotations/creationAsk' -import { backToProperties, popVertex } from '@/editor/annotations/creationWork' -import type { Creation } from '@/editor/annotations/workStore' +import { backToProperties } from '@/editor/annotations/creationWork' import { useT } from '@/i18n/useT' import EditorGlyph from '../EditorGlyph' const COMMAND = 'min-h-11 gap-1.5 xl:min-h-9' -/** The vertices a resumed tracing holds now; null for a point. */ -const tracedCount = (work: Creation) => - !work.closed && work.pending.geometry.type === 'polygon' - ? work.pending.geometry.points.length - : null - /** * Board 04 C: the dialog hidden by « Replacer le point » or « Reprendre le tracé ». « Revenir - * aux propriétés » shows it again (a tracing closes first, three vertices at least); - * « Abandonner » asks first, the shape always exists (A12). + * aux propriétés » shows it again with the shape as it is now (a resumed trace stays closed: + * its handles edit it); « Abandonner » asks first, the shape always exists (A12). */ -export default function CreationCommands({ creation }: { creation: Creation }) { +export default function CreationCommands() { const t = useT() - const count = tracedCount(creation) return (
backToProperties()} + onClick={backToProperties} > {t('editor.annotations.back_to_properties')} - {count !== null && ( - - )}