Files
faunosteo/apps/app/e2e/shell/editor-structures.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

355 lines
14 KiB
TypeScript

import { fr } from '@/i18n/fr'
import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, expectAccessible, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
addReference,
bareShape,
closeFinding,
editorActor,
expectNoDialog,
findingDialog,
libraryRoot,
openEditor,
openTab,
openSection,
pickAnnotation,
pointOf,
revisionText,
saveDraft,
saveLine,
seedDraft,
selectTab,
serverDocument,
serverRevision,
shapeWith,
showDrawing,
openProperties,
} from '../support/editor'
// V1-2.6 A4 (contract C9 to C12, C19): the structures around the drawing. Annotation
// categories, references, vertebral regions, then the findings tree (zones, categories,
// nodes): add, edit, reorder, mark reviewed, delete with and without dependents.
const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const dialog = (page: Page) => page.getByRole('dialog')
/** The deletion dialog over the finding dialog: the last dialog open. */
const deleteDialog = (page: Page) => page.locator('dialog[open]').last()
const button = (page: Page, name: string) =>
page.getByRole('button', { name, exact: true })
async function open(page: Page, ...annotations: unknown[]) {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, { shape: shapeWith(...annotations) })
await openEditor(page, dict, actor, seed.sheetId)
return { actor, seed }
}
async function commitText(field: Locator, value: string) {
await field.fill(value)
await field.press('Enter')
}
test.describe('editor structures (A4)', () => {
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('categories, references and regions: add, edit, reorder, delete', async ({
page,
requests,
}) => {
const { actor, seed } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
// A category added, then renamed in place.
await openSection(page, dict, 'categories')
await page.locator('#category-new-fr').fill('Catégorie B')
await page.locator('#category-new-en').fill('Category B')
await page
.getByRole('button', { name: dict['editor.general.category_add'] })
.click()
const names = page.locator('[id^="category-"][id$="-name-fr"]')
await expect(page.locator('#category-new-fr')).toHaveValue('')
await expect(names).toHaveCount(2)
await commitText(names.nth(1), 'Catégorie B bis')
await expect(names.nth(1)).toHaveValue('Catégorie B bis')
await expectAccessible(page, 'the categories section')
// Two references added in the Références tab, the second moved up (the shape's
// « Référence A » stays first: it is cited by « Constat A »).
await openTab(page, dict, 'references')
for (const citation of ['Première référence', 'Seconde référence']) {
await addReference(page, dict, citation)
await expect(
page.getByRole('button', { name: new RegExp(`^${citation}`) }),
).toBeVisible()
}
const tiles = page.locator('[id^="tab-reference-"][id$="-header"]')
const tileOf = (citation: string) =>
page.getByRole('listitem').filter({ hasText: citation }).first()
await expect(tiles).toHaveCount(3)
await expect(
libraryRoot(page).getByText(dict['editor.references.uncited']),
).toHaveCount(2)
await expect(libraryRoot(page).getByText('Citée 1 fois')).toHaveCount(1)
const search = page.getByRole('searchbox', {
name: dict['editor.references.search'],
})
await search.fill('seconde')
await expect(tiles).toHaveCount(1)
await search.fill('')
await expect(tiles).toHaveCount(3)
// An added tile is closed (the list does not move, R2F-5): open it, then move it.
await tiles.filter({ hasText: 'Seconde référence' }).click()
await tileOf('Seconde référence')
.getByRole('button', { name: dict['editor.action.move_up'] })
.click()
await expect(tiles.nth(1)).toContainText('Seconde référence')
await tiles.filter({ hasText: 'Première référence' }).click()
await tileOf('Première référence')
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await dialog(page)
.getByRole('button', { name: dict['editor.delete.confirm'] })
.click()
await expect(tiles).toHaveCount(2)
// A region with its count.
await openSection(page, dict, 'regions')
await page.locator('#region-new-code').fill('T')
await page.locator('#region-new-fr').fill('Thoracique')
await page.locator('#region-new-en').fill('Thoracic')
await page.locator('#region-new-count').fill('18')
await page
.getByRole('button', { name: dict['editor.vertebra.add'] })
.click()
await commitText(page.locator('#region-T-count'), '17')
await expect(page.locator('#region-T-count')).toHaveValue('17')
await saveDraft(page, dict, seed.revision + 1)
const saved = await serverDocument<{
categories: { name: { fr: string } }[]
references: { citation: string }[]
vertebral_config: { regions: { code: string; count: number }[] }
}>(seed.draftId)
expect(saved.categories.map((c) => c.name.fr)).toEqual([
'Catégorie A',
'Catégorie B bis',
])
expect(saved.references.map((r) => r.citation)).toEqual([
'Référence A',
'Seconde référence',
])
expect(saved.vertebral_config.regions).toEqual([
expect.objectContaining({ code: 'T', count: 17 }),
])
})
test('the findings tree: add zone, category and node, review, reorder', async ({
page,
requests,
}) => {
const { actor, seed } = await open(page)
requests.forbid(actor.account.email, actor.account.password)
await selectTab(page, dict, 'findings')
const items = page.getByTestId('finding-item')
// The seeded zone is open: the zone and its category show, the node is folded.
await expect(items).toHaveCount(2)
await page
.getByRole('button', { name: dict['editor.findings.add_zone'] })
.click()
await page.locator('#finding-new-name-fr').fill('Zone B')
await page.locator('#finding-new-name-en').fill('Zone B en')
await page
.getByRole('button', { name: dict['editor.findings.create'] })
.click()
// « Créer » turns the dialog into the new zone's view: close it.
await closeFinding(page, dict)
await expect(items.filter({ hasText: 'Zone B' })).toBeVisible()
await page
.getByRole('button', { name: dict['editor.findings.add_category'] })
.click()
await page.locator('#finding-new-zone').selectOption({ label: 'Zone B' })
await page.locator('#finding-new-kind').selectOption('anamnesis')
await page.locator('#finding-new-name-fr').fill('Anamnèse B')
await page.locator('#finding-new-name-en').fill('History B')
await page
.getByRole('button', { name: dict['editor.findings.create'] })
.click()
await closeFinding(page, dict)
const category = items.filter({ hasText: 'Anamnèse B' })
await expect(category).toBeVisible()
await expect(
category.getByText(dict['editor.findings.status.to_confirm']),
).toBeVisible()
await page
.getByRole('button', { name: dict['editor.findings.add_node'] })
.click()
await page.locator('#finding-new-name-fr').fill('Constat B1')
await page.locator('#finding-new-name-en').fill('Finding B1')
await page
.getByRole('button', { name: dict['editor.findings.create'] })
.click()
const node = items.filter({ hasText: 'Constat B1' })
// The dialog shows the new node: marked reviewed there, the badge of the row follows.
await findingDialog(page)
.getByRole('button', { name: dict['editor.findings.mark_reviewed'] })
.click()
await closeFinding(page, dict)
await expect(node).toBeVisible()
await expect(
node.getByText(dict['editor.findings.status.reviewed']),
).toBeVisible()
// The tab row (history buttons included) scrolled under the sticky top bar is not a
// target-size finding of its own: audit it from the top.
await page.evaluate(() => window.scrollTo(0, 0))
await expectAccessible(page, 'the findings tree')
// Reorder: the new zone moves above the seeded one, from its dialog.
await items.filter({ hasText: 'Zone B' }).first().click()
await findingDialog(page)
.getByRole('button', { name: dict['editor.action.move_up'] })
.click()
await closeFinding(page, dict)
await expect(items.first()).toContainText('Zone B')
await saveDraft(page, dict, seed.revision + 1)
const saved = await serverDocument<{
finding_zones: { name: { fr: string } }[]
}>(seed.draftId)
expect(saved.finding_zones.map((z) => z.name.fr)).toEqual([
'Zone B',
'Zone A',
])
})
test('a draft stored with bare nodes loads filled: rename, save, reload clean', async ({
page,
requests,
}) => {
const actor = await editorActor('fr')
requests.forbid(actor.account.email, actor.account.password)
const seed = await seedDraft(actor, { shape: bareShape })
await openEditor(page, dict, actor, seed.sheetId)
await selectTab(page, dict, 'findings')
const items = page.getByTestId('finding-item')
await items.filter({ hasText: 'Catégorie nue' }).click()
await findingDialog(page)
.getByRole('button', { name: dict['editor.findings.edit'] })
.click()
await page.locator('#finding-edit-name-fr').fill('Catégorie renommée')
await findingDialog(page)
.getByRole('button', { name: dict['editor.findings.save'] })
.click()
await closeFinding(page, dict)
await saveDraft(page, dict, seed.revision + 1)
const saved = await serverDocument<{
finding_zones: { categories: { reference_ids: string[] }[] }[]
}>(seed.draftId)
expect(saved.finding_zones[0].categories[0].reference_ids).toEqual([])
expect(await serverRevision(seed.draftId)).toBe(seed.revision + 1)
await page.reload()
await selectTab(page, dict, 'findings')
await expect(items.filter({ hasText: 'Catégorie renommée' })).toBeVisible()
await expect(saveLine(page)).toHaveText(
revisionText(dict, seed.revision + 1),
)
await expect(
button(page, dict['editor.draft.recovery.restore']),
).toHaveCount(0)
})
test('delete with dependents: refused with the list; without, descendants named', async ({
page,
requests,
}) => {
const { actor } = await open(
page,
pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point lié'),
)
requests.forbid(actor.account.email, actor.account.password)
// The category is used by the point: the dialog lists it and offers no deletion.
await openSection(page, dict, 'categories')
await page
.getByRole('listitem')
.filter({ has: page.locator('#category-cat-a-name-fr') })
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(
dialog(page).getByText(
dict['editor.delete.blocked'].replace('{name}', 'Catégorie A'),
),
).toBeVisible()
await expect(dialog(page).getByText('Point lié')).toBeVisible()
await expect(
dialog(page).getByRole('button', { name: dict['editor.delete.confirm'] }),
).toHaveCount(0)
await dialog(page)
.getByRole('button', { name: dict['editor.delete.close'], exact: true })
.last()
.click()
// The zone is linked by the point as well: refused.
await selectTab(page, dict, 'findings')
const zone = page.getByTestId('finding-item').filter({ hasText: 'Zone A' })
await zone.first().click()
await findingDialog(page)
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(
deleteDialog(page).getByText(
dict['editor.delete.blocked'].replace('{name}', 'Zone A'),
),
).toBeVisible()
await deleteDialog(page)
.getByRole('button', { name: dict['editor.delete.close'], exact: true })
.last()
.click()
await expect(page.locator('dialog[open]')).toHaveCount(1)
await closeFinding(page, dict)
// The point goes first; the zone then deletes with its descendants named.
await showDrawing(page, dict)
await pickAnnotation(page, dict, /Point lié/)
// U2 Task 6: « Supprimer » sits in the properties dialog; its confirmation lies over it.
const properties = await openProperties(page, dict)
await properties
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await deleteDialog(page)
.getByRole('button', { name: dict['editor.delete.confirm'] })
.click()
await expect(page.locator('dialog[open]')).toHaveCount(0)
await selectTab(page, dict, 'findings')
await zone.first().click()
await findingDialog(page)
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(
deleteDialog(page).getByText(dict['editor.delete.descendants']),
).toBeVisible()
await expect(deleteDialog(page).getByText('Dysfonction A')).toBeVisible()
await deleteDialog(page)
.getByRole('button', { name: dict['editor.delete.confirm'] })
.click()
// The deletion closes both dialogs at once.
await expectNoDialog(page)
await expect(page.getByTestId('finding-item')).toHaveCount(0)
await expect(page.getByText(dict['editor.findings.empty'])).toBeVisible()
})
})