Files
faunosteo/apps/app/e2e/shell/editor-structures.spec.ts
T
bchanot 3baac4dbb5 feat(editor): search, sort, count and add in the Références tab
Search (citation, DOI, URL) with « Effacer la recherche » and Escape;
« Trier par » sheet order, citation (locale collator), citation count,
type (business order); every sort stable on stored order, display only:
document, stored order, ids and history unchanged (unit + e2e). Count
« {n} références » / « {n} sur {total} » counts matching references
only. « Monter » / « Descendre » only in sheet order without search
(A1). « Ajouter une référence » resets search and sort and appends a
draft tile in edit; a tile in edit stays pinned while sorted or
searched; tile state pruned of absent ids. Reset path ready for « Tout
afficher » (R2.4).

Gates: typecheck, lint, test:run (app 1452), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 115
passed / 102 skipped / 2 failed: editor-structures (test-side, fixed,
rerun with editor-references 12 passed / 11 skipped) and admin.spec A0
« Target crashed » during axe on the rights screen (not R2: that
screen renders every grant, 1 282 accumulated e2e fixtures; reported as
an open risk); full-row guard: no pre-existing row changed in any table.

## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-tab.test.tsx | `#tab-reference-new-citation` present on load | null until « Ajouter une référence » |
| same | no match text « Aucune référence ne correspond. » | notice « Aucune référence ne contient « zzz ». » |
| same | add: form always visible, add clears the search, `getByText('Nouvelle source')` | click « Ajouter une référence » first; new tile header open, focused, search empty, 4 tiles |
| same | « a refused add keeps the search » | REMOVED (P24: add resets the search at once); replaced by « draft opens with citation focused, refused add keeps the draft, no write » |
| editor-tabs-lists.test.tsx | add form directly | click « Ajouter une référence » before the form assertions (same assertions after) |
| editor-keep-alive.test.tsx | form survives tab round trip | same, after opening the draft |
| editor-no-loss.test.tsx | reference form keeps typed text | same, after opening the draft |
| e2e editor-shell.spec (2), editor-shell-crossing.spec, editor-structures.spec | fill `#tab-reference-new-*` directly; `getByText(citation)` visible | open the draft first; structures asserts the new header is focused |
| e2e editor-references.spec keyboard walk | focus search, Tab reaches header 0 | focus « Ajouter une référence » (search, sort, add precede the headers) |
Other readers of `editor.reference.add`/new ids: grep of src, tests, e2e incl. editor-equine found none left unlisted. editor-equine is not affected ("updated, not run": nothing to update).

## i18n (fr / en)
Added: `editor.references.add` Ajouter une référence / Add a reference; `add_help` Type et citation obligatoires. / Type and citation required.; `clear_search` Effacer la recherche / Clear the search; `sort_by` Trier par / Sort by; `sort.sheet|citation|count|type` Ordre de la fiche, Citation (A → Z), Nombre de citations, Type / Sheet order, Citation (A → Z), Number of citations, Type; `count_one|other` {count} référence(s) / reference(s); `count_of_one|other` {count} référence(s) sur {total} / {count} reference(s) of {total}; `reorder_hint` Pour réorganiser, affichez l'ordre de la fiche sans recherche. / To reorder, show the sheet order without a search.; `no_result` Aucune référence ne contient « {q} ». / No reference contains “{q}”.; `no_result_scope` La recherche porte sur la citation, le DOI et l'URL. / The search covers the citation, the DOI and the URL. (REVUE sentence split in two keys so the first half is bold).
Changed: none. Removed: none (`editor.references.no_match` kept, the panel's EmptyLine still uses it).
2026-11-12 21:18:56 +01:00

342 lines
13 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 {
bareShape,
editorActor,
libraryRoot,
openEditor,
openTab,
openSection,
pickAnnotation,
pointOf,
revisionText,
saveDraft,
saveLine,
seedDraft,
selectTab,
serverDocument,
serverRevision,
shapeWith,
showDrawing,
} 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')
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 page
.getByRole('button', { name: dict['editor.references.add'] })
.click()
await page.locator('#tab-reference-new-type').selectOption('book')
await page.locator('#tab-reference-new-citation').fill(citation)
await page
.getByRole('button', { name: dict['editor.reference.add'] })
.click()
await expect(
page.getByRole('button', { name: new RegExp(`^${citation}`) }),
).toBeFocused()
}
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 stays open (P24): no click, a click would close it.
await expect(
tiles.filter({ hasText: 'Seconde référence' }),
).toHaveAttribute('aria-expanded', 'true')
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 expect(
tiles.filter({ hasText: 'Première référence' }),
).toHaveAttribute('aria-expanded', 'true')
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()
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()
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' })
await expect(node).toBeVisible()
// Marked reviewed: the badge of the row follows.
await page
.getByRole('button', { name: dict['editor.findings.mark_reviewed'] })
.click()
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.
await items.filter({ hasText: 'Zone B' }).first().click()
await page
.getByRole('button', { name: dict['editor.action.move_up'] })
.click()
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 commitText(page.locator('#finding-name-fr'), 'Catégorie renommée')
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 page
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(
dialog(page).getByText(
dict['editor.delete.blocked'].replace('{name}', 'Zone A'),
),
).toBeVisible()
await dialog(page)
.getByRole('button', { name: dict['editor.delete.close'], exact: true })
.last()
.click()
// The point goes first; the zone then deletes with its descendants named.
await showDrawing(page, dict)
await pickAnnotation(page, dict, /Point lié/)
await page
.getByTestId('annotation-properties')
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await dialog(page)
.getByRole('button', { name: dict['editor.delete.confirm'] })
.click()
await selectTab(page, dict, 'findings')
await zone.first().click()
await page
.getByRole('button', { name: dict['editor.action.delete'] })
.click()
await expect(
dialog(page).getByText(dict['editor.delete.descendants']),
).toBeVisible()
await expect(dialog(page).getByText('Dysfonction A')).toBeVisible()
await dialog(page)
.getByRole('button', { name: dict['editor.delete.confirm'] })
.click()
await expect(page.getByTestId('finding-item')).toHaveCount(0)
await expect(page.getByText(dict['editor.findings.empty'])).toBeVisible()
})
})