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
@@ -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