import { fr } from '@/i18n/fr' import type { CDPSession, Locator, Page, TestInfo } from '@playwright/test' import { expect, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { annotationList, clickDrawing, clientOf, creationPanel, editorActor, geometryField, historyButton, openEditor, openReferences, pickAnnotation, place, pointOf, reloadAccepting, revisionText, saveLine, seedDraft, selectionTag, selectTab, serverDocument, serverRevision, shapeWith, toolButton, UNSAVED_LINE, } from '../support/editor' // R1 (« Défaire » / « Refaire », « Désélectionner », Escape) and D6b (an empty tap or click // on the drawing deselects): the button, Escape by place, mouse, touch (with a recorder // of the events each step really produced) and the read-only twin at 375 px. const dict = fr const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' const properties = (page: Page) => page.getByTestId('annotation-properties') const overview = (page: Page) => page.getByTestId('annotation-overview') const box = (page: Page) => page.getByTestId('annotation-canvas') const liveRegion = (page: Page) => page .locator('p[aria-live="polite"]') .filter({ hasText: dict['editor.annotations.deselected'] }) /** A screenshot attached to the test report. */ async function shoot(info: TestInfo, name: string, target: Locator) { const png = await target.screenshot() await info.attach(name, { body: png, contentType: 'image/png' }) } const POINT = 'Pt Alpha' const ZONE = 'Zone Beta' const LINK = 'Accès Gamma' // Away from every annotation: the inner circle, the inner rect, the root, the box margin. const IN_CIRCLE = { x: 500, y: 300 } const IN_RECT = { x: 400, y: 700 } const IN_ROOT = { x: 20, y: 20 } const zone = { ...pointOf('zone-b', 'main', { cx: 0, cy: 0, r: 1 }, ZONE), kind: 'zone', geometry: { type: 'polygon', points: [ [100, 100], [250, 100], [250, 250], [100, 250], ], }, } const link = { id: 'link-g', kind: 'detail_trigger', view_id: 'main', category_id: 'cat-a', laterality: 'unpaired', geometry: { type: 'polygon', points: [ [750, 500], [900, 500], [900, 650], [750, 650], ], }, review_status: 'reviewed', name: { fr: LINK, en: LINK }, opens_view_id: 'detail-a', } async function open(page: Page, editable = true) { const actor = await editorActor('fr') const seed = await seedDraft(actor, { shape: shapeWith( pointOf('pt-a', 'main', { cx: 700, cy: 250, r: 30 }, POINT), zone, link, ), }) const saves: string[] = [] page.on('request', (request) => { if (request.url().includes('save_sheet_draft')) saves.push(request.url()) }) await openEditor(page, dict, actor, seed.sheetId) if (editable) await expect(toolButton(page, dict, 'point')).toBeEnabled() return { actor, seed, saves } } const frames = (page: Page) => page.evaluate( () => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(() => done())), ), ) async function expectSelected(page: Page, name: string) { await expect(selectionTag(page)).toContainText(name) await expect(properties(page)).toBeVisible() } async function expectDeselected(page: Page) { await expect(selectionTag(page)).toHaveCount(0) await expect(properties(page)).toHaveCount(0) await expect(overview(page)).toBeVisible() } /** A negative check: the state is still there after two animation frames. */ async function expectKept(page: Page, name: string) { await frames(page) await expectSelected(page, name) } const select = async (page: Page, name: string) => { await pickAnnotation(page, dict, name) await expectSelected(page, name) } /** Clicks a drawing point (coordinates recomputed at the press, LRN-104). */ const clickAt = (page: Page, at: { x: number; y: number }) => clickDrawing(page, at.x, at.y) async function mouseJitter(page: Page, x: number, y: number) { const at = await clientOf(page, x, y) await page.mouse.move(at.x, at.y) await page.mouse.down() await page.mouse.move(at.x + 2, at.y + 1) await page.mouse.up() } test.describe('deselect and D6b (editor, mouse and keyboard)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) 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('« Désélectionner »: live region, focus on the row, document unchanged', async ({ page, requests, }, info) => { const { actor, seed, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) const before = await serverDocument(seed.draftId) await select(page, POINT) await shoot(info, 'r1-panel-desktop', properties(page)) await page.evaluate(() => window.scrollTo(0, 0)) await shoot( info, 'r1-history-desktop', page .getByTestId('history-buttons') .locator('xpath=ancestor::*[.//*[@role="tablist"]][1]'), ) await properties(page) .getByRole('button', { name: dict['editor.annotations.deselect'] }) .click() await expectDeselected(page) await expect(liveRegion(page)).toHaveCount(1) await expect( annotationList(page, dict).getByRole('button', { name: POINT }), ).toBeFocused() await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) expect(await reloadAccepting(page), 'no unsaved-changes prompt').toEqual([]) await expect(saveLine(page)).toHaveText(revisionText(dict, 1)) expect(await serverRevision(seed.draftId)).toBe(1) expect(await serverDocument(seed.draftId)).toEqual(before) expect(saves).toEqual([]) }) test('Escape: canvas, field, delete dialog, references panel, tracing', async ({ page, requests, }) => { const { actor, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) // The canvas box focused: the selection goes. await select(page, POINT) await box(page).focus() await page.keyboard.press('Escape') await expectDeselected(page) // A field focused: nothing happens, the field keeps the focus. await select(page, POINT) const cx = geometryField(page, dict, 'cx') await cx.focus() await page.keyboard.press('Escape') await expectKept(page, POINT) await expect(cx).toBeFocused() // The delete dialog: only it closes (LRN-111: wait until it is gone). await properties(page) .getByRole('button', { name: dict['editor.action.delete'] }) .click() const dialog = page.getByRole('dialog') await expect(dialog).toBeVisible() await page.keyboard.press('Escape') await expect(dialog).toHaveCount(0) await expectKept(page, POINT) // The references panel: it closes, the selection stays, a second Escape deselects. await openReferences(page, dict) await page.keyboard.press('Escape') await expect(place(page, 'references')).toHaveCount(0) await expectKept(page, POINT) await box(page).focus() await page.keyboard.press('Escape') await expectDeselected(page) // A tracing: Escape cancels the tracing only. await select(page, POINT) await toolButton(page, dict, 'zone').click() await clickAt(page, { x: 300, y: 500 }) await clickAt(page, { x: 400, y: 500 }) const bar = page.getByTestId('tracing-bar') await expect(bar).toBeVisible() await box(page).focus() await page.keyboard.press('Escape') await expect(bar).toHaveCount(0) await expectKept(page, POINT) expect(saves).toEqual([]) }) test('mouse: empty clicks deselect, annotations select, the selected one stays', async ({ page, requests, }) => { const { actor, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) await select(page, POINT) for (const at of [IN_CIRCLE, IN_RECT, IN_ROOT]) { await clickAt(page, at) await expectDeselected(page) await select(page, POINT) } // The margin of the box beside the drawing (the box is 4:3, the drawing 5:4). const rect = (await box(page).boundingBox())! const content = [ await clientOf(page, 0, 0), await clientOf(page, 1000, 800), ] const band = (rect.x + content[0].x) / 2 expect( content[0].x - rect.x, 'a letterbox band left of the drawing', ).toBeGreaterThan(8) expect(band).toBeGreaterThan(rect.x) expect(band).toBeLessThan(content[0].x) expect(content[1].x).toBeLessThan(rect.x + rect.width) await page.mouse.click(band, rect.y + rect.height / 2) await expectDeselected(page) // Selecting: point, zone interior, link. const targets: [string, { x: number; y: number }][] = [ [POINT, { x: 700, y: 250 }], [ZONE, { x: 175, y: 175 }], [LINK, { x: 825, y: 575 }], ] for (const [name, at] of targets) { await clickAt(page, at) await expectSelected(page, name) } // The selected point and zone: click, double click and a 2 px jitter keep them. for (const [name, at] of targets.slice(0, 2)) { await clickAt(page, at) await expectSelected(page, name) await clickAt(page, at) await expectKept(page, name) const now = await clientOf(page, at.x, at.y) await page.mouse.dblclick(now.x, now.y) await expectKept(page, name) await mouseJitter(page, at.x, at.y) await expectKept(page, name) } await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) expect(saves).toEqual([]) }) test('the drawing does not move when the selection changes (no visible tag)', async ({ page, requests, }) => { const { actor } = await open(page) requests.forbid(actor.account.email, actor.account.password) const top = async () => (await box(page).boundingBox())!.y const before = await top() for (const [name, at] of [ [POINT, { x: 700, y: 250 }], [ZONE, { x: 175, y: 175 }], [LINK, { x: 825, y: 575 }], ] as [string, { x: number; y: number }][]) { await clickAt(page, at) await expectSelected(page, name) await expect(selectionTag(page)).toHaveCSS('position', 'absolute') expect(await top(), `${name} selected`).toBe(before) await clickAt(page, IN_ROOT) await expectDeselected(page) expect(await top(), `${name} deselected`).toBe(before) } }) test('zoom, pan, marker drag and Ctrl+wheel keep the selection; a 2 px jitter on empty deselects', async ({ page, requests, }) => { const { actor, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) await select(page, POINT) await page.getByRole('button', { name: dict['catalogue.zoom.in'] }).click() await expectKept(page, POINT) // A drag-pan of 20 px on empty. const from = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y) await page.mouse.move(from.x, from.y) await page.mouse.down() await page.mouse.move(from.x + 10, from.y + 4, { steps: 3 }) await page.mouse.move(from.x + 20, from.y + 8, { steps: 3 }) await page.mouse.up() await expectKept(page, POINT) // Ctrl+wheel over empty. const wheel = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y) await page.mouse.move(wheel.x, wheel.y) await page.keyboard.down('Control') await page.mouse.wheel(0, -120) await page.keyboard.up('Control') await expectKept(page, POINT) // Back to the whole drawing, then a marker drag: the selection stays, the move is // undone from the header. await page.getByRole('button', { name: dict['catalogue.zoom.fit'] }).click() const start = await clientOf(page, 700, 250) await page.mouse.move(start.x, start.y) await page.mouse.down() await page.mouse.move(start.x - 40, start.y + 30, { steps: 6 }) await page.mouse.up() await expectKept(page, POINT) await expect(saveLine(page)).toHaveText(UNSAVED_LINE) await historyButton(page, dict, 'undo').click() await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) await expectSelected(page, POINT) // A 2 px jitter on empty is a tap. await mouseJitter(page, IN_CIRCLE.x, IN_CIRCLE.y) await expectDeselected(page) expect(saves).toEqual([]) }) test('a typed value is applied by the click that deselects; « Désélectionner » commits in one click', async ({ page, requests, }) => { const { actor, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) const cx = geometryField(page, dict, 'cx') // Valid value, no blur, ONE click on the drawing. await select(page, POINT) await expect(cx).toHaveValue('700') await cx.fill('720') await clickAt(page, IN_CIRCLE) await expectDeselected(page) await expect(saveLine(page)).toHaveText(/1 modification non enregistrée/) // Undo reverts the value. await historyButton(page, dict, 'undo').click() await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) await select(page, POINT) await expect(cx).toHaveValue('700') // « Désélectionner » with an unblurred refused value: closed at once, unchanged. const deselect = properties(page).getByRole('button', { name: dict['editor.annotations.deselect'], }) await cx.fill('abc') await deselect.click() await expectDeselected(page) await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE) await select(page, POINT) await expect(cx).toHaveValue('700') // « Désélectionner » with an unblurred valid value: committed and closed. await cx.fill('730') await deselect.click() await expectDeselected(page) await expect(saveLine(page)).toHaveText(/1 modification non enregistrée/) await select(page, POINT) await expect(cx).toHaveValue('730') expect(saves).toEqual([]) }) }) interface Recorded { type: string primary: boolean pointerType: string anno: string | null /** Distance a pointermove covered since the previous one of the same pointer. */ dist: number } /** A capture-phase recorder: what the page really received for each gesture. */ async function startRecorder(page: Page) { await page.evaluate(() => { const w = window as unknown as { __rec: Recorded[]; __live: string[] } w.__rec = [] w.__live = [] const anno = (target: EventTarget | null) => target instanceof Element ? (target.closest('[data-anno-id]')?.getAttribute('data-anno-id') ?? null) : null const last = new Map() const types = ['pointerdown', 'pointermove', 'pointerup', 'pointercancel'] for (const type of [...types, 'click']) document.addEventListener( type, (event) => { const pointer = event as PointerEvent const before = last.get(pointer.pointerId) const dist = type === 'pointermove' && before ? Math.hypot( pointer.clientX - before.x, pointer.clientY - before.y, ) : 0 last.set(pointer.pointerId, { x: pointer.clientX, y: pointer.clientY, }) w.__rec.push({ type, primary: pointer.isPrimary, pointerType: pointer.pointerType ?? '', anno: anno(event.target), dist, }) }, true, ) for (const live of document.querySelectorAll('p[aria-live="polite"]')) new MutationObserver(() => w.__live.push(live.textContent ?? '')).observe( live, { childList: true, characterData: true, subtree: true }, ) }) } async function takeRecord(page: Page) { return page.evaluate(() => { const w = window as unknown as { __rec: Recorded[]; __live: string[] } return { events: w.__rec.splice(0), live: w.__live.splice(0) } }) } /** The numbers the guard assertions read from a step's events. */ function guards(events: Recorded[]) { const of = (type: string) => events.filter((e) => e.type === type) return { nonPrimary: of('pointerdown').filter((e) => !e.primary).length, clicks: of('click').length, cancels: of('pointercancel').length, moved: of('pointermove').reduce((sum, e) => sum + e.dist, 0), } } function summary(events: Recorded[]): string { const count = (pick: (e: Recorded) => boolean) => events.filter(pick).length const clicks = events.filter((e) => e.type === 'click') return [ `pointerdown primary ${count((e) => e.type === 'pointerdown' && e.primary)}`, `pointerdown non-primary ${count((e) => e.type === 'pointerdown' && !e.primary)}`, `pointerup ${count((e) => e.type === 'pointerup')}`, `pointercancel ${count((e) => e.type === 'pointercancel')}`, `pointermove ${count((e) => e.type === 'pointermove')} (moved ${Math.round(guards(events).moved)} px)`, `click ${clicks.length}`, `click targets [${clicks.map((c) => c.anno ?? 'none').join(', ')}]`, ].join('; ') } type TouchPoint = { x: number; y: number } const touch = ( cdp: CDPSession, type: 'touchStart' | 'touchMove' | 'touchEnd', points: TouchPoint[], ) => cdp.send('Input.dispatchTouchEvent', { type, touchPoints: points.map((p, id) => ({ x: p.x, y: p.y, id })), }) async function tap(cdp: CDPSession, at: TouchPoint) { await touch(cdp, 'touchStart', [at]) await touch(cdp, 'touchEnd', []) } async function drag(cdp: CDPSession, from: TouchPoint, to: TouchPoint) { await touch(cdp, 'touchStart', [from]) for (let step = 1; step <= 6; step++) await touch(cdp, 'touchMove', [ { x: from.x + ((to.x - from.x) * step) / 6, y: from.y + ((to.y - from.y) * step) / 6, }, ]) await touch(cdp, 'touchEnd', []) } /** The id of the annotated element under a client point, null on empty drawing. */ const annotationUnder = (page: Page, at: TouchPoint) => page.evaluate( ({ x, y }) => document .elementFromPoint(x, y) ?.closest('[data-anno-id]') ?.getAttribute('data-anno-id') ?? null, at, ) test.describe('deselect and D6b (touch, editor at 1 280 px)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000, hasTouch: true, viewport: { width: 1280, height: 800 }, }) test.beforeEach(async ({ context }, info) => { test.skip(isPhone(info), 'touch at 1 280 px runs on desktop') // 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('taps deselect once, near annotations and the canvas bottom; drags, two fingers and pinch keep', async ({ page, context, requests, }, info) => { const { actor, saves } = await open(page) requests.forbid(actor.account.email, actor.account.password) const cdp = await context.newCDPSession(page) await startRecorder(page) const report = async (step: string) => { const { events, live } = await takeRecord(page) const line = `${summary(events)}; live ${JSON.stringify(live)}` info.annotations.push({ type: `recorder ${step}`, description: line }) console.log(`RECORDER ${step}: ${line}`) return { events, live } } const announced = (live: string[]) => live.some((text) => text.includes(dict['editor.annotations.deselected'])) await box(page).scrollIntoViewIfNeeded() // a. A tap on the inner circle. await select(page, POINT) await takeRecord(page) await tap(cdp, await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y)) await expectDeselected(page) const plain = await report('a tap on empty') expect(announced(plain.live)).toBe(true) // b. Empty drawing, a zone about 40 px below the tap. await select(page, POINT) await takeRecord(page) const top = await clientOf(page, 175, 100) const above = { x: top.x, y: top.y - 40 } expect(await annotationUnder(page, above)).toBeNull() await tap(cdp, above) await expectDeselected(page) await expect(creationPanel(page)).toHaveCount(0) await report('b tap 40 px above a zone') // c. Within 36 px of the canvas bottom, above the add buttons. await select(page, POINT) await takeRecord(page) await box(page).scrollIntoViewIfNeeded() const rect = (await box(page).boundingBox())! const bottom = { x: rect.x + rect.width / 2, y: rect.y + rect.height - 36 } expect(bottom.y).toBeLessThan(800) expect(await annotationUnder(page, bottom)).toBeNull() await tap(cdp, bottom) await expectDeselected(page) await expect(creationPanel(page)).toHaveCount(0) await report('c tap 36 px above the canvas bottom') // d. About 6 px outside a marker: the marker or nothing, never both. await select(page, ZONE) await takeRecord(page) const centre = await clientOf(page, 700, 250) const edge = await clientOf(page, 730, 250) const near = { x: edge.x + 6, y: centre.y } await tap(cdp, near) await frames(page) const nearRecord = await report('d tap 6 px outside a marker') const marker = await selectionTag(page).count() if (marker > 0) { await expect(selectionTag(page)).toContainText(POINT) expect(announced(nearRecord.live), 'selected AND announced').toBe(false) } else { await expectDeselected(page) } info.annotations.push({ type: 'near-miss outcome', description: marker > 0 ? 'marker selected' : 'deselected', }) // e. One-finger drag on empty drawing. await select(page, POINT) await takeRecord(page) const dragFrom = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y) await drag(cdp, dragFrom, { x: dragFrom.x + 40, y: dragFrom.y + 20 }) await expectKept(page, POINT) const e = guards((await report('e one-finger drag')).events) expect(e.clicks, 'e: no click after a drag').toBe(0) expect(e.moved, 'e: moved more than the 4 px slop').toBeGreaterThan(4) // f. Two-finger tap on empty drawing. await takeRecord(page) const two = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y) const pair = [two, { x: two.x + 40, y: two.y }] await touch(cdp, 'touchStart', pair) await touch(cdp, 'touchEnd', []) await expectKept(page, POINT) const f = guards((await report('f two-finger tap')).events) expect(f.nonPrimary, 'f: a non-primary pointerdown').toBeGreaterThan(0) expect(f.clicks, 'f: no click').toBe(0) // g. Pinch on empty drawing. await takeRecord(page) const mid = await clientOf(page, IN_CIRCLE.x, IN_CIRCLE.y) await touch(cdp, 'touchStart', [ { x: mid.x - 20, y: mid.y }, { x: mid.x + 20, y: mid.y }, ]) for (let step = 1; step <= 5; step++) await touch(cdp, 'touchMove', [ { x: mid.x - 20 - step * 8, y: mid.y }, { x: mid.x + 20 + step * 8, y: mid.y }, ]) await touch(cdp, 'touchEnd', []) await expectKept(page, POINT) const g = guards((await report('g pinch')).events) expect(g.nonPrimary, 'g: a non-primary pointerdown').toBeGreaterThan(0) expect(g.clicks, 'g: no click').toBe(0) expect(saves).toEqual([]) }) }) test.describe('deselect and D6b (read-only twin at 375 px)', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { test.skip(!isPhone(info), 'the twin is the phone view') // 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('tap a marker, tap the rect: deselected, focus on the box; drag and two fingers keep', async ({ page, context, requests, }, info) => { const { actor, saves } = await open(page, false) requests.forbid(actor.account.email, actor.account.password) await selectTab(page, dict, 'annotations') const canvas = page.getByTestId('catalogue-canvas') await expect(canvas).toBeVisible() const cdp = await context.newCDPSession(page) await startRecorder(page) const report = async (step: string) => { const { events } = await takeRecord(page) info.annotations.push({ type: `recorder ${step}`, description: summary(events), }) console.log(`RECORDER ${step}: ${summary(events)}`) return events } /** Client point of a drawing coordinate, through the twin's own svg. */ const twinAt = async (x: number, y: number) => { await canvas.scrollIntoViewIfNeeded() return page .getByTestId('catalogue-canvas-drawing') .locator('svg') .first() .evaluate( (svg, at) => { const root = svg as unknown as SVGSVGElement const p = root.createSVGPoint() p.x = at.x p.y = at.y const m = p.matrixTransform(root.getScreenCTM()!) return { x: m.x, y: m.y } }, { x, y }, ) } const markerAt = async () => { const found = await page .getByTestId('catalogue-canvas-drawing') .locator('[data-anno-id="pt-a"]') .first() .boundingBox() return { x: found!.x + found!.width / 2, y: found!.y + found!.height / 2 } } await takeRecord(page) await tap(cdp, await markerAt()) await expect(selectionTag(page)).toContainText(POINT) await shoot(info, 'r1-panel-375', properties(page)) await report('twin tap on a marker') await takeRecord(page) await tap(cdp, await twinAt(IN_RECT.x, IN_RECT.y)) await expect(selectionTag(page)).toHaveCount(0) await expect(canvas).toBeFocused() await report('twin tap on the rect') await tap(cdp, await markerAt()) await expect(selectionTag(page)).toContainText(POINT) await takeRecord(page) const from = await twinAt(IN_CIRCLE.x, IN_CIRCLE.y) await drag(cdp, from, { x: from.x + 30, y: from.y + 10 }) await frames(page) await expect(selectionTag(page)).toContainText(POINT) const drag1 = guards(await report('twin one-finger drag')) expect(drag1.clicks, 'twin drag: no click').toBe(0) expect( drag1.cancels > 0 || drag1.moved > 4, 'twin drag: pointercancel, or movement recorded', ).toBe(true) await takeRecord(page) const two = await twinAt(IN_CIRCLE.x, IN_CIRCLE.y) await touch(cdp, 'touchStart', [two, { x: two.x + 30, y: two.y }]) await touch(cdp, 'touchEnd', []) await frames(page) await expect(selectionTag(page)).toContainText(POINT) const pair = guards(await report('twin two-finger tap')) expect(pair.nonPrimary, 'twin: a non-primary pointerdown').toBeGreaterThan( 0, ) expect(pair.clicks, 'twin two-finger: no click').toBe(0) expect(saves).toEqual([]) }) test('the twin does not move when the selection changes (no visible tag)', async ({ page, context, requests, }) => { const { actor } = await open(page, false) requests.forbid(actor.account.email, actor.account.password) await selectTab(page, dict, 'annotations') const canvas = page.getByTestId('catalogue-canvas') await expect(canvas).toBeVisible() await canvas.scrollIntoViewIfNeeded() const cdp = await context.newCDPSession(page) const drawing = page .getByTestId('catalogue-canvas-drawing') .locator('svg') .first() const twinAt = (x: number, y: number) => drawing.evaluate( (svg, at) => { const root = svg as unknown as SVGSVGElement const p = root.createSVGPoint() p.x = at.x p.y = at.y const m = p.matrixTransform(root.getScreenCTM()!) return { x: m.x, y: m.y } }, { x, y }, ) const top = async () => (await canvas.boundingBox())!.y const before = await top() for (const [name, at] of [ [POINT, { x: 700, y: 250 }], [ZONE, { x: 175, y: 175 }], [LINK, { x: 825, y: 575 }], ] as [string, { x: number; y: number }][]) { await tap(cdp, await twinAt(at.x, at.y)) await expect(selectionTag(page)).toHaveCount(1) await expect(selectionTag(page)).toContainText(name) await expect(selectionTag(page)).toHaveCSS('position', 'absolute') expect(await top(), `${name} selected`).toBe(before) await tap(cdp, await twinAt(IN_RECT.x, IN_RECT.y)) await expect(selectionTag(page)).toHaveCount(0) expect(await top(), `${name} deselected`).toBe(before) } }) test('Escape closes « Plus » first, then deselects the twin', async ({ page, context, requests, }) => { const { actor, saves } = await open(page, false) requests.forbid(actor.account.email, actor.account.password) await selectTab(page, dict, 'annotations') const canvas = page.getByTestId('catalogue-canvas') await expect(canvas).toBeVisible() const cdp = await context.newCDPSession(page) await canvas.scrollIntoViewIfNeeded() const marker = await page .getByTestId('catalogue-canvas-drawing') .locator('[data-anno-id="pt-a"]') .first() .boundingBox() await tap(cdp, { x: marker!.x + marker!.width / 2, y: marker!.y + marker!.height / 2, }) await expect(selectionTag(page)).toContainText(POINT) const more = page.locator('#editor-tabs-more-button') await more.click() await expect(more).toHaveAttribute('aria-expanded', 'true') await canvas.focus() await page.keyboard.press('Escape') await expect(more).toHaveAttribute('aria-expanded', 'false') await expect(more).toBeFocused() await expectKept(page, POINT) await page.keyboard.press('Escape') await expectDeselected(page) await expect(liveRegion(page)).toHaveCount(1) expect(saves).toEqual([]) }) })