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.
626 lines
22 KiB
TypeScript
626 lines
22 KiB
TypeScript
/** R2.1 and R2.2: the Références tab, the library (search, order, counts, add, « Aller à »). */
|
||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||
import {
|
||
cleanup,
|
||
fireEvent,
|
||
render,
|
||
screen,
|
||
within,
|
||
} from '@testing-library/react'
|
||
import userEvent from '@testing-library/user-event'
|
||
import ReferenceFacts from '@/components/editor/references/ReferenceFacts'
|
||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||
import { useLocaleStore } from '@/state/localeStore'
|
||
import { targetOfKey } from '@/editor/navigation'
|
||
import { edit, insert } from '../helpers/editorFixtures'
|
||
import {
|
||
baseText,
|
||
openReady,
|
||
resetStore,
|
||
serverHas,
|
||
store,
|
||
} from '../helpers/editorHarness'
|
||
import { mountDraft, setWidth } from '../helpers/editorRoute'
|
||
|
||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||
getSheetVersion: vi.fn(),
|
||
downloadSheetDrawing: vi.fn(),
|
||
saveSheetDraft: vi.fn(),
|
||
getOfficialSheetAdmin: vi.fn(),
|
||
submitSheetReview: vi.fn(),
|
||
}))
|
||
|
||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||
afterEach(() => {
|
||
cleanup()
|
||
resetStore()
|
||
setWidth(1024)
|
||
})
|
||
|
||
const name = (n: string) => ({ fr: n, en: n })
|
||
const ref = (id: string, citation: string, url = '', doi = '') =>
|
||
({
|
||
kind: 'reference',
|
||
value: {
|
||
id,
|
||
type: 'book',
|
||
citation,
|
||
url: url || null,
|
||
doi: doi || null,
|
||
},
|
||
}) as const
|
||
|
||
function sheetText(): string {
|
||
let text = baseText()
|
||
text = insert(text, ref('ref-a', 'Barone, Ostéologie'))
|
||
text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule'))
|
||
text = insert(text, ref('ref-c', 'Code rural', '', '10.1000/ABC'))
|
||
text = insert(text, {
|
||
kind: 'zone',
|
||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||
})
|
||
return edit(text, {
|
||
op: 'insert',
|
||
parent: { kind: 'zone', id: 'zone-a' },
|
||
element: {
|
||
kind: 'finding_category',
|
||
value: {
|
||
id: 'fcat-a',
|
||
kind: 'dysfunction',
|
||
name: name('Cat A'),
|
||
description: {},
|
||
reference_ids: ['ref-a', 'ref-b'],
|
||
review_status: 'to_confirm',
|
||
children: [],
|
||
},
|
||
},
|
||
})
|
||
}
|
||
|
||
/** The sheet with a finding under « Cat A » that cites ref-a too (ref-a: two citers). */
|
||
function citedTwiceText(): string {
|
||
return edit(sheetText(), {
|
||
op: 'insert',
|
||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||
element: {
|
||
kind: 'finding_node',
|
||
value: {
|
||
id: 'fnode-a',
|
||
name: name('Node A'),
|
||
description: {},
|
||
requires_vet_referral: false,
|
||
reference_ids: ['ref-a'],
|
||
review_status: 'to_confirm',
|
||
children: [],
|
||
},
|
||
},
|
||
})
|
||
}
|
||
|
||
type User = ReturnType<typeof userEvent.setup>
|
||
|
||
const ready = () =>
|
||
screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||
const tabPanel = () => screen.getByRole('tabpanel', { name: 'Références' })
|
||
const cards = () => within(tabPanel()).getAllByRole('listitem')
|
||
const header = (citation: string) =>
|
||
within(tabPanel()).getByRole('button', { name: new RegExp(`^${citation}`) })
|
||
const openAll = async (user: User) => {
|
||
for (const button of within(tabPanel()).getAllByRole('button', {
|
||
expanded: false,
|
||
})) {
|
||
if (button.hasAttribute('aria-controls')) await user.click(button)
|
||
}
|
||
}
|
||
const search = () =>
|
||
within(tabPanel()).getByRole('searchbox', {
|
||
name: 'Rechercher une référence',
|
||
})
|
||
|
||
async function mount(width = 1280, text = citedTwiceText()) {
|
||
serverHas(text, 3)
|
||
const user = userEvent.setup()
|
||
mountDraft({ width })
|
||
await ready()
|
||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||
return user
|
||
}
|
||
|
||
describe('the Références tab', () => {
|
||
it('is the fifth tab, there is no header button, and it lists every card', async () => {
|
||
await mount()
|
||
const tabs = screen.getAllByRole('tab').map((tab) => tab.textContent)
|
||
expect(tabs).toEqual([
|
||
'Général',
|
||
'Annotations',
|
||
'Constats',
|
||
'Références',
|
||
'Vérification',
|
||
])
|
||
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
|
||
expect(cards()).toHaveLength(3)
|
||
expect(
|
||
within(tabPanel()).getByRole('heading', { name: 'Références' }),
|
||
).toBeInTheDocument()
|
||
})
|
||
|
||
it('each card says how often it is cited, the ids carry the tab prefix', async () => {
|
||
await mount()
|
||
const texts = cards().map((card) => card.textContent)
|
||
expect(texts[0]).toContain('Citée 2 fois')
|
||
expect(texts[1]).toContain('Citée 1 fois')
|
||
expect(texts[2]).toContain('Non citée')
|
||
expect(
|
||
tabPanel().querySelector('#tab-reference-0-ref-a-header'),
|
||
).not.toBeNull()
|
||
expect(tabPanel().querySelector('#tab-reference-new-citation')).toBeNull()
|
||
})
|
||
|
||
it('matches the citation, the DOI and the URL, ignoring case and accents', async () => {
|
||
const user = await mount()
|
||
await user.type(search(), 'OSTEOLOGIE')
|
||
expect(cards()).toHaveLength(1)
|
||
await user.clear(search())
|
||
await user.type(search(), '10.1000/abc')
|
||
expect(cards()).toHaveLength(1)
|
||
await user.clear(search())
|
||
await user.type(search(), 'epaule')
|
||
expect(cards()).toHaveLength(1)
|
||
await user.clear(search())
|
||
await user.type(search(), 'zzz')
|
||
expect(
|
||
within(tabPanel()).getByText('Aucune référence ne contient « zzz ».'),
|
||
).toBeInTheDocument()
|
||
})
|
||
|
||
it('shows ↑ / ↓ in open tiles, and only without a search', async () => {
|
||
const user = await mount()
|
||
await openAll(user)
|
||
expect(
|
||
within(tabPanel()).getAllByRole('button', { name: 'Descendre' }).length,
|
||
).toBe(3)
|
||
await user.type(search(), 'a')
|
||
expect(
|
||
within(tabPanel()).queryByRole('button', { name: 'Descendre' }),
|
||
).toBeNull()
|
||
})
|
||
|
||
it('Ctrl+Z reverts a reference edit', async () => {
|
||
const user = await mount()
|
||
await user.click(header('Barone'))
|
||
await user.click(
|
||
within(tabPanel()).getByRole('button', { name: 'Modifier' }),
|
||
)
|
||
const field = within(tabPanel()).getByLabelText('Citation', {
|
||
selector: '#tab-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 no edit control, only the search', async () => {
|
||
const user = await mount(800)
|
||
await openAll(user)
|
||
expect(
|
||
within(tabPanel()).queryByRole('button', { name: 'Supprimer' }),
|
||
).toBeNull()
|
||
expect(
|
||
within(tabPanel()).queryByRole('button', {
|
||
name: 'Ajouter la référence',
|
||
}),
|
||
).toBeNull()
|
||
expect(search()).toBeInTheDocument()
|
||
})
|
||
})
|
||
|
||
describe('« Aller à » a reference', () => {
|
||
it('clears the search that hides it, opens its tile and focuses its button', async () => {
|
||
serverHas(sheetText(), 3)
|
||
await openReady({ text: sheetText() })
|
||
const user = userEvent.setup()
|
||
const view = render(
|
||
<ReferencesTab
|
||
readOnly={false}
|
||
navigate={vi.fn()}
|
||
reloadSheet={vi.fn()}
|
||
/>,
|
||
)
|
||
const box = screen.getByRole('searchbox', {
|
||
name: 'Rechercher une référence',
|
||
})
|
||
await user.type(box, 'Code')
|
||
expect(screen.getAllByRole('listitem')).toHaveLength(1)
|
||
const focus = {
|
||
target: targetOfKey({ kind: 'reference', id: 'ref-a' }),
|
||
serial: 1,
|
||
}
|
||
view.rerender(
|
||
<ReferencesTab
|
||
readOnly={false}
|
||
navigate={vi.fn()}
|
||
reloadSheet={vi.fn()}
|
||
focus={focus}
|
||
/>,
|
||
)
|
||
expect(box).toHaveValue('')
|
||
expect(document.querySelectorAll('button[aria-controls]')).toHaveLength(3)
|
||
expect(document.activeElement?.getAttribute('data-focus-key')).toContain(
|
||
'ref-a',
|
||
)
|
||
expect(document.activeElement).toHaveAttribute('aria-expanded', 'true')
|
||
})
|
||
})
|
||
|
||
describe('the reset signal', () => {
|
||
it('empties the search once per bump and leaves other state alone', async () => {
|
||
await openReady({ text: sheetText() })
|
||
const user = userEvent.setup()
|
||
const view = render(
|
||
<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(
|
||
<ReferencesTab
|
||
readOnly={false}
|
||
navigate={vi.fn()}
|
||
reloadSheet={vi.fn()}
|
||
libraryReset={0}
|
||
/>,
|
||
)
|
||
expect(box).toHaveValue('Code')
|
||
view.rerender(
|
||
<ReferencesTab
|
||
readOnly={false}
|
||
navigate={vi.fn()}
|
||
reloadSheet={vi.fn()}
|
||
libraryReset={1}
|
||
/>,
|
||
)
|
||
expect(box).toHaveValue('')
|
||
await user.type(box, 'a')
|
||
view.rerender(
|
||
<ReferencesTab
|
||
readOnly={false}
|
||
navigate={vi.fn()}
|
||
reloadSheet={vi.fn()}
|
||
libraryReset={1}
|
||
/>,
|
||
)
|
||
expect(box).toHaveValue('a')
|
||
})
|
||
})
|
||
|
||
describe('adding a reference', () => {
|
||
const addButton = () =>
|
||
within(tabPanel()).getByRole('button', { name: 'Ajouter une référence' })
|
||
async function add(user: User) {
|
||
await user.click(addButton())
|
||
const byId = (id: string) => tabPanel().querySelector<HTMLElement>(id)!
|
||
await user.selectOptions(byId('#tab-reference-new-type'), 'book')
|
||
await user.type(byId('#tab-reference-new-citation'), 'Nouvelle source')
|
||
await user.click(
|
||
within(tabPanel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||
)
|
||
}
|
||
|
||
it('resets the search, shows the new tile open and focuses its button', async () => {
|
||
const user = await mount()
|
||
await user.type(search(), 'Barone')
|
||
expect(cards()).toHaveLength(1)
|
||
await add(user)
|
||
expect(search()).toHaveValue('')
|
||
expect(cards()).toHaveLength(4)
|
||
expect(header('Nouvelle source')).toHaveAttribute('aria-expanded', 'true')
|
||
expect(document.activeElement).toBe(header('Nouvelle source'))
|
||
expect(within(tabPanel()).queryByLabelText('Citation')).toBeNull()
|
||
})
|
||
|
||
it('opens a draft tile with the citation focused, and a refused add keeps it', async () => {
|
||
const user = await mount()
|
||
await user.type(search(), 'Barone')
|
||
await user.click(addButton())
|
||
expect(search()).toHaveValue('')
|
||
expect(document.activeElement).toBe(
|
||
tabPanel().querySelector('#tab-reference-new-citation'),
|
||
)
|
||
await user.click(
|
||
within(tabPanel()).getByRole('button', { name: 'Ajouter la référence' }),
|
||
)
|
||
expect(within(tabPanel()).getByRole('alert')).toHaveTextContent(
|
||
'Choisissez un type',
|
||
)
|
||
expect(doc().references).toHaveLength(3)
|
||
})
|
||
})
|
||
|
||
const tile = (citation: string) => header(citation).closest('li')!
|
||
const doc = () => JSON.parse(store.getState().documentText)
|
||
|
||
/** Opens the tile and enters edit; answers the tile, whose header then names the edit. */
|
||
async function startEdit(user: User, citation: string) {
|
||
const item = tile(citation)
|
||
await user.click(header(citation))
|
||
await user.click(within(item).getByRole('button', { name: 'Modifier' }))
|
||
return item
|
||
}
|
||
|
||
describe('the tile disclosure', () => {
|
||
it('opens and closes from the keyboard, and several stay open', async () => {
|
||
const user = await mount()
|
||
const first = header('Barone')
|
||
expect(first).toHaveAttribute('aria-expanded', 'false')
|
||
expect(first).toHaveAttribute('aria-controls', 'tab-reference-0-ref-a-body')
|
||
first.focus()
|
||
await user.keyboard('{Enter}')
|
||
expect(first).toHaveAttribute('aria-expanded', 'true')
|
||
header('Denoix').focus()
|
||
await user.keyboard(' ')
|
||
expect(first).toHaveAttribute('aria-expanded', 'true')
|
||
expect(header('Denoix')).toHaveAttribute('aria-expanded', 'true')
|
||
first.focus()
|
||
await user.keyboard('{Enter}')
|
||
expect(first).toHaveAttribute('aria-expanded', 'false')
|
||
expect(tabPanel().querySelector('#tab-reference-0-ref-a-body')).toBeNull()
|
||
})
|
||
|
||
it('is a natural tab stop that carries only the focus key', async () => {
|
||
await mount()
|
||
const button = header('Barone')
|
||
expect(button).not.toHaveAttribute('tabindex')
|
||
expect(button.closest('[data-focus-key]')).toBe(button)
|
||
})
|
||
})
|
||
|
||
describe('an open tile', () => {
|
||
it('shows type, DOI and URL as safe links, « Aucun » / « Aucune » when absent', async () => {
|
||
const user = await mount()
|
||
await user.click(header('Code rural'))
|
||
await user.click(header('Denoix'))
|
||
const doi = within(tile('Code rural')).getByRole('link', {
|
||
name: /10\.1000\/ABC/,
|
||
})
|
||
expect(doi).toHaveAttribute('href', 'https://doi.org/10.1000/ABC')
|
||
expect(doi).toHaveAttribute('target', '_blank')
|
||
expect(doi).toHaveAttribute('rel', 'noopener noreferrer')
|
||
expect(within(tile('Code rural')).getByText('Aucune')).toBeInTheDocument()
|
||
const url = within(tile('Denoix')).getByRole('link', {
|
||
name: /exemple\.org/,
|
||
})
|
||
expect(url).toHaveAttribute('href', 'https://exemple.org/%C3%89paule')
|
||
expect(within(tile('Denoix')).getByText('Aucun')).toBeInTheDocument()
|
||
})
|
||
|
||
it('lists the citers, a family marked, and the count is the list length', async () => {
|
||
const user = await mount()
|
||
await user.click(header('Barone'))
|
||
const open = within(tile('Barone'))
|
||
expect(open.getByText('Citée 2 fois, par :')).toBeInTheDocument()
|
||
expect(open.getAllByRole('button', { name: 'Aller à' })).toHaveLength(2)
|
||
expect(open.getAllByText('famille')).toHaveLength(1)
|
||
expect(open.getByText(/Zone A › Cat A ›/)).toBeInTheDocument()
|
||
})
|
||
|
||
it('says so when nothing cites it, and offers « Supprimer » only then', async () => {
|
||
const user = await mount()
|
||
await user.click(header('Barone'))
|
||
await user.click(header('Code rural'))
|
||
const cited = within(tile('Barone'))
|
||
expect(cited.queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
||
expect(
|
||
cited.getByText(/Pour supprimer cette référence/),
|
||
).toBeInTheDocument()
|
||
const uncited = within(tile('Code rural'))
|
||
expect(
|
||
uncited.getByText(
|
||
'Aucun constat ni aucune famille ne cite cette référence.',
|
||
),
|
||
).toBeInTheDocument()
|
||
expect(
|
||
uncited.getByRole('button', { name: 'Supprimer' }),
|
||
).toBeInTheDocument()
|
||
expect(uncited.queryByText(/Pour supprimer cette référence/)).toBeNull()
|
||
})
|
||
|
||
it('« Aller à » on a citer opens the Constats tab on it', async () => {
|
||
const user = await mount()
|
||
await user.click(header('Barone'))
|
||
const [family] = within(tile('Barone')).getAllByRole('button', {
|
||
name: 'Aller à',
|
||
})
|
||
await user.click(family)
|
||
expect(screen.getByRole('tab', { name: 'Constats' })).toHaveAttribute(
|
||
'aria-selected',
|
||
'true',
|
||
)
|
||
})
|
||
|
||
it('never links a javascript: address', () => {
|
||
const risky = {
|
||
id: 'ref-x',
|
||
type: 'web',
|
||
citation: 'X',
|
||
url: 'javascript:alert(1)',
|
||
doi: 'javascript:alert(2)',
|
||
} as const
|
||
render(<ReferenceFacts reference={risky} />)
|
||
expect(screen.queryByRole('link')).toBeNull()
|
||
expect(screen.getByText('javascript:alert(1)')).toBeInTheDocument()
|
||
})
|
||
})
|
||
|
||
describe('a tile in edit', () => {
|
||
it('shows the fields, the citers and « Terminer », and hides the other actions', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
expect(view.getByText('Modifier la référence')).toBeInTheDocument()
|
||
expect(document.activeElement).toBe(view.getByLabelText('Citation'))
|
||
expect(view.getByText('Citée 2 fois, par :')).toBeInTheDocument()
|
||
expect(view.getAllByRole('button', { name: 'Aller à' })).toHaveLength(2)
|
||
for (const name of ['Modifier', 'Supprimer', 'Monter', 'Descendre']) {
|
||
expect(view.queryByRole('button', { name })).toBeNull()
|
||
}
|
||
await user.click(view.getByRole('button', { name: 'Terminer' }))
|
||
expect(view.queryByLabelText('Citation')).toBeNull()
|
||
expect(document.activeElement).toBe(
|
||
item.querySelector('button[aria-expanded]'),
|
||
)
|
||
expect(view.getByRole('button', { name: 'Modifier' })).toBeInTheDocument()
|
||
})
|
||
|
||
it('keeps edit and focuses the field when the URL is refused', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
const url = view.getByLabelText('Adresse web (URL)')
|
||
await user.type(url, 'exemple.org')
|
||
await user.click(view.getByRole('button', { name: 'Terminer' }))
|
||
expect(view.getByRole('button', { name: 'Terminer' })).toBeInTheDocument()
|
||
expect(document.activeElement).toBe(url)
|
||
expect(view.getByRole('alert')).toBeInTheDocument()
|
||
expect(doc().references[0].url).toBeNull()
|
||
})
|
||
|
||
it('keeps edit and focuses the citation when it is left blank', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
const citation = view.getByLabelText('Citation')
|
||
await user.clear(citation)
|
||
await user.click(view.getByRole('button', { name: 'Terminer' }))
|
||
expect(view.getByRole('button', { name: 'Terminer' })).toBeInTheDocument()
|
||
expect(document.activeElement).toBe(citation)
|
||
expect(view.getByText('Ce champ est obligatoire.')).toBeInTheDocument()
|
||
expect(doc().references[0].citation).toBe('Barone, Ostéologie')
|
||
})
|
||
|
||
it('a refused field A, then B applied, then « Terminer » keeps edit', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
const url = view.getByLabelText('Adresse web (URL)')
|
||
await user.type(url, 'exemple.org')
|
||
await user.tab()
|
||
await user.type(view.getByLabelText('DOI'), '10.1000/xyz')
|
||
await user.tab()
|
||
expect(doc().references[0].doi).toBe('10.1000/xyz')
|
||
await user.click(view.getByRole('button', { name: 'Terminer' }))
|
||
expect(view.getByRole('button', { name: 'Terminer' })).toBeInTheDocument()
|
||
expect(document.activeElement).toBe(url)
|
||
})
|
||
|
||
it('a press on « Terminer » keeps the focus in the field (no refusal shifts it), the click keeps edit', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
const url = view.getByLabelText('Adresse web (URL)')
|
||
await user.type(url, 'exemple.org')
|
||
const done = view.getByRole('button', { name: 'Terminer' })
|
||
await user.pointer({ keys: '[MouseLeft>]', target: done })
|
||
expect(view.queryByRole('alert')).toBeNull()
|
||
expect(document.activeElement).toBe(url)
|
||
await user.pointer({ keys: '[/MouseLeft]', target: done })
|
||
expect(view.getByRole('alert')).toBeInTheDocument()
|
||
expect(document.activeElement).toBe(url)
|
||
expect(view.getByRole('button', { name: 'Terminer' })).toBeInTheDocument()
|
||
})
|
||
|
||
it('applies every pending field on « Terminer », as one history entry each', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
const view = within(item)
|
||
await user.type(view.getByLabelText('DOI'), '10.1000/xyz')
|
||
await user.type(view.getByLabelText('Adresse web (URL)'), 'https://a.org/')
|
||
await user.click(view.getByRole('button', { name: 'Terminer' }))
|
||
expect(doc().references[0]).toMatchObject({
|
||
doi: '10.1000/xyz',
|
||
url: 'https://a.org/',
|
||
})
|
||
expect(view.queryByLabelText('Citation')).toBeNull()
|
||
})
|
||
|
||
it('switching to another tile leaves edit only when the fields apply', async () => {
|
||
const user = await mount()
|
||
const barone = await startEdit(user, 'Barone')
|
||
const denoix = tile('Denoix')
|
||
const url = within(barone).getByLabelText('Adresse web (URL)')
|
||
await user.type(url, 'exemple.org')
|
||
await user.click(header('Denoix'))
|
||
const modify = () =>
|
||
within(denoix).getByRole('button', { name: 'Modifier' })
|
||
await user.click(modify())
|
||
expect(within(barone).getByLabelText('Citation')).toBeInTheDocument()
|
||
expect(within(denoix).queryByLabelText('Citation')).toBeNull()
|
||
await user.clear(url)
|
||
await user.click(modify())
|
||
expect(within(barone).queryByLabelText('Citation')).toBeNull()
|
||
expect(within(denoix).getByLabelText('Citation')).toBeInTheDocument()
|
||
})
|
||
|
||
it('survives a tab change with the typed text', async () => {
|
||
const user = await mount()
|
||
const item = await startEdit(user, 'Barone')
|
||
await user.type(within(item).getByLabelText('DOI'), '10.1000/kept')
|
||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||
await user.click(screen.getByRole('tab', { name: 'Références' }))
|
||
const view = within(item)
|
||
expect(view.getByLabelText('DOI')).toHaveValue('10.1000/kept')
|
||
expect(doc().references[0].doi).toBe('10.1000/kept')
|
||
})
|
||
})
|
||
|
||
describe('read-only tiles', () => {
|
||
it('keep DOI, URL and « Aller à », and offer no edit control', async () => {
|
||
const user = await mount(800)
|
||
await user.click(header('Barone'))
|
||
await user.click(header('Denoix'))
|
||
const cited = within(tile('Barone'))
|
||
expect(cited.getAllByRole('button', { name: 'Aller à' })).toHaveLength(2)
|
||
expect(
|
||
within(tile('Denoix')).getByRole('link', { name: /exemple\.org/ }),
|
||
).toBeInTheDocument()
|
||
expect(
|
||
within(tabPanel()).queryByRole('button', { name: 'Modifier' }),
|
||
).toBeNull()
|
||
expect(
|
||
within(tabPanel()).queryByRole('textbox', { name: 'Citation' }),
|
||
).toBeNull()
|
||
})
|
||
})
|
||
|
||
describe('reopening the editor', () => {
|
||
it('starts with every tile closed and none in edit', async () => {
|
||
const user = await mount()
|
||
await startEdit(user, 'Barone')
|
||
await user.click(header('Denoix'))
|
||
cleanup()
|
||
await mount()
|
||
const opened = within(tabPanel()).queryAllByRole('button', {
|
||
expanded: true,
|
||
})
|
||
expect(opened).toHaveLength(0)
|
||
expect(
|
||
within(tabPanel()).queryByLabelText('Citation', {
|
||
selector: '#tab-reference-0-ref-a-citation',
|
||
}),
|
||
).toBeNull()
|
||
})
|
||
})
|