Files
faunosteo/apps/app/e2e/shell/editor-deselect.spec.ts
T
bchanot 4499bc740c feat(editor): fifth tab « Références », citations panel from a finding
The reference library moves into a fifth editor tab (Général,
Annotations, Constats, Références, Vérification; under « Plus » below
640 px with Général and Constats). The header « Références » button is
removed. The side panel becomes the citations list of one finding,
opened only from a finding's trigger (owner GO 2026-11-12: never from a
family; the family keeps its inline list with « Retirer »). Selecting a
tab closes it; every close records one pending move applied after the
panel is gone, focus back to the trigger else the active tab button.
Vérification's reference issues land on the tab. e2e seed gains a
reference cited by « Constat A ».

Gates: typecheck, lint, test:run (app 1396), build, e2e:ui 251 passed;
e2e:shell 15 specs on db:sandbox (editor-equine never listed): 107
passed / 95 skipped / 2 failed (test remap dropped its edit), fixed and
rerun: editor-shell.spec 11 passed; full-row data guard: no
pre-existing row changed in any table. editor-equine.spec.ts helper
calls updated, not run.

## R-24 table (removed or rewritten assertions; old = fc3fec7 line, new = current file)

Unit tests:

| file:old line | old | new |
|---|---|---|
| editor-verification.test.tsx:87-96 | `navigate` called with target AND `expect.any(HTMLElement)` | called with the target only (opener dropped) |
| editor-verification.test.tsx:238-241 | `references[0]` path -> `{place:'references', citedBy:null}` | `{place:'tab', tab:'references', section:null}` |
| editor-verification.test.tsx:262-264 | `placeKey(references[9])` = `editor.place.references` | `editor.tab.references` |
| editor-navigation.test.ts:63 | targetOfKey reference -> `{place:'references', key, citedBy:null}` | `{place:'tab', tab:'references', section:null, key}` |
| editor-navigation.test.ts:80 | `referencesMounted` false at start | `citationsOf` null and `libraryReset` 0 |
| editor-navigation.test.ts:95-110 | go_to a reference opens the panel over the place | go_to a reference shows the Références tab with its focus request |
| editor-navigation.test.ts:112-122 | go_to a tab closes the panel (`references` object) | same, via `citationsOf` null |
| editor-navigation.test.ts:124-136 | select_tab keeps the panel | select_tab CLOSES the panel (P21), keeps section, no request |
| editor-navigation.test.ts:138-146 | `clear_cited_by` drops the filter | removed (action gone); replaced by `open_citations` refuses family/zone/view, `show_all_references` (closes, tab, reset bump), plain go_to leaves reset alone |
| editor-navigation.test.ts:160-175 | open/close references keep tab and section | open/close citations, same assertions on `citationsOf` |
| editor-mode.test.ts:100-109 | tabsFor four tabs, small more = general, findings | five tabs, small more = general, findings, references |
| editor-route.test.tsx:46,50 | TABS four, title « four tabs » | five |
| editor-route.test.tsx:139-146 | 640-1023 px four tabs | five tabs, tablist has `flex-wrap` |
| editor-route.test.tsx:149-161 | « Plus » lists Général, Constats | lists Général, Constats, Références |
| editor-route.test.tsx:168-190 | header button opens panel, ✕ returns focus to button | no header button, panel not mounted at start (full panel flow moved to editor-references-panel.test.tsx) |
| editor-route.test.tsx:192-206 | Escape closes, panel content kept for next opening | removed: the panel is no longer kept mounted (design choice 3); Escape/close covered in editor-references-panel + editor-escape |
| editor-route.test.tsx:208-218 | read-only: panel lists references, no edit control | read-only: the Références tab lists them, no textbox, no add button; plus new: tab keeps mounted when left |
| editor-tabs-lists.test.tsx:47,75,114,130 | render `ReferencesPanel` | render `ReferencesTab` |
| editor-tabs-lists.test.tsx:77 | selector `#reference-ref-a-url` | `#tab-reference-ref-a-url` |
| editor-tabs-lists.test.tsx:131-135 | read-only buttons = only « Fermer les références » | no button at all |
| editor-focus-request.test.tsx:166-171,200-202,346 | `ReferencesPanel` with `panel` props and focus | `ReferenceLibrary` with focus (same assertions) |
| editor-focus-request.test.tsx:226 | `ownedBy(ref,'citations')` is the request | `ownedBy(ref,'references')` is the request, `'citations'` undefined |
| editor-focus-request.test.tsx (Probe) | none | new: Vérification « Aller à » reference -> tab + focused row; reference path naming no element -> tab heading |
| editor-keep-alive.test.tsx:71,178-190 | add form survives closing/reopening the panel | survives leaving/returning to the Références tab (`#tab-reference-new-citation`) |
| editor-keep-alive.test.tsx:300-326 | « Aller à » without focus move commits Références text | a tab click without focus move commits it (one undo entry): « Aller à » is not reachable from the Références tab in R2.1 |
| editor-keep-alive.test.tsx:333-347 | Escape in panel reference field commits, panel hides | same, panel opened from a finding node, field `#panel-reference-ref-1-citation` |
| editor-keep-alive.test.tsx:350-363 | header toggle (no focus move) closes after committing | scrim click (no focus move) closes after committing |
| editor-keep-alive.test.tsx:425 | `referencesButton` click in the all-places sweep | `Références` added to the tab loop |
| editor-escape.test.tsx:218-227 | header button toggle, Escape on body closes panel, annotation selection kept | trigger-opened panel (A5), Escape closes it, `aria-expanded` back to false, selection kept after returning to Annotations |
| editor-escape.test.tsx:255-266 | Escape from tab row closes panel | same from the Constats tab button |
| editor-no-loss.test.tsx:146-153 | reference creation form, in the panel | in the Références tab, id `tab-reference-new-citation` |
| editor-no-loss.test.tsx:285-291 | focused header button survives crossing | focused tab button (Constats) survives crossing: no header button left |
| editor-no-loss.test.tsx:293-307 | references search in panel keeps focus/text | same in the Références tab body |
| editor-no-loss.test.tsx:390-400 | `everyPlace` ends by opening the panel | visits Références in the tab loop, no panel open |
| editor-no-loss-decisions.test.tsx:248-259 | open references panel holds the decision back | REMOVED: the panel exists only over Constats, decisions live in Annotations (hidden then); « a widening on another tab opens nothing » (same file) covers the withholding |
| editor-route-recovery.test.tsx:93-97 | recovery offer: header button opens panel, `aria-labelledby` | tab Références shows `editor-tab-references` labelled by `editor-references-title` |
| editor-references-panel.test.tsx (all) | header-button-driven panel tests incl. search, order, add, « Aller à » | split: panel tests (finding path only) stay in this file; library tests moved to new editor-references-tab.test.tsx (search matching, ↑/↓ only without search, counts, Ctrl+Z, read-only, « Aller à », add clears search, refused add keeps it); new: reset signal, ids unique with both mounted (P14), P6 fallback under « Plus » |

e2e (updated only, not run):

| file:old line | old | new |
|---|---|---|
| editor-shell.spec.ts:95-108 | panel keeps form text, no id repeats | Références tab keeps form text (`#tab-reference-new-citation`), ids unique with the panel open |
| editor-shell.spec.ts:121-142 | open panel leaves header and tab row clickable (incl. header Références button, add form) | `openCitations`; header button target and form steps dropped |
| editor-shell-journeys.spec.ts:113-123 | four tabs, `old` list includes « Références » | five tabs, « Références » removed from the old-layout list |
| editor-shell-journeys.spec.ts:246-249 | Aller à reference -> panel visible, close | `place('references')` visible, tab Références selected, row focus key, no close |
| editor-shell-layout.spec.ts:84-103 | overflow on four tabs + panel over drawing | five tabs + `openCitations`/`closeCitations` |
| editor-shell-layout.spec.ts:54-63 | local `goToTab` | removed, uses `openTab` |
| editor-shell-layout.spec.ts:140-158 | canvas width without/with panel over the drawing | E1: width measured before open and after a P21 switch to Annotations, asserted equal |
| editor-shell-layout.spec.ts:161-189 | axe on four tabs + open panel | five tabs + citations panel |
| editor-shell-layout.spec.ts:~255-310 | keyboard order began with `header` (the Références button) | `header` dropped from both orders (no focusable header control while the draft is clean); panel test selects Annotations before walking to `side` |
| editor-access.spec.ts:150-152,191-194,219-220 | axe/overflow with the panel at 320/375/768/800, 1024, read-only | same checks through `openCitations` (`showDrawing` calls dropped) |
| editor-shell-crossing.spec.ts:194-206 | references form with panel open, tab `annotations` | in the tab, focus expected on `editor-tab-references` |
| editor-shell-crossing.spec.ts:264-282 | panel open + add-form text across crossing | citations panel over a crossing, no typed-text step |
| editor-shell-crossing.spec.ts:~385-410 | decision withheld while panel open, Reprendre | REMOVED (state unreachable, see unit row) |
| editor-deselect.spec.ts:226-229 | Escape closes header-opened panel, selection kept | opened via Constats, Escape, back to Annotations, selection kept |
| editor-structures.spec.ts:80-122 | two references added, counts 2/1 | shape now holds `ref-a`: counts 3/2, `nth(1)` after move, saved list `['Référence A','Seconde référence']`, no panel |
| editor-equine.spec.ts:304-305,404-405 | openReferences/closeReferences | `openTab(page, dict, 'references')`: mis à jour, non exécuté, non vérifié |

Fix round 1: 1. e2e/shell/editor-shell.spec.ts « the open citations panel leaves the header and the tab row clickable »: before `openCitations`, the test now opens the Références tab and adds a reference through the library form (`#tab-reference-new-type` book, `#tab-reference-new-citation` « Smith 1999 », « Ajouter la référence »), so the draft is dirty and Save is enabled. All original assertion
2026-11-12 20:29:27 +01:00

862 lines
30 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,
geometryField,
historyButton,
openEditor,
openCitations,
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<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, citations 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 citations panel (over Constats): it closes, the selection stays, back on
// Annotations a second Escape deselects.
await openCitations(page, dict, 'Constat A')
await page.keyboard.press('Escape')
await expect(place(page, 'citations')).toHaveCount(0)
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-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<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)
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([])
})
})