From 4499bc740c83ef8924f636d669b013e0cc4a36d9 Mon Sep 17 00:00:00 2001 From: bchanot Date: Thu, 12 Nov 2026 20:29:27 +0100 Subject: [PATCH] =?UTF-8?q?feat(editor):=20fifth=20tab=20=C2=AB=20R=C3=A9f?= =?UTF-8?q?=C3=A9rences=20=C2=BB,=20citations=20panel=20from=20a=20finding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- apps/app/e2e/shell/editor-access.spec.ts | 23 +- apps/app/e2e/shell/editor-deselect.spec.ts | 10 +- apps/app/e2e/shell/editor-equine.spec.ts | 9 +- .../e2e/shell/editor-shell-crossing.spec.ts | 56 +-- .../e2e/shell/editor-shell-journeys.spec.ts | 17 +- .../app/e2e/shell/editor-shell-layout.spec.ts | 84 ++--- apps/app/e2e/shell/editor-shell.spec.ts | 38 +- apps/app/e2e/shell/editor-structures.spec.ts | 29 +- apps/app/e2e/support/editor.ts | 69 +++- apps/app/e2e/support/warm-up.ts | 10 +- .../app/src/components/editor/DraftHeader.tsx | 15 +- .../src/components/editor/EditorTabBody.tsx | 2 + apps/app/src/components/editor/EditorTabs.tsx | 5 +- .../src/components/editor/EditorWorkspace.tsx | 58 ++- .../src/components/editor/HeaderActions.tsx | 22 +- .../editor/annotations/PropertiesPanel.tsx | 7 +- .../editor/findings/FindingContent.tsx | 17 +- .../editor/findings/FindingDetail.tsx | 2 +- .../editor/references/ReferenceForm.tsx | 18 +- .../editor/references/ReferenceLibrary.tsx | 112 ++++++ .../editor/references/ReferenceList.tsx | 44 +++ .../editor/references/ReferenceRow.tsx | 7 +- .../editor/references/ReferencesPanel.tsx | 203 ++--------- .../editor/references/referenceTypes.ts | 3 + .../components/editor/tabs/FindingsTab.tsx | 9 +- .../components/editor/tabs/ReferencesTab.tsx | 33 ++ .../editor/verification/IssueList.tsx | 4 +- apps/app/src/editor/editingContext.ts | 4 +- apps/app/src/editor/focusRequest.ts | 21 +- apps/app/src/editor/navigation.ts | 87 +++-- apps/app/src/editor/tabs.ts | 15 +- apps/app/src/editor/useEditorNavigation.ts | 134 ++++--- apps/app/src/editor/useViewport.ts | 2 +- apps/app/src/editor/verification.ts | 1 - apps/app/src/i18n/en.ts | 2 +- apps/app/src/i18n/fr.ts | 2 +- apps/app/tests/unit/editor-escape.test.tsx | 98 ++++- apps/app/tests/unit/editor-findings.test.tsx | 47 +++ .../tests/unit/editor-focus-request.test.tsx | 85 ++++- .../app/tests/unit/editor-keep-alive.test.tsx | 100 ++--- apps/app/tests/unit/editor-mode.test.ts | 9 +- apps/app/tests/unit/editor-navigation.test.ts | 95 +++-- .../unit/editor-no-loss-decisions.test.tsx | 13 - apps/app/tests/unit/editor-no-loss.test.tsx | 28 +- .../unit/editor-references-panel.test.tsx | 342 +++++++++--------- .../tests/unit/editor-references-tab.test.tsx | 261 +++++++++++++ .../tests/unit/editor-route-recovery.test.tsx | 19 +- apps/app/tests/unit/editor-route.test.tsx | 93 +++-- .../app/tests/unit/editor-tabs-lists.test.tsx | 18 +- .../tests/unit/editor-verification.test.tsx | 22 +- 50 files changed, 1487 insertions(+), 917 deletions(-) create mode 100644 apps/app/src/components/editor/references/ReferenceLibrary.tsx create mode 100644 apps/app/src/components/editor/references/ReferenceList.tsx create mode 100644 apps/app/src/components/editor/tabs/ReferencesTab.tsx create mode 100644 apps/app/tests/unit/editor-references-tab.test.tsx diff --git a/apps/app/e2e/shell/editor-access.spec.ts b/apps/app/e2e/shell/editor-access.spec.ts index 01761643..4671ad93 100644 --- a/apps/app/e2e/shell/editor-access.spec.ts +++ b/apps/app/e2e/shell/editor-access.spec.ts @@ -11,19 +11,18 @@ import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { SECTIONS, TABS, - closeReferences, + closeCitations, draftPath, draftTitle, editorActor, makeActor, openEditor, - openReferences, + openCitations, openSection, pointOf, seedDraft, selectTab, shapeWith, - showDrawing, type Actor, } from '../support/editor' import { signIn } from '../support/shell' @@ -147,9 +146,9 @@ test.describe('editor access, narrow screens and axe', () => { ).toHaveCount(0) await expectNoHorizontalOverflow(page, `the draft at ${width} px`) await expectAccessible(page, `the draft at ${width} px`) - await openReferences(page, dict) + await openCitations(page, dict, 'Constat A') await expectNoHorizontalOverflow(page, `the panel at ${width} px`) - await expectAccessible(page, `the references panel at ${width} px`) + await expectAccessible(page, `the citations panel at ${width} px`) }) } @@ -187,11 +186,10 @@ test.describe('editor access, narrow screens and axe', () => { ) await expectAccessible(page, `the ${section} section (edit)`) } - await showDrawing(page, dict) - await openReferences(page, dict) - await expectNoHorizontalOverflow(page, 'the references panel at 1 024 px') - await expectAccessible(page, 'the references panel (edit)') - await closeReferences(page, dict) + await openCitations(page, dict, 'Constat A') + await expectNoHorizontalOverflow(page, 'the citations panel at 1 024 px') + await expectAccessible(page, 'the citations panel (edit)') + await closeCitations(page, dict) }) test('axe on every tab of a read-only draft', async ({ page, requests }) => { @@ -215,8 +213,7 @@ test.describe('editor access, narrow screens and axe', () => { await openSection(page, dict, section) await expectAccessible(page, `the ${section} section (read-only)`) } - await showDrawing(page, dict) - await openReferences(page, dict) - await expectAccessible(page, 'the references panel (read-only)') + await openCitations(page, dict, 'Constat A') + await expectAccessible(page, 'the citations panel (read-only)') }) }) diff --git a/apps/app/e2e/shell/editor-deselect.spec.ts b/apps/app/e2e/shell/editor-deselect.spec.ts index bdc31716..259637b8 100644 --- a/apps/app/e2e/shell/editor-deselect.spec.ts +++ b/apps/app/e2e/shell/editor-deselect.spec.ts @@ -11,7 +11,7 @@ import { geometryField, historyButton, openEditor, - openReferences, + openCitations, pickAnnotation, place, pointOf, @@ -192,7 +192,7 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => { expect(saves).toEqual([]) }) - test('Escape: canvas, field, delete dialog, references panel, tracing', async ({ + test('Escape: canvas, field, delete dialog, citations panel, tracing', async ({ page, requests, }) => { @@ -223,10 +223,12 @@ test.describe('deselect and D6b (editor, mouse and keyboard)', () => { await expect(dialog).toHaveCount(0) await expectKept(page, POINT) - // The references panel: it closes, the selection stays, a second Escape deselects. - await openReferences(page, dict) + // 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') diff --git a/apps/app/e2e/shell/editor-equine.spec.ts b/apps/app/e2e/shell/editor-equine.spec.ts index accf6e0a..1558ad13 100644 --- a/apps/app/e2e/shell/editor-equine.spec.ts +++ b/apps/app/e2e/shell/editor-equine.spec.ts @@ -14,10 +14,9 @@ import { place, type Actor, annotationList, - closeReferences, editorActor, openEditor, - openReferences, + openTab, openSection, SECTIONS, seedDraft, @@ -301,8 +300,7 @@ test.describe('equine working copy and commit latency', () => { for (const tab of ['general', 'verification']) await selectTab(page, dict, tab) for (const section of SECTIONS) await openSection(page, dict, section) - await openReferences(page, dict) - await closeReferences(page, dict) + await openTab(page, dict, 'references') expect(errors, 'page errors on the equine copy').toEqual([]) }) @@ -401,8 +399,7 @@ test.describe('equine working copy and commit latency', () => { for (const tab of ['general', 'findings', 'verification']) await selectTab(page, dict, tab) for (const section of SECTIONS) await openSection(page, dict, section) - await openReferences(page, dict) - await closeReferences(page, dict) + await openTab(page, dict, 'references') const renames = await measureRenames(page, 'equine, all places: rename') const additions = await measureAdditions(page, 'equine, all places: add') for (const line of [renames, additions]) diff --git a/apps/app/e2e/shell/editor-shell-crossing.spec.ts b/apps/app/e2e/shell/editor-shell-crossing.spec.ts index 9bd2324e..6fdb8c34 100644 --- a/apps/app/e2e/shell/editor-shell-crossing.spec.ts +++ b/apps/app/e2e/shell/editor-shell-crossing.spec.ts @@ -3,16 +3,16 @@ import type { Locator, Page, TestInfo } from '@playwright/test' import { expect, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { - INKSCAPE_EXPORT, clientOf, - closeReferences, + closeCitations, copyKeyOf, editorActor, geometryField, historyButton, libraryRoot, openEditor, - openReferences, + openCitations, + openTab, openSection, pickAnnotation, place, @@ -191,18 +191,17 @@ test.describe('editor shell, width crossing (H)', () => { ) }) - test('the references form keeps its typed text with the panel open', async ({ + test('the references form keeps its typed text, in the Références tab', async ({ page, }) => { await open(page) - await openReferences(page, dict) + await openTab(page, dict, 'references') await keepsTypedValue( page, - page.locator('#reference-new-citation'), + page.locator('#tab-reference-new-citation'), dict['editor.reference.add'], - 'annotations', + 'references', ) - await expect(place(page, 'citations')).toBeVisible() await expect(libraryRoot(page).getByRole('searchbox')).toBeVisible() }) @@ -260,25 +259,21 @@ test.describe('editor shell, width crossing (H)', () => { await expect(saveLine(page)).toHaveText(UNSAVED_LINE) }) - test('the panel open: read-only below the threshold, unsaved work kept, edit back on widening', async ({ + test('the citations panel open: read-only below the threshold, unsaved work kept, edit back on widening', async ({ page, }) => { await open(page) await commitName(page, 'Nom conservé') - await openReferences(page, dict) - await page.locator('#reference-new-citation').fill('Smith 1999') + await openCitations(page, dict, 'Constat A') await cross(page, NARROW) await expectReadOnly(page) await expect(place(page, 'citations')).toBeVisible() await expect(saveLine(page)).toHaveText(UNSAVED_LINE) await cross(page, WIDE) - await expect(page.locator('#reference-new-citation')).toHaveValue( - 'Smith 1999', - ) await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), ).toBeEnabled() - await closeReferences(page, dict) + await closeCitations(page, dict) }) test('text typed without a blur is unsaved after the crossing and the copy is written', async ({ @@ -364,35 +359,4 @@ test.describe('editor shell, width crossing (H)', () => { await cross(page, WIDE) await expect(saveLine(page)).toHaveText(UNSAVED_LINE) }) - - test('a decision withheld while the panel was open waits for « Reprendre »; tabs keep the focus', async ({ - page, - }) => { - const actor = await editorActor('fr') - const seed = await seedDraft(actor, { drawing: null, shape: standardShape }) - await openEditor(page, dict, actor, seed.sheetId) - await openSection(page, dict, 'views') - await openReferences(page, dict) - await page.getByTestId('view-main-file').setInputFiles({ - name: 'inkscape.svg', - mimeType: 'image/svg+xml', - buffer: INKSCAPE_EXPORT, - }) - await expect( - page.getByText(dict['editor.views.pending.cleaning']), - ).toBeVisible() - await closeReferences(page, dict) - await expect(dialogs(page)).toHaveCount(0) - await selectTab(page, dict, 'general') - await page.getByRole('tab', { name: dict['editor.tab.general'] }).focus() - await page.keyboard.press('ArrowRight') - await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations') - await expect(dialogs(page)).toHaveCount(0) - await page - .getByRole('button', { name: dict['editor.views.pending.resume'] }) - .click() - await expect( - page.getByRole('dialog', { name: dict['editor.cleaning.title'] }), - ).toBeVisible() - }) }) diff --git a/apps/app/e2e/shell/editor-shell-journeys.spec.ts b/apps/app/e2e/shell/editor-shell-journeys.spec.ts index 0be1260b..e927c488 100644 --- a/apps/app/e2e/shell/editor-shell-journeys.spec.ts +++ b/apps/app/e2e/shell/editor-shell-journeys.spec.ts @@ -4,7 +4,6 @@ import { expect, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { TABS, - closeReferences, draftTitle, editorActor, historyButton, @@ -20,7 +19,7 @@ import { UNSAVED_LINE, } from '../support/editor' -// V1-2.6 U1 H (AC1, AC5, AC12, AC13, AC17): the journeys of the four-tab shell in a real +// V1-2.6 U1 H (AC1, AC5, AC12, AC13, AC17): the journeys of the five-tab shell in a real // browser. Every query is scoped to the visible place (`place()`) or goes by role, so a // hidden, kept-mounted copy never answers. @@ -111,16 +110,16 @@ test.describe('editor shell journeys (H)', () => { await dropLateReplays(context) }) - test('four tabs and no tab of the old layout', async ({ page }) => { + test('five tabs and no tab of the old layout', async ({ page }) => { await open(page) const tabs = page.getByRole('tablist').getByRole('tab') - await expect(tabs).toHaveCount(4) + await expect(tabs).toHaveCount(5) for (const [index, tab] of TABS.entries()) { await expect(tabs.nth(index)).toHaveText( new RegExp(`^${dict[`editor.tab.${tab}`]}`), ) } - for (const old of ['Vues et illustrations', 'Références', 'Vertèbres']) { + for (const old of ['Vues et illustrations', 'Vertèbres']) { await expect(page.getByRole('tab', { name: old })).toHaveCount(0) } }) @@ -244,9 +243,13 @@ test.describe('editor shell journeys (H)', () => { await selectTab(page, dict, 'verification') await goTo('Barone, Ostéologie') - await expect(place(page, 'citations')).toBeVisible() + await expect(place(page, 'references')).toBeVisible() + await expect( + page.getByRole('tab', { + name: new RegExp(`^${dict['editor.tab.references']}`), + }), + ).toHaveAttribute('aria-selected', 'true') await focusKey('ref-a') - await closeReferences(page, dict) }) test('the save line goes from the count to « Enregistrement… » to the time and the revision', async ({ diff --git a/apps/app/e2e/shell/editor-shell-layout.spec.ts b/apps/app/e2e/shell/editor-shell-layout.spec.ts index 9b852e51..7ec2f01c 100644 --- a/apps/app/e2e/shell/editor-shell-layout.spec.ts +++ b/apps/app/e2e/shell/editor-shell-layout.spec.ts @@ -11,15 +11,17 @@ import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { SECTIONS, TABS, - closeReferences, + closeCitations, draftPath, draftTitle, editorActor, historyButton, openEditor, - openReferences, + openCitations, + openTab, openSection, pickAnnotation, + place, pointOf, seedDraft, selectTab, @@ -28,7 +30,7 @@ import { } from '../support/editor' import { signIn } from '../support/shell' -// V1-2.6 U1 H (AC10, AC11, AC17): the layout of the four-tab shell at every width, the +// V1-2.6 U1 H (AC10, AC11, AC17): the layout of the five-tab shell at every width, the // keyboard order of the editor, and axe on every place, edit and narrow read-only. const dict = fr @@ -50,18 +52,6 @@ async function open(page: Page) { return { ...seed, actor } } -/** Opens the tab, through « Plus » when the width keeps it out of the row. */ -async function goToTab(page: Page, tab: (typeof TABS)[number]) { - const direct = page.locator(`#editor-tab-${tab}`) - if ((await direct.count()) === 0) { - await page.getByRole('button', { name: dict['editor.tab.more'] }).click() - } - await direct.click() - await expect( - page.locator(`[data-place^="${tab}"]:visible`).first(), - ).toBeVisible() -} - async function settle(page: Page) { await page.evaluate( () => @@ -81,7 +71,7 @@ test.describe('editor shell layout (H)', () => { await dropLateReplays(context) }) - test('no horizontal scroll from 1 024 to 1 280 px on the four tabs, the three sections and the open panel', async ({ + test('no horizontal scroll from 1 024 to 1 280 px on the five tabs, the three sections and the open citations panel', async ({ page, }) => { test.setTimeout(150_000) @@ -96,14 +86,13 @@ test.describe('editor shell layout (H)', () => { await openSection(page, dict, section) await expectNoHorizontalOverflow(page, `${section} at ${width} px`) } - await showDrawing(page, dict) - await openReferences(page, dict) + await openCitations(page, dict, 'Constat A') await expectNoHorizontalOverflow(page, `the panel at ${width} px`) - await closeReferences(page, dict) + await closeCitations(page, dict) } }) - test('read-only at 320, 375 and 768 px: the four tabs fit and pass axe', async ({ + test('read-only at 320, 375 and 768 px: the five tabs fit and pass axe', async ({ page, requests, }) => { @@ -121,7 +110,7 @@ test.describe('editor shell layout (H)', () => { page.getByRole('heading', { level: 1, name: draftTitle(dict) }), ).toBeVisible() for (const tab of TABS) { - await goToTab(page, tab) + await openTab(page, dict, tab) await expectNoHorizontalOverflow(page, `${tab} at ${width} px`) await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), @@ -137,28 +126,32 @@ test.describe('editor shell layout (H)', () => { } }) - test('the canvas width, the same measure without and with the references panel', async ({ + test('the canvas width is the same before the citations panel opens and after a tab switch closes it', async ({ page, }) => { test.setTimeout(150_000) await open(page) - for (const panel of [false, true]) { - for (const width of WIDTHS) { - await page.setViewportSize({ width, height: 800 }) - await showDrawing(page, dict) - await pickAnnotation(page, dict, 'Point libre') - if (panel) await openReferences(page, dict) - const canvas = await page.getByTestId('annotation-canvas').boundingBox() - test.info().annotations.push({ - type: panel ? 'canvas-width-panel' : 'canvas-width', - description: `${canvas?.width}px at ${width}px`, - }) - if (panel) await closeReferences(page, dict) - } + const measure = async () => + (await page.getByTestId('annotation-canvas').boundingBox())?.width + for (const width of WIDTHS) { + await page.setViewportSize({ width, height: 800 }) + await showDrawing(page, dict) + await pickAnnotation(page, dict, 'Point libre') + const before = await measure() + test.info().annotations.push({ + type: 'canvas-width', + description: `${before}px at ${width}px`, + }) + await openCitations(page, dict, 'Constat A') + // The panel exists on Constats only: leaving for Annotations closes it (P21). + await selectTab(page, dict, 'annotations') + await expect(place(page, 'citations')).toHaveCount(0) + await expect(page.getByTestId('annotation-canvas')).toBeVisible() + expect(await measure()).toBe(before) } }) - test('axe from the top on the four tabs, each section and the open panel', async ({ + test('axe from the top on the five tabs, each section and the open citations panel', async ({ page, }) => { test.setTimeout(150_000) @@ -179,13 +172,12 @@ test.describe('editor shell layout (H)', () => { await expect(page.locator('dialog[open]')).toHaveCount(0) await expectAccessible(page, `${name} at ${width} px`) } - await showDrawing(page, dict) - await openReferences(page, dict) + await openCitations(page, dict, 'Constat A') await settle(page) await page.evaluate(() => window.scrollTo(0, 0)) await expect(page.locator('dialog[open]')).toHaveCount(0) await expectAccessible(page, `the open panel at ${width} px`) - await closeReferences(page, dict) + await closeCitations(page, dict) } }) @@ -268,7 +260,9 @@ test.describe('editor shell keyboard order (H)', () => { await dropLateReplays(context) }) - test('header, tab list, Défaire, Refaire, then the tools, the canvas and the side column', async ({ + // The header holds no focusable control after the title while the draft is clean: its + // buttons (« Abandonner », « Enregistrer ») are disabled, and « Références » left it. + test('tab list, Défaire, Refaire, then the tools, the canvas and the side column', async ({ page, }) => { await open(page) @@ -280,7 +274,6 @@ test.describe('editor shell keyboard order (H)', () => { description: order.join(' > '), }) expect(order).toEqual([ - 'header', 'tab', 'undo', 'redo', @@ -290,23 +283,24 @@ test.describe('editor shell keyboard order (H)', () => { ]) }) - test('with the panel open: header, tab list, Défaire, Refaire, the panel, then the page content', async ({ + test('with the panel open: tab list, Défaire, Refaire, the panel, then the page content', async ({ page, }) => { await open(page) - await openReferences(page, dict) + await openCitations(page, dict, 'Constat A') const order = await walk(page, 'panel') test.info().annotations.push({ type: 'keyboard-order-panel', description: order.join(' > '), }) - expect(order).toEqual(['header', 'tab', 'undo', 'redo', 'panel']) + expect(order).toEqual(['tab', 'undo', 'redo', 'panel']) await page.keyboard.press('Escape') await expect(page.locator('[data-place="citations"]:visible')).toHaveCount( 0, ) + await selectTab(page, dict, 'annotations') const after = await walk(page, 'side') - expect(after.slice(0, 4)).toEqual(['header', 'tab', 'undo', 'redo']) + expect(after.slice(0, 3)).toEqual(['tab', 'undo', 'redo']) expect(after).not.toContain('panel') expect(after.at(-1)).toBe('side') }) diff --git a/apps/app/e2e/shell/editor-shell.spec.ts b/apps/app/e2e/shell/editor-shell.spec.ts index 767a7ee2..d3376872 100644 --- a/apps/app/e2e/shell/editor-shell.spec.ts +++ b/apps/app/e2e/shell/editor-shell.spec.ts @@ -6,10 +6,10 @@ import { backToDrawing, copyKeyOf, storedCopy, - closeReferences, + closeCitations, editorActor, openEditor, - openReferences, + openCitations, openSection, pickAnnotation, place, @@ -19,9 +19,10 @@ import { shapeWith, showDrawing, historyButton, + openTab, } from '../support/editor' -// V1-2.6 U1 B2a: tabs, Annotations sections and the references panel stay mounted. What +// V1-2.6 U1 B2a: tabs, Annotations sections and the Références tab stay mounted. What // was typed, the canvas zoom and the focus survive a change of place; focus lands on a // named element, never on `body`. happy-dom does not refuse focus on hidden elements, so // the focus rules are checked here with `document.activeElement`. @@ -92,53 +93,52 @@ test.describe('editor shell, kept places (B2a)', () => { expect(await layerTransform(page)).toBe(zoomed) }) - test('the references panel keeps its form text and no id repeats', async ({ + test('the Références tab keeps its form text and no id repeats, panel open included', async ({ page, }) => { await open(page) - await openReferences(page, dict) - await page.locator('#reference-new-citation').fill('Smith 1999') - await closeReferences(page, dict) - await openReferences(page, dict) - await expect(page.locator('#reference-new-citation')).toHaveValue( + await openTab(page, dict, 'references') + await page.locator('#tab-reference-new-citation').fill('Smith 1999') + await openTab(page, dict, 'general') + await openTab(page, dict, 'references') + await expect(page.locator('#tab-reference-new-citation')).toHaveValue( 'Smith 1999', ) - // The tab panels are inert while the panel is open (AC3): close it to reach them. - await closeReferences(page, dict) for (const tab of ['general', 'findings', 'verification']) { await selectTab(page, dict, tab) } for (const section of ['views', 'categories', 'regions'] as const) { await openSection(page, dict, section) } + // The tab bodies stay mounted under the panel: its card ids carry their own prefix. + await openCitations(page, dict, 'Constat A') const repeated = await page.evaluate(() => { const ids = [...document.querySelectorAll('[id]')].map((e) => e.id) return ids.filter((id, i) => ids.indexOf(id) !== i) }) expect(repeated).toEqual([]) + await closeCitations(page, dict) }) for (const width of [1024, 1280]) { - test(`the open references panel leaves the header and the tab row clickable at ${width} px`, async ({ + test(`the open citations panel leaves the header and the tab row clickable at ${width} px`, async ({ page, }) => { await page.setViewportSize({ width, height: 800 }) await open(page) - await openReferences(page, dict) - await page.locator('#reference-new-type').selectOption('book') - await page.locator('#reference-new-citation').fill('Smith 1999') + // An edit first, so « Enregistrer » is enabled: a reference added in its tab. + await openTab(page, dict, 'references') + await page.locator('#tab-reference-new-type').selectOption('book') + await page.locator('#tab-reference-new-citation').fill('Smith 1999') await page .getByRole('button', { name: dict['editor.reference.add'] }) .click() + await openCitations(page, dict, 'Constat A') const header = page.locator('main header').first() const tabs = page.getByRole('tablist') const panel = place(page, 'citations') const targets = [ page.getByRole('button', { name: dict['common.save'], exact: true }), - page.getByRole('button', { - name: dict['editor.references.open'], - exact: true, - }), page.getByRole('tab', { name: new RegExp(`^${dict['editor.tab.findings']}`), }), diff --git a/apps/app/e2e/shell/editor-structures.spec.ts b/apps/app/e2e/shell/editor-structures.spec.ts index fd1ac04c..ce765dd4 100644 --- a/apps/app/e2e/shell/editor-structures.spec.ts +++ b/apps/app/e2e/shell/editor-structures.spec.ts @@ -4,11 +4,10 @@ import { expect, expectAccessible, test } from '../support/browser' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { bareShape, - closeReferences, editorActor, libraryRoot, openEditor, - openReferences, + openTab, openSection, pickAnnotation, pointOf, @@ -77,23 +76,23 @@ test.describe('editor structures (A4)', () => { await expect(names.nth(1)).toHaveValue('Catégorie B bis') await expectAccessible(page, 'the categories section') - // Two references, the second moved up. - await openReferences(page, dict) + // 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.locator('#reference-new-type').selectOption('book') - await page.locator('#reference-new-citation').fill(citation) + 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.getByText(citation)).toBeVisible() } const citations = page.locator( - '[id^="reference-"][id$="-citation"]:not(#reference-new-citation)', + '[id^="tab-reference-"][id$="-citation"]:not(#tab-reference-new-citation)', ) - await expect(citations).toHaveCount(2) - await expect( - libraryRoot(page).getByText('citée 0 fois'), - ).toHaveCount(2) + await expect(citations).toHaveCount(3) + await expect(libraryRoot(page).getByText('citée 0 fois')).toHaveCount(2) + await expect(libraryRoot(page).getByText('citée 1 fois')).toHaveCount(1) await page .getByRole('searchbox', { name: dict['editor.references.search'] }) .fill('seconde') @@ -101,13 +100,13 @@ test.describe('editor structures (A4)', () => { await page .getByRole('searchbox', { name: dict['editor.references.search'] }) .fill('') - await expect(citations).toHaveCount(2) + await expect(citations).toHaveCount(3) await page .getByRole('listitem') .filter({ hasText: 'Seconde référence' }) .getByRole('button', { name: dict['editor.action.move_up'] }) .click() - await expect(citations.first()).toHaveValue('Seconde référence') + await expect(citations.nth(1)).toHaveValue('Seconde référence') await page .getByRole('listitem') .filter({ hasText: 'Première référence' }) @@ -116,10 +115,9 @@ test.describe('editor structures (A4)', () => { await dialog(page) .getByRole('button', { name: dict['editor.delete.confirm'] }) .click() - await expect(citations).toHaveCount(1) + await expect(citations).toHaveCount(2) // A region with its count. - await closeReferences(page, dict) await openSection(page, dict, 'regions') await page.locator('#region-new-code').fill('T') await page.locator('#region-new-fr').fill('Thoracique') @@ -142,6 +140,7 @@ test.describe('editor structures (A4)', () => { '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([ diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts index c8565bcd..7fcdd3a4 100644 --- a/apps/app/e2e/support/editor.ts +++ b/apps/app/e2e/support/editor.ts @@ -236,6 +236,15 @@ export async function seedDraft( * `bareShape` below omits the defaulted fields (the loader fills them from the core). */ export function standardShape(document: Record) { + document.references = [ + { + id: 'ref-a', + type: 'book', + citation: 'Référence A', + url: null, + doi: null, + }, + ] document.categories = [ { id: 'cat-a', name: text('Catégorie A'), color: null }, ] @@ -257,7 +266,7 @@ export function standardShape(document: Record) { name: text('Constat A'), description: {}, requires_vet_referral: false, - reference_ids: [], + reference_ids: ['ref-a'], review_status: 'reviewed', children: [], }, @@ -323,11 +332,12 @@ export async function openDraft(page: Page, dict: Dict, sheetId: string) { await expect(page.getByRole('tablist')).toBeVisible() } -/** The four tabs of the editor (U1): the references moved to a panel, the rest to Annotations. */ +/** The five tabs of the editor (R2.1), in the order of the row. */ export const TABS = [ 'general', 'annotations', 'findings', + 'references', 'verification', ] as const @@ -373,23 +383,56 @@ export async function openSection( await expect(place(page, `annotations.${section}`)).toBeVisible() } -/** Where the references library shows: today the citations panel (R2.1 moves it to its tab). */ +/** Where the references library shows: the Références tab. */ export function libraryRoot(page: Page): Locator { - return place(page, 'citations') + return place(page, 'references') } -/** Opens the references panel from the header button. */ -export async function openReferences(page: Page, dict: Dict) { - const toggle = page.getByRole('button', { - name: dict['editor.references.open'], - exact: true, - }) - if ((await toggle.getAttribute('aria-expanded')) !== 'true') - await toggle.click() +/** Below this width the tabs other than Annotations and Vérification sit under « Plus ». */ +const SMALL_TIER_WIDTH = 640 + +/** + * Shows a tab whatever the width: the tab button from 640 px, below it « Plus » opened and + * the tab picked in its list. Waits for the body of a tab that has a `data-place` of its + * own (every one but Annotations, which names its sections). + */ +export async function openTab(page: Page, dict: Dict, tab: string) { + const width = page.viewportSize()?.width ?? SMALL_TIER_WIDTH + const name = new RegExp(`^${dict[`editor.tab.${tab}`]}( |$)`) + const listed = ['annotations', 'verification'].includes(tab) + if (width < SMALL_TIER_WIDTH && !listed) { + const more = page.getByRole('button', { + name: dict['editor.tab.more'], + exact: true, + }) + if ((await more.getAttribute('aria-expanded')) !== 'true') + await more.click() + await page.locator('#editor-tabs-more').getByRole('button', { name }).click() + } else { + await page.getByRole('tab', { name }).click() + } + if (tab !== 'annotations') await expect(place(page, tab)).toBeVisible() +} + +/** + * Opens the citations panel of the finding named `element`: the Constats tab, the tree + * expanded down to it, the element selected, its « n références » trigger pressed. + */ +export async function openCitations(page: Page, dict: Dict, element: string) { + await openTab(page, dict, 'findings') + const item = page.getByRole('treeitem', { name: element }) + for (let depth = 0; depth < 4 && (await item.count()) === 0; depth++) { + const closed = page.getByRole('treeitem', { expanded: false }).first() + await closed.focus() + await closed.press('ArrowRight') + } + await item.click() + await page.locator('[data-citations-trigger]:visible').click() await expect(place(page, 'citations')).toBeVisible() } -export async function closeReferences(page: Page, dict: Dict) { +/** Closes the citations panel with its ✕ button. */ +export async function closeCitations(page: Page, dict: Dict) { await page .getByRole('button', { name: dict['editor.references.close'] }) .click() diff --git a/apps/app/e2e/support/warm-up.ts b/apps/app/e2e/support/warm-up.ts index c244e674..a88c9c96 100644 --- a/apps/app/e2e/support/warm-up.ts +++ b/apps/app/e2e/support/warm-up.ts @@ -2,7 +2,7 @@ * Global setup of the shell suite (V1-2.6): the Vite dev server discovers some * dependencies only when a route first loads them and answers with a full page * reload, which wiped a form a test had begun to fill. One throwaway session - * visits the editor routes, every tab, every Annotations section and the references panel once before the tests start, so the + * visits the editor routes, every tab, every Annotations section and the citations panel once before the tests start, so the * reload happens here and not in a test. */ import { chromium, type FullConfig } from '@playwright/test' @@ -10,10 +10,10 @@ import { fr } from '@/i18n/fr' import { stepUpAdmin } from './admin' import { TABS, - closeReferences, + closeCitations, draftPath, editorActor, - openReferences, + openCitations, openSection, secondSession, seedDraft, @@ -47,8 +47,8 @@ export default async function warmUp(config: FullConfig): Promise { await openSection(page, fr, section) await page.waitForLoadState('networkidle') } - await openReferences(page, fr) - await closeReferences(page, fr) + await openCitations(page, fr, 'Constat A') + await closeCitations(page, fr) await page.goto('/app/admin/sheets/new') await page.waitForLoadState('networkidle') await browser.close() diff --git a/apps/app/src/components/editor/DraftHeader.tsx b/apps/app/src/components/editor/DraftHeader.tsx index 7acc596c..7d3521b2 100644 --- a/apps/app/src/components/editor/DraftHeader.tsx +++ b/apps/app/src/components/editor/DraftHeader.tsx @@ -45,19 +45,15 @@ function Breadcrumb({ } /** - * The draft's header: breadcrumb, title and badges, then the actions (references, the - * save line, « Abandonner les modifications » and « Enregistrer » in edit mode). + * The draft's header: breadcrumb, title and badges, then the actions (the save line, + * « Abandonner les modifications » and « Enregistrer » in edit mode). */ export default function DraftHeader({ sheet, mode, - referencesOpen, - onToggleReferences, }: { sheet: OfficialSheetAdmin mode: EditorMode - referencesOpen: boolean - onToggleReferences: (opener: HTMLElement) => void }) { const t = useT() const heading = usePageHeading() @@ -85,12 +81,7 @@ export default function DraftHeader({ {t('editor.draft.read_only')} )} - + {failure && {failure}} diff --git a/apps/app/src/components/editor/EditorTabBody.tsx b/apps/app/src/components/editor/EditorTabBody.tsx index 79a96706..95c73038 100644 --- a/apps/app/src/components/editor/EditorTabBody.tsx +++ b/apps/app/src/components/editor/EditorTabBody.tsx @@ -11,6 +11,7 @@ import KeptPlace from './KeptPlace' import AnnotationsTab from './tabs/AnnotationsTab' import FindingsTab from './tabs/FindingsTab' import GeneralTab from './tabs/GeneralTab' +import ReferencesTab from './tabs/ReferencesTab' import VerificationTab from './tabs/VerificationTab' const BODIES: Record< @@ -19,6 +20,7 @@ const BODIES: Record< > = { general: GeneralTab, findings: FindingsTab, + references: ReferencesTab, verification: VerificationTab, } diff --git a/apps/app/src/components/editor/EditorTabs.tsx b/apps/app/src/components/editor/EditorTabs.tsx index 9ee21c14..fb6ec0c5 100644 --- a/apps/app/src/components/editor/EditorTabs.tsx +++ b/apps/app/src/components/editor/EditorTabs.tsx @@ -64,7 +64,7 @@ function TabList({ shown, active, onSelect }: TabListProps) { role="tablist" aria-label={t('editor.tab.list')} onKeyDown={onKeyDown} - className="flex gap-1" + className="flex flex-wrap gap-1" > {shown.map((tab) => ( -