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
@@ -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')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user