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
This commit is contained in:
1 parent
fc3fec7654
commit
4499bc740c
50 files changed
+1487
-917
No files matched your search
@@ -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)')
|
||||
})
|
||||
})
|
||||
@@ -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')
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
@@ -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 ({
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
|
||||
@@ -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']}`),
|
||||
}),
|
||||
|
||||
@@ -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([
|
||||
|
||||
@@ -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<string, unknown>) {
|
||||
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<string, unknown>) {
|
||||
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()
|
||||
|
||||
@@ -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<void> {
|
||||
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()
|
||||
|
||||
@@ -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')}
|
||||
</Badge>
|
||||
)}
|
||||
<HeaderActions
|
||||
editable={mode === 'edit'}
|
||||
referencesOpen={referencesOpen}
|
||||
onToggleReferences={onToggleReferences}
|
||||
onFailure={setFailure}
|
||||
/>
|
||||
<HeaderActions editable={mode === 'edit'} onFailure={setFailure} />
|
||||
</div>
|
||||
{failure && <Notice tone="error">{failure}</Notice>}
|
||||
</header>
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -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) => (
|
||||
<button
|
||||
@@ -168,7 +168,8 @@ interface EditorTabsProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* The draft's tab row (boards 04 and 05): the four tabs from 640 px, Annotations and
|
||||
* The draft's tab row (boards 04 and 05): the five tabs from 640 px (the row may wrap
|
||||
* between 640 and 1 023 px, never scroll sideways), Annotations and
|
||||
* Vérification below it with « Plus » opening a disclosure of the others (no measurement).
|
||||
* « Défaire » and « Refaire » sit at the right end of the row on every tab.
|
||||
*/
|
||||
|
||||
@@ -2,11 +2,7 @@ import { useEffect, useRef, type ReactNode } from 'react'
|
||||
import type { OfficialSheetAdmin } from '@faunosteo/supabase'
|
||||
import Notice from '@/components/ui/Notice'
|
||||
import { ReadOnlyContext, ReferencesOpenContext } from '@/editor/editingContext'
|
||||
import {
|
||||
AnnounceContext,
|
||||
FocusConsumedContext,
|
||||
ownedBy,
|
||||
} from '@/editor/focusRequest'
|
||||
import { AnnounceContext, FocusConsumedContext } from '@/editor/focusRequest'
|
||||
import { saveFailureMessage } from '@/editor/messages'
|
||||
import type { EditorMode } from '@/editor/mode'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
@@ -78,26 +74,25 @@ interface PlacesProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* Under the tab row: the tab panels and the references panel beside them. The container
|
||||
* starts after the tab row, so the panel and its scrim never cover the header or the tabs;
|
||||
* while the panel is open the tab panels are inert (the scrim sits over them).
|
||||
* Under the tab row: the tab panels and the citations panel of a finding beside them. The
|
||||
* container starts after the tab row, so the panel and its scrim never cover the header or
|
||||
* the tabs; while the panel is open the tab panels are inert (the scrim sits over them).
|
||||
*/
|
||||
function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
const { state } = nav
|
||||
const open = state.references.open
|
||||
const open = state.citationsOf !== null
|
||||
return (
|
||||
<div className={`relative ${open ? 'min-h-[calc(100dvh-3.5rem)]' : ''}`}>
|
||||
{state.referencesMounted && (
|
||||
{state.citationsOf && (
|
||||
<KeptPlace
|
||||
name="citations"
|
||||
visible={open}
|
||||
visible
|
||||
className="absolute bottom-0 right-0 top-0 z-20 w-[min(27rem,100%)]"
|
||||
>
|
||||
<ReferencesPanel
|
||||
readOnly={readOnly}
|
||||
focus={ownedBy(state.focus, 'citations')}
|
||||
onClose={nav.closeReferences}
|
||||
citedBy={state.references.citedBy}
|
||||
citedBy={state.citationsOf}
|
||||
onClose={nav.closeCitations}
|
||||
onShowAll={nav.showAllReferences}
|
||||
/>
|
||||
</KeptPlace>
|
||||
@@ -106,7 +101,7 @@ function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
<div
|
||||
aria-hidden="true"
|
||||
data-testid="references-scrim"
|
||||
onClick={nav.closeReferences}
|
||||
onClick={nav.closeCitations}
|
||||
className="absolute inset-0 z-10 bg-[rgba(31,27,22,0.25)]"
|
||||
/>
|
||||
)}
|
||||
@@ -116,6 +111,8 @@ function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
visited={state.visitedTabs}
|
||||
readOnly={readOnly}
|
||||
navigate={nav.navigate}
|
||||
openCitations={nav.openCitations}
|
||||
libraryReset={state.libraryReset}
|
||||
focus={state.focus}
|
||||
reloadSheet={reloadSheet}
|
||||
annotations={{
|
||||
@@ -132,7 +129,7 @@ function Places({ nav, readOnly, reloadSheet }: PlacesProps) {
|
||||
|
||||
/**
|
||||
* A keydown aimed at `body` (nothing focused) never reaches the workspace's own handler:
|
||||
* while the references panel is open, Escape there closes it all the same, unless a
|
||||
* while the citations panel is open, Escape there closes it all the same, unless a
|
||||
* modal dialog is open or the key was already handled.
|
||||
*/
|
||||
function useBodyEscape(open: boolean, close: () => void) {
|
||||
@@ -153,7 +150,7 @@ function useBodyEscape(open: boolean, close: () => void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The draft page once the version is ready: header, notices, tab row, the references
|
||||
* The draft page once the version is ready: header, notices, tab row, the citations
|
||||
* panel and the shown place. Owns the navigation state, so the first tab is known at
|
||||
* mount (`initialTab`) and later edits never move the user off their tab.
|
||||
*/
|
||||
@@ -163,35 +160,30 @@ export default function EditorWorkspace(props: Props) {
|
||||
const nav = useEditorNavigation(
|
||||
previewState ? initialTab(previewState, tier) : 'annotations',
|
||||
)
|
||||
const { state } = nav
|
||||
const toggleReferences = (opener: HTMLElement) =>
|
||||
state.references.open
|
||||
? nav.closeReferences()
|
||||
: nav.openReferences(null, opener)
|
||||
useBodyEscape(state.references.open, nav.closeReferences)
|
||||
const open = nav.state.citationsOf !== null
|
||||
useBodyEscape(open, nav.closeCitations)
|
||||
return (
|
||||
<EditingState readOnly={readOnly} referencesOpen={state.references.open}>
|
||||
<EditingState readOnly={readOnly} referencesOpen={open}>
|
||||
<div
|
||||
className="space-y-4"
|
||||
data-editor-workspace
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== 'Escape' || event.defaultPrevented) return
|
||||
if (event.nativeEvent.isComposing || !state.references.open) return
|
||||
if (event.nativeEvent.isComposing || !open) return
|
||||
event.preventDefault()
|
||||
nav.closeReferences()
|
||||
nav.closeCitations()
|
||||
}}
|
||||
>
|
||||
<DraftHeader
|
||||
sheet={sheet}
|
||||
mode={mode}
|
||||
referencesOpen={state.references.open}
|
||||
onToggleReferences={toggleReferences}
|
||||
/>
|
||||
<DraftHeader sheet={sheet} mode={mode} />
|
||||
<ModeNotice mode={mode} sheet={sheet} />
|
||||
<SaveFailureNotice />
|
||||
<RecoveryNotice />
|
||||
<CopyIssueNotice />
|
||||
<EditorTabs active={state.tab} tier={tier} onSelect={nav.selectTab} />
|
||||
<EditorTabs
|
||||
active={nav.state.tab}
|
||||
tier={tier}
|
||||
onSelect={nav.selectTab}
|
||||
/>
|
||||
<FocusConsumedContext value={nav.consumed}>
|
||||
<AnnounceContext value={nav.announce}>
|
||||
<Places nav={nav} readOnly={readOnly} reloadSheet={reloadSheet} />
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import Button from '@/components/ui/Button'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import { useEditorStore } from '@/editor/state/editorStore'
|
||||
import { REFERENCES_BUTTON_ID } from '@/editor/tabs'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import DiscardButton from './DiscardButton'
|
||||
import SaveLine from './SaveLine'
|
||||
@@ -9,8 +7,6 @@ import SaveLine from './SaveLine'
|
||||
interface Props {
|
||||
/** Edit mode: « Abandonner » and « Enregistrer » are offered. */
|
||||
editable: boolean
|
||||
referencesOpen: boolean
|
||||
onToggleReferences: (opener: HTMLElement) => void
|
||||
/** A failed reload after a discard, worded for the notice under the header. */
|
||||
onFailure: (message: string | null) => void
|
||||
}
|
||||
@@ -31,26 +27,10 @@ function SaveButton() {
|
||||
)
|
||||
}
|
||||
|
||||
/** The right group of the header: references, the save line, discard and save. */
|
||||
/** The right group of the header: the save line, discard and save. */
|
||||
export default function HeaderActions(props: Props) {
|
||||
const t = useT()
|
||||
return (
|
||||
<div className="ml-auto flex flex-wrap items-center gap-2">
|
||||
<Button
|
||||
id={REFERENCES_BUTTON_ID}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
aria-expanded={props.referencesOpen}
|
||||
aria-controls="editor-citations-panel"
|
||||
onClick={(event) => props.onToggleReferences(event.currentTarget)}
|
||||
>
|
||||
<Icon name="book" size={16} className="mr-2" />
|
||||
{t('editor.references.open')}
|
||||
</Button>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="hidden h-6 w-px bg-[var(--color-border)] sm:block"
|
||||
/>
|
||||
<SaveLine />
|
||||
{props.editable && (
|
||||
<>
|
||||
|
||||
@@ -236,12 +236,7 @@ export function UnmeasuredHint({
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
onClick={(event) =>
|
||||
navigate(
|
||||
targetOfKey({ kind: 'view', id: viewId }),
|
||||
event.currentTarget,
|
||||
)
|
||||
}
|
||||
onClick={() => navigate(targetOfKey({ kind: 'view', id: viewId }))}
|
||||
>
|
||||
{t('editor.place.views')}
|
||||
</button>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { useContext } from 'react'
|
||||
import ActionButton from '@/components/editor/fields/ActionButton'
|
||||
import ReadOnlyValue from '@/components/editor/fields/ReadOnlyValue'
|
||||
import SelectField from '@/components/editor/fields/SelectField'
|
||||
import TextField from '@/components/editor/fields/TextField'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import { ReferencesOpenContext } from '@/editor/editingContext'
|
||||
import {
|
||||
patchElement,
|
||||
type FindingItem,
|
||||
@@ -18,6 +20,7 @@ interface ContentProps {
|
||||
item: FindingItem
|
||||
readOnly: boolean
|
||||
edit: EditCommandApi
|
||||
/** Opens the citations panel; given for a finding only, a family has no panel. */
|
||||
onShowReferences?: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
@@ -45,7 +48,14 @@ export default function FindingContent(props: ContentProps) {
|
||||
patch={patch}
|
||||
/>
|
||||
)}
|
||||
<Citations {...props} ids={element.value.reference_ids} patch={patch} />
|
||||
<Citations
|
||||
{...props}
|
||||
ids={element.value.reference_ids}
|
||||
patch={patch}
|
||||
onShowReferences={
|
||||
element.kind === 'finding_node' ? props.onShowReferences : undefined
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -119,6 +129,7 @@ function VetFlag({
|
||||
}
|
||||
|
||||
function Citations({
|
||||
item,
|
||||
readOnly,
|
||||
edit,
|
||||
ids,
|
||||
@@ -128,6 +139,7 @@ function Citations({
|
||||
const t = useT()
|
||||
const plural = usePlural()
|
||||
const doc = useSheetDocument()
|
||||
const panelOpen = useContext(ReferencesOpenContext)
|
||||
const references = doc?.references ?? []
|
||||
const citation = (id: string) =>
|
||||
references.find((r) => r.id === id)?.citation ?? id
|
||||
@@ -144,6 +156,9 @@ function Citations({
|
||||
{ids.length > 0 && onShowReferences && (
|
||||
<button
|
||||
type="button"
|
||||
data-citations-trigger={JSON.stringify(item.key)}
|
||||
aria-expanded={panelOpen}
|
||||
aria-controls="editor-citations-panel"
|
||||
onClick={(event) => onShowReferences(event.currentTarget)}
|
||||
className="inline-flex min-h-11 items-center gap-1 rounded-full border border-[var(--color-border)] px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]"
|
||||
>
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface FindingDetailProps {
|
||||
item: FindingItem
|
||||
readOnly: boolean
|
||||
onDelete: () => void
|
||||
/** Opens the references panel filtered to this element. */
|
||||
/** Opens the citations panel of this finding (a family has none). */
|
||||
onShowReferences?: (opener: HTMLElement) => void
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import SelectField from '@/components/editor/fields/SelectField'
|
||||
import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { REFERENCE_TYPES } from './referenceTypes'
|
||||
import { REFERENCE_TYPES, type ReferenceHost } from './referenceTypes'
|
||||
|
||||
const EMPTY = { type: '', citation: '', url: '', doi: '' }
|
||||
|
||||
@@ -14,7 +14,13 @@ const EMPTY = { type: '', citation: '', url: '', doi: '' }
|
||||
* Adds a reference: the type and the citation are required, URL and DOI optional.
|
||||
* `onAdded` runs after a successful add, so the list can show the new reference.
|
||||
*/
|
||||
export default function ReferenceForm({ onAdded }: { onAdded?: () => void }) {
|
||||
export default function ReferenceForm({
|
||||
host,
|
||||
onAdded,
|
||||
}: {
|
||||
host: ReferenceHost
|
||||
onAdded?: () => void
|
||||
}) {
|
||||
const t = useT()
|
||||
const edit = useEditCommand()
|
||||
const [form, setForm] = useState(EMPTY)
|
||||
@@ -53,27 +59,27 @@ export default function ReferenceForm({ onAdded }: { onAdded?: () => void }) {
|
||||
<p className="text-sm font-medium">{t('editor.reference.new')}</p>
|
||||
<div className="grid gap-3">
|
||||
<SelectField
|
||||
id="reference-new-type"
|
||||
id={`${host}-reference-new-type`}
|
||||
label={t('editor.reference.type')}
|
||||
value={form.type}
|
||||
options={options}
|
||||
onCommit={(type) => set({ type })}
|
||||
/>
|
||||
<DraftField
|
||||
id="reference-new-citation"
|
||||
id={`${host}-reference-new-citation`}
|
||||
label={t('editor.reference.citation')}
|
||||
value={form.citation}
|
||||
onChange={(citation) => set({ citation })}
|
||||
multiline
|
||||
/>
|
||||
<DraftField
|
||||
id="reference-new-url"
|
||||
id={`${host}-reference-new-url`}
|
||||
label={t('editor.reference.url')}
|
||||
value={form.url}
|
||||
onChange={(url) => set({ url })}
|
||||
/>
|
||||
<DraftField
|
||||
id="reference-new-doi"
|
||||
id={`${host}-reference-new-doi`}
|
||||
label={t('editor.reference.doi')}
|
||||
value={form.doi}
|
||||
onChange={(doi) => set({ doi })}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { ElementKey, Reference } from '@faunosteo/core-wasm/types'
|
||||
import DeleteDialog, {
|
||||
type DeleteTarget,
|
||||
} from '@/components/editor/DeleteDialog'
|
||||
import EditOnly from '@/components/editor/EditOnly'
|
||||
import Input from '@/components/ui/Input'
|
||||
import {
|
||||
focusRow,
|
||||
useFocusRequest,
|
||||
type FocusRequest,
|
||||
} from '@/editor/focusRequest'
|
||||
import { citationCounts } from '@/editor/references/citations'
|
||||
import { visibleReferences } from '@/editor/references/filter'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import ReferenceForm from './ReferenceForm'
|
||||
import { EmptyLine, ReferenceList } from './ReferenceList'
|
||||
|
||||
interface Props {
|
||||
readOnly: boolean
|
||||
focus?: FocusRequest
|
||||
/** Bumped by « Tout afficher »: the search is emptied once per bump. */
|
||||
resetSignal?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* « Aller à » a reference: the search is cleared first when it may hide the card, and the
|
||||
* card is focused after the commit that shows it (it does not exist while hidden).
|
||||
*/
|
||||
function useReferenceFocus(
|
||||
focus: FocusRequest | undefined,
|
||||
query: string,
|
||||
clearQuery: () => void,
|
||||
) {
|
||||
const [late, setLate] = useState<ElementKey | null>(null)
|
||||
useEffect(() => {
|
||||
if (late === null) return
|
||||
focusRow(late)
|
||||
setLate(null)
|
||||
}, [late])
|
||||
useFocusRequest(focus, (target) => {
|
||||
if (target.key === null) return 'none'
|
||||
if (query === '') return focusRow(target.key) ? 'found' : 'none'
|
||||
clearQuery()
|
||||
setLate(target.key)
|
||||
return 'found'
|
||||
})
|
||||
}
|
||||
|
||||
/** The search text, emptied each time `resetSignal` changes (the tab stays mounted). */
|
||||
function useSearchQuery(resetSignal: number) {
|
||||
const [query, setQuery] = useState('')
|
||||
const [seen, setSeen] = useState(resetSignal)
|
||||
if (seen !== resetSignal) {
|
||||
setSeen(resetSignal)
|
||||
setQuery('')
|
||||
}
|
||||
return [query, setQuery] as const
|
||||
}
|
||||
|
||||
/**
|
||||
* The sheet's bibliography: a search, one card per reference with how often it is cited,
|
||||
* the add form and the delete dialog. Lives in the Références tab (ids prefixed `tab-`).
|
||||
*/
|
||||
export default function ReferenceLibrary({
|
||||
readOnly,
|
||||
focus,
|
||||
resetSignal = 0,
|
||||
}: Props) {
|
||||
const t = useT()
|
||||
const doc = useSheetDocument()
|
||||
const [query, setQuery] = useSearchQuery(resetSignal)
|
||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||
useReferenceFocus(focus, query, () => setQuery(''))
|
||||
const all: readonly Reference[] = doc?.references ?? []
|
||||
const shown = visibleReferences(all, null, query)
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
type="search"
|
||||
aria-label={t('editor.references.search')}
|
||||
placeholder={t('editor.references.search')}
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
{doc && (
|
||||
<>
|
||||
<EmptyLine total={all.length} shown={shown.length} />
|
||||
<ReferenceList
|
||||
host="tab"
|
||||
shown={shown}
|
||||
all={all}
|
||||
counts={citationCounts(doc)}
|
||||
movable={query.trim() === ''}
|
||||
readOnly={readOnly}
|
||||
onDelete={(reference) =>
|
||||
setDeleting({
|
||||
key: { kind: 'reference', id: reference.id },
|
||||
label: reference.citation,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<EditOnly readOnly={readOnly}>
|
||||
<ReferenceForm host="tab" onAdded={() => setQuery('')} />
|
||||
</EditOnly>
|
||||
</>
|
||||
)}
|
||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { Reference } from '@faunosteo/core-wasm/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import ReferenceRow from './ReferenceRow'
|
||||
import type { ReferenceHost } from './referenceTypes'
|
||||
|
||||
interface ListProps {
|
||||
host: ReferenceHost
|
||||
shown: readonly Reference[]
|
||||
all: readonly Reference[]
|
||||
counts: ReadonlyMap<string, number>
|
||||
movable: boolean
|
||||
readOnly: boolean
|
||||
onDelete: (reference: Reference) => void
|
||||
}
|
||||
|
||||
/** The cards of `shown`, each knowing its place in the whole bibliography `all`. */
|
||||
export function ReferenceList({ shown, all, counts, ...rest }: ListProps) {
|
||||
return (
|
||||
<ul className="space-y-3">
|
||||
{shown.map((reference) => (
|
||||
<ReferenceRow
|
||||
key={reference.id}
|
||||
host={rest.host}
|
||||
reference={reference}
|
||||
index={all.indexOf(reference)}
|
||||
count={all.length}
|
||||
cited={counts.get(reference.id) ?? 0}
|
||||
movable={rest.movable}
|
||||
readOnly={rest.readOnly}
|
||||
onDelete={() => rest.onDelete(reference)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/** The empty line: no reference at all, or none that matches. */
|
||||
export function EmptyLine({ total, shown }: { total: number; shown: number }) {
|
||||
const t = useT()
|
||||
if (shown > 0) return null
|
||||
const key =
|
||||
total === 0 ? 'editor.reference.empty' : 'editor.references.no_match'
|
||||
return <p className="text-sm text-[var(--color-ink-muted)]">{t(key)}</p>
|
||||
}
|
||||
@@ -8,12 +8,13 @@ import { isBlank, nullable } from '@/editor/sheetDocument'
|
||||
import { useEditCommand } from '@/editor/useEditCommand'
|
||||
import { usePlural } from '@/editor/plural'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { REFERENCE_TYPES } from './referenceTypes'
|
||||
import { REFERENCE_TYPES, type ReferenceHost } from './referenceTypes'
|
||||
|
||||
const CARD = 'space-y-3 rounded-lg border border-[var(--color-border)] p-3'
|
||||
|
||||
/** One reference: fields commit one by one, ↑ / ↓ reorder, delete asks the core. */
|
||||
export default function ReferenceRow({
|
||||
host,
|
||||
reference,
|
||||
index,
|
||||
count,
|
||||
@@ -22,6 +23,8 @@ export default function ReferenceRow({
|
||||
readOnly,
|
||||
onDelete,
|
||||
}: {
|
||||
/** The place showing the row: its field ids carry it, both can be mounted at once. */
|
||||
host: ReferenceHost
|
||||
reference: Reference
|
||||
/** Position in the whole bibliography, not in a filtered list. */
|
||||
index: number
|
||||
@@ -47,7 +50,7 @@ export default function ReferenceRow({
|
||||
value: type,
|
||||
label: t(`editor.reference.type.${type}`),
|
||||
}))
|
||||
const prefix = `reference-${reference.id}`
|
||||
const prefix = `${host}-reference-${reference.id}`
|
||||
return (
|
||||
<li {...focusAttrs(key)} className={`${CARD} ${FOCUS_CLASS}`}>
|
||||
<p className="text-right text-sm text-[var(--color-ink-muted)]">
|
||||
|
||||
@@ -1,67 +1,28 @@
|
||||
import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type KeyboardEvent,
|
||||
type RefObject,
|
||||
} from 'react'
|
||||
import type { ElementKey, Reference } from '@faunosteo/core-wasm/types'
|
||||
import { useEffect, useMemo, useState, type KeyboardEvent } from 'react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import DeleteDialog, {
|
||||
type DeleteTarget,
|
||||
} from '@/components/editor/DeleteDialog'
|
||||
import EditOnly from '@/components/editor/EditOnly'
|
||||
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
||||
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
||||
import Icon from '@/components/ui/Icon'
|
||||
import Input from '@/components/ui/Input'
|
||||
import {
|
||||
focusRow,
|
||||
useFocusRequest,
|
||||
type FocusRequest,
|
||||
} from '@/editor/focusRequest'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { citationCounts } from '@/editor/references/citations'
|
||||
import {
|
||||
citedIds,
|
||||
citingFinding,
|
||||
visibleReferences,
|
||||
} from '@/editor/references/filter'
|
||||
import { useSheetDocument } from '@/editor/sheetDocument'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { ReferenceList } from './ReferenceList'
|
||||
|
||||
interface Props {
|
||||
readOnly: boolean
|
||||
focus?: FocusRequest
|
||||
/** The finding whose citations the panel lists. */
|
||||
citedBy: ElementKey
|
||||
/** ✕, Escape, and the finding vanishing (deleted, or an undo removed it). */
|
||||
onClose: () => void
|
||||
/** The finding the list is filtered to (opened from its detail), if any. */
|
||||
citedBy?: ElementKey | null
|
||||
/** « Tout afficher »: drops the filter. */
|
||||
onShowAll?: () => void
|
||||
}
|
||||
|
||||
/**
|
||||
* « Aller à » a reference: the search is cleared first when it may hide the card, and the
|
||||
* card is focused after the commit that shows it (it does not exist while hidden).
|
||||
*/
|
||||
function useReferenceFocus(
|
||||
focus: FocusRequest | undefined,
|
||||
query: string,
|
||||
clearQuery: () => void,
|
||||
) {
|
||||
const [late, setLate] = useState<ElementKey | null>(null)
|
||||
useEffect(() => {
|
||||
if (late === null) return
|
||||
focusRow(late)
|
||||
setLate(null)
|
||||
}, [late])
|
||||
useFocusRequest(focus, (target) => {
|
||||
if (target.key === null) return 'none'
|
||||
if (query === '') return focusRow(target.key) ? 'found' : 'none'
|
||||
clearQuery()
|
||||
setLate(target.key)
|
||||
return 'found'
|
||||
})
|
||||
/** « Tout afficher »: closes the panel and opens the Références tab. */
|
||||
onShowAll: () => void
|
||||
}
|
||||
|
||||
function PanelHeader({ onClose }: { onClose: () => void }) {
|
||||
@@ -89,7 +50,7 @@ function PanelHeader({ onClose }: { onClose: () => void }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** The finding filter: « Citées par « nom » (n) » and « Tout afficher (N) ». */
|
||||
/** « Citées par « nom » (n) » and « Tout afficher (N) ». */
|
||||
function FilterChip({
|
||||
name,
|
||||
cited,
|
||||
@@ -124,112 +85,32 @@ function FilterChip({
|
||||
)
|
||||
}
|
||||
|
||||
function SearchField({
|
||||
value,
|
||||
onChange,
|
||||
inputRef,
|
||||
}: {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
inputRef: RefObject<HTMLInputElement | null>
|
||||
}) {
|
||||
const t = useT()
|
||||
return (
|
||||
<Input
|
||||
ref={inputRef}
|
||||
type="search"
|
||||
aria-label={t('editor.references.search')}
|
||||
placeholder={t('editor.references.search')}
|
||||
value={value}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
interface ListProps {
|
||||
shown: readonly Reference[]
|
||||
all: readonly Reference[]
|
||||
counts: ReadonlyMap<string, number>
|
||||
movable: boolean
|
||||
readOnly: boolean
|
||||
onDelete: (reference: Reference) => void
|
||||
}
|
||||
|
||||
function ReferenceList({ shown, all, counts, ...rest }: ListProps) {
|
||||
return (
|
||||
<ul className="space-y-3">
|
||||
{shown.map((reference) => (
|
||||
<ReferenceRow
|
||||
key={reference.id}
|
||||
reference={reference}
|
||||
index={all.indexOf(reference)}
|
||||
count={all.length}
|
||||
cited={counts.get(reference.id) ?? 0}
|
||||
movable={rest.movable}
|
||||
readOnly={rest.readOnly}
|
||||
onDelete={() => rest.onDelete(reference)}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
/** What the list shows: the finding filter (dropped once the finding is gone) and the query. */
|
||||
function useShownReferences(
|
||||
citedBy: ElementKey | null,
|
||||
query: string,
|
||||
onShowAll: (() => void) | undefined,
|
||||
) {
|
||||
/** The finding read from the current document; `gone` once the document lacks it. */
|
||||
function useCitingFinding(citedBy: ElementKey, onGone: () => void) {
|
||||
const doc = useSheetDocument()
|
||||
const finding = useMemo(
|
||||
() => (doc ? citingFinding(doc, citedBy) : null),
|
||||
[doc, citedBy],
|
||||
)
|
||||
const gone = doc !== null && citedBy !== null && finding === null
|
||||
const gone = doc !== null && finding === null
|
||||
useEffect(() => {
|
||||
if (gone) onShowAll?.()
|
||||
}, [gone, onShowAll])
|
||||
const all = doc?.references ?? []
|
||||
const cited = finding ? citedIds(finding) : null
|
||||
const shown = visibleReferences(all, cited, query)
|
||||
return { doc, finding, all, cited, shown }
|
||||
}
|
||||
|
||||
/** The empty line: no reference at all, or none that matches. */
|
||||
function EmptyLine({ total, shown }: { total: number; shown: number }) {
|
||||
const t = useT()
|
||||
if (shown > 0) return null
|
||||
const key =
|
||||
total === 0 ? 'editor.reference.empty' : 'editor.references.no_match'
|
||||
return <p className="text-sm text-[var(--color-ink-muted)]">{t(key)}</p>
|
||||
if (gone) onGone()
|
||||
}, [gone, onGone])
|
||||
return { doc, finding }
|
||||
}
|
||||
|
||||
/**
|
||||
* The references side panel: the sheet's bibliography, filtered to the finding that opened
|
||||
* it or searched, each reference with how often it is cited. Not a dialog: the page stays
|
||||
* usable. The workspace mounts it at the first opening and keeps it (hidden) afterwards.
|
||||
* The citations of one finding: the references it cites, each with how often it is cited.
|
||||
* Not a dialog: the workspace makes the page behind it inert. Opened only from a finding's
|
||||
* trigger; the whole library lives in the Références tab.
|
||||
*/
|
||||
export default function ReferencesPanel(props: Props) {
|
||||
const { readOnly, focus, onClose, citedBy = null, onShowAll } = props
|
||||
const { readOnly, citedBy, onClose, onShowAll } = props
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
const [query, setQuery] = useState('')
|
||||
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
||||
useReferenceFocus(focus, query, () => setQuery(''))
|
||||
const { doc, finding, all, cited, shown } = useShownReferences(
|
||||
citedBy,
|
||||
query,
|
||||
onShowAll,
|
||||
)
|
||||
const showAll = () => {
|
||||
onShowAll?.()
|
||||
searchRef.current?.focus()
|
||||
}
|
||||
// A new reference is neither cited by the filtered finding nor named by the search.
|
||||
const showAdded = () => {
|
||||
setQuery('')
|
||||
if (citedBy !== null) onShowAll?.()
|
||||
}
|
||||
const { doc, finding } = useCitingFinding(citedBy, onClose)
|
||||
const all = doc?.references ?? []
|
||||
const cited = finding ? citedIds(finding) : []
|
||||
const onKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key !== 'Escape' || event.defaultPrevented) return
|
||||
event.stopPropagation()
|
||||
@@ -244,35 +125,29 @@ export default function ReferencesPanel(props: Props) {
|
||||
className="sticky top-14 h-[calc(100dvh-3.5rem)] space-y-3 overflow-y-auto border-l border-[var(--color-border)] bg-[var(--color-surface)] p-4 shadow-xl"
|
||||
>
|
||||
<PanelHeader onClose={onClose} />
|
||||
{finding && cited && (
|
||||
{finding && (
|
||||
<FilterChip
|
||||
name={finding.name[locale]}
|
||||
cited={cited.length}
|
||||
total={all.length}
|
||||
onShowAll={showAll}
|
||||
onShowAll={onShowAll}
|
||||
/>
|
||||
)}
|
||||
<SearchField value={query} onChange={setQuery} inputRef={searchRef} />
|
||||
{doc && (
|
||||
<>
|
||||
<EmptyLine total={all.length} shown={shown.length} />
|
||||
<ReferenceList
|
||||
shown={shown}
|
||||
all={all}
|
||||
counts={citationCounts(doc)}
|
||||
movable={cited === null && query.trim() === ''}
|
||||
readOnly={readOnly}
|
||||
onDelete={(reference) =>
|
||||
setDeleting({
|
||||
key: { kind: 'reference', id: reference.id },
|
||||
label: reference.citation,
|
||||
})
|
||||
}
|
||||
/>
|
||||
<EditOnly readOnly={readOnly}>
|
||||
<ReferenceForm onAdded={showAdded} />
|
||||
</EditOnly>
|
||||
</>
|
||||
<ReferenceList
|
||||
host="panel"
|
||||
shown={visibleReferences(all, cited, '')}
|
||||
all={all}
|
||||
counts={citationCounts(doc)}
|
||||
movable={false}
|
||||
readOnly={readOnly}
|
||||
onDelete={(reference) =>
|
||||
setDeleting({
|
||||
key: { kind: 'reference', id: reference.id },
|
||||
label: reference.citation,
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
||||
</section>
|
||||
|
||||
@@ -8,3 +8,6 @@ export const REFERENCE_TYPES: readonly ReferenceType[] = [
|
||||
'web',
|
||||
'manual',
|
||||
]
|
||||
|
||||
/** Where reference cards are shown: the Références tab or a finding's citations panel. */
|
||||
export type ReferenceHost = 'tab' | 'panel'
|
||||
@@ -64,7 +64,7 @@ function useFindingDeletion(
|
||||
export default function FindingsTab({
|
||||
readOnly,
|
||||
focus,
|
||||
navigate,
|
||||
openCitations,
|
||||
}: EditorPlaceProps) {
|
||||
const t = useT()
|
||||
const doc = useSheetDocument()
|
||||
@@ -155,11 +155,8 @@ export default function FindingsTab({
|
||||
item={selected}
|
||||
readOnly={readOnly}
|
||||
onDelete={() => askDelete(selected)}
|
||||
onShowReferences={(opener) =>
|
||||
navigate(
|
||||
{ place: 'references', key: null, citedBy: selected.key },
|
||||
opener,
|
||||
)
|
||||
onShowReferences={
|
||||
openCitations && ((opener) => openCitations(selected.key, opener))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import type { EditorPlaceProps } from '@/editor/tabs'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
/** The fifth tab: the sheet's reference library under its own heading. */
|
||||
export default function ReferencesTab({
|
||||
readOnly,
|
||||
focus,
|
||||
libraryReset,
|
||||
}: EditorPlaceProps) {
|
||||
const t = useT()
|
||||
return (
|
||||
<section
|
||||
data-testid="editor-tab-references"
|
||||
aria-labelledby="editor-references-title"
|
||||
className="min-h-24 space-y-3"
|
||||
>
|
||||
<h2
|
||||
id="editor-references-title"
|
||||
tabIndex={-1}
|
||||
data-place-heading
|
||||
className="font-serif text-xl outline-none"
|
||||
>
|
||||
{t('editor.tab.references')}
|
||||
</h2>
|
||||
<ReferenceLibrary
|
||||
readOnly={readOnly}
|
||||
focus={focus}
|
||||
resetSignal={libraryReset}
|
||||
/>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -44,9 +44,7 @@ export default function IssueList({
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="mt-2"
|
||||
onClick={(event) =>
|
||||
navigate(target.target, event.currentTarget)
|
||||
}
|
||||
onClick={() => navigate(target.target)}
|
||||
>
|
||||
{t('editor.verification.goto').replace(
|
||||
'{tab}',
|
||||
|
||||
@@ -4,7 +4,7 @@ import { usePlaceVisible } from '@/lib/placeVisibility'
|
||||
/** The editor cannot be edited now (route rule: mode, recovery, store not in step). */
|
||||
export const ReadOnlyContext = createContext(false)
|
||||
|
||||
/** The references panel is open: a place beside it is not where a modal may open. */
|
||||
/** The citations panel is open: a place beside it is not where a modal may open. */
|
||||
export const ReferencesOpenContext = createContext(false)
|
||||
|
||||
export function useEditorReadOnly(): boolean {
|
||||
@@ -13,7 +13,7 @@ export function useEditorReadOnly(): boolean {
|
||||
|
||||
/**
|
||||
* Whether a decision dialog of a kept part may open: only while editing, in a shown
|
||||
* place, with the references panel closed, so no native modal ever sits inside a hidden
|
||||
* place, with the citations panel closed, so no native modal ever sits inside a hidden
|
||||
* subtree and focus is never lost to `body`.
|
||||
*/
|
||||
export function useDecisionsOpen(): boolean {
|
||||
|
||||
@@ -15,14 +15,16 @@ export type { FocusRequest }
|
||||
*/
|
||||
export type FocusOutcome = 'found' | 'kept' | 'none'
|
||||
|
||||
/** The `data-place` name of the place a target shows. */
|
||||
/**
|
||||
* The `data-place` name of a place. `citations` (the panel) is no navigation target: it
|
||||
* is a name only for its heading and its focus scope.
|
||||
*/
|
||||
export type PlaceName =
|
||||
| EditorTabId
|
||||
| `annotations.${AnnotationSection}`
|
||||
| 'citations'
|
||||
|
||||
export function placeOf(target: EditorTarget): PlaceName {
|
||||
if (target.place === 'references') return 'citations'
|
||||
if (target.tab !== 'annotations') return target.tab
|
||||
return `annotations.${target.section ?? 'drawing'}`
|
||||
}
|
||||
@@ -74,10 +76,16 @@ export function useFocusRequest(
|
||||
}, [focus, apply, consumed])
|
||||
}
|
||||
|
||||
/** The first element matching `selector` that no hidden place contains. */
|
||||
export function visibleElement(selector: string): HTMLElement | null {
|
||||
/** The first element matching `selector` (and `accept`) that no hidden place contains. */
|
||||
export function visibleElement(
|
||||
selector: string,
|
||||
accept: (element: HTMLElement) => boolean = () => true,
|
||||
): HTMLElement | null {
|
||||
const found = [...document.querySelectorAll<HTMLElement>(selector)]
|
||||
return found.find((element) => !element.closest('[hidden]')) ?? null
|
||||
return (
|
||||
found.find((element) => !element.closest('[hidden]') && accept(element)) ??
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
/** Scrolls to and focuses the visible row tagged with `key`; false when there is none. */
|
||||
@@ -117,7 +125,8 @@ const NON_TEXT_INPUTS = new Set([
|
||||
|
||||
/** A field that takes typed text (or a choice): Escape there belongs to the field. */
|
||||
export function isTextField(target: EventTarget | null): boolean {
|
||||
if (target instanceof HTMLInputElement) return !NON_TEXT_INPUTS.has(target.type)
|
||||
if (target instanceof HTMLInputElement)
|
||||
return !NON_TEXT_INPUTS.has(target.type)
|
||||
return (
|
||||
target instanceof HTMLTextAreaElement ||
|
||||
target instanceof HTMLSelectElement ||
|
||||
|
||||
@@ -9,15 +9,16 @@ export const ANNOTATION_SECTIONS = [
|
||||
] as const
|
||||
export type AnnotationSection = (typeof ANNOTATION_SECTIONS)[number]
|
||||
|
||||
/** One encoding: a target on Annotations always names its section, null elsewhere. */
|
||||
export type EditorTarget =
|
||||
| {
|
||||
place: 'tab'
|
||||
tab: EditorTabId
|
||||
section: AnnotationSection | null
|
||||
key: ElementKey | null
|
||||
}
|
||||
| { place: 'references'; key: ElementKey | null; citedBy: ElementKey | null }
|
||||
/**
|
||||
* One encoding: a target on Annotations always names its section, null elsewhere. The
|
||||
* citations panel is no place to go to: it opens only through `open_citations`.
|
||||
*/
|
||||
export interface EditorTarget {
|
||||
place: 'tab'
|
||||
tab: EditorTabId
|
||||
section: AnnotationSection | null
|
||||
key: ElementKey | null
|
||||
}
|
||||
|
||||
/** « Aller à … »: the place to show and a serial so each request is consumed once. */
|
||||
export interface FocusRequest {
|
||||
@@ -28,11 +29,13 @@ export interface FocusRequest {
|
||||
export interface NavigationState {
|
||||
tab: EditorTabId
|
||||
section: AnnotationSection
|
||||
references: { open: boolean; citedBy: ElementKey | null }
|
||||
/** The finding whose citations panel is open; null while it is closed. */
|
||||
citationsOf: ElementKey | null
|
||||
/** Bumped by `show_all_references`: the library resets its search once per bump. */
|
||||
libraryReset: number
|
||||
/** Places already shown, so a body mounts on first visit and stays mounted. */
|
||||
visitedTabs: readonly EditorTabId[]
|
||||
visitedSections: readonly AnnotationSection[]
|
||||
referencesMounted: boolean
|
||||
focus: FocusRequest | undefined
|
||||
/** Last serial issued: it survives `focus_consumed`, so a serial is never reused. */
|
||||
serial: number
|
||||
@@ -42,9 +45,9 @@ export type NavigationAction =
|
||||
| { type: 'select_tab'; tab: EditorTabId }
|
||||
| { type: 'open_section'; section: AnnotationSection }
|
||||
| { type: 'back_to_drawing' }
|
||||
| { type: 'open_references'; citedBy: ElementKey | null }
|
||||
| { type: 'close_references' }
|
||||
| { type: 'clear_cited_by' }
|
||||
| { type: 'open_citations'; citedBy: ElementKey }
|
||||
| { type: 'close_citations' }
|
||||
| { type: 'show_all_references' }
|
||||
| { type: 'go_to'; target: EditorTarget }
|
||||
| { type: 'focus_consumed'; serial: number }
|
||||
|
||||
@@ -69,7 +72,7 @@ export function targetOfKey(key: ElementKey): EditorTarget {
|
||||
case 'finding':
|
||||
return { place: 'tab', tab: TAB_OF_KIND[key.kind], section: null, key }
|
||||
case 'reference':
|
||||
return { place: 'references', key, citedBy: null }
|
||||
return { place: 'tab', tab: 'references', section: null, key }
|
||||
default:
|
||||
return {
|
||||
place: 'tab',
|
||||
@@ -98,57 +101,69 @@ export function initialNavigation(tab: EditorTabId): NavigationState {
|
||||
return shown({
|
||||
tab,
|
||||
section: 'drawing',
|
||||
references: { open: false, citedBy: null },
|
||||
citationsOf: null,
|
||||
libraryReset: 0,
|
||||
visitedTabs: [],
|
||||
visitedSections: [],
|
||||
referencesMounted: false,
|
||||
focus: undefined,
|
||||
serial: 0,
|
||||
})
|
||||
}
|
||||
|
||||
function openReferences(state: NavigationState, citedBy: ElementKey | null) {
|
||||
return {
|
||||
...state,
|
||||
references: { open: true, citedBy },
|
||||
referencesMounted: true,
|
||||
}
|
||||
/**
|
||||
* A finding node (kind `finding` below its family, path of two or more ids). A zone and a
|
||||
* family list their citations inline and have no panel.
|
||||
*/
|
||||
export function isFindingNode(key: ElementKey): boolean {
|
||||
return key.kind === 'finding' && key.path.length > 1
|
||||
}
|
||||
|
||||
/** Only a finding node has a citations panel: any other key leaves the state as it is. */
|
||||
function openCitations(state: NavigationState, citedBy: ElementKey) {
|
||||
return isFindingNode(citedBy) ? { ...state, citationsOf: citedBy } : state
|
||||
}
|
||||
|
||||
function goTo(state: NavigationState, target: EditorTarget): NavigationState {
|
||||
const serial = state.serial + 1
|
||||
const focus = { target, serial }
|
||||
if (target.place === 'references') {
|
||||
return { ...openReferences(state, target.citedBy), focus, serial }
|
||||
}
|
||||
const moved = {
|
||||
...state,
|
||||
tab: target.tab,
|
||||
section: target.section ?? state.section,
|
||||
references: { open: false, citedBy: null },
|
||||
focus,
|
||||
citationsOf: null,
|
||||
focus: { target, serial },
|
||||
serial,
|
||||
}
|
||||
return shown(moved)
|
||||
}
|
||||
|
||||
/** « Tout afficher dans l'onglet Références »: the panel closes, the library starts afresh. */
|
||||
function showAllReferences(state: NavigationState): NavigationState {
|
||||
const moved = {
|
||||
...state,
|
||||
tab: 'references' as const,
|
||||
citationsOf: null,
|
||||
libraryReset: state.libraryReset + 1,
|
||||
}
|
||||
return shown(moved)
|
||||
}
|
||||
|
||||
export function navigationReducer(
|
||||
state: NavigationState,
|
||||
action: NavigationAction,
|
||||
): NavigationState {
|
||||
switch (action.type) {
|
||||
case 'select_tab':
|
||||
return shown({ ...state, tab: action.tab })
|
||||
return shown({ ...state, tab: action.tab, citationsOf: null })
|
||||
case 'open_section':
|
||||
return shown({ ...state, section: action.section })
|
||||
case 'back_to_drawing':
|
||||
return shown({ ...state, section: 'drawing' })
|
||||
case 'open_references':
|
||||
return openReferences(state, action.citedBy)
|
||||
case 'close_references':
|
||||
return { ...state, references: { open: false, citedBy: null } }
|
||||
case 'clear_cited_by':
|
||||
return { ...state, references: { ...state.references, citedBy: null } }
|
||||
case 'open_citations':
|
||||
return openCitations(state, action.citedBy)
|
||||
case 'close_citations':
|
||||
return { ...state, citationsOf: null }
|
||||
case 'show_all_references':
|
||||
return showAllReferences(state)
|
||||
case 'go_to':
|
||||
return goTo(state, action.target)
|
||||
case 'focus_consumed':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { PreviewState } from '@faunosteo/core-wasm/types'
|
||||
import type { ElementKey, PreviewState } from '@faunosteo/core-wasm/types'
|
||||
import type { EditorTarget, FocusRequest } from './navigation'
|
||||
import { unmeasuredViews } from './issues'
|
||||
import type { TabTier } from './useViewport'
|
||||
@@ -7,6 +7,7 @@ export const EDITOR_TABS = [
|
||||
'general',
|
||||
'annotations',
|
||||
'findings',
|
||||
'references',
|
||||
'verification',
|
||||
] as const
|
||||
export type EditorTabId = (typeof EDITOR_TABS)[number]
|
||||
@@ -37,14 +38,18 @@ export function initialTab(state: PreviewState, tier: TabTier): EditorTabId {
|
||||
return SHOWN[tier].includes(wanted) ? wanted : 'annotations'
|
||||
}
|
||||
|
||||
/** Props of every place (tab body, Annotations section, references panel). */
|
||||
/** Props of every place (tab body, Annotations section). */
|
||||
export interface EditorPlaceProps {
|
||||
/** Not editable now: a mode that cannot save, or a recovery offer not answered yet. */
|
||||
readOnly: boolean
|
||||
/** « Aller à … » and any link between places; `opener` takes the focus back on return. */
|
||||
navigate: (target: EditorTarget, opener?: HTMLElement | null) => void
|
||||
/** « Aller à … » and any link between places. */
|
||||
navigate: (target: EditorTarget) => void
|
||||
/** « Aller à … » with an element: the place seeds its own selection from it once. */
|
||||
focus?: FocusRequest
|
||||
/** Opens the citations panel of one finding (only Constats offers it). */
|
||||
openCitations?: (citedBy: ElementKey, opener?: HTMLElement | null) => void
|
||||
/** Bumped by « Tout afficher »: the references library resets its search once per bump. */
|
||||
libraryReset?: number
|
||||
/** Reads the sheet's overview again (after a submission: the round freezes the draft). */
|
||||
reloadSheet: () => void
|
||||
}
|
||||
@@ -53,5 +58,3 @@ export const tabDomId = (tab: EditorTabId) => `editor-tab-${tab}`
|
||||
export const panelDomId = (tab: EditorTabId) => `editor-panel-${tab}`
|
||||
/** The « Plus » disclosure button, focused when the active tab sits under it. */
|
||||
export const MORE_BUTTON_ID = 'editor-tabs-more-button'
|
||||
/** The header button that toggles the references panel. */
|
||||
export const REFERENCES_BUTTON_ID = 'editor-references-button'
|
||||
@@ -11,6 +11,7 @@ import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import { useT } from '@/i18n/useT'
|
||||
import {
|
||||
commitFocusedField,
|
||||
focusActiveTab,
|
||||
placeOf,
|
||||
visibleElement,
|
||||
type FocusOutcome,
|
||||
@@ -18,25 +19,23 @@ import {
|
||||
} from './focusRequest'
|
||||
import {
|
||||
initialNavigation,
|
||||
isFindingNode,
|
||||
navigationReducer,
|
||||
type AnnotationSection,
|
||||
type EditorTarget,
|
||||
type NavigationAction,
|
||||
type NavigationState,
|
||||
} from './navigation'
|
||||
import {
|
||||
MORE_BUTTON_ID,
|
||||
REFERENCES_BUTTON_ID,
|
||||
tabDomId,
|
||||
type EditorTabId,
|
||||
} from './tabs'
|
||||
import { MORE_BUTTON_ID, tabDomId, type EditorTabId } from './tabs'
|
||||
|
||||
type MoveKind =
|
||||
| 'go_to'
|
||||
| 'section'
|
||||
| 'back'
|
||||
| 'references'
|
||||
| 'references_closed'
|
||||
| 'citations'
|
||||
| 'citations_closed'
|
||||
| 'show_all'
|
||||
| 'tab_selected'
|
||||
|
||||
/** A programmatic move: a new object per move, so the effect after it runs once. */
|
||||
interface Move {
|
||||
@@ -49,13 +48,15 @@ export interface EditorNavigation {
|
||||
state: NavigationState
|
||||
/** The polite live region's text; a repeat alternates a trailing no-break space. */
|
||||
live: string
|
||||
navigate: (target: EditorTarget, opener?: Opener) => void
|
||||
navigate: (target: EditorTarget) => void
|
||||
selectTab: (tab: EditorTabId) => void
|
||||
openSection: (section: AnnotationSection, opener?: Opener) => void
|
||||
backToDrawing: () => void
|
||||
openReferences: (citedBy: ElementKey | null, opener?: Opener) => void
|
||||
closeReferences: () => void
|
||||
/** « Tout afficher »: drops the finding filter; no move, no announcement. */
|
||||
/** Opens the citations panel of a finding node; any other key is ignored. */
|
||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||
/** Every close (✕, Escape, scrim, element gone): the focus goes to P6's fallbacks. */
|
||||
closeCitations: () => void
|
||||
/** « Tout afficher dans l'onglet Références »: panel closed, tab shown, library reset. */
|
||||
showAllReferences: () => void
|
||||
consumed: (serial: number, outcome: FocusOutcome) => void
|
||||
announce: (text: string) => void
|
||||
@@ -87,7 +88,6 @@ function useMoveText(): (target: EditorTarget) => string {
|
||||
const t = useT()
|
||||
return useCallback(
|
||||
(target) => {
|
||||
if (target.place === 'references') return t('editor.place.references')
|
||||
const tab = t(`editor.tab.${target.tab}`)
|
||||
if (!target.section) return tab
|
||||
return `${tab} · ${t(`editor.place.${target.section}`)}`
|
||||
@@ -105,7 +105,9 @@ function useLiveRegion() {
|
||||
}
|
||||
|
||||
interface Openers {
|
||||
references: RefObject<HTMLElement | null>
|
||||
/** The trigger that opened the citations panel, and the finding it belongs to. */
|
||||
citations: RefObject<HTMLElement | null>
|
||||
citedBy: RefObject<ElementKey | null>
|
||||
section: RefObject<HTMLElement | null>
|
||||
}
|
||||
|
||||
@@ -132,13 +134,9 @@ function useSectionMoves(go: Go, openers: Openers) {
|
||||
const t = useT()
|
||||
const moveText = useMoveText()
|
||||
const navigate = useCallback(
|
||||
(target: EditorTarget, opener?: Opener) => {
|
||||
if (target.place === 'references') {
|
||||
openers.references.current = opener ?? null
|
||||
}
|
||||
go({ type: 'go_to', target }, 'go_to', moveText(target))
|
||||
},
|
||||
[go, moveText, openers],
|
||||
(target: EditorTarget) =>
|
||||
go({ type: 'go_to', target }, 'go_to', moveText(target)),
|
||||
[go, moveText],
|
||||
)
|
||||
const openSection = useCallback(
|
||||
(section: AnnotationSection, opener?: Opener) => {
|
||||
@@ -156,30 +154,33 @@ function useSectionMoves(go: Go, openers: Openers) {
|
||||
return { navigate, openSection, backToDrawing }
|
||||
}
|
||||
|
||||
/** The references panel moves: open (optionally filtered) and close. */
|
||||
function useReferenceMoves(
|
||||
go: Go,
|
||||
openers: Openers,
|
||||
dispatch: Dispatch<NavigationAction>,
|
||||
) {
|
||||
/** The citations panel moves: open from a finding, close, « Tout afficher ». */
|
||||
function useCitationsMoves(go: Go, openers: Openers) {
|
||||
const t = useT()
|
||||
const openReferences = useCallback(
|
||||
(citedBy: ElementKey | null, opener?: Opener) => {
|
||||
openers.references.current = opener ?? null
|
||||
const action = { type: 'open_references', citedBy } as const
|
||||
go(action, 'references', t('editor.place.references'))
|
||||
const openCitations = useCallback(
|
||||
(citedBy: ElementKey, opener?: Opener) => {
|
||||
if (!isFindingNode(citedBy)) return
|
||||
openers.citations.current = opener ?? null
|
||||
openers.citedBy.current = citedBy
|
||||
const action = { type: 'open_citations', citedBy } as const
|
||||
go(action, 'citations', t('editor.place.references'))
|
||||
},
|
||||
[go, openers, t],
|
||||
)
|
||||
const closeReferences = useCallback(() => {
|
||||
const closeCitations = useCallback(() => {
|
||||
const text = t('editor.live.references_closed')
|
||||
go({ type: 'close_references' }, 'references_closed', text)
|
||||
go({ type: 'close_citations' }, 'citations_closed', text)
|
||||
}, [go, t])
|
||||
const showAllReferences = useCallback(
|
||||
() => dispatch({ type: 'clear_cited_by' }),
|
||||
[dispatch],
|
||||
() =>
|
||||
go(
|
||||
{ type: 'show_all_references' },
|
||||
'show_all',
|
||||
t('editor.tab.references'),
|
||||
),
|
||||
[go, t],
|
||||
)
|
||||
return { openReferences, closeReferences, showAllReferences }
|
||||
return { openCitations, closeCitations, showAllReferences }
|
||||
}
|
||||
|
||||
/** « Retour au dessin »: the entry that opened the section, else the canvas box. */
|
||||
@@ -190,15 +191,34 @@ function backTarget(opener: HTMLElement | null): HTMLElement | null {
|
||||
return again || visibleElement(CANVAS_BOX)
|
||||
}
|
||||
|
||||
/** Panel closed: the opener when it is shown, else the header button. */
|
||||
function referencesBack(opener: HTMLElement | null): HTMLElement | null {
|
||||
/** The trigger of a finding's citations, found by comparing `dataset` values. */
|
||||
function triggerOf(openers: Openers): HTMLElement | null {
|
||||
const opener = openers.citations.current
|
||||
if (opener && isShown(opener)) return opener
|
||||
return document.getElementById(REFERENCES_BUTTON_ID)
|
||||
const wanted = JSON.stringify(openers.citedBy.current)
|
||||
return visibleElement('[data-citations-trigger]', (element) => {
|
||||
return element.dataset.citationsTrigger === wanted
|
||||
})
|
||||
}
|
||||
|
||||
/** Focuses `element` and says whether it really holds the focus now. */
|
||||
function focusHeld(element: HTMLElement | null): boolean {
|
||||
element?.focus()
|
||||
return element !== null && document.activeElement === element
|
||||
}
|
||||
|
||||
/** Panel closed (P6): the trigger when it is shown, else the active tab's button. */
|
||||
function focusAfterClose(openers: Openers) {
|
||||
if (!focusHeld(triggerOf(openers))) focusActiveTab()
|
||||
}
|
||||
|
||||
/** Where the focus lands after a programmatic move; never `body`. */
|
||||
function landingOf(move: Move, state: NavigationState): HTMLElement | null {
|
||||
if (move.kind === 'references') return headingOf('citations')
|
||||
if (move.kind === 'citations') return headingOf('citations')
|
||||
if (move.kind === 'show_all') {
|
||||
return headingOf('references') ?? tabButton(state.tab)
|
||||
}
|
||||
if (move.kind === 'tab_selected') return tabButton(state.tab)
|
||||
const place = state.focus ? placeOf(state.focus.target) : shownPlace(state)
|
||||
return headingOf(place) ?? tabButton(state.tab)
|
||||
}
|
||||
@@ -218,8 +238,8 @@ function useMoveFocus(
|
||||
useEffect(() => {
|
||||
if (!move || handled.current === move) return
|
||||
handled.current = move
|
||||
if (move.kind === 'references_closed') {
|
||||
referencesBack(openers.references.current)?.focus()
|
||||
if (move.kind === 'citations_closed') {
|
||||
focusAfterClose(openers)
|
||||
return
|
||||
}
|
||||
const serial = state.focus?.serial
|
||||
@@ -234,7 +254,7 @@ function useMoveFocus(
|
||||
}, [move, state, outcomes, dispatch, openers])
|
||||
}
|
||||
|
||||
/** Tab selection, and the outcomes the places report for each focus request. */
|
||||
/** The outcomes the places report for each focus request. */
|
||||
function useReceipts(dispatch: Dispatch<NavigationAction>) {
|
||||
const outcomes = useRef(new Map<number, FocusOutcome>())
|
||||
const consumed = useCallback(
|
||||
@@ -244,14 +264,25 @@ function useReceipts(dispatch: Dispatch<NavigationAction>) {
|
||||
},
|
||||
[dispatch],
|
||||
)
|
||||
const selectTab = useCallback(
|
||||
return { outcomes, consumed }
|
||||
}
|
||||
|
||||
/** A tab choice; with the citations panel open it closes and the new tab takes the focus. */
|
||||
function useTabSelect(
|
||||
go: Go,
|
||||
dispatch: Dispatch<NavigationAction>,
|
||||
open: boolean,
|
||||
) {
|
||||
const t = useT()
|
||||
return useCallback(
|
||||
(tab: EditorTabId) => {
|
||||
const action = { type: 'select_tab', tab } as const
|
||||
if (open) return go(action, 'tab_selected', t(`editor.tab.${tab}`))
|
||||
commitFocusedField()
|
||||
dispatch({ type: 'select_tab', tab })
|
||||
dispatch(action)
|
||||
},
|
||||
[dispatch],
|
||||
[go, dispatch, open, t],
|
||||
)
|
||||
return { outcomes, consumed, selectTab }
|
||||
}
|
||||
|
||||
/** Navigation of the draft editor: the reducer plus the DOM side (focus, live region). */
|
||||
@@ -263,7 +294,8 @@ export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
|
||||
)
|
||||
const { move, go, live, announce } = useGo(dispatch)
|
||||
const openers = useRef<Openers>({
|
||||
references: { current: null },
|
||||
citations: { current: null },
|
||||
citedBy: { current: null },
|
||||
section: { current: null },
|
||||
}).current
|
||||
const receipts = useReceipts(dispatch)
|
||||
@@ -273,8 +305,8 @@ export function useEditorNavigation(initialTab: EditorTabId): EditorNavigation {
|
||||
live,
|
||||
announce,
|
||||
consumed: receipts.consumed,
|
||||
selectTab: receipts.selectTab,
|
||||
selectTab: useTabSelect(go, dispatch, state.citationsOf !== null),
|
||||
...useSectionMoves(go, openers),
|
||||
...useReferenceMoves(go, openers, dispatch),
|
||||
...useCitationsMoves(go, openers),
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { commitFocusedField, heldElement, refocusIfHidden } from './focusRequest'
|
||||
import { MIN_EDIT_WIDTH } from './mode'
|
||||
|
||||
/** The tab lists of board 05: all, the four of 640 px and over, the two below. */
|
||||
/** The tab lists of board 05: all, the five of 640 px and over, the two below. */
|
||||
export type TabTier = 'wide' | 'medium' | 'small'
|
||||
|
||||
const MEDIUM_WIDTH = 640
|
||||
|
||||
@@ -157,7 +157,6 @@ export function issueTarget(
|
||||
|
||||
/** The i18n key of the name of the place a target shows. */
|
||||
export function placeKey(target: EditorTarget): string {
|
||||
if (target.place === 'references') return 'editor.place.references'
|
||||
if (target.section && target.section !== 'drawing') {
|
||||
return `editor.place.${target.section}`
|
||||
}
|
||||
|
||||
@@ -1194,6 +1194,7 @@ export const en: Dict = {
|
||||
'editor.tab.general': 'General',
|
||||
'editor.tab.annotations': 'Annotations',
|
||||
'editor.tab.findings': 'Findings',
|
||||
'editor.tab.references': 'References',
|
||||
'editor.tab.verification': 'Verification',
|
||||
'editor.tab.more': 'More',
|
||||
'editor.tab.errors_one': '{count} error',
|
||||
@@ -1227,7 +1228,6 @@ export const en: Dict = {
|
||||
'editor.annotations.show_all': 'All annotations',
|
||||
'editor.annotations.deselect': 'Deselect',
|
||||
'editor.annotations.deselected': 'No annotation selected.',
|
||||
'editor.references.open': 'References',
|
||||
'editor.references.close': 'Close the references',
|
||||
'editor.references.search': 'Search a reference',
|
||||
'editor.references.cited_by': 'Cited by « {name} » ({count})',
|
||||
|
||||
@@ -1225,6 +1225,7 @@ export const fr: Dict = {
|
||||
'editor.tab.general': 'Général',
|
||||
'editor.tab.annotations': 'Annotations',
|
||||
'editor.tab.findings': 'Constats',
|
||||
'editor.tab.references': 'Références',
|
||||
'editor.tab.verification': 'Vérification',
|
||||
'editor.tab.more': 'Plus',
|
||||
'editor.tab.errors_one': '{count} erreur',
|
||||
@@ -1258,7 +1259,6 @@ export const fr: Dict = {
|
||||
'editor.annotations.show_all': 'Toutes les annotations',
|
||||
'editor.annotations.deselect': 'Désélectionner',
|
||||
'editor.annotations.deselected': 'Aucune annotation sélectionnée.',
|
||||
'editor.references.open': 'Références',
|
||||
'editor.references.close': 'Fermer les références',
|
||||
'editor.references.search': 'Rechercher une référence',
|
||||
'editor.references.cited_by': 'Citées par « {name} » ({count})',
|
||||
|
||||
@@ -13,7 +13,7 @@ import userEvent from '@testing-library/user-event'
|
||||
import type { Annotation } from '@faunosteo/core-wasm/types'
|
||||
import ModalDialog from '@/components/ui/ModalDialog'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { drawnText, edit, insert, point } from '../helpers/editorFixtures'
|
||||
import { resetStore, serverHas, store } from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
@@ -56,6 +56,57 @@ const ZONE = () =>
|
||||
} as Annotation,
|
||||
})
|
||||
|
||||
/** TWO plus a finding node that cites one reference: the citations panel has a trigger. */
|
||||
const WITH_NODE = () => {
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
let text = insert(TWO(), {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id: 'ref-a',
|
||||
type: 'book',
|
||||
citation: 'Alpha',
|
||||
url: null,
|
||||
doi: null,
|
||||
},
|
||||
})
|
||||
text = insert(text, {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
})
|
||||
text = edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
id: 'fcat-a',
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat A'),
|
||||
description: {},
|
||||
reference_ids: [],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
return edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
reference_ids: ['ref-a'],
|
||||
requires_vet_referral: false,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const shown = (selector: string) =>
|
||||
[...document.querySelectorAll<HTMLElement>(selector)].find(
|
||||
(element) => !element.closest('[hidden]'),
|
||||
@@ -86,6 +137,17 @@ async function select(user: ReturnType<typeof userEvent.setup>, id = 'anno-a') {
|
||||
}
|
||||
const canvasBox = () =>
|
||||
shown('[data-place="annotations.drawing"] [role="group"][tabindex="0"]')!
|
||||
const citations = () => screen.queryByTestId('editor-citations-panel')
|
||||
|
||||
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
||||
async function openCitations(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
await user.keyboard('{ArrowRight}')
|
||||
await user.click(screen.getByRole('treeitem', { name: /Node A/ }))
|
||||
await user.click(screen.getByRole('button', { name: '1 référence' }))
|
||||
expect(citations()).not.toBeNull()
|
||||
}
|
||||
const inPanel = (name: string) => within(panel()!).getByRole('button', { name })
|
||||
|
||||
describe('Escape deselects', () => {
|
||||
@@ -215,14 +277,16 @@ describe('Escape with the focus on the page', () => {
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
it('the references panel open: it closes, the selection is kept', async () => {
|
||||
const user = await mount()
|
||||
it('the citations panel open: it closes, the annotation selection is kept', async () => {
|
||||
const user = await mount(WITH_NODE())
|
||||
await select(user)
|
||||
const toggle = screen.getByRole('button', { name: 'Références' })
|
||||
await user.click(toggle)
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'true')
|
||||
await openCitations(user)
|
||||
const trigger = screen.getByRole('button', { name: '1 référence' })
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'true')
|
||||
escape(document.body)
|
||||
expect(toggle).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(citations()).toBeNull()
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
@@ -242,8 +306,9 @@ describe('Escape with the focus on the page', () => {
|
||||
const user = await mount(TWO(), 500)
|
||||
const more = screen.getByRole('button', { name: 'Plus' })
|
||||
await user.click(more)
|
||||
const filter = within(shown('[data-testid="annotation-overview"]')!)
|
||||
.getByRole('searchbox', { name: 'Filtrer par nom' })
|
||||
const filter = within(
|
||||
shown('[data-testid="annotation-overview"]')!,
|
||||
).getByRole('searchbox', { name: 'Filtrer par nom' })
|
||||
filter.focus()
|
||||
escape(filter)
|
||||
expect(more).toHaveAttribute('aria-expanded', 'true')
|
||||
@@ -252,16 +317,13 @@ describe('Escape with the focus on the page', () => {
|
||||
})
|
||||
|
||||
describe('Escape and the other layers', () => {
|
||||
it('closes the references panel from the tab row, the selection kept', async () => {
|
||||
const user = await mount()
|
||||
it('closes the citations panel from the tab row, the selection kept', async () => {
|
||||
const user = await mount(WITH_NODE())
|
||||
await select(user)
|
||||
await user.click(screen.getByRole('button', { name: 'Références' }))
|
||||
const tab = screen.getByRole('tab', { name: 'Annotations' })
|
||||
escape(tab)
|
||||
expect(screen.getByRole('button', { name: 'Références' })).toHaveAttribute(
|
||||
'aria-expanded',
|
||||
'false',
|
||||
)
|
||||
await openCitations(user)
|
||||
escape(screen.getByRole('tab', { name: 'Constats' }))
|
||||
expect(citations()).toBeNull()
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
import FindingCreateForm from '@/components/editor/findings/FindingCreateForm'
|
||||
import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import { buildItems, keyMove, visibleItems } from '@/editor/findings/tree'
|
||||
import { initialNavigation, navigationReducer } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
@@ -553,6 +554,52 @@ describe('Constats tab', () => {
|
||||
expect(node().reference_ids).toEqual([])
|
||||
})
|
||||
|
||||
it('the trigger shows exactly for the keys open_citations accepts', async () => {
|
||||
let text = insert(treeText(), {
|
||||
kind: 'reference',
|
||||
value: { id: 'ref-a', type: 'book', citation: 'A', url: null, doi: null },
|
||||
})
|
||||
for (const item of buildItems(JSON.parse(text))) {
|
||||
if (item.element.kind === 'zone') continue
|
||||
text = edit(text, {
|
||||
op: 'update',
|
||||
key: item.key,
|
||||
element: {
|
||||
...item.element,
|
||||
value: { ...item.element.value, reference_ids: ['ref-a'] },
|
||||
} as never,
|
||||
})
|
||||
}
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
const openCitations = vi.fn()
|
||||
render(<FindingsTab {...props} openCitations={openCitations} />)
|
||||
await user.click(items()[1])
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}{ArrowRight}')
|
||||
const all = buildItems(doc())
|
||||
expect(items()).toHaveLength(all.length)
|
||||
const truth: [string, boolean][] = []
|
||||
for (const [index, item] of all.entries()) {
|
||||
await user.click(items()[index])
|
||||
const shown = screen.queryByRole('button', { name: /^1 référence$/ })
|
||||
const start = initialNavigation('findings')
|
||||
const accepted =
|
||||
navigationReducer(start, { type: 'open_citations', citedBy: item.key })
|
||||
.citationsOf !== null
|
||||
expect(shown !== null, item.id).toBe(accepted)
|
||||
truth.push([item.kind, shown !== null])
|
||||
}
|
||||
expect(truth).toEqual([
|
||||
['zone', false],
|
||||
['category', false],
|
||||
['node', true],
|
||||
['node', true],
|
||||
['zone', false],
|
||||
])
|
||||
expect(all.some((item) => item.kind === 'category')).toBe(true)
|
||||
expect(all.filter((item) => item.kind === 'node')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('a category has no vet flag; read-only hides the editing actions', async () => {
|
||||
await openReady({ text: treeText() })
|
||||
const user = userEvent.setup()
|
||||
|
||||
@@ -17,7 +17,7 @@ import FindingsTab from '@/components/editor/tabs/FindingsTab'
|
||||
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||
import EditorTabBody from '@/components/editor/EditorTabBody'
|
||||
import EditorTabs from '@/components/editor/EditorTabs'
|
||||
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||
import ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import {
|
||||
FocusConsumedContext,
|
||||
@@ -54,7 +54,6 @@ const section = {
|
||||
onOpenSection: vi.fn(),
|
||||
onBack: vi.fn(),
|
||||
}
|
||||
const panel = { open: true, onClose: vi.fn() }
|
||||
const request = (key: ElementKey, serial = 1): FocusRequest => ({
|
||||
target: targetOfKey(key),
|
||||
serial,
|
||||
@@ -163,9 +162,8 @@ describe('focus requests', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
render(
|
||||
<ReferencesPanel
|
||||
<ReferenceLibrary
|
||||
{...base}
|
||||
{...panel}
|
||||
focus={request({ kind: 'reference', id: 'ref-a' })}
|
||||
/>,
|
||||
)
|
||||
@@ -197,9 +195,9 @@ describe('focus requests', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const focus = request({ kind: 'reference', id: 'ref-a' })
|
||||
const view = render(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||
const view = render(<ReferenceLibrary {...base} focus={focus} />)
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
view.rerender(<ReferencesPanel {...base} {...panel} focus={focus} />)
|
||||
view.rerender(<ReferenceLibrary {...base} focus={focus} />)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -223,7 +221,8 @@ describe('ownedBy', () => {
|
||||
expect(ownedBy(view, 'annotations.drawing')).toBeUndefined()
|
||||
expect(ownedBy(view, 'general')).toBeUndefined()
|
||||
const ref = request({ kind: 'reference', id: 'ref-a' })
|
||||
expect(ownedBy(ref, 'citations')).toBe(ref)
|
||||
expect(ownedBy(ref, 'references')).toBe(ref)
|
||||
expect(ownedBy(ref, 'citations')).toBeUndefined()
|
||||
expect(ownedBy(ref, 'findings')).toBeUndefined()
|
||||
expect(ownedBy(undefined, 'general')).toBeUndefined()
|
||||
})
|
||||
@@ -267,6 +266,7 @@ function Probe({ go, tier }: { go: EditorTarget; tier: 'wide' | 'small' }) {
|
||||
visited={state.visitedTabs}
|
||||
{...base}
|
||||
navigate={nav.navigate}
|
||||
openCitations={nav.openCitations}
|
||||
focus={state.focus}
|
||||
annotations={{
|
||||
section: state.section,
|
||||
@@ -279,6 +279,30 @@ function Probe({ go, tier }: { go: EditorTarget; tier: 'wide' | 'small' }) {
|
||||
)
|
||||
}
|
||||
|
||||
function ShowAllProbe() {
|
||||
const nav = useEditorNavigation('findings')
|
||||
return (
|
||||
<>
|
||||
<EditorTabs active={nav.state.tab} tier="wide" onSelect={nav.selectTab} />
|
||||
<button onClick={nav.showAllReferences}>show all</button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
describe('« Tout afficher » landing', () => {
|
||||
it('falls back to the tab button when the tab heading is absent', async () => {
|
||||
await openReady()
|
||||
const user = userEvent.setup()
|
||||
render(<ShowAllProbe />)
|
||||
await user.click(screen.getByText('show all'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('tab', { name: 'Références' }),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a request that finds nothing', () => {
|
||||
const missing: EditorTarget = {
|
||||
place: 'tab',
|
||||
@@ -311,6 +335,51 @@ describe('a request that finds nothing', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('Vérification « Aller à » a reference: the tab shows, its row holds the focus', async () => {
|
||||
const text = insert(baseText(), {
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id: 'ref-a',
|
||||
type: 'book',
|
||||
citation: 'Alpha',
|
||||
url: null,
|
||||
doi: null,
|
||||
},
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
const key: ElementKey = { kind: 'reference', id: 'ref-a' }
|
||||
render(<Probe go={targetOfKey(key)} tier="wide" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||
'ref-a',
|
||||
),
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: 'Références' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
})
|
||||
|
||||
it('a reference path that names no element lands on the tab heading', async () => {
|
||||
await openReady()
|
||||
const user = userEvent.setup()
|
||||
const alone: EditorTarget = {
|
||||
place: 'tab',
|
||||
tab: 'references',
|
||||
section: null,
|
||||
key: null,
|
||||
}
|
||||
render(<Probe go={alone} tier="wide" />)
|
||||
await user.click(screen.getByText('go'))
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('heading', { name: 'Références' }),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('a found element keeps the focus it took', async () => {
|
||||
await openReady({ text: findingsText() })
|
||||
const user = userEvent.setup()
|
||||
@@ -343,7 +412,7 @@ function Harness() {
|
||||
switch
|
||||
</button>
|
||||
{shown === 'references' ? (
|
||||
<ReferencesPanel {...base} {...panel} focus={focus} />
|
||||
<ReferenceLibrary {...base} focus={focus} />
|
||||
) : (
|
||||
<RegionsSection {...base} focus={focus} />
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/** U1 Lot B2a: tabs, Annotations sections and the references panel stay mounted. */
|
||||
/** U1 Lot B2a: tabs, Annotations sections and the Références tab stay mounted. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
@@ -68,16 +68,14 @@ const entry = (name: string | RegExp) => screen.getByRole('button', { name })
|
||||
const place = (name: string) =>
|
||||
document.querySelector<HTMLElement>(`[data-place="${name}"]`)!
|
||||
const inPlace = (name: string) => within(place(name))
|
||||
const referencesButton = () =>
|
||||
screen.getByRole('button', { name: 'Références' })
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
|
||||
function findingsText(): string {
|
||||
const text = insert(baseText(), {
|
||||
function findingsText(from = baseText(), nodeRefs?: string[]): string {
|
||||
const text = insert(from, {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
})
|
||||
return edit(text, {
|
||||
const family = edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
@@ -93,6 +91,23 @@ function findingsText(): string {
|
||||
},
|
||||
},
|
||||
})
|
||||
if (!nodeRefs) return family
|
||||
return edit(family, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
reference_ids: nodeRefs,
|
||||
requires_vet_referral: false,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function referenceText(): string {
|
||||
@@ -108,6 +123,15 @@ function referenceText(): string {
|
||||
})
|
||||
}
|
||||
|
||||
/** Constats, the node selected, its « 1 référence » trigger pressed. */
|
||||
async function openCitations(user: Awaited<ReturnType<typeof mount>>) {
|
||||
await user.click(tab('Constats'))
|
||||
await user.click(screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
await user.keyboard('{ArrowRight}')
|
||||
await user.click(screen.getByRole('treeitem', { name: /Node A/ }))
|
||||
await user.click(screen.getByRole('button', { name: '1 référence' }))
|
||||
}
|
||||
|
||||
async function mount(text = baseText()) {
|
||||
serverHas(text, 3)
|
||||
const user = userEvent.setup()
|
||||
@@ -175,16 +199,16 @@ describe('text typed in a place that is left', () => {
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
|
||||
it('the reference add form survives closing and reopening the panel', async () => {
|
||||
it('the reference add form survives leaving and returning to the Références tab', async () => {
|
||||
const user = await mount()
|
||||
await user.click(referencesButton())
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
selector: '#reference-new-citation',
|
||||
await user.click(tab('Références'))
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-new-citation',
|
||||
})
|
||||
await user.type(field, 'Smith 1999')
|
||||
await user.click(referencesButton())
|
||||
expect(place('citations')).not.toBeVisible()
|
||||
await user.click(referencesButton())
|
||||
await user.click(tab('Annotations'))
|
||||
expect(place('references')).not.toBeVisible()
|
||||
await user.click(tab('Références'))
|
||||
expect(field).toHaveValue('Smith 1999')
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
@@ -300,46 +324,35 @@ describe('a field still focused while a place is left', () => {
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('« Aller à » activated without a focus move commits it, as one undo entry', async () => {
|
||||
const bare = point('anno-bare', 10, 10, 2)
|
||||
const value = { ...bare.value, geometry: null, name: name('Sans tracé') }
|
||||
const text = insert(referenceText(), {
|
||||
kind: 'annotation',
|
||||
value,
|
||||
} as typeof bare)
|
||||
const user = await mount(text)
|
||||
it('a tab click without a focus move commits the Références text, as one undo entry', async () => {
|
||||
const user = await mount(referenceText())
|
||||
const before = store.getState().documentText
|
||||
await user.click(tab(/Vérification/))
|
||||
await user.click(referencesButton())
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
selector: '#reference-ref-1-citation',
|
||||
await user.click(tab('Références'))
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2023' } })
|
||||
fireEvent.click(
|
||||
inPlace('verification').getAllByRole('button', {
|
||||
name: 'Aller à Sans tracé',
|
||||
})[0],
|
||||
)
|
||||
fireEvent.click(tab(/Vérification/))
|
||||
expect(
|
||||
JSON.parse(store.getState().documentText).references[0].citation,
|
||||
).toBe('Doe 2023')
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
expect(place('citations')).not.toBeVisible()
|
||||
expect(place('references')).not.toBeVisible()
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('Escape in a reference field commits the text before the panel hides', async () => {
|
||||
const user = await mount(referenceText())
|
||||
await user.click(referencesButton())
|
||||
it('Escape in a citations panel field commits the text before the panel closes', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
await openCitations(user)
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
selector: '#reference-ref-1-citation',
|
||||
selector: '#panel-reference-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2021' } })
|
||||
await user.keyboard('{Escape}')
|
||||
expect(place('citations')).not.toBeVisible()
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
const doc: AnatomicalSheetDocument = JSON.parse(
|
||||
store.getState().documentText,
|
||||
)
|
||||
@@ -347,16 +360,16 @@ describe('a field still focused while a place is left', () => {
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
})
|
||||
|
||||
it('the header toggle (no focus move) closes the panel after committing', async () => {
|
||||
const user = await mount(referenceText())
|
||||
await user.click(referencesButton())
|
||||
it('the scrim (no focus move) closes the panel after committing', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
await openCitations(user)
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
selector: '#reference-ref-1-citation',
|
||||
selector: '#panel-reference-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2022' } })
|
||||
fireEvent.click(referencesButton())
|
||||
expect(place('citations')).not.toBeVisible()
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(
|
||||
JSON.parse(store.getState().documentText).references[0].citation,
|
||||
).toBe('Doe 2022')
|
||||
@@ -419,10 +432,9 @@ describe('ids and parses', () => {
|
||||
await user.click(entry('Modifier les catégories'))
|
||||
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||
await user.click(entry(/^Régions vertébrales/))
|
||||
for (const name of ['Général', 'Constats', /Vérification/]) {
|
||||
for (const name of ['Général', 'Constats', 'Références', /Vérification/]) {
|
||||
await user.click(tab(name))
|
||||
}
|
||||
await user.click(referencesButton())
|
||||
expect(composedHosts()).toHaveLength(0)
|
||||
await user.click(tab('Annotations'))
|
||||
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||
|
||||
@@ -97,15 +97,20 @@ describe('modeAfterSave', () => {
|
||||
})
|
||||
|
||||
describe('tabsFor', () => {
|
||||
it('the static lists of board 05, four tabs', () => {
|
||||
it('the static lists of board 05, five tabs', () => {
|
||||
expect(tabsFor('wide').more).toEqual([])
|
||||
expect(tabsFor('medium').shown).toEqual([
|
||||
'general',
|
||||
'annotations',
|
||||
'findings',
|
||||
'references',
|
||||
'verification',
|
||||
])
|
||||
expect(tabsFor('small').shown).toEqual(['annotations', 'verification'])
|
||||
expect(tabsFor('small').more).toEqual(['general', 'findings'])
|
||||
expect(tabsFor('small').more).toEqual([
|
||||
'general',
|
||||
'findings',
|
||||
'references',
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
|
||||
const view: ElementKey = { kind: 'view', id: 'v1' }
|
||||
const finding: ElementKey = { kind: 'finding', zone_id: 'z1', path: ['a'] }
|
||||
const node: ElementKey = { kind: 'finding', zone_id: 'z1', path: ['a', 'b'] }
|
||||
|
||||
function run(
|
||||
state: NavigationState,
|
||||
@@ -59,11 +60,7 @@ describe('targetOfKey', () => {
|
||||
],
|
||||
[
|
||||
{ kind: 'reference', id: 'x' },
|
||||
{
|
||||
place: 'references',
|
||||
key: { kind: 'reference', id: 'x' },
|
||||
citedBy: null,
|
||||
},
|
||||
tab('references', null, { kind: 'reference', id: 'x' }) as EditorTarget,
|
||||
],
|
||||
]
|
||||
it.each(cases)('maps %j', (key, expected) => {
|
||||
@@ -77,7 +74,8 @@ describe('navigationReducer', () => {
|
||||
expect(state.visitedTabs).toEqual(['annotations'])
|
||||
expect(state.visitedSections).toEqual(['drawing'])
|
||||
expect(initialNavigation('general').visitedSections).toEqual([])
|
||||
expect(state.referencesMounted).toBe(false)
|
||||
expect(state.citationsOf).toBeNull()
|
||||
expect(state.libraryReset).toBe(0)
|
||||
})
|
||||
|
||||
it('go_to sets the place and increments the serial', () => {
|
||||
@@ -93,56 +91,78 @@ describe('navigationReducer', () => {
|
||||
expect(again.focus?.serial).toBe(2)
|
||||
})
|
||||
|
||||
it('go_to a reference opens the panel over the current place', () => {
|
||||
const base = run(initialNavigation('annotations'), {
|
||||
type: 'open_section',
|
||||
section: 'views',
|
||||
})
|
||||
const state = run(base, {
|
||||
it('go_to a reference shows the Références tab with its element', () => {
|
||||
const key: ElementKey = { kind: 'reference', id: 'x' }
|
||||
const state = run(initialNavigation('general'), {
|
||||
type: 'go_to',
|
||||
target: targetOfKey({ kind: 'reference', id: 'x' }),
|
||||
target: targetOfKey(key),
|
||||
})
|
||||
expect(state).toMatchObject({
|
||||
tab: 'annotations',
|
||||
section: 'views',
|
||||
referencesMounted: true,
|
||||
})
|
||||
expect(state.references.open).toBe(true)
|
||||
expect(state).toMatchObject({ tab: 'references', citationsOf: null })
|
||||
expect(state.visitedTabs).toEqual(['general', 'references'])
|
||||
expect(state.focus?.target).toEqual(targetOfKey(key))
|
||||
})
|
||||
|
||||
it('go_to a tab closes the panel', () => {
|
||||
it('go_to a tab closes the citations panel', () => {
|
||||
const state = run(
|
||||
initialNavigation('general'),
|
||||
{ type: 'open_references', citedBy: view },
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
{ type: 'go_to', target: targetOfKey(finding) },
|
||||
)
|
||||
expect(state.references).toEqual({ open: false, citedBy: null })
|
||||
expect(state.referencesMounted).toBe(true)
|
||||
expect(state.citationsOf).toBeNull()
|
||||
})
|
||||
|
||||
it('select_tab keeps section and panel and issues no request', () => {
|
||||
it('select_tab closes the panel and keeps the section, no request', () => {
|
||||
const state = run(
|
||||
initialNavigation('annotations'),
|
||||
{ type: 'open_section', section: 'regions' },
|
||||
{ type: 'open_references', citedBy: view },
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
{ type: 'select_tab', tab: 'findings' },
|
||||
)
|
||||
expect(state).toMatchObject({
|
||||
tab: 'findings',
|
||||
section: 'regions',
|
||||
citationsOf: null,
|
||||
focus: undefined,
|
||||
})
|
||||
expect(state.references).toEqual({ open: true, citedBy: view })
|
||||
})
|
||||
|
||||
it('clear_cited_by drops the filter and keeps the panel open', () => {
|
||||
it('open_citations opens for a finding node only', () => {
|
||||
const base = initialNavigation('findings')
|
||||
expect(
|
||||
run(base, { type: 'open_citations', citedBy: node }).citationsOf,
|
||||
).toBe(node)
|
||||
for (const refused of [
|
||||
finding,
|
||||
view,
|
||||
{ kind: 'zone', id: 'z1' } as const,
|
||||
]) {
|
||||
const state = run(base, { type: 'open_citations', citedBy: refused })
|
||||
expect(state).toBe(base)
|
||||
}
|
||||
})
|
||||
|
||||
it('show_all_references closes the panel, shows the tab and bumps the reset', () => {
|
||||
const state = run(
|
||||
initialNavigation('annotations'),
|
||||
{ type: 'open_references', citedBy: view },
|
||||
{ type: 'clear_cited_by' },
|
||||
initialNavigation('findings'),
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
{ type: 'show_all_references' },
|
||||
)
|
||||
expect(state.references).toEqual({ open: true, citedBy: null })
|
||||
expect(state.focus).toBeUndefined()
|
||||
expect(state).toMatchObject({
|
||||
tab: 'references',
|
||||
citationsOf: null,
|
||||
libraryReset: 1,
|
||||
focus: undefined,
|
||||
})
|
||||
expect(state.visitedTabs).toEqual(['findings', 'references'])
|
||||
expect(run(state, { type: 'show_all_references' }).libraryReset).toBe(2)
|
||||
})
|
||||
|
||||
it('a plain go_to a reference leaves the library reset alone', () => {
|
||||
const state = run(initialNavigation('findings'), {
|
||||
type: 'go_to',
|
||||
target: targetOfKey({ kind: 'reference', id: 'x' }),
|
||||
})
|
||||
expect(state.libraryReset).toBe(0)
|
||||
})
|
||||
|
||||
it('opens a section and goes back to the drawing', () => {
|
||||
@@ -156,21 +176,20 @@ describe('navigationReducer', () => {
|
||||
expect(back.visitedSections).toEqual(['drawing', 'views'])
|
||||
})
|
||||
|
||||
it('open and close references keep tab and section', () => {
|
||||
it('open and close citations keep tab and section', () => {
|
||||
const opened = run(
|
||||
initialNavigation('annotations'),
|
||||
{ type: 'open_section', section: 'views' },
|
||||
{ type: 'open_references', citedBy: view },
|
||||
{ type: 'open_citations', citedBy: node },
|
||||
)
|
||||
expect(opened).toMatchObject({ tab: 'annotations', section: 'views' })
|
||||
expect(opened.references).toEqual({ open: true, citedBy: view })
|
||||
const closed = run(opened, { type: 'close_references' })
|
||||
expect(opened.citationsOf).toBe(node)
|
||||
const closed = run(opened, { type: 'close_citations' })
|
||||
expect(closed).toMatchObject({
|
||||
tab: 'annotations',
|
||||
section: 'views',
|
||||
referencesMounted: true,
|
||||
citationsOf: null,
|
||||
})
|
||||
expect(closed.references.open).toBe(false)
|
||||
})
|
||||
|
||||
it('focus_consumed clears only its serial and serials are not reused', () => {
|
||||
|
||||
@@ -245,19 +245,6 @@ describe('a decision that settles in a place that is not shown', () => {
|
||||
expect(screen.getByText(PENDING)).toBeVisible()
|
||||
})
|
||||
|
||||
it('the open references panel holds the decision back, « Reprendre » waits for it to close', async () => {
|
||||
const user = await mountViews()
|
||||
const held = heldFile(DIRTY)
|
||||
pick(held.file)
|
||||
await user.click(button('Références'))
|
||||
await act(async () => held.release())
|
||||
expect(dialogs()).toBe(0)
|
||||
expect(button(RESUME)).toBeDisabled()
|
||||
await user.click(button('Références'))
|
||||
await user.click(button(RESUME))
|
||||
expect(await screen.findByRole('dialog')).toBeVisible()
|
||||
})
|
||||
|
||||
it('an upload settling while read-only lands in the live hook, its notice shown', async () => {
|
||||
const user = await mountViews()
|
||||
let finish: (value: string) => void = () => undefined
|
||||
|
||||
@@ -143,12 +143,12 @@ describe('typed values come back after a 1 024 px crossing', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('the reference creation form, in the references panel', async () => {
|
||||
it('the reference creation form, in the Références tab', async () => {
|
||||
const user = await mount()
|
||||
await user.click(button('Références'))
|
||||
await user.click(tab('Références'))
|
||||
await keepsTypedValue(
|
||||
user,
|
||||
'reference-new-citation',
|
||||
'tab-reference-new-citation',
|
||||
'Citation',
|
||||
'Ajouter la référence',
|
||||
)
|
||||
@@ -273,28 +273,26 @@ describe('the guards of a width change', () => {
|
||||
|
||||
it('a focused drawing tool hands its focus to the shown tab', async () => {
|
||||
const user = await mount()
|
||||
await waitFor(() =>
|
||||
expect(button('Zone')).toBeEnabled(),
|
||||
)
|
||||
await waitFor(() => expect(button('Zone')).toBeEnabled())
|
||||
await user.click(button('Zone'))
|
||||
expect(document.activeElement).toBe(button('Zone'))
|
||||
cross(800)
|
||||
expect(document.activeElement).toBe(tab('Annotations'))
|
||||
})
|
||||
|
||||
it('a focused header button stays where it is', async () => {
|
||||
it('a focused tab button stays where it is', async () => {
|
||||
await mount()
|
||||
const refs = button('Références')
|
||||
act(() => refs.focus())
|
||||
const findings = tab('Constats')
|
||||
act(() => findings.focus())
|
||||
cross(800)
|
||||
expect(document.activeElement).toBe(refs)
|
||||
expect(document.activeElement).toBe(findings)
|
||||
})
|
||||
|
||||
it('the references search, shown in both modes, keeps its focus and its text', async () => {
|
||||
const user = await mount()
|
||||
await user.click(button('Références'))
|
||||
const panel = screen.getByTestId('editor-citations-panel')
|
||||
const search = within(panel).getByRole('searchbox', {
|
||||
await user.click(tab('Références'))
|
||||
const body = screen.getByRole('tabpanel', { name: 'Références' })
|
||||
const search = within(body).getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
await user.type(search, 'code')
|
||||
@@ -389,13 +387,13 @@ describe('the guards of a width change', () => {
|
||||
|
||||
describe('ids stay unique', () => {
|
||||
async function everyPlace(user: User) {
|
||||
for (const name of ['Général', 'Constats', /Vérification/, 'Annotations']) {
|
||||
const names = ['Général', 'Constats', 'Références', /Vérification/]
|
||||
for (const name of [...names, 'Annotations']) {
|
||||
await user.click(tab(name))
|
||||
}
|
||||
await user.click(button('Gérer les vues'))
|
||||
await user.click(button('Modifier le recadrage'))
|
||||
await user.click(button('Retour au dessin'))
|
||||
await user.click(button('Références'))
|
||||
}
|
||||
const text = () => insert(baseText(), detail())
|
||||
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
/** U1 Lot D: the references side panel, filter, search, counts, non-modal layout. */
|
||||
/** R2.1: the citations panel of one finding (opened from its trigger only), non-modal layout. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import { act, cleanup, fireEvent, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
baseText,
|
||||
commitMove,
|
||||
openReady,
|
||||
resetStore,
|
||||
serverHas,
|
||||
store,
|
||||
@@ -80,159 +70,203 @@ function sheetText(): string {
|
||||
})
|
||||
}
|
||||
|
||||
/** The sheet plus one finding node under Cat A, citing ref-a and ref-c. */
|
||||
function nodeText(): string {
|
||||
return edit(sheetText(), {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
reference_ids: ['ref-a', 'ref-c'],
|
||||
requires_vet_referral: false,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const header = () => screen.getByRole('button', { name: 'Références' })
|
||||
const panel = () => screen.getByTestId('editor-citations-panel')
|
||||
const cards = () => within(panel()).getAllByRole('listitem')
|
||||
const search = () =>
|
||||
within(panel()).getByRole('searchbox', { name: 'Rechercher une référence' })
|
||||
const trigger = () =>
|
||||
within(screen.getByRole('tabpanel', { name: 'Constats' })).getByRole(
|
||||
'button',
|
||||
{ name: '2 références' },
|
||||
)
|
||||
|
||||
async function mount(width = 1280) {
|
||||
serverHas(sheetText(), 3)
|
||||
serverHas(nodeText(), 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width })
|
||||
await ready()
|
||||
return user
|
||||
}
|
||||
|
||||
async function openFromFinding(user: ReturnType<typeof userEvent.setup>) {
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
async function select(user: User, label: RegExp) {
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
const tabPanel = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
await user.click(
|
||||
within(tabPanel).getByRole('button', { name: '2 références' }),
|
||||
)
|
||||
const family = screen.getByRole('treeitem', { name: /Cat A/ })
|
||||
if (!screen.queryByRole('treeitem', { name: /Node A/ })) {
|
||||
await user.click(family)
|
||||
await user.keyboard('{ArrowRight}')
|
||||
}
|
||||
await user.click(screen.getByRole('treeitem', { name: label }))
|
||||
}
|
||||
|
||||
describe('references panel opening', () => {
|
||||
it('the header button opens it on its heading', async () => {
|
||||
const openFromFinding = async (user: User) => {
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
}
|
||||
|
||||
describe('citations panel opening', () => {
|
||||
it('has no header button, only a finding opens it on its heading', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
await select(user, /Node A/)
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
|
||||
await user.click(trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(
|
||||
within(panel()).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
expect(cards()).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('a finding that cites references opens the panel filtered to it', async () => {
|
||||
it('a family keeps its inline list and has no trigger', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
const detail = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /références?$/ }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(detail).getAllByRole('button', { name: /^Retirer / }),
|
||||
).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('lists only the references of the finding, each with its count', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
const chip = within(panel()).getByTestId('references-filter-chip')
|
||||
expect(chip).toHaveTextContent('Citées par « Cat A » (2)')
|
||||
expect(chip).toHaveTextContent('Citées par « Node A » (2)')
|
||||
expect(cards()).toHaveLength(2)
|
||||
expect(cards()[0].textContent).toContain('citée 2 fois')
|
||||
expect(cards()[1].textContent).toContain('citée 1 fois')
|
||||
})
|
||||
|
||||
it('has no search, no add form and no order buttons', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(within(panel()).queryByRole('searchbox')).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Ajouter la référence' }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Descendre' }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('field ids carry the panel prefix', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(
|
||||
panel().querySelector('#panel-reference-ref-a-citation'),
|
||||
).not.toBeNull()
|
||||
expect(document.querySelector('#tab-reference-ref-a-citation')).toBeNull()
|
||||
})
|
||||
|
||||
it('« Tout afficher » closes the panel and shows the tab on its heading', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Tout afficher (3)' }),
|
||||
)
|
||||
expect(within(panel()).queryByTestId('references-filter-chip')).toBeNull()
|
||||
expect(cards()).toHaveLength(3)
|
||||
expect(document.activeElement).toBe(search())
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(screen.getByRole('tab', { name: 'Références' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
const tabPanel = screen.getByRole('tabpanel', { name: 'Références' })
|
||||
expect(document.activeElement).toBe(
|
||||
within(tabPanel).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
expect(within(tabPanel).getAllByRole('listitem')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('each card says how often it is cited', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
const texts = cards().map((card) => card.textContent)
|
||||
expect(texts[0]).toContain('citée 1 fois')
|
||||
expect(texts[2]).toContain('citée 0 fois')
|
||||
})
|
||||
|
||||
it('undo removing the cited finding drops the filter', async () => {
|
||||
it('undo removing the cited finding closes the panel, the tab takes the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
expect(within(panel()).queryByTestId('references-filter-chip')).toBeNull()
|
||||
expect(cards()).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe('search and order buttons', () => {
|
||||
it('matches the citation, the DOI and the URL, ignoring case and accents', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
await user.type(search(), 'OSTEOLOGIE')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), '10.1000/abc')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'epaule')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'zzz')
|
||||
expect(
|
||||
within(panel()).getByText('Aucune référence ne correspond.'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows ↑ / ↓ only with neither filter nor search', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
expect(
|
||||
within(panel()).getAllByRole('button', { name: 'Descendre' }).length,
|
||||
).toBe(3)
|
||||
await user.type(search(), 'a')
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Descendre' }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('hides ↑ / ↓ while filtered to a finding', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Descendre' }),
|
||||
).toBeNull()
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('tab', { name: 'Constats' }),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('closing and layout', () => {
|
||||
it('Escape, ✕ and the scrim close it, the focus goes back to the opener', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
await user.keyboard('{Escape}')
|
||||
expect(panel()).not.toBeVisible()
|
||||
expect(document.activeElement).toBe(header())
|
||||
await user.click(header())
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
expect(panel()).not.toBeVisible()
|
||||
await user.click(header())
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
expect(panel()).not.toBeVisible()
|
||||
expect(document.activeElement).toBe(header())
|
||||
})
|
||||
|
||||
it('the finding button gets the focus back when it is still shown', async () => {
|
||||
it('Escape, ✕ and the scrim close it, the focus goes back to the trigger', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.keyboard('{Escape}')
|
||||
expect(document.activeElement).toHaveTextContent('2 références')
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(trigger())
|
||||
await user.click(trigger())
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(trigger())
|
||||
await user.click(trigger())
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(trigger())
|
||||
})
|
||||
|
||||
it('selecting a tab closes it, the new tab button takes the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('tab', { name: 'Vérification' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('makes the tab panels inert while it is open, the header stays usable', async () => {
|
||||
const user = await mount()
|
||||
const tabPanel = () => screen.getAllByRole('tabpanel', { hidden: true })[0]
|
||||
act(() => void commitMove(40))
|
||||
await user.click(header())
|
||||
await openFromFinding(user)
|
||||
expect(tabPanel().parentElement).toHaveAttribute('inert')
|
||||
expect(screen.getByRole('button', { name: /Enregistrer/ })).toBeEnabled()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
await user.click(header())
|
||||
await user.keyboard('{Escape}')
|
||||
expect(tabPanel().parentElement).not.toHaveAttribute('inert')
|
||||
})
|
||||
|
||||
it('Ctrl+Z reverts a reference edit while open', async () => {
|
||||
const user = await mount()
|
||||
await user.click(header())
|
||||
await openFromFinding(user)
|
||||
const field = within(panel()).getByLabelText('Citation', {
|
||||
selector: '#reference-ref-a-citation',
|
||||
selector: '#panel-reference-ref-a-citation',
|
||||
})
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
@@ -245,74 +279,50 @@ describe('closing and layout', () => {
|
||||
})
|
||||
|
||||
describe('read-only modes', () => {
|
||||
it('show no edit control, only the search', async () => {
|
||||
it('show the citations with no edit control', async () => {
|
||||
const user = await mount(800)
|
||||
await user.click(header())
|
||||
await openFromFinding(user)
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Supprimer' }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Ajouter la référence' }),
|
||||
).toBeNull()
|
||||
expect(search()).toBeInTheDocument()
|
||||
expect(within(panel()).queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Aller à » a reference', () => {
|
||||
it('clears the search that hides it and focuses its card', async () => {
|
||||
serverHas(sheetText(), 3)
|
||||
await openReady({ text: sheetText() })
|
||||
const user = userEvent.setup()
|
||||
const props = { readOnly: false, onClose: vi.fn() }
|
||||
const view = render(<ReferencesPanel {...props} />)
|
||||
const box = screen.getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
describe('ids', () => {
|
||||
it('stay unique with the Références tab mounted and the panel open (P14)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
await openFromFinding(user)
|
||||
const ids = [...document.querySelectorAll('[id]')].map((e) => e.id)
|
||||
expect(ids.filter((id, i) => ids.indexOf(id) !== i)).toEqual([])
|
||||
expect(ids).toContain('tab-reference-ref-a-citation')
|
||||
expect(ids).toContain('panel-reference-ref-a-citation')
|
||||
})
|
||||
})
|
||||
|
||||
describe('focus fallbacks (P6)', () => {
|
||||
it('below 640 px the active tab sits under « Plus »: the finding vanishing gives it the focus', async () => {
|
||||
const user = await mount(375)
|
||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
await user.keyboard('{ArrowRight}')
|
||||
await user.click(screen.getByRole('treeitem', { name: /Node A/ }))
|
||||
await user.click(trigger())
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
await user.type(box, 'Code')
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(1)
|
||||
const focus = {
|
||||
target: targetOfKey({ kind: 'reference', id: 'ref-a' }),
|
||||
serial: 1,
|
||||
}
|
||||
view.rerender(<ReferencesPanel {...props} focus={focus} />)
|
||||
expect(box).toHaveValue('')
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(3)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||
'ref-a',
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('button', { name: 'Plus' }),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding a reference', () => {
|
||||
async function add(user: ReturnType<typeof userEvent.setup>) {
|
||||
const byId = (id: string) => panel().querySelector<HTMLElement>(id)!
|
||||
await user.selectOptions(byId('#reference-new-type'), 'book')
|
||||
await user.type(byId('#reference-new-citation'), 'Nouvelle source')
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
}
|
||||
|
||||
it('clears the finding filter and the search so the new reference shows', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.type(search(), 'Barone')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await add(user)
|
||||
expect(search()).toHaveValue('')
|
||||
expect(within(panel()).queryByTestId('references-filter-chip')).toBeNull()
|
||||
expect(cards()).toHaveLength(4)
|
||||
expect(within(panel()).getByText('Nouvelle source')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a refused add keeps the filter and the search', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.type(search(), 'Barone')
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
expect(search()).toHaveValue('Barone')
|
||||
expect(within(panel()).getByTestId('references-filter-chip')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,261 @@
|
||||
/** R2.1: the Références tab, the library (search, order, counts, add, « Aller à »). */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
baseText,
|
||||
openReady,
|
||||
resetStore,
|
||||
serverHas,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
setWidth(1024)
|
||||
})
|
||||
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
const ref = (id: string, citation: string, url = '', doi = '') =>
|
||||
({
|
||||
kind: 'reference',
|
||||
value: {
|
||||
id,
|
||||
type: 'book',
|
||||
citation,
|
||||
url: url || null,
|
||||
doi: doi || null,
|
||||
},
|
||||
}) as const
|
||||
|
||||
function sheetText(): string {
|
||||
let text = baseText()
|
||||
text = insert(text, ref('ref-a', 'Barone, Ostéologie'))
|
||||
text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule'))
|
||||
text = insert(text, ref('ref-c', 'Code rural', '', '10.1000/ABC'))
|
||||
text = insert(text, {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
})
|
||||
return edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
id: 'fcat-a',
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat A'),
|
||||
description: {},
|
||||
reference_ids: ['ref-a', 'ref-b'],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const tabPanel = () => screen.getByRole('tabpanel', { name: 'Références' })
|
||||
const cards = () => within(tabPanel()).getAllByRole('listitem')
|
||||
const search = () =>
|
||||
within(tabPanel()).getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
async function mount(width = 1280) {
|
||||
serverHas(sheetText(), 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width })
|
||||
await ready()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
return user
|
||||
}
|
||||
|
||||
describe('the Références tab', () => {
|
||||
it('is the fifth tab, there is no header button, and it lists every card', async () => {
|
||||
await mount()
|
||||
const tabs = screen.getAllByRole('tab').map((tab) => tab.textContent)
|
||||
expect(tabs).toEqual([
|
||||
'Général',
|
||||
'Annotations',
|
||||
'Constats',
|
||||
'Références',
|
||||
'Vérification',
|
||||
])
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(cards()).toHaveLength(3)
|
||||
expect(
|
||||
within(tabPanel()).getByRole('heading', { name: 'Références' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('each card says how often it is cited, the ids carry the tab prefix', async () => {
|
||||
await mount()
|
||||
const texts = cards().map((card) => card.textContent)
|
||||
expect(texts[0]).toContain('citée 1 fois')
|
||||
expect(texts[2]).toContain('citée 0 fois')
|
||||
expect(
|
||||
tabPanel().querySelector('#tab-reference-ref-a-citation'),
|
||||
).not.toBeNull()
|
||||
expect(
|
||||
tabPanel().querySelector('#tab-reference-new-citation'),
|
||||
).not.toBeNull()
|
||||
})
|
||||
|
||||
it('matches the citation, the DOI and the URL, ignoring case and accents', async () => {
|
||||
const user = await mount()
|
||||
await user.type(search(), 'OSTEOLOGIE')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), '10.1000/abc')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'epaule')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'zzz')
|
||||
expect(
|
||||
within(tabPanel()).getByText('Aucune référence ne correspond.'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows ↑ / ↓ only without a search', async () => {
|
||||
const user = await mount()
|
||||
expect(
|
||||
within(tabPanel()).getAllByRole('button', { name: 'Descendre' }).length,
|
||||
).toBe(3)
|
||||
await user.type(search(), 'a')
|
||||
expect(
|
||||
within(tabPanel()).queryByRole('button', { name: 'Descendre' }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('Ctrl+Z reverts a reference edit', async () => {
|
||||
const user = await mount()
|
||||
const field = within(tabPanel()).getByLabelText('Citation', {
|
||||
selector: '#tab-reference-ref-a-citation',
|
||||
})
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
fireEvent.blur(field)
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
expect(doc().references[0].citation).toBe('Neuf')
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
})
|
||||
|
||||
describe('read-only modes', () => {
|
||||
it('show no edit control, only the search', async () => {
|
||||
await mount(800)
|
||||
expect(
|
||||
within(tabPanel()).queryByRole('button', { name: 'Supprimer' }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(tabPanel()).queryByRole('button', {
|
||||
name: 'Ajouter la référence',
|
||||
}),
|
||||
).toBeNull()
|
||||
expect(search()).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Aller à » a reference', () => {
|
||||
it('clears the search that hides it and focuses its card', async () => {
|
||||
serverHas(sheetText(), 3)
|
||||
await openReady({ text: sheetText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(<ReferenceLibrary readOnly={false} />)
|
||||
const box = screen.getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
await user.type(box, 'Code')
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(1)
|
||||
const focus = {
|
||||
target: targetOfKey({ kind: 'reference', id: 'ref-a' }),
|
||||
serial: 1,
|
||||
}
|
||||
view.rerender(<ReferenceLibrary readOnly={false} focus={focus} />)
|
||||
expect(box).toHaveValue('')
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(3)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||||
'ref-a',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the reset signal', () => {
|
||||
it('empties the search once per bump and leaves other state alone', async () => {
|
||||
await openReady({ text: sheetText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(<ReferenceLibrary readOnly={false} resetSignal={0} />)
|
||||
const box = screen.getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
await user.type(box, 'Code')
|
||||
view.rerender(<ReferenceLibrary readOnly={false} resetSignal={0} />)
|
||||
expect(box).toHaveValue('Code')
|
||||
view.rerender(<ReferenceLibrary readOnly={false} resetSignal={1} />)
|
||||
expect(box).toHaveValue('')
|
||||
await user.type(box, 'a')
|
||||
view.rerender(<ReferenceLibrary readOnly={false} resetSignal={1} />)
|
||||
expect(box).toHaveValue('a')
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding a reference', () => {
|
||||
async function add(user: User) {
|
||||
const byId = (id: string) => tabPanel().querySelector<HTMLElement>(id)!
|
||||
await user.selectOptions(byId('#tab-reference-new-type'), 'book')
|
||||
await user.type(byId('#tab-reference-new-citation'), 'Nouvelle source')
|
||||
await user.click(
|
||||
within(tabPanel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
}
|
||||
|
||||
it('clears the search so the new reference shows', async () => {
|
||||
const user = await mount()
|
||||
await user.type(search(), 'Barone')
|
||||
expect(cards()).toHaveLength(1)
|
||||
await add(user)
|
||||
expect(search()).toHaveValue('')
|
||||
expect(cards()).toHaveLength(4)
|
||||
expect(within(tabPanel()).getByText('Nouvelle source')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a refused add keeps the search', async () => {
|
||||
const user = await mount()
|
||||
await user.type(search(), 'Barone')
|
||||
await user.click(
|
||||
within(tabPanel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
expect(search()).toHaveValue('Barone')
|
||||
})
|
||||
})
|
||||
@@ -90,10 +90,11 @@ describe('the blocking offer', () => {
|
||||
).toBeEnabled()
|
||||
expect(useLeaveGuardStore.getState().armed).toBe(true)
|
||||
// consultation: tabs still switch
|
||||
await user.click(screen.getByRole('button', { name: 'Références' }))
|
||||
expect(screen.getByTestId('editor-citations-panel')).toHaveAttribute(
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
expect(screen.getByTestId('editor-tab-references')).toBeVisible()
|
||||
expect(screen.getByTestId('editor-tab-references')).toHaveAttribute(
|
||||
'aria-labelledby',
|
||||
'editor-citations-title',
|
||||
'editor-references-title',
|
||||
)
|
||||
// editing: refused by the store, no save offered
|
||||
expect(commitMove(40)).toMatchObject({
|
||||
@@ -122,7 +123,9 @@ describe('the blocking offer', () => {
|
||||
await ready()
|
||||
await user.click(screen.getByRole('button', { name: 'Restaurer la copie' }))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(/^Modifications non enregistrées$/),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
/^Modifications non enregistrées$/,
|
||||
),
|
||||
)
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Restaurer la copie' }),
|
||||
@@ -232,7 +235,9 @@ describe('cap and quota', () => {
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(fr['editor.draft.status.copy_cap']),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
fr['editor.draft.status.copy_cap'],
|
||||
),
|
||||
)
|
||||
expect(storedCopy()).toBeNull()
|
||||
const items = screen
|
||||
@@ -270,7 +275,9 @@ describe('cap and quota', () => {
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(fr['editor.draft.status.copy_quota']),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
fr['editor.draft.status.copy_quota'],
|
||||
),
|
||||
)
|
||||
expect(
|
||||
screen.getByText(fr['editor.draft.copy_issue.quota']),
|
||||
|
||||
@@ -43,10 +43,16 @@ afterEach(() => {
|
||||
|
||||
const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const TABS = ['Général', 'Annotations', 'Constats', 'Vérification']
|
||||
const TABS = [
|
||||
'Général',
|
||||
'Annotations',
|
||||
'Constats',
|
||||
'Références',
|
||||
'Vérification',
|
||||
]
|
||||
|
||||
describe('edit mode', () => {
|
||||
it('header, badges, the four tabs, nothing read-only', async () => {
|
||||
it('header, badges, the five tabs, nothing read-only', async () => {
|
||||
mountDraft()
|
||||
await ready()
|
||||
expect(screen.getByText('Brouillon')).toBeInTheDocument()
|
||||
@@ -81,11 +87,15 @@ describe('edit mode', () => {
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(/^1 modification non enregistrée$/),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
/^1 modification non enregistrée$/,
|
||||
),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(/^Enregistré · révision 4$/),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
/^Enregistré · révision 4$/,
|
||||
),
|
||||
)
|
||||
expect(sb.saveSheetDraft).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
@@ -100,7 +110,9 @@ describe('edit mode', () => {
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
await user.click(
|
||||
await screen.findByRole('button', { name: 'Abandonner les modifications' }),
|
||||
await screen.findByRole('button', {
|
||||
name: 'Abandonner les modifications',
|
||||
}),
|
||||
)
|
||||
const asked = await screen.findByRole('dialog')
|
||||
expect(asked).toHaveTextContent(fr['editor.draft.discard_ask'])
|
||||
@@ -133,20 +145,16 @@ describe('tabs', () => {
|
||||
expect(screen.getByRole('tabpanel')).toHaveAccessibleName('Constats')
|
||||
})
|
||||
|
||||
it('640 to 1 023 px: the four tabs, no « Plus »', async () => {
|
||||
it('640 to 1 023 px: the five tabs, no « Plus », the row may wrap', async () => {
|
||||
mountDraft({ width: 800 })
|
||||
await ready()
|
||||
const shown = within(screen.getByRole('tablist')).getAllByRole('tab')
|
||||
expect(shown.map((tab) => tab.textContent)).toEqual([
|
||||
'Général',
|
||||
'Annotations',
|
||||
'Constats',
|
||||
'Vérification',
|
||||
])
|
||||
expect(shown.map((tab) => tab.textContent)).toEqual(TABS)
|
||||
expect(screen.getByRole('tablist').className).toContain('flex-wrap')
|
||||
expect(screen.queryByRole('button', { name: 'Plus' })).toBeNull()
|
||||
})
|
||||
|
||||
it('below 640 px: two tabs and « Plus » listing Général and Constats', async () => {
|
||||
it('below 640 px: two tabs and « Plus » listing Général, Constats and Références', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width: 375 })
|
||||
await ready()
|
||||
@@ -158,62 +166,45 @@ describe('tabs', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||
const more = document.getElementById('editor-tabs-more') as HTMLElement
|
||||
const rest = within(more).getAllByRole('button')
|
||||
expect(rest.map((b) => b.textContent)).toEqual(['Général', 'Constats'])
|
||||
expect(rest.map((b) => b.textContent)).toEqual([
|
||||
'Général',
|
||||
'Constats',
|
||||
'Références',
|
||||
])
|
||||
await user.click(rest[1])
|
||||
expect(screen.getByTestId('editor-tab-findings')).toBeInTheDocument()
|
||||
expect(document.getElementById('editor-tabs-more')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('references panel', () => {
|
||||
const button = () => screen.getByRole('button', { name: 'Références' })
|
||||
|
||||
it('the header button opens it on its heading and ✕ returns the focus', async () => {
|
||||
const user = userEvent.setup()
|
||||
describe('citations panel', () => {
|
||||
it('has no header button and is not mounted until a finding opens it', async () => {
|
||||
mountDraft()
|
||||
await ready()
|
||||
expect(button()).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
await user.click(button())
|
||||
const panel = screen.getByTestId('editor-citations-panel')
|
||||
expect(panel).toBeVisible()
|
||||
expect(button()).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(
|
||||
within(panel).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: 'Annotations' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await user.click(
|
||||
within(panel).getByRole('button', { name: 'Fermer les références' }),
|
||||
)
|
||||
expect(panel).not.toBeVisible()
|
||||
expect(document.activeElement).toBe(button())
|
||||
})
|
||||
|
||||
it('Escape inside the panel closes it, the content is kept for the next opening', async () => {
|
||||
it('the Références tab hosts the library and keeps it mounted when left', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
await ready()
|
||||
await user.click(button())
|
||||
const panel = screen.getByTestId('editor-citations-panel')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(panel).not.toBeVisible()
|
||||
await user.click(button())
|
||||
expect(screen.getByTestId('editor-citations-panel')).toBe(panel)
|
||||
expect(panel).toBeVisible()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
const body = screen.getByTestId('editor-tab-references')
|
||||
expect(body).toBeVisible()
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(body).not.toBeVisible()
|
||||
})
|
||||
|
||||
it('read-only: the panel lists the references with no edit control', async () => {
|
||||
it('read-only: the tab lists the references with no edit control', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width: 800 })
|
||||
await ready()
|
||||
await user.click(button())
|
||||
const panel = screen.getByTestId('editor-citations-panel')
|
||||
expect(within(panel).queryByRole('textbox')).toBeNull()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
const body = screen.getByTestId('editor-tab-references')
|
||||
expect(within(body).queryByRole('textbox')).toBeNull()
|
||||
expect(
|
||||
within(panel).queryByRole('button', { name: 'Ajouter la référence' }),
|
||||
within(body).queryByRole('button', { name: 'Ajouter la référence' }),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -424,7 +415,9 @@ describe('permission lost during the session', () => {
|
||||
await ready()
|
||||
act(() => void commitMove(40))
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(fr['editor.draft.status.copy_quota']),
|
||||
expect(screen.getByTestId('save-line')).toHaveTextContent(
|
||||
fr['editor.draft.status.copy_quota'],
|
||||
),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
const notice = await screen.findByText(/Votre session a expiré/)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/** Lot F: Références and Vertèbres. */
|
||||
/** Lot F: the Références tab and Vertèbres. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||
@@ -44,7 +44,7 @@ describe('Références', () => {
|
||||
it('adds a reference only with a type and a citation', async () => {
|
||||
await openReady()
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesPanel {...props} onClose={vi.fn()} />)
|
||||
render(<ReferencesTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
@@ -72,9 +72,9 @@ describe('Références', () => {
|
||||
)
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesPanel {...props} onClose={vi.fn()} />)
|
||||
render(<ReferencesTab {...props} />)
|
||||
const url = screen.getByLabelText('Adresse web (URL)', {
|
||||
selector: '#reference-ref-a-url',
|
||||
selector: '#tab-reference-ref-a-url',
|
||||
})
|
||||
await user.type(url, 'https://example.org')
|
||||
await user.tab()
|
||||
@@ -111,7 +111,7 @@ describe('Références', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesPanel {...props} onClose={vi.fn()} />)
|
||||
render(<ReferencesTab {...props} />)
|
||||
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[0])
|
||||
const refused = await screen.findByRole('dialog')
|
||||
expect(within(refused).getByText(/cite cette référence/)).toBeTruthy()
|
||||
@@ -127,12 +127,10 @@ describe('Références', () => {
|
||||
|
||||
it('read-only shows the citations as text', async () => {
|
||||
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
||||
render(<ReferencesPanel {...props} onClose={vi.fn()} readOnly />)
|
||||
render(<ReferencesTab {...props} readOnly />)
|
||||
expect(screen.getByText('Alpha')).toBeTruthy()
|
||||
expect(screen.queryByRole('textbox')).toBeNull()
|
||||
expect(
|
||||
screen.getAllByRole('button').map((b) => b.getAttribute('aria-label')),
|
||||
).toEqual(['Fermer les références'])
|
||||
expect(screen.queryAllByRole('button')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -84,15 +84,12 @@ describe('Vérification panel', () => {
|
||||
await user.click(
|
||||
screen.getAllByRole('button', { name: 'Aller à Sans tracé' })[0],
|
||||
)
|
||||
expect(navigate).toHaveBeenCalledWith(
|
||||
{
|
||||
place: 'tab',
|
||||
tab: 'annotations',
|
||||
section: 'drawing',
|
||||
key: { kind: 'annotation', id: 'anno-bare' },
|
||||
},
|
||||
expect.any(HTMLElement),
|
||||
)
|
||||
expect(navigate).toHaveBeenCalledWith({
|
||||
place: 'tab',
|
||||
tab: 'annotations',
|
||||
section: 'drawing',
|
||||
key: { kind: 'annotation', id: 'anno-bare' },
|
||||
})
|
||||
expect(screen.queryByText('Aucun problème détecté')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -236,8 +233,9 @@ describe('issueTarget', () => {
|
||||
section: 'regions',
|
||||
})
|
||||
expect(at('references[0].citation')).toMatchObject({
|
||||
place: 'references',
|
||||
citedBy: null,
|
||||
place: 'tab',
|
||||
tab: 'references',
|
||||
section: null,
|
||||
})
|
||||
expect(at('finding_zones[0].name')).toMatchObject({
|
||||
place: 'tab',
|
||||
@@ -260,7 +258,7 @@ describe('issueTarget', () => {
|
||||
})
|
||||
expect(placeKey(gone!)).toBe('editor.place.views')
|
||||
expect(placeKey(at('references[9].citation')!)).toBe(
|
||||
'editor.place.references',
|
||||
'editor.tab.references',
|
||||
)
|
||||
expect(placeKey(at('annotations[9].geometry')!)).toBe(
|
||||
'editor.tab.annotations',
|
||||
|
||||
Reference in new issue
Block a user