feat(editor): contextual citations panel of a finding (board 25)
The panel opens only from a finding's « {n} références » trigger: 34 rem
at most, never wider than the room, a scrim, slide in 180 ms and out
140 ms (motion/react; none under reduced motion, callbacks still fire).
It lists the finding's references as tiles with « Modifier », « Retirer
de ce constat » (one « Défaire » restores it and the review status) and
« Aller à »; dangling ids read « Référence introuvable »; zero left
reads « Ce constat ne cite plus aucune référence. ». « Tout afficher
dans l'onglet Références » resets search and sort, keeps open tiles and
edits. Every close (✕, Escape outside fields, scrim, tab, « Aller à »,
« Tout afficher », element gone) records one pending move applied
after the exit, page inert until then; focus back to the trigger, else
the active tab button. A refused draft cancels a user close; a forced
close drops it and announces « Saisie non appliquée : {field} ». Places
keeps a permanent dvh min-height; the panel fits the visible viewport
at every scroll position, document size unchanged.
Gates: typecheck, lint, test:run (app 1488), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (admin and editor-equine excluded):
117 passed / 107 skipped / 0 failed, rerun after the fix rounds: 118
passed / 108 skipped / 0 failed; layout spec 13 passed after round 2;
full-row guard: no pre-existing row changed in any table. Known limit:
landscape 667 x 375 at scroll 0 leaves ~13 px of panel (the trigger is
below the fold there).
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-panel.test.tsx (whole file) | R2.1 interim-panel tests, synchronous closes | rewritten: 39 tests (opening, motion, close matrix in both modes, exit, Retirer, P22'', library + history) |
| same, opening | heading `Références` focused right after the click | heading `Références citées` focused after the enter (`waitFor`), `aria-expanded` only after click |
| same | chip `references-filter-chip` « Citées par « Node A » (2) » | REMOVED (REVUE: path line + count line « 2 références citées par ce constat ») |
| same | `listitem` cards « Citée 2 fois » | tiles (`ul > li`) with the same counts, in the finding's order |
| same | field id `#panel-reference-0-ref-a-citation` present at once | tile opened + « Modifier » first (tiles since R2.2) |
| same | « Tout afficher (3) », sync | « Tout afficher dans l'onglet Références », after exit, heading focus asserted |
| same | Escape / ✕ / scrim / tab / vanish: sync null panel | all `await closed()` + `document.activeElement` checks, `describe.each` normal / reduced motion |
| same | « makes the tab panels inert while open, header usable » | split: inert page + inert panel until the exit ends then lifted; « Défaire / Refaire usable »; the `Enregistrer` enabled check dropped (covered by the focus-moved-off test) |
| same | Ctrl+Z test on an always-open field | open tile + Modifier first |
| same | read-only: no Supprimer, no textbox | open tile: no Modifier, no Retirer, no textbox |
| same | P6 under « Plus »: sync | in the close matrix, awaited |
| editor-escape.test.tsx (2 tests) | `expect(citations()).toBeNull()` right after Escape | `await waitFor(...)`; trigger `aria-expanded` false after exit |
| editor-keep-alive.test.tsx | « Escape in a citations panel field commits the text before the panel closes » | REPLACED by « Escape in a field of a panel tile neither closes nor commits » (A5, P27) |
| same | scrim click closes the panel after committing, sync, id on a closed tile | tile opened in edit first, close awaited, commit asserted before the exit |
| editor-focus-request.test.tsx | `ReferenceLibrary` with `resetSignal`; `ownedBy(ref,'citations')` undefined | `ReferencesTab` (+ `reloadSheet`); the `'citations'` assertion removed with the type |
| editor-references-tab / -view.test.tsx | `ReferenceLibrary`, `resetSignal` | `ReferencesTab`, `libraryReset` (+ `reloadSheet`) |
| e2e support `openCitations` | waited for the panel visible | also waits for the heading focus (slide over) |
New unit coverage: editor-citations-exit.test.tsx (hook, fake timers), editor-findings (aria-expanded per finding),
`useDecisionsOpen` gate, panel file (Retirer + status + one undo, P20 chain, zero state, dangling id, P4 reset, P6 after undo,
P22'' four paths, reduced motion, inert/exit, second close, tab replace, focus-moved-off).
## i18n (FR / EN)
Added: `editor.references.panel_title` Références citées / Cited references; `panel_count_one|other` « {count} référence citée par
ce constat » / « {count} références citées par ce constat » and « {count} reference cited by this finding » / « … references … »;
`panel_show_all` Tout afficher dans l'onglet Références / Show all in the References tab; `panel_empty` Ce constat ne cite plus
aucune référence. / This finding no longer cites any reference.; `remove_citation` Retirer de ce constat / Remove from this finding;
`this_finding` ce constat / this finding; `missing` Référence introuvable / Reference not found; `draft_dropped`
Saisie non appliquée : {field} / Entry not applied: {field}.
Changed: none. Removed: `editor.references.cited_by` (« Citées par « {name} » ({count}) » / « Cited by « {name} » ({count}) »),
`editor.references.show_all` (« Tout afficher ({count}) » / « Show all ({count}) »). R10 grep over src, tests and e2e including
editor-equine: no reader left. `editor-equine` has no panel reference: « updated, not run » (nothing to update). The three
provisional FR labels are exactly as listed in the brief; `…` = the refused field's label.
This commit is contained in:
1 parent
3baac4dbb5
commit
8db6f4287f
38 files changed
+2524
-705
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { vi } from 'vitest'
|
||||
|
||||
const preference = { reduced: false, listeners: new Set<() => void>() }
|
||||
|
||||
/**
|
||||
* `prefers-reduced-motion` under the test's control. motion reads the query once per
|
||||
* module and keeps the listener, so the stub is installed at import and answers the
|
||||
* current value; a switch notifies the listener and applies to the next mount.
|
||||
*/
|
||||
vi.stubGlobal('matchMedia', (query: string) => ({
|
||||
get matches() {
|
||||
return query.includes('prefers-reduced-motion') && preference.reduced
|
||||
},
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: (listener: () => void) => preference.listeners.add(listener),
|
||||
removeListener: (listener: () => void) =>
|
||||
preference.listeners.delete(listener),
|
||||
addEventListener: () => undefined,
|
||||
removeEventListener: () => undefined,
|
||||
dispatchEvent: () => false,
|
||||
}))
|
||||
|
||||
export function setReducedMotion(reduced: boolean): void {
|
||||
preference.reduced = reduced
|
||||
preference.listeners.forEach((listener) => listener())
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/** R2.4: the exit coordinator of the citations panel (P9, P28) and the gates it feeds. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
renderHook,
|
||||
render,
|
||||
screen,
|
||||
} from '@testing-library/react'
|
||||
import type { ElementKey } from '@faunosteo/core-wasm/types'
|
||||
import {
|
||||
ReadOnlyContext,
|
||||
ReferencesOpenContext,
|
||||
useDecisionsOpen,
|
||||
} from '@/editor/editingContext'
|
||||
import {
|
||||
PANEL_EXIT_S,
|
||||
useCitationsExit,
|
||||
type PendingClose,
|
||||
} from '@/editor/useCitationsExit'
|
||||
|
||||
beforeEach(() => vi.useFakeTimers())
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
const move = (kind: PendingClose['kind']): PendingClose => ({
|
||||
action: { type: 'close_citations' },
|
||||
kind,
|
||||
text: kind,
|
||||
})
|
||||
|
||||
describe('useCitationsExit', () => {
|
||||
it('applies the pending move once, from the callback', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
expect(result.current.exiting).toBe(true)
|
||||
act(() => result.current.complete())
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
expect(apply).toHaveBeenCalledWith(move('citations_closed'))
|
||||
expect(result.current.exiting).toBe(false)
|
||||
})
|
||||
|
||||
it('applies it from the one-shot timer when the callback never fires', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('show_all')))
|
||||
act(() => void vi.advanceTimersByTime(PANEL_EXIT_S * 1000 + 99))
|
||||
expect(apply).not.toHaveBeenCalled()
|
||||
act(() => void vi.advanceTimersByTime(2))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
act(() => result.current.complete())
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('a callback that comes first cancels the timer', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('go_to')))
|
||||
act(() => result.current.complete())
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('a second close is a no-op, a tab choice replaces the move', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
act(() => result.current.record(move('show_all')))
|
||||
expect(result.current.busy()).toBe(true)
|
||||
act(() => result.current.record(move('tab_selected')))
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledWith(move('tab_selected'))
|
||||
})
|
||||
|
||||
it('a tab choice keeps the note of a forced close it replaces', () => {
|
||||
const apply = vi.fn()
|
||||
const { result } = renderHook(() => useCitationsExit(apply))
|
||||
const note = 'Saisie non appliquée : Citation'
|
||||
act(() => result.current.record({ ...move('citations_closed'), note }))
|
||||
act(() => result.current.record(move('tab_selected')))
|
||||
act(() => result.current.complete())
|
||||
expect(apply).toHaveBeenCalledWith({ ...move('tab_selected'), note })
|
||||
})
|
||||
|
||||
it('a timer left running does not fire after the editor is left', () => {
|
||||
const apply = vi.fn()
|
||||
const { result, unmount } = renderHook(() => useCitationsExit(apply))
|
||||
act(() => result.current.record(move('citations_closed')))
|
||||
unmount()
|
||||
act(() => void vi.advanceTimersByTime(1000))
|
||||
expect(apply).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('useDecisionsOpen while the citations panel is open', () => {
|
||||
const key: ElementKey = { kind: 'finding', zone_id: 'z', path: ['c', 'n'] }
|
||||
const Probe = () => <p>{useDecisionsOpen() ? 'open' : 'held'}</p>
|
||||
const within = (readOnly: boolean, citationsOf: ElementKey | null) =>
|
||||
render(
|
||||
<ReadOnlyContext value={readOnly}>
|
||||
<ReferencesOpenContext value={citationsOf}>
|
||||
<Probe />
|
||||
</ReferencesOpenContext>
|
||||
</ReadOnlyContext>,
|
||||
)
|
||||
|
||||
it('holds every decision dialog back, panel open or still leaving (no modal in an inert page)', () => {
|
||||
within(false, key)
|
||||
expect(screen.getByText('held')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lets them open once the panel is gone, and never while read-only', () => {
|
||||
within(false, null)
|
||||
expect(screen.getByText('open')).toBeInTheDocument()
|
||||
cleanup()
|
||||
within(true, null)
|
||||
expect(screen.getByText('held')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,53 @@
|
||||
/** R2.4 fix: the layer's heading focus survives a reopen during a slow exit; it fits the viewport. */
|
||||
import type { ComponentProps } from 'react'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, waitFor } from '@testing-library/react'
|
||||
import { AnimatePresence } from 'motion/react'
|
||||
import CitationsLayer from '@/components/editor/references/CitationsLayer'
|
||||
import '../helpers/motion'
|
||||
|
||||
vi.mock('@/components/editor/references/CitationsPanel', () => ({
|
||||
default: () => (
|
||||
<h2 tabIndex={-1} data-place-heading>
|
||||
Panel
|
||||
</h2>
|
||||
),
|
||||
}))
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
const props: ComponentProps<typeof CitationsLayer> = {
|
||||
readOnly: false,
|
||||
citedBy: { kind: 'finding', zone_id: 'z', path: ['c', 'n'] },
|
||||
onClose: () => undefined,
|
||||
onGone: () => undefined,
|
||||
onShowAll: () => undefined,
|
||||
navigate: () => undefined,
|
||||
registerCanLeave: () => undefined,
|
||||
}
|
||||
|
||||
const harness = (show: boolean) => (
|
||||
<AnimatePresence>
|
||||
{show && <CitationsLayer key="citations" {...props} />}
|
||||
</AnimatePresence>
|
||||
)
|
||||
const heading = () => screen.getByRole('heading', { name: 'Panel' })
|
||||
|
||||
describe('CitationsLayer', () => {
|
||||
it('focuses its heading again when reopened with the same key during the exit', async () => {
|
||||
const view = render(harness(true))
|
||||
await waitFor(() => expect(document.activeElement).toBe(heading()))
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
view.rerender(harness(false))
|
||||
view.rerender(harness(true))
|
||||
await waitFor(() => expect(document.activeElement).toBe(heading()))
|
||||
})
|
||||
|
||||
it('writes a pixel height on the panel, never on the page', async () => {
|
||||
render(harness(true))
|
||||
const panel = heading().closest('[data-place="citations"]')!
|
||||
.firstElementChild as HTMLElement
|
||||
expect(panel.style.height).toMatch(/^\d+(\.\d+)?px$/)
|
||||
expect(document.documentElement.style.height).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -284,7 +284,7 @@ describe('Escape with the focus on the page', () => {
|
||||
const trigger = screen.getByRole('button', { name: '1 référence' })
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'true')
|
||||
escape(document.body)
|
||||
expect(citations()).toBeNull()
|
||||
await waitFor(() => expect(citations()).toBeNull())
|
||||
expect(trigger).toHaveAttribute('aria-expanded', 'false')
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
@@ -322,7 +322,7 @@ describe('Escape and the other layers', () => {
|
||||
await select(user)
|
||||
await openCitations(user)
|
||||
escape(screen.getByRole('tab', { name: 'Constats' }))
|
||||
expect(citations()).toBeNull()
|
||||
await waitFor(() => expect(citations()).toBeNull())
|
||||
await user.click(screen.getByRole('tab', { name: 'Annotations' }))
|
||||
expect(panel()).toBeDefined()
|
||||
})
|
||||
|
||||
@@ -4,12 +4,14 @@ import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type {
|
||||
AnatomicalSheetDocument,
|
||||
ElementKey,
|
||||
FindingNode,
|
||||
} from '@faunosteo/core-wasm/types'
|
||||
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 { ReferencesOpenContext } from '@/editor/editingContext'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
@@ -600,6 +602,41 @@ describe('Constats tab', () => {
|
||||
expect(all.filter((item) => item.kind === 'node')).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('the trigger reads « expanded » only for the finding the panel shows', async () => {
|
||||
let text = insert(treeText(), {
|
||||
kind: 'reference',
|
||||
value: { id: 'ref-a', type: 'book', citation: 'A', url: null, doi: null },
|
||||
})
|
||||
const nodes = buildItems(JSON.parse(text)).filter((i) => i.kind === 'node')
|
||||
for (const item of nodes) {
|
||||
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 shows = (citationsOf: ElementKey | null) => (
|
||||
<ReferencesOpenContext value={citationsOf}>
|
||||
<FindingsTab {...props} openCitations={vi.fn()} />
|
||||
</ReferencesOpenContext>
|
||||
)
|
||||
const { rerender } = render(shows(nodes[1].key))
|
||||
await user.click(items()[1])
|
||||
await user.keyboard('{ArrowRight}{ArrowDown}')
|
||||
await user.click(items()[2])
|
||||
const trigger = () => screen.getByRole('button', { name: /^1 référence$/ })
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
rerender(shows(nodes[0].key))
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
rerender(shows(null))
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
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 ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
|
||||
import {
|
||||
FocusConsumedContext,
|
||||
@@ -162,7 +162,7 @@ describe('focus requests', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
render(
|
||||
<ReferenceLibrary
|
||||
<ReferencesTab
|
||||
{...base}
|
||||
focus={request({ kind: 'reference', id: 'ref-a' })}
|
||||
/>,
|
||||
@@ -195,9 +195,9 @@ describe('focus requests', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const focus = request({ kind: 'reference', id: 'ref-a' })
|
||||
const view = render(<ReferenceLibrary {...base} focus={focus} />)
|
||||
const view = render(<ReferencesTab {...base} focus={focus} />)
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
view.rerender(<ReferenceLibrary {...base} focus={focus} />)
|
||||
view.rerender(<ReferencesTab {...base} focus={focus} />)
|
||||
expect(document.activeElement?.getAttribute('data-focus-key')).toBeNull()
|
||||
})
|
||||
|
||||
@@ -222,7 +222,6 @@ describe('ownedBy', () => {
|
||||
expect(ownedBy(view, 'general')).toBeUndefined()
|
||||
const ref = request({ kind: 'reference', id: 'ref-a' })
|
||||
expect(ownedBy(ref, 'references')).toBe(ref)
|
||||
expect(ownedBy(ref, 'citations')).toBeUndefined()
|
||||
expect(ownedBy(ref, 'findings')).toBeUndefined()
|
||||
expect(ownedBy(undefined, 'general')).toBeUndefined()
|
||||
})
|
||||
@@ -412,7 +411,7 @@ function Harness() {
|
||||
switch
|
||||
</button>
|
||||
{shown === 'references' ? (
|
||||
<ReferenceLibrary {...base} focus={focus} />
|
||||
<ReferencesTab {...base} focus={focus} />
|
||||
) : (
|
||||
<RegionsSection {...base} focus={focus} />
|
||||
)}
|
||||
|
||||
@@ -350,36 +350,42 @@ describe('a field still focused while a place is left', () => {
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('Escape in a citations panel field commits the text before the panel closes', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
/** The panel's first tile opened in edit, its citation field typed in (not blurred). */
|
||||
async function typeInPanelTile(user: Awaited<ReturnType<typeof mount>>) {
|
||||
await openCitations(user)
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
const panel = inPlace('citations')
|
||||
await user.click(panel.getByRole('button', { name: /Doe/ }))
|
||||
await user.click(panel.getByRole('button', { name: 'Modifier' }))
|
||||
const field = panel.getByLabelText('Citation', {
|
||||
selector: '#panel-reference-0-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2021' } })
|
||||
return field
|
||||
}
|
||||
|
||||
const savedCitation = () =>
|
||||
(JSON.parse(store.getState().documentText) as AnatomicalSheetDocument)
|
||||
.references[0].citation
|
||||
|
||||
it('Escape in a field of a panel tile neither closes the panel nor commits the text (A5)', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
const before = store.getState().documentText
|
||||
await typeInPanelTile(user)
|
||||
await user.keyboard('{Escape}')
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
const doc: AnatomicalSheetDocument = JSON.parse(
|
||||
store.getState().documentText,
|
||||
)
|
||||
expect(doc.references[0].citation).toBe('Doe 2021')
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
expect(screen.getByTestId('editor-citations-panel')).toBeInTheDocument()
|
||||
expect(store.getState().documentText).toBe(before)
|
||||
})
|
||||
|
||||
it('the scrim (no focus move) closes the panel after committing', async () => {
|
||||
it('the scrim (no focus move) commits the typed text, then closes the panel after its exit', async () => {
|
||||
const user = await mount(findingsText(referenceText(), ['ref-1']))
|
||||
await openCitations(user)
|
||||
const field = inPlace('citations').getByLabelText('Citation', {
|
||||
selector: '#panel-reference-0-ref-1-citation',
|
||||
})
|
||||
await user.click(field)
|
||||
fireEvent.change(field, { target: { value: 'Doe 2022' } })
|
||||
await typeInPanelTile(user)
|
||||
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')
|
||||
expect(savedCitation()).toBe('Doe 2021')
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull(),
|
||||
)
|
||||
expect(store.getState().unsaved).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
/** R2.1: the citations panel of one finding (opened from its trigger only), non-modal layout. */
|
||||
/** R2.4: the citations panel of one finding (board 25): contents, « Retirer », motion, closes, focus. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, fireEvent, screen, within } from '@testing-library/react'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
@@ -12,6 +19,7 @@ import {
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||||
import { setReducedMotion } from '../helpers/motion'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
@@ -28,6 +36,7 @@ afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
setWidth(1024)
|
||||
setReducedMotion(false)
|
||||
})
|
||||
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
@@ -70,8 +79,8 @@ function sheetText(): string {
|
||||
})
|
||||
}
|
||||
|
||||
/** The sheet plus one finding node under Cat A, citing ref-a and ref-c. */
|
||||
function nodeText(): string {
|
||||
/** The sheet plus one finding node under Cat A (default: citing ref-a and ref-c). */
|
||||
function nodeText(ids = ['ref-a', 'ref-c']): string {
|
||||
return edit(sheetText(), {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
@@ -81,7 +90,7 @@ function nodeText(): string {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
reference_ids: ['ref-a', 'ref-c'],
|
||||
reference_ids: ids,
|
||||
requires_vet_referral: false,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
@@ -93,15 +102,28 @@ function nodeText(): string {
|
||||
const ready = () =>
|
||||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
const panel = () => screen.getByTestId('editor-citations-panel')
|
||||
const cards = () => within(panel()).getAllByRole('listitem')
|
||||
const trigger = () =>
|
||||
const hasPanel = () => screen.queryByTestId('editor-citations-panel') !== null
|
||||
const layer = () => panel().closest('[data-place="citations"]')!
|
||||
const tiles = () => [...panel().querySelectorAll('ul > li')]
|
||||
const trigger = (name = '2 références') =>
|
||||
within(screen.getByRole('tabpanel', { name: 'Constats' })).getByRole(
|
||||
'button',
|
||||
{ name: '2 références' },
|
||||
{ name },
|
||||
)
|
||||
const heading = () =>
|
||||
within(panel()).getByRole('heading', { name: 'Références citées' })
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
const nodeA = () =>
|
||||
doc().finding_zones[0].categories[0].children[0] as {
|
||||
reference_ids: string[]
|
||||
review_status: string
|
||||
}
|
||||
const closed = () => waitFor(() => expect(hasPanel()).toBe(false))
|
||||
const focusIs = (element: () => Element) =>
|
||||
waitFor(() => expect(document.activeElement).toBe(element()))
|
||||
|
||||
async function mount(width = 1280) {
|
||||
serverHas(nodeText(), 3)
|
||||
async function mount(width = 1280, text = nodeText()) {
|
||||
serverHas(text, 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width })
|
||||
await ready()
|
||||
@@ -120,27 +142,37 @@ async function select(user: User, label: RegExp) {
|
||||
await user.click(screen.getByRole('treeitem', { name: label }))
|
||||
}
|
||||
|
||||
const openFromFinding = async (user: User) => {
|
||||
/** The panel of Node A, open and in place: its heading holds the focus. */
|
||||
async function openFromFinding(user: User, name = '2 références') {
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
await user.click(trigger(name))
|
||||
await focusIs(heading)
|
||||
}
|
||||
|
||||
describe('citations panel opening', () => {
|
||||
it('has no header button, only a finding opens it on its heading', async () => {
|
||||
const link = () =>
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
})
|
||||
|
||||
const closeButton = () =>
|
||||
within(panel()).getByRole('button', { name: 'Fermer les références' })
|
||||
|
||||
describe('opening', () => {
|
||||
it('has no header button; only a finding opens it, its heading takes the focus after the slide', async () => {
|
||||
const user = await mount()
|
||||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
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(document.activeElement).not.toBe(heading())
|
||||
await focusIs(heading)
|
||||
expect(panel()).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
})
|
||||
|
||||
it('a family keeps its inline list and has no trigger', async () => {
|
||||
it('a family keeps its inline list: no trigger, no panel', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
const detail = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
@@ -150,58 +182,189 @@ describe('citations panel opening', () => {
|
||||
expect(
|
||||
within(detail).getAllByRole('button', { name: /^Retirer / }),
|
||||
).toHaveLength(2)
|
||||
expect(hasPanel()).toBe(false)
|
||||
})
|
||||
|
||||
it('lists only the references of the finding, each with its count', async () => {
|
||||
it('shows the path, the count, and only the references of the finding as tiles', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
const chip = within(panel()).getByTestId('references-filter-chip')
|
||||
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')
|
||||
expect(panel()).toHaveTextContent('Zone A › Cat A › Node A')
|
||||
expect(panel()).toHaveTextContent('2 références citées par ce constat')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
expect(tiles()[0].textContent).toContain('Barone')
|
||||
expect(tiles()[0].textContent).toContain('Citée 2 fois')
|
||||
expect(tiles()[1].textContent).toContain('Code rural')
|
||||
expect(tiles()[1].textContent).toContain('Citée 1 fois')
|
||||
expect(panel()).not.toHaveTextContent('Denoix')
|
||||
})
|
||||
|
||||
it('has no search, no add form and no order buttons', async () => {
|
||||
it('an open tile marks the current finding and offers Modifier and « Retirer de ce constat »', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
const tile = tiles()[0] as HTMLElement
|
||||
expect(within(tile).getByText('ce constat')).toBeInTheDocument()
|
||||
expect(
|
||||
within(tile).getAllByRole('button', { name: 'Aller à' }),
|
||||
).toHaveLength(2)
|
||||
expect(within(tile).getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
expect(
|
||||
within(tile).getByRole('button', { name: 'Retirer de ce constat' }),
|
||||
).toBeVisible()
|
||||
for (const absent of ['Supprimer', 'Monter', 'Descendre']) {
|
||||
expect(within(panel()).queryByRole('button', { name: absent })).toBeNull()
|
||||
}
|
||||
})
|
||||
|
||||
it('has no search, no add control; field ids carry the panel prefix', 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' }),
|
||||
within(panel()).queryByRole('button', { name: /Ajouter/ }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Descendre' }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('field ids carry the panel prefix', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
expect(
|
||||
panel().querySelector('#panel-reference-0-ref-a-citation'),
|
||||
).not.toBeNull()
|
||||
expect(document.querySelector('[id^="tab-reference-"]')).toBeNull()
|
||||
})
|
||||
|
||||
it('« Tout afficher » closes the panel and shows the tab on its heading', async () => {
|
||||
it('ids 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 user.click(screen.getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'Modifier' }))
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
const ids = [...document.querySelectorAll('[id]')].map((e) => e.id)
|
||||
expect(ids.filter((id, i) => ids.indexOf(id) !== i)).toEqual([])
|
||||
expect(ids).toContain('tab-reference-0-ref-a-citation')
|
||||
expect(ids).toContain('panel-reference-0-ref-a-citation')
|
||||
})
|
||||
|
||||
it('read-only: the tiles show, no Modifier, no Retirer, no field', async () => {
|
||||
const user = await mount(800)
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Modifier' }),
|
||||
).toBeNull()
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
expect(within(panel()).queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('motion', () => {
|
||||
const slid = () => (layer().firstElementChild as HTMLElement).style.transform
|
||||
|
||||
it('slides in from the right and fades the scrim, the page behind inert', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).toMatch(/translateX\(/)
|
||||
expect(screen.getByTestId('references-scrim')).toBeInTheDocument()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
await focusIs(heading)
|
||||
expect(slid()).not.toMatch(/translateX\([1-9]/)
|
||||
})
|
||||
|
||||
it('reduced motion: no slide, the same lifecycle', async () => {
|
||||
setReducedMotion(true)
|
||||
const user = await mount()
|
||||
await select(user, /Node A/)
|
||||
await user.click(trigger())
|
||||
expect(slid()).not.toMatch(/translateX\(/)
|
||||
await focusIs(heading)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
})
|
||||
|
||||
const MODES = [
|
||||
['motion', false],
|
||||
['reduced motion', true],
|
||||
] as const
|
||||
|
||||
describe.each(MODES)('closing, %s', (_label, reduced) => {
|
||||
beforeEach(() => setReducedMotion(reduced))
|
||||
|
||||
it('✕, Escape and the scrim each close it after the exit: the trigger holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
await user.keyboard('{Escape}')
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('Escape with nothing focused closes it too', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
;(document.activeElement as HTMLElement).blur()
|
||||
await user.keyboard('{Escape}')
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
|
||||
it('« Tout afficher » closes it, shows the tab, the heading holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', { name: 'Tout afficher (3)' }),
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
)
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
await closed()
|
||||
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(
|
||||
await focusIs(() =>
|
||||
within(tabPanel).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
expect(within(tabPanel).getAllByRole('listitem')).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('undo removing the cited finding closes the panel, the tab takes the focus', async () => {
|
||||
it('selecting a tab closes it, the new tab button holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
await closed()
|
||||
expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Vérification' }))
|
||||
})
|
||||
|
||||
it('« Aller à » a citer from a panel tile closes it and lands on that finding', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
const go = within(panel()).getAllByRole('button', { name: 'Aller à' })
|
||||
await user.click(go[0])
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('treeitem', { name: /Cat A/ }))
|
||||
})
|
||||
|
||||
it('the finding vanishing closes it, the active tab button holds the focus', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
act(() => {
|
||||
@@ -214,97 +377,11 @@ describe('citations panel opening', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
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 trigger', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.keyboard('{Escape}')
|
||||
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())
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
})
|
||||
|
||||
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 openFromFinding(user)
|
||||
expect(tabPanel().parentElement).toHaveAttribute('inert')
|
||||
expect(screen.getByRole('button', { name: /Enregistrer/ })).toBeEnabled()
|
||||
expect(panel().closest('header')).toBeNull()
|
||||
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 openFromFinding(user)
|
||||
const field = within(panel()).getByLabelText('Citation', {
|
||||
selector: '#panel-reference-0-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 the citations with no edit control', async () => {
|
||||
const user = await mount(800)
|
||||
await openFromFinding(user)
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: 'Supprimer' }),
|
||||
).toBeNull()
|
||||
expect(within(panel()).queryByRole('textbox')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
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 user.click(screen.getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'Modifier' }))
|
||||
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-0-ref-a-citation')
|
||||
expect(ids).toContain('panel-reference-0-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 () => {
|
||||
it('below 640 px the active tab sits under « Plus »: it holds the focus', async () => {
|
||||
const user = await mount(375)
|
||||
await user.click(screen.getByRole('button', { name: 'Plus' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Constats' }))
|
||||
@@ -312,6 +389,7 @@ describe('focus fallbacks (P6)', () => {
|
||||
await user.keyboard('{ArrowRight}')
|
||||
await user.click(screen.getByRole('treeitem', { name: /Node A/ }))
|
||||
await user.click(trigger())
|
||||
await focusIs(heading)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
@@ -322,9 +400,308 @@ describe('focus fallbacks (P6)', () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
expect(screen.queryByTestId('editor-citations-panel')).toBeNull()
|
||||
expect(document.activeElement).toBe(
|
||||
screen.getByRole('button', { name: 'Plus' }),
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('button', { name: 'Plus' }))
|
||||
})
|
||||
})
|
||||
|
||||
describe('the exit', () => {
|
||||
it('keeps the page and the panel inert until it is over, then lifts it', async () => {
|
||||
const user = await mount()
|
||||
const page = () =>
|
||||
screen.getAllByRole('tabpanel', { hidden: true })[0].parentElement
|
||||
await openFromFinding(user)
|
||||
expect(page()).toHaveAttribute('inert')
|
||||
await user.click(closeButton())
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(layer()).toHaveAttribute('inert')
|
||||
expect(page()).toHaveAttribute('inert')
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
|
||||
await closed()
|
||||
expect(page()).not.toHaveAttribute('inert')
|
||||
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
|
||||
})
|
||||
|
||||
it('a second close is a no-op, a tab choice replaces the pending move', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
fireEvent.keyDown(layer(), { key: 'Escape' })
|
||||
fireEvent.click(screen.getByTestId('references-scrim'))
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
await closed()
|
||||
expect(screen.getByRole('tab', { name: 'Vérification' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Vérification' }))
|
||||
})
|
||||
|
||||
it('leaves a focus the user placed elsewhere during the exit alone', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
await user.click(closeButton())
|
||||
const save = screen.getByRole('button', { name: /Enregistrer/ })
|
||||
act(() => save.focus())
|
||||
await closed()
|
||||
await new Promise((resolve) => setTimeout(resolve, 50))
|
||||
expect(document.activeElement).toBe(save)
|
||||
})
|
||||
|
||||
it('Défaire and Refaire stay usable while it is open', async () => {
|
||||
const user = await mount()
|
||||
act(() => void commitMove(40))
|
||||
await openFromFinding(user)
|
||||
const undo = screen.getByRole('button', { name: /Défaire/ })
|
||||
await waitFor(() => expect(undo).toBeEnabled())
|
||||
await user.click(undo)
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(screen.getByRole('button', { name: /Refaire/ })).toBeEnabled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the library and the history around the panel', () => {
|
||||
it('« Tout afficher » resets the search and the sort of the tab, open tiles kept (P4)', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||||
const tab = () => screen.getByRole('tabpanel', { name: 'Références' })
|
||||
await user.type(within(tab()).getByRole('searchbox'), 'Barone')
|
||||
await user.click(within(tab()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.selectOptions(
|
||||
within(tab()).getByLabelText('Trier par'),
|
||||
'citation',
|
||||
)
|
||||
await openFromFinding(user)
|
||||
await user.click(link())
|
||||
await closed()
|
||||
expect(within(tab()).getByRole('searchbox')).toHaveValue('')
|
||||
expect(within(tab()).getByLabelText('Trier par')).toHaveValue('sheet')
|
||||
expect(within(tab()).getAllByRole('listitem').length).toBeGreaterThan(2)
|
||||
expect(
|
||||
within(tab()).getByRole('button', { name: /^Barone/ }),
|
||||
).toHaveAttribute('aria-expanded', 'true')
|
||||
await focusIs(() =>
|
||||
within(tab()).getByRole('heading', { name: 'Références' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('an undo that removes the finding closes it: the active tab button holds the focus (P6)', async () => {
|
||||
const user = await mount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-b',
|
||||
name: name('Node B'),
|
||||
description: {},
|
||||
reference_ids: ['ref-b'],
|
||||
requires_vet_referral: false,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
await select(user, /Node B/)
|
||||
await user.click(trigger('1 référence'))
|
||||
await focusIs(heading)
|
||||
act(() => void store.getState().undoStep())
|
||||
await closed()
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Retirer de ce constat »', () => {
|
||||
const retire = (user: User, at = 0) =>
|
||||
user.click(
|
||||
within(panel()).getAllByRole('button', { name: 'Retirer de ce constat' })[
|
||||
at
|
||||
],
|
||||
)
|
||||
|
||||
async function openTile(user: User, citation: RegExp) {
|
||||
await user.click(within(panel()).getByRole('button', { name: citation }))
|
||||
}
|
||||
|
||||
it('removes only that id, the reference stays, one undo restores it with the status', async () => {
|
||||
const user = await mount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'set_status',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
status: 'reviewed',
|
||||
})
|
||||
})
|
||||
expect(nodeA().review_status).toBe('reviewed')
|
||||
await openFromFinding(user)
|
||||
const history = store.getState().undo.length
|
||||
await openTile(user, /^Barone/)
|
||||
await retire(user)
|
||||
expect(nodeA().reference_ids).toEqual(['ref-c'])
|
||||
expect(nodeA().review_status).toBe('to_confirm')
|
||||
expect(doc().references).toHaveLength(3)
|
||||
expect(store.getState().undo.length).toBe(history + 1)
|
||||
expect(tiles()).toHaveLength(1)
|
||||
expect(panel()).toHaveTextContent('1 référence citée par ce constat')
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(nodeA().reference_ids).toEqual(['ref-a', 'ref-c'])
|
||||
expect(nodeA().review_status).toBe('reviewed')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('the focus goes to the next tile, else the previous, else the heading', async () => {
|
||||
const ids = ['ref-a', 'ref-b', 'ref-c']
|
||||
const user = await mount(1280, nodeText(ids))
|
||||
await openFromFinding(user, '3 références')
|
||||
const header = (at: number) => () =>
|
||||
tiles()[at].querySelector('button') as HTMLElement
|
||||
await openTile(user, /^Barone/)
|
||||
await retire(user)
|
||||
await focusIs(header(0))
|
||||
expect(header(0)().textContent).toContain('Denoix')
|
||||
await openTile(user, /^Code rural/)
|
||||
await retire(user, 0)
|
||||
await focusIs(header(0))
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await openTile(user, /^Denoix/)
|
||||
await retire(user)
|
||||
await focusIs(heading)
|
||||
})
|
||||
|
||||
it('the last citation gone: the panel stays with its line and « Tout afficher »', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a']))
|
||||
await openFromFinding(user, '1 référence')
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await retire(user)
|
||||
expect(panel()).toHaveTextContent(
|
||||
'Ce constat ne cite plus aucune référence.',
|
||||
)
|
||||
expect(
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
).toBeVisible()
|
||||
expect(hasPanel()).toBe(true)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
// the trigger is gone with its count: the active tab button takes the focus (P6)
|
||||
await focusIs(() => screen.getByRole('tab', { name: 'Constats' }))
|
||||
})
|
||||
|
||||
it('a dangling id is a « Référence introuvable » row with Retirer, counted like the rest', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a', 'ref-gone']))
|
||||
await openFromFinding(user)
|
||||
expect(panel()).toHaveTextContent('2 références citées par ce constat')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
expect(tiles()[1]).toHaveTextContent('Référence introuvable')
|
||||
await user.click(
|
||||
within(tiles()[1] as HTMLElement).getByRole('button', {
|
||||
name: /^Retirer/,
|
||||
}),
|
||||
)
|
||||
expect(nodeA().reference_ids).toEqual(['ref-a'])
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await focusIs(() => tiles()[0].querySelector('button')!)
|
||||
})
|
||||
})
|
||||
|
||||
describe("a tile in edit when the panel closes (P22'')", () => {
|
||||
async function edit(user: User) {
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await user.click(within(panel()).getByRole('button', { name: 'Modifier' }))
|
||||
return panel().querySelector(
|
||||
'#panel-reference-0-ref-a-citation',
|
||||
) as HTMLTextAreaElement
|
||||
}
|
||||
|
||||
it('a valid draft is committed before the close, then the panel closes', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
await user.click(closeButton())
|
||||
expect(doc().references[0].citation).toBe('Neuf')
|
||||
await closed()
|
||||
await focusIs(() => trigger())
|
||||
})
|
||||
|
||||
it('a refused draft cancels a user close: panel open, field focused, message shown', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.click(closeButton())
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(layer()).not.toHaveAttribute('inert')
|
||||
expect(document.activeElement).toBe(field)
|
||||
expect(within(panel()).getByRole('alert')).toBeVisible()
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
it('a refused draft cancels a tab switch and « Tout afficher »', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.click(screen.getByRole('tab', { name: 'Vérification' }))
|
||||
expect(screen.getByRole('tab', { name: 'Constats' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
await user.click(
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
)
|
||||
expect(hasPanel()).toBe(true)
|
||||
})
|
||||
|
||||
it('a forced close (finding vanished) drops a refused draft and says so', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
})
|
||||
})
|
||||
await closed()
|
||||
expect(
|
||||
screen.getByText(/Saisie non appliquée : Citation/),
|
||||
).toBeInTheDocument()
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
it('Escape in a field of the tile neither closes nor commits', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(hasPanel()).toBe(true)
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
|
||||
it('Ctrl+Z reverts a reference edit while the panel is open', async () => {
|
||||
const user = await mount()
|
||||
const field = await edit(user)
|
||||
await user.clear(field)
|
||||
await user.type(field, 'Neuf')
|
||||
fireEvent.blur(field)
|
||||
expect(doc().references[0].citation).toBe('Neuf')
|
||||
fireEvent.keyDown(document.body, { key: 'z', ctrlKey: true })
|
||||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||||
})
|
||||
})
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import ReferenceFacts from '@/components/editor/references/ReferenceFacts'
|
||||
import ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
@@ -228,7 +228,11 @@ describe('« Aller à » a reference', () => {
|
||||
await openReady({ text: sheetText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
const box = screen.getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
@@ -240,7 +244,12 @@ describe('« Aller à » a reference', () => {
|
||||
serial: 1,
|
||||
}
|
||||
view.rerender(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} focus={focus} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
focus={focus}
|
||||
/>,
|
||||
)
|
||||
expect(box).toHaveValue('')
|
||||
expect(document.querySelectorAll('button[aria-controls]')).toHaveLength(3)
|
||||
@@ -256,23 +265,43 @@ describe('the reset signal', () => {
|
||||
await openReady({ text: sheetText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} resetSignal={0} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
libraryReset={0}
|
||||
/>,
|
||||
)
|
||||
const box = screen.getByRole('searchbox', {
|
||||
name: 'Rechercher une référence',
|
||||
})
|
||||
await user.type(box, 'Code')
|
||||
view.rerender(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} resetSignal={0} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
libraryReset={0}
|
||||
/>,
|
||||
)
|
||||
expect(box).toHaveValue('Code')
|
||||
view.rerender(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} resetSignal={1} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
libraryReset={1}
|
||||
/>,
|
||||
)
|
||||
expect(box).toHaveValue('')
|
||||
await user.type(box, 'a')
|
||||
view.rerender(
|
||||
<ReferenceLibrary readOnly={false} navigate={vi.fn()} resetSignal={1} />,
|
||||
<ReferencesTab
|
||||
readOnly={false}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
libraryReset={1}
|
||||
/>,
|
||||
)
|
||||
expect(box).toHaveValue('a')
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { ReferenceType } from '@faunosteo/core-wasm/types'
|
||||
import ReferenceLibrary from '@/components/editor/references/ReferenceLibrary'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import { targetOfKey } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
@@ -86,7 +86,12 @@ function sortText(): string {
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
const doc = () => JSON.parse(store.getState().documentText)
|
||||
const lib = (readOnly = false, extra = {}) => (
|
||||
<ReferenceLibrary readOnly={readOnly} navigate={vi.fn()} {...extra} />
|
||||
<ReferencesTab
|
||||
readOnly={readOnly}
|
||||
navigate={vi.fn()}
|
||||
reloadSheet={vi.fn()}
|
||||
{...extra}
|
||||
/>
|
||||
)
|
||||
async function mount(readOnly = false) {
|
||||
await openReady({ text: sortText() })
|
||||
@@ -420,12 +425,12 @@ describe('the reset path (« Tout afficher »)', () => {
|
||||
it('empties the search and the sort, keeping open tiles and the tile in edit', async () => {
|
||||
await openReady({ text: sortText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(lib(false, { resetSignal: 0 }))
|
||||
const view = render(lib(false, { libraryReset: 0 }))
|
||||
await user.click(header('r2'))
|
||||
const item = await startEdit(user, 'r1')
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
await user.type(search(), 'e')
|
||||
view.rerender(lib(false, { resetSignal: 1 }))
|
||||
view.rerender(lib(false, { libraryReset: 1 }))
|
||||
expect(search()).toHaveValue('')
|
||||
expect(sortBox()).toHaveValue('sheet')
|
||||
expect(order()).toHaveLength(5)
|
||||
|
||||
Reference in new issue
Block a user