Files
faunosteo/apps/app/e2e/shell/editor-deselect.spec.ts
T
bchanot cd794f3c39 feat(editor): properties dialog over the column, transactional save
U2 Task 6 (A1, A2, A3, A9, A10, R-3, R-5, R-6, R-14, R-16).

- Dialog: `anchor` places the panel at the column's left and width,
  from its top, under a 22 % ink veil that ignores clicks; the visual
  viewport below 320 px; centred without an anchor box.
- Navigation: `annotation` layer (LAYERS, EditorView, history entry,
  leave guards, left-draft flag); Back closes, Forward reopens.
- AnnotationDialog: read body, « Modifier » form (CreationFields with
  « Couleur », missingFields, R-3 messages), one `update` on the
  current annotation by id, « Marquer comme relu », « Modifier la
  forme », « Supprimer »; read-only flip keeps the draft.
- The column always shows the overview, selected row marked; Enter on
  it, a second click or a double click, the strip's « Propriétés »
  open the dialog. « Aller à » focuses the row (R-5).
- Read-only twin: strip and read-only dialog at 1 024 px and wider,
  inline read body below. PropertiesPanel and AnnotationFields gone.
- Strip lead 256 px and a fixed status slot, so the commands fit at
  1 024 px and a status change moves nothing.
- e2e: `aside-content` exemption removed; scroll-to-top workarounds
  of editor-geometry, editor-zones and editor-journey removed.

Removed assertions mapped:
  editor-annotations-tab.test.tsx:
  - selectFromList waited for `annotation-properties` -> waits for the strip's « Propriétés » (selection without dialog, A1)
  - refused place: issues block `annotation-geometry-issues` in the panel -> the strip notice alert (present, then gone)
  - keyboard creation / C26 confirmation: `annotation-properties` after create -> strip « Propriétés » (new element selected)
  - Désélectionner from the panel -> « Désélectionner » in the strip (all 7 tests); « panel closes » -> strip has no « Propriétés »
  - undo after deselect (typed name) -> handle key series then deselect then undo
  - commits a valid typed value once without blur (name field) -> a pending handle key series committed once by the strip deselect
  - a refused typed value: the panel closes (two tests: strip deselect, tap deselect) -> removed: no field outside the dialog; the dialog's draft writes nothing before « Enregistrer » (new dialog tests)
  - not offered while a replace tracing runs: panel's Désélectionner absent -> strip offers neither « Désélectionner » nor « Propriétés » during the tracing
  - tap: isDeselected read `annotation-properties` -> strip « Propriétés » absent; link select -> strip title data-selection
  - tap: undo after tap deselect (typed name) -> handle series; typed value committed on blur -> handle series committed on blur
  - strip geometry issues: list read in the panel -> list read in the properties dialog's issues block
  - a new commit replaces the message (typed name) -> « Marquer comme relu » in the dialog
  editor-escape.test.tsx:
  - `panel()` = `annotation-properties` -> the strip's « Propriétés » or the phone twin's inline read body
  - Escape from a panel button (« Marquer comme relu ») -> from the selected row in the side column: focus on the row
  - after A then B from the panel (via « Toutes les annotations ») -> select A, select B, Escape from a button of the side column: focus on B's row
  - a text field (panel « Nom (FR) ») -> the overview « Filtrer par nom »
  - redraw via the panel's « Remplacer par un polygone » -> the strip's command
  - modal / delete dialog opened by the panel's « Supprimer » -> « Supprimer » of the properties dialog
  - read-only width: hidden `annotation-properties` -> hidden strip « Propriétés » of the kept edit body
  editor-history-buttons.test.tsx (typed text and the press, 8 tests): the annotation's committed « Nom (FR) » field of the panel -> the sheet's committed « Nom (FR) » on Général (same TextField commit-on-blur path; annotation fields are now a dialog draft)
  editor-focus-request.test.tsx: « Aller à » focuses `data-properties-heading` inside `annotation-properties` -> focuses the annotation's row, marked aria-current, no dialog (R-5)
  editor-sections.test.tsx: « Aller à » with nothing in progress focused the properties heading -> focuses the row (R-5); creation kept: no `annotation-properties` -> no strip « Propriétés »
  editor-overview.test.tsx (edit and read-only): row opens `annotation-properties`, « Toutes les annotations » returns -> row selects, stays marked aria-current, no dialog; strip « Désélectionner » returns focus to the row; filter kept across select and « Désélectionner »
  editor-citations-guards.test.tsx: LAYERS_TOP_DOWN gains 'annotation' at the bottom
  editor-keep-alive.test.tsx: `annotation-properties` visible after the round trip -> the strip's « Propriétés » visible (selection kept)
  editor-no-loss.test.tsx: ids `ro-annotation-name-fr` and `annotation-name-fr` (both panels' fields) -> the twin's inline read body (no ids), then the dialog edit form's `annotation-edit-fr`, kept through a flip to 800 px, no duplicate id; « Aller à » visible `annotation-properties` -> visible `annotation-read` (inline twin), none at 1 280
  editor-point-edit.test.tsx / editor-zone-edit.test.tsx: `select()` waited for `annotation-properties` and returned it -> waits for the strip's « Propriétés » and returns the strip (its « Désélectionner » and « Remplacer par un polygone » moved there)
  - move mode Escape: `annotation-properties` still there -> the strip's « Propriétés » back after the mode
  - « Toutes les annotations » asks first during a started move -> Enter on the selected row asks first (no dialog), and the strip offers neither « Propriétés » nor « Désélectionner » during the mode
  - Escape from the handle / slider: `annotation-properties` gone -> the strip's « Propriétés » gone
  - I-3 touch tap: `annotation-properties` gone -> the strip's « Propriétés » gone
  e2e (sandbox):
  - support/layout.ts: `aside-content` exemption removed (ShiftExemption type, the loose compare); every `swaps`/`SWAPS` argument removed (editor-annotations, editor-zones, editor-geometry)
  - support/editor.ts pickAnnotation: clicked « Toutes les annotations » first when the panel showed -> the overview is always shown: clicks the row, then scrolls back to the top (the page no longer shortens)
  - editor-annotations: `annotation-properties` visible after a creation -> strip with « Propriétés »; review toggle and « Supprimer » of the panel -> the properties dialog's; a jitter click on the selected point now opens the dialog (A1), closed by Escape before the drag; handle names exact (the marked row shares the prefix); trace close moved out of expectNoShift (creation panel until Task 7, shortcut + TODO)
  - editor-deselect: `annotation-properties` -> the strip with « Propriétés » or the twin's inline read body; Escape in a field: panel « Nom (FR) » -> overview filter; delete dialog from the panel -> from the properties dialog (Escape closes it, then the dialog); « a typed value is applied by the click that deselects » (name field, refused blank) -> a pending point-handle key series applied by the deselecting click and by « Désélectionner » (refused value: no field outside the dialog); « the selected one stays » -> a second click, double click and jitter open the dialog, Escape closes it, selection kept
  - editor-geometry: `annotation-geometry-issues` in the panel -> read in the properties dialog, then the strip notice; after the refusal the error count unchanged; scroll-to-top workaround removed
  - editor-zones: panel « Désélectionner » -> strip; scroll-to-top after pickAnnotation removed (helper does it)
  - editor-structures: panel « Supprimer » -> properties dialog « Supprimer », confirmation over it
  - editor-journey: `#annotation-name-fr` committed field + `#annotation-laterality` -> the dialog's edit form, one « Enregistrer »; scroll-to-top removed
  - editor-shell / editor-shell-journeys: « Aller à » focus on `data-properties-heading` -> the annotation's row (aria-current), no dialog (R-5)
  - editor-shell-layout: focus kind `annotation-properties` -> removed (the overview is the side)
2026-11-17 22:01:57 +01:00

894 lines
31 KiB
TypeScript

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,
historyButton,
openEditor,
expectNoDialog,
findingDialog,
layersSettled,
openCitations,
pickAnnotation,
place,
pointOf,
reloadAccepting,
revisionText,
saveLine,
seedDraft,
selectionTag,
selectTab,
serverDocument,
serverRevision,
shapeWith,
toolButton,
twinSelectionTag,
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'
/**
* The selection's commands (U2 Task 6: the properties left the side column): the strip
* that offers « Propriétés », or the phone twin's inline read body.
*/
const properties = (page: Page) =>
page.locator(
'[data-testid="edit-strip"]:has([data-properties-button]), [data-annotation-aside] [data-testid="annotation-read"]',
)
/** A text field of the workspace, outside any dialog: the overview's filter. */
const filterField = (page: Page) =>
page.getByRole('searchbox', { name: dict['editor.overview.filter'] })
const pointHandle = (page: Page) => page.getByTestId('point-handle')
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<void>((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 dialog, 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 name = filterField(page)
await name.focus()
await page.keyboard.press('Escape')
await expectKept(page, POINT)
await expect(name).toBeFocused()
// The delete dialog over the properties dialog: only it closes (LRN-111: wait until
// it is gone), then the properties dialog; the selection stays.
await properties(page)
.getByRole('button', { name: dict['editor.annotations.properties'] })
.click()
const sheet = page.getByRole('dialog', { name: POINT })
await sheet
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
const ask = page.getByRole('dialog', {
name: new RegExp(dict['editor.action.delete']),
})
await expect(ask).toBeVisible()
await page.keyboard.press('Escape')
await expect(ask).toHaveCount(0)
await expect(sheet).toBeVisible()
await page.keyboard.press('Escape')
await expect(sheet).toHaveCount(0)
await expectKept(page, POINT)
// The references dialog (over the finding dialog over Constats): Escape closes it
// only, a second one the finding dialog, the selection stays, back on Annotations a
// third Escape deselects.
await openCitations(page, dict, 'Constat A')
await page.keyboard.press('Escape')
await expect(place(page, 'citations')).toHaveCount(0)
await expect(findingDialog(page)).toBeVisible()
await page.keyboard.press('Escape')
await expectNoDialog(page)
await layersSettled(page)
await selectTab(page, dict, 'annotations')
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-commands')
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 opens and 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: a click, a double click and a 2 px jitter keep them
// and open their properties (A1, U2 Task 6); Escape closes the dialog only.
const closeProperties = async (name: string) => {
await expect(page.getByRole('dialog', { name })).toBeVisible()
await page.keyboard.press('Escape')
await expect(page.getByRole('dialog')).toHaveCount(0)
await expectKept(page, name)
}
for (const [name, at] of targets.slice(0, 2)) {
await clickAt(page, at)
await expectSelected(page, name)
await clickAt(page, at)
await closeProperties(name)
const now = await clientOf(page, at.x, at.y)
await page.mouse.dblclick(now.x, now.y)
await closeProperties(name)
await mouseJitter(page, at.x, at.y)
await closeProperties(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)
// The name shows in the fixed-height strip, which never moves the drawing.
await expect(page.getByTestId('edit-strip')).toHaveCSS('height', '64px')
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 pending key series is applied by the click that deselects; « Désélectionner » commits it in one click', async ({
page,
requests,
}) => {
const { actor, saves } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
// U2 Task 6: the annotation's fields left the side column (one dialog save); the point
// handle's key series is the pending typing a deselect must not lose.
// A step, no Enter, ONE click on the drawing.
await select(page, POINT)
await pointHandle(page).focus()
await page.keyboard.press('ArrowRight')
await clickAt(page, IN_CIRCLE)
await expectDeselected(page)
await expect(saveLine(page)).toHaveText(/1 modification non enregistrée/)
// Undo reverts it.
await historyButton(page, dict, 'undo').click()
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
// « Désélectionner » with a pending step: committed and closed.
await select(page, POINT)
await pointHandle(page).focus()
await page.keyboard.press('ArrowRight')
await properties(page)
.getByRole('button', { name: dict['editor.annotations.deselect'] })
.click()
await expectDeselected(page)
await expect(saveLine(page)).toHaveText(/1 modification non enregistrée/)
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<number, { x: number; y: number }>()
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)
// The page ends lower once the overview is back: the drawing stays where it was.
expect((await box(page).boundingBox())!.y).toBe(rect.y)
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(twinSelectionTag(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(twinSelectionTag(page)).toHaveCount(0)
await expect(canvas).toBeFocused()
await report('twin tap on the rect')
await tap(cdp, await markerAt())
await expect(twinSelectionTag(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(twinSelectionTag(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(twinSelectionTag(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(twinSelectionTag(page)).toHaveCount(1)
await expect(twinSelectionTag(page)).toContainText(name)
await expect(twinSelectionTag(page)).toHaveCSS('position', 'absolute')
expect(await top(), `${name} selected`).toBe(before)
await tap(cdp, await twinAt(IN_RECT.x, IN_RECT.y))
await expect(twinSelectionTag(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(twinSelectionTag(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 frames(page)
await expect(twinSelectionTag(page)).toContainText(POINT)
await page.keyboard.press('Escape')
await expect(twinSelectionTag(page)).toHaveCount(0)
await expect(properties(page)).toHaveCount(0)
await expect(overview(page)).toBeVisible()
await expect(liveRegion(page)).toHaveCount(1)
expect(saves).toEqual([])
})
})