feat(editor): search, sort, count and add in the Références tab
Search (citation, DOI, URL) with « Effacer la recherche » and Escape;
« Trier par » sheet order, citation (locale collator), citation count,
type (business order); every sort stable on stored order, display only:
document, stored order, ids and history unchanged (unit + e2e). Count
« {n} références » / « {n} sur {total} » counts matching references
only. « Monter » / « Descendre » only in sheet order without search
(A1). « Ajouter une référence » resets search and sort and appends a
draft tile in edit; a tile in edit stays pinned while sorted or
searched; tile state pruned of absent ids. Reset path ready for « Tout
afficher » (R2.4).
Gates: typecheck, lint, test:run (app 1452), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 115
passed / 102 skipped / 2 failed: editor-structures (test-side, fixed,
rerun with editor-references 12 passed / 11 skipped) and admin.spec A0
« Target crashed » during axe on the rights screen (not R2: that
screen renders every grant, 1 282 accumulated e2e fixtures; reported as
an open risk); full-row guard: no pre-existing row changed in any table.
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-references-tab.test.tsx | `#tab-reference-new-citation` present on load | null until « Ajouter une référence » |
| same | no match text « Aucune référence ne correspond. » | notice « Aucune référence ne contient « zzz ». » |
| same | add: form always visible, add clears the search, `getByText('Nouvelle source')` | click « Ajouter une référence » first; new tile header open, focused, search empty, 4 tiles |
| same | « a refused add keeps the search » | REMOVED (P24: add resets the search at once); replaced by « draft opens with citation focused, refused add keeps the draft, no write » |
| editor-tabs-lists.test.tsx | add form directly | click « Ajouter une référence » before the form assertions (same assertions after) |
| editor-keep-alive.test.tsx | form survives tab round trip | same, after opening the draft |
| editor-no-loss.test.tsx | reference form keeps typed text | same, after opening the draft |
| e2e editor-shell.spec (2), editor-shell-crossing.spec, editor-structures.spec | fill `#tab-reference-new-*` directly; `getByText(citation)` visible | open the draft first; structures asserts the new header is focused |
| e2e editor-references.spec keyboard walk | focus search, Tab reaches header 0 | focus « Ajouter une référence » (search, sort, add precede the headers) |
Other readers of `editor.reference.add`/new ids: grep of src, tests, e2e incl. editor-equine found none left unlisted. editor-equine is not affected ("updated, not run": nothing to update).
## i18n (fr / en)
Added: `editor.references.add` Ajouter une référence / Add a reference; `add_help` Type et citation obligatoires. / Type and citation required.; `clear_search` Effacer la recherche / Clear the search; `sort_by` Trier par / Sort by; `sort.sheet|citation|count|type` Ordre de la fiche, Citation (A → Z), Nombre de citations, Type / Sheet order, Citation (A → Z), Number of citations, Type; `count_one|other` {count} référence(s) / reference(s); `count_of_one|other` {count} référence(s) sur {total} / {count} reference(s) of {total}; `reorder_hint` Pour réorganiser, affichez l'ordre de la fiche sans recherche. / To reorder, show the sheet order without a search.; `no_result` Aucune référence ne contient « {q} ». / No reference contains “{q}”.; `no_result_scope` La recherche porte sur la citation, le DOI et l'URL. / The search covers the citation, the DOI and the URL. (REVUE sentence split in two keys so the first half is bold).
Changed: none. Removed: none (`editor.references.no_match` kept, the panel's EmptyLine still uses it).
This commit is contained in:
1 parent
c21995b3fb
commit
3baac4dbb5
26 files changed
+1544
-219
No files matched your search
@@ -202,6 +202,9 @@ describe('text typed in a place that is left', () => {
|
||||
it('the reference add form survives leaving and returning to the Références tab', async () => {
|
||||
const user = await mount()
|
||||
await user.click(tab('Références'))
|
||||
await user.click(
|
||||
inPlace('references').getByRole('button', { name: 'Ajouter une référence' }),
|
||||
)
|
||||
const field = inPlace('references').getByLabelText('Citation', {
|
||||
selector: '#tab-reference-new-citation',
|
||||
})
|
||||
|
||||
@@ -146,6 +146,7 @@ describe('typed values come back after a 1 024 px crossing', () => {
|
||||
it('the reference creation form, in the Références tab', async () => {
|
||||
const user = await mount()
|
||||
await user.click(tab('Références'))
|
||||
await user.click(button('Ajouter une référence'))
|
||||
await keepsTypedValue(
|
||||
user,
|
||||
'tab-reference-new-citation',
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/** R2.3: the four display orders and the shown set are pure and never touch their inputs. */
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { Reference, ReferenceType } from '@faunosteo/core-wasm/types'
|
||||
import { sortReferenceIds } from '@/editor/references/sort'
|
||||
import { shownPositions } from '@/editor/references/view'
|
||||
|
||||
const ref = (id: string, citation: string, type: ReferenceType): Reference => ({
|
||||
id,
|
||||
type,
|
||||
citation,
|
||||
url: null,
|
||||
doi: null,
|
||||
})
|
||||
|
||||
// Accents, case, numbers, equal citations and mixed types, in stored order r1..r5.
|
||||
const refs: readonly Reference[] = [
|
||||
ref('r1', 'Zèbre 10', 'web'),
|
||||
ref('r2', 'zebre 9', 'journal'),
|
||||
ref('r3', 'Étude', 'book'),
|
||||
ref('r4', 'etude', 'book'),
|
||||
ref('r5', 'Alpha', 'legal'),
|
||||
]
|
||||
const COUNTS: Record<string, number> = { r1: 1, r2: 2, r5: 1 }
|
||||
const context = {
|
||||
locale: 'fr' as const,
|
||||
citedCount: (id: string) => COUNTS[id] ?? 0,
|
||||
}
|
||||
const all = [0, 1, 2, 3, 4]
|
||||
const ids = (positions: number[]) => positions.map((at) => refs[at].id)
|
||||
|
||||
function permutations<T>(items: readonly T[]): T[][] {
|
||||
if (items.length < 2) return [[...items]]
|
||||
return items.flatMap((item, at) =>
|
||||
permutations([...items.slice(0, at), ...items.slice(at + 1)]).map(
|
||||
(rest) => [item, ...rest],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
describe('sortReferenceIds', () => {
|
||||
it('sheet keeps the stored order', () => {
|
||||
expect(ids(sortReferenceIds(refs, all, 'sheet', context))).toEqual([
|
||||
'r1',
|
||||
'r2',
|
||||
'r3',
|
||||
'r4',
|
||||
'r5',
|
||||
])
|
||||
})
|
||||
|
||||
it('citation: collator, accents and case ignored, numbers by value, ties stored', () => {
|
||||
expect(ids(sortReferenceIds(refs, all, 'citation', context))).toEqual([
|
||||
'r5',
|
||||
'r3',
|
||||
'r4',
|
||||
'r2',
|
||||
'r1',
|
||||
])
|
||||
})
|
||||
|
||||
it('count: most cited first, ties in sheet order', () => {
|
||||
expect(ids(sortReferenceIds(refs, all, 'count', context))).toEqual([
|
||||
'r2',
|
||||
'r1',
|
||||
'r5',
|
||||
'r3',
|
||||
'r4',
|
||||
])
|
||||
})
|
||||
|
||||
it('type: REFERENCE_TYPES order, ties in sheet order', () => {
|
||||
expect(ids(sortReferenceIds(refs, all, 'type', context))).toEqual([
|
||||
'r3',
|
||||
'r4',
|
||||
'r2',
|
||||
'r5',
|
||||
'r1',
|
||||
])
|
||||
})
|
||||
|
||||
it('a type outside the list sorts after the listed ones, stored order among them', () => {
|
||||
const odd = [
|
||||
ref('x1', 'a', 'unknown' as ReferenceType),
|
||||
ref('x2', 'b', 'web'),
|
||||
ref('x3', 'c', 'other' as ReferenceType),
|
||||
]
|
||||
expect(
|
||||
sortReferenceIds(odd, [0, 1, 2], 'type', context).map((at) => odd[at].id),
|
||||
).toEqual(['x2', 'x1', 'x3'])
|
||||
})
|
||||
|
||||
it('every permutation of the input gives the same output', () => {
|
||||
for (const sort of ['sheet', 'citation', 'count', 'type'] as const) {
|
||||
const expected = sortReferenceIds(refs, all, sort, context)
|
||||
for (const input of permutations(all)) {
|
||||
expect(sortReferenceIds(refs, input, sort, context)).toEqual(expected)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('returns a new array and leaves frozen inputs untouched', () => {
|
||||
const frozen = Object.freeze([...refs.map((r) => Object.freeze({ ...r }))])
|
||||
const positions = Object.freeze([4, 3, 2, 1, 0])
|
||||
const out = sortReferenceIds(frozen, positions, 'citation', context)
|
||||
expect(out).not.toBe(positions)
|
||||
expect(positions).toEqual([4, 3, 2, 1, 0])
|
||||
expect(frozen.map((r) => r.id)).toEqual(['r1', 'r2', 'r3', 'r4', 'r5'])
|
||||
})
|
||||
|
||||
it('numbers in English too', () => {
|
||||
const en = { ...context, locale: 'en' as const }
|
||||
expect(ids(sortReferenceIds(refs, all, 'citation', en))[3]).toBe('r2')
|
||||
})
|
||||
})
|
||||
|
||||
describe('shownPositions', () => {
|
||||
const view = { query: '', sort: 'citation' } as const
|
||||
|
||||
it('searches, then sorts', () => {
|
||||
expect(
|
||||
ids(
|
||||
shownPositions(
|
||||
refs,
|
||||
{ query: 'ZEBRE', sort: 'citation' },
|
||||
context,
|
||||
null,
|
||||
),
|
||||
),
|
||||
).toEqual(['r2', 'r1'])
|
||||
})
|
||||
|
||||
it('puts the pinned tile back at its index, hidden by the search or not', () => {
|
||||
const search = { query: 'etude', sort: 'citation' } as const
|
||||
const pinned = shownPositions(refs, search, context, {
|
||||
position: 0,
|
||||
index: 1,
|
||||
})
|
||||
expect(ids(pinned)).toEqual(['r3', 'r1', 'r4'])
|
||||
const clamped = shownPositions(refs, view, context, {
|
||||
position: 0,
|
||||
index: 99,
|
||||
})
|
||||
expect(ids(clamped)).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
|
||||
const first = shownPositions(refs, view, context, { position: 1, index: 0 })
|
||||
expect(ids(first)).toEqual(['r2', 'r5', 'r3', 'r4', 'r1'])
|
||||
})
|
||||
})
|
||||
@@ -155,9 +155,7 @@ describe('the Références tab', () => {
|
||||
expect(
|
||||
tabPanel().querySelector('#tab-reference-0-ref-a-header'),
|
||||
).not.toBeNull()
|
||||
expect(
|
||||
tabPanel().querySelector('#tab-reference-new-citation'),
|
||||
).not.toBeNull()
|
||||
expect(tabPanel().querySelector('#tab-reference-new-citation')).toBeNull()
|
||||
})
|
||||
|
||||
it('matches the citation, the DOI and the URL, ignoring case and accents', async () => {
|
||||
@@ -173,7 +171,7 @@ describe('the Références tab', () => {
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'zzz')
|
||||
expect(
|
||||
within(tabPanel()).getByText('Aucune référence ne correspond.'),
|
||||
within(tabPanel()).getByText('Aucune référence ne contient « zzz ».'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -281,7 +279,10 @@ describe('the reset signal', () => {
|
||||
})
|
||||
|
||||
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')
|
||||
@@ -290,23 +291,33 @@ describe('adding a reference', () => {
|
||||
)
|
||||
}
|
||||
|
||||
it('clears the search so the new reference shows', async () => {
|
||||
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')).toBeInTheDocument()
|
||||
expect(header('Nouvelle source')).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(header('Nouvelle source'))
|
||||
expect(within(tabPanel()).queryByLabelText('Citation')).toBeNull()
|
||||
})
|
||||
|
||||
it('a refused add keeps the search', async () => {
|
||||
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(search()).toHaveValue('Barone')
|
||||
expect(within(tabPanel()).getByRole('alert')).toHaveTextContent(
|
||||
'Choisissez un type',
|
||||
)
|
||||
expect(doc().references).toHaveLength(3)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,489 @@
|
||||
/** R2.3: search, sort, count, no-result notice, A1, the add flow, the pin and the reset. */
|
||||
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 { targetOfKey } from '@/editor/navigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
baseText,
|
||||
openReady,
|
||||
resetStore,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
const name = (n: string) => ({ fr: n, en: n })
|
||||
const ref = (id: string, citation: string, type: ReferenceType) =>
|
||||
({
|
||||
kind: 'reference',
|
||||
value: { id, type, citation, url: null, doi: null },
|
||||
}) as const
|
||||
|
||||
/** Stored order r1..r5; counts r2: 2, r1: 1, r5: 1, r3: 0, r4: 0. */
|
||||
function sortText(): string {
|
||||
let text = baseText()
|
||||
text = insert(text, ref('r1', 'Zèbre 10', 'web'))
|
||||
text = insert(text, ref('r2', 'zebre 9', 'journal'))
|
||||
text = insert(text, ref('r3', 'Étude', 'book'))
|
||||
text = insert(text, ref('r4', 'etude', 'book'))
|
||||
text = insert(text, ref('r5', 'Alpha', 'legal'))
|
||||
text = insert(text, {
|
||||
kind: 'zone',
|
||||
value: { id: 'zone-a', name: name('Zone A'), categories: [] },
|
||||
})
|
||||
text = edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
id: 'fcat-a',
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat A'),
|
||||
description: {},
|
||||
reference_ids: ['r1', 'r2', 'r5'],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
return edit(text, {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
kind: 'finding_node',
|
||||
value: {
|
||||
id: 'fnode-a',
|
||||
name: name('Node A'),
|
||||
description: {},
|
||||
requires_vet_referral: false,
|
||||
reference_ids: ['r2'],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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} />
|
||||
)
|
||||
async function mount(readOnly = false) {
|
||||
await openReady({ text: sortText() })
|
||||
const user = userEvent.setup()
|
||||
const view = render(lib(readOnly))
|
||||
return { user, view }
|
||||
}
|
||||
|
||||
const search = () =>
|
||||
screen.getByRole('searchbox', { name: 'Rechercher une référence' })
|
||||
const sortBox = () => screen.getByLabelText('Trier par')
|
||||
/** The ids shown, in display order (header ids `tab-reference-<position>-<id>-header`). */
|
||||
const order = () =>
|
||||
[...document.querySelectorAll('button[id$="-header"]')].map((button) =>
|
||||
button.id.replace(/^tab-reference-\d+-(.*)-header$/, '$1'),
|
||||
)
|
||||
const header = (id: string) =>
|
||||
document.querySelector<HTMLElement>(`button[id$="-${id}-header"]`)!
|
||||
const snapshot = () => ({
|
||||
text: store.getState().documentText,
|
||||
history: store.getState().undo.length,
|
||||
unsaved: store.getState().unsaved,
|
||||
})
|
||||
|
||||
describe('the four sorts', () => {
|
||||
it('reorder the tiles for display, each stable on ties', async () => {
|
||||
const { user } = await mount()
|
||||
expect(order()).toEqual(['r1', 'r2', 'r3', 'r4', 'r5'])
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
expect(order()).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
|
||||
await user.selectOptions(sortBox(), 'count')
|
||||
expect(order()).toEqual(['r2', 'r1', 'r5', 'r3', 'r4'])
|
||||
await user.selectOptions(sortBox(), 'type')
|
||||
expect(order()).toEqual(['r3', 'r4', 'r2', 'r5', 'r1'])
|
||||
await user.selectOptions(sortBox(), 'sheet')
|
||||
expect(order()).toEqual(['r1', 'r2', 'r3', 'r4', 'r5'])
|
||||
})
|
||||
|
||||
it('offers the four labelled options', async () => {
|
||||
await mount()
|
||||
const labels = within(sortBox())
|
||||
.getAllByRole('option')
|
||||
.map((option) => option.textContent)
|
||||
expect(labels).toEqual([
|
||||
'Ordre de la fiche',
|
||||
'Citation (A → Z)',
|
||||
'Nombre de citations',
|
||||
'Type',
|
||||
])
|
||||
})
|
||||
|
||||
it('keep the document, its stored order and the history untouched (BDR-114)', async () => {
|
||||
const { user } = await mount()
|
||||
const before = snapshot()
|
||||
for (const sort of ['citation', 'count', 'type', 'sheet']) {
|
||||
await user.selectOptions(sortBox(), sort)
|
||||
}
|
||||
await user.type(search(), 'zebre')
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'zzz')
|
||||
await user.click(
|
||||
screen.getAllByRole('button', { name: 'Effacer la recherche' })[0],
|
||||
)
|
||||
expect(snapshot()).toEqual(before)
|
||||
expect(doc().references.map((r: { id: string }) => r.id)).toEqual([
|
||||
'r1',
|
||||
'r2',
|
||||
'r3',
|
||||
'r4',
|
||||
'r5',
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('the count line', () => {
|
||||
it('says « {n} références », then « {n} références sur {total} »', async () => {
|
||||
const { user } = await mount()
|
||||
expect(screen.getByText('5 références')).toBeInTheDocument()
|
||||
await user.type(search(), 'zebre')
|
||||
expect(screen.getByText('2 références sur 5')).toBeInTheDocument()
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'alpha')
|
||||
expect(screen.getByText('1 référence sur 5')).toBeInTheDocument()
|
||||
await user.clear(search())
|
||||
await user.type(search(), 'zzz')
|
||||
expect(screen.getByText('0 référence sur 5')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('the count with a pinned tile', () => {
|
||||
it('counts the matches only, the pinned tile stays shown', async () => {
|
||||
const { user } = await mount()
|
||||
await startEdit(user, 'r1')
|
||||
await user.type(search(), 'alpha')
|
||||
expect(order()).toEqual(['r1', 'r5'])
|
||||
expect(screen.getByText('1 référence sur 5')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearing the search', () => {
|
||||
it('the button appears with a query, empties it and refocuses the field', async () => {
|
||||
const { user } = await mount()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Effacer la recherche' }),
|
||||
).toBeNull()
|
||||
await user.type(search(), 'etude')
|
||||
expect(order()).toEqual(['r3', 'r4'])
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Effacer la recherche' }),
|
||||
)
|
||||
expect(search()).toHaveValue('')
|
||||
expect(document.activeElement).toBe(search())
|
||||
expect(order()).toHaveLength(5)
|
||||
})
|
||||
|
||||
it('Escape empties a non-empty search and stops there (P12)', async () => {
|
||||
const { user } = await mount()
|
||||
const bubbled = vi.fn()
|
||||
document.body.addEventListener('keydown', bubbled)
|
||||
await user.type(search(), 'etude')
|
||||
await user.keyboard('{Escape}')
|
||||
expect(search()).toHaveValue('')
|
||||
expect(bubbled.mock.calls.at(-1)?.[0].defaultPrevented).toBe(true)
|
||||
bubbled.mockClear()
|
||||
await user.keyboard('{Escape}')
|
||||
expect(bubbled).toHaveBeenCalledTimes(1)
|
||||
expect(bubbled.mock.calls[0][0].defaultPrevented).toBe(false)
|
||||
document.body.removeEventListener('keydown', bubbled)
|
||||
})
|
||||
})
|
||||
|
||||
describe('no result (board 24 B)', () => {
|
||||
it('shows the notice with its own clear button, and no reorder hint', async () => {
|
||||
const { user } = await mount()
|
||||
await user.type(search(), 'radiographie')
|
||||
expect(order()).toEqual([])
|
||||
const notice = screen.getByRole('status', {
|
||||
name: '',
|
||||
})
|
||||
expect(notice).toHaveTextContent(
|
||||
"Aucune référence ne contient « radiographie ». La recherche porte sur la citation, le DOI et l'URL.",
|
||||
)
|
||||
expect(screen.queryByText(/Pour réorganiser/)).toBeNull()
|
||||
await user.click(
|
||||
within(notice).getByRole('button', { name: 'Effacer la recherche' }),
|
||||
)
|
||||
expect(search()).toHaveValue('')
|
||||
expect(document.activeElement).toBe(search())
|
||||
expect(order()).toHaveLength(5)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the move buttons (A1)', () => {
|
||||
const movers = () => screen.queryAllByRole('button', { name: 'Descendre' })
|
||||
const hint = () => screen.queryByText(/Pour réorganiser, affichez/)
|
||||
const openAll = async (user: User) => {
|
||||
for (const button of document.querySelectorAll<HTMLElement>(
|
||||
'button[id$="-header"]',
|
||||
)) {
|
||||
await user.click(button)
|
||||
}
|
||||
}
|
||||
|
||||
it('exist only in sheet order without a search', async () => {
|
||||
const { user } = await mount()
|
||||
await openAll(user)
|
||||
expect(movers()).toHaveLength(5)
|
||||
expect(hint()).toBeNull()
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
expect(movers()).toHaveLength(0)
|
||||
expect(hint()).not.toBeNull()
|
||||
await user.selectOptions(sortBox(), 'sheet')
|
||||
expect(movers()).toHaveLength(5)
|
||||
await user.type(search(), 'e')
|
||||
expect(movers()).toHaveLength(0)
|
||||
expect(hint()).not.toBeNull()
|
||||
await user.selectOptions(sortBox(), 'type')
|
||||
expect(movers()).toHaveLength(0)
|
||||
await user.clear(search())
|
||||
expect(movers()).toHaveLength(0)
|
||||
expect(hint()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('are absent in read-only, and so is the hint', async () => {
|
||||
const { user } = await mount(true)
|
||||
await openAll(user)
|
||||
await user.selectOptions(sortBox(), 'count')
|
||||
expect(movers()).toHaveLength(0)
|
||||
expect(hint()).toBeNull()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Ajouter une référence' }),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
/** Opens the tile of `id` and enters edit. */
|
||||
async function startEdit(user: User, id: string) {
|
||||
await user.click(header(id))
|
||||
const item = header(id).closest('li')!
|
||||
await user.click(within(item).getByRole('button', { name: 'Modifier' }))
|
||||
return item
|
||||
}
|
||||
|
||||
describe('the tile in edit is pinned (P23)', () => {
|
||||
it('keeps its index when the sort changes', async () => {
|
||||
const { user } = await mount()
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
await startEdit(user, 'r1')
|
||||
expect(order()).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
|
||||
await user.selectOptions(sortBox(), 'count')
|
||||
expect(order()).toEqual(['r2', 'r5', 'r3', 'r4', 'r1'])
|
||||
await user.selectOptions(sortBox(), 'sheet')
|
||||
expect(order()).toEqual(['r1', 'r2', 'r3', 'r4', 'r5'])
|
||||
})
|
||||
|
||||
it('starts in sheet order and holds its place under a later sort', async () => {
|
||||
const { user } = await mount()
|
||||
await startEdit(user, 'r3')
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
expect(order()).toEqual(['r5', 'r4', 'r3', 'r2', 'r1'])
|
||||
})
|
||||
|
||||
it('stays shown under a search that does not match it, until it leaves edit', async () => {
|
||||
const { user } = await mount()
|
||||
const item = await startEdit(user, 'r1')
|
||||
await user.type(search(), 'alpha')
|
||||
expect(order()).toEqual(['r1', 'r5'])
|
||||
expect(within(item).getByLabelText('Citation')).toBeInTheDocument()
|
||||
await user.click(within(item).getByRole('button', { name: 'Terminer' }))
|
||||
expect(order()).toEqual(['r5'])
|
||||
})
|
||||
|
||||
it('is suspended in read-only: the tile renders its read view', async () => {
|
||||
const { user, view } = await mount()
|
||||
await startEdit(user, 'r1')
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
view.rerender(lib(true))
|
||||
expect(screen.queryByLabelText('Citation')).toBeNull()
|
||||
expect(order()).toEqual(['r5', 'r3', 'r4', 'r2', 'r1'])
|
||||
await user.type(search(), 'alpha')
|
||||
expect(order()).toEqual(['r5'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('adding (P24)', () => {
|
||||
const add = () =>
|
||||
screen.getByRole('button', { name: 'Ajouter une référence' })
|
||||
const draftCitation = () =>
|
||||
document.querySelector<HTMLElement>('#tab-reference-new-citation')
|
||||
|
||||
it('resets search and sort, appends a draft tile in edit, citation focused', async () => {
|
||||
const { user } = await mount()
|
||||
await user.selectOptions(sortBox(), 'count')
|
||||
await user.type(search(), 'e')
|
||||
await user.click(add())
|
||||
expect(search()).toHaveValue('')
|
||||
expect(sortBox()).toHaveValue('sheet')
|
||||
expect(order()).toHaveLength(5)
|
||||
expect(document.activeElement).toBe(draftCitation())
|
||||
expect(screen.getByLabelText('Type')).toHaveValue('')
|
||||
expect(
|
||||
within(screen.getByLabelText('Type')).getByText('Choisir…'),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText('Type et citation obligatoires.'),
|
||||
).toBeInTheDocument()
|
||||
expect(snapshot().history).toBe(0)
|
||||
})
|
||||
|
||||
it('creates the reference in one modification; the tile stays open, out of edit, focused', async () => {
|
||||
const { user } = await mount()
|
||||
await user.click(add())
|
||||
await user.selectOptions(screen.getByLabelText('Type'), 'book')
|
||||
await user.type(draftCitation()!, 'Nouvelle source')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
expect(store.getState().undo.length).toBe(1)
|
||||
expect(doc().references).toHaveLength(6)
|
||||
const id = doc().references[5].id
|
||||
expect(order()).toHaveLength(6)
|
||||
expect(header(id)).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(header(id))
|
||||
expect(draftCitation()).toBeNull()
|
||||
expect(
|
||||
within(header(id).closest('li')!).getByRole('button', {
|
||||
name: 'Modifier',
|
||||
}),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('a second click on the button takes the focus back to the citation', async () => {
|
||||
const { user } = await mount()
|
||||
await user.click(add())
|
||||
await user.click(search())
|
||||
await user.click(add())
|
||||
expect(document.activeElement).toBe(draftCitation())
|
||||
expect(
|
||||
document.querySelectorAll('#tab-reference-new-citation'),
|
||||
).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('leaves the tile in edit first: a refused field cancels the add (P22)', async () => {
|
||||
const { user } = await mount()
|
||||
const item = await startEdit(user, 'r1')
|
||||
const url = within(item).getByLabelText('Adresse web (URL)')
|
||||
await user.type(url, 'exemple.org')
|
||||
await user.click(add())
|
||||
expect(draftCitation()).toBeNull()
|
||||
expect(document.activeElement).toBe(url)
|
||||
await user.clear(url)
|
||||
await user.click(add())
|
||||
expect(draftCitation()).not.toBeNull()
|
||||
expect(within(item).queryByLabelText('Citation')).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps the draft hidden in read-only and resumes it when editable again', async () => {
|
||||
const { user, view } = await mount()
|
||||
await user.click(add())
|
||||
await user.type(draftCitation()!, 'En cours')
|
||||
view.rerender(lib(true))
|
||||
expect(draftCitation()).not.toBeVisible()
|
||||
view.rerender(lib(false))
|
||||
expect(draftCitation()).toBeVisible()
|
||||
expect(draftCitation()).toHaveValue('En cours')
|
||||
})
|
||||
})
|
||||
|
||||
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 }))
|
||||
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 }))
|
||||
expect(search()).toHaveValue('')
|
||||
expect(sortBox()).toHaveValue('sheet')
|
||||
expect(order()).toHaveLength(5)
|
||||
expect(header('r2')).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(within(item).getByLabelText('Citation')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Aller à » a reference hidden by the search (P3, P8)', () => {
|
||||
const request = (id: string, serial: number) => ({
|
||||
target: targetOfKey({ kind: 'reference', id }),
|
||||
serial,
|
||||
})
|
||||
|
||||
it('clears the search only, opens the tile, focuses its button, keeps other tiles open', async () => {
|
||||
const { user, view } = await mount()
|
||||
await user.click(header('r2'))
|
||||
await user.selectOptions(sortBox(), 'citation')
|
||||
await user.type(search(), 'alpha')
|
||||
await act(async () =>
|
||||
view.rerender(lib(false, { focus: request('r3', 1) })),
|
||||
)
|
||||
expect(search()).toHaveValue('')
|
||||
expect(sortBox()).toHaveValue('citation')
|
||||
expect(header('r3')).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(header('r2')).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(document.activeElement).toBe(header('r3'))
|
||||
})
|
||||
|
||||
it('keeps a search that does not hide it', async () => {
|
||||
const { user, view } = await mount()
|
||||
await user.type(search(), 'etude')
|
||||
await act(async () =>
|
||||
view.rerender(lib(false, { focus: request('r4', 1) })),
|
||||
)
|
||||
expect(search()).toHaveValue('etude')
|
||||
expect(document.activeElement).toBe(header('r4'))
|
||||
expect(header('r4')).toHaveAttribute('aria-expanded', 'true')
|
||||
})
|
||||
})
|
||||
|
||||
describe('state of a reference that left the document (P23-prime)', () => {
|
||||
it('is dropped: undoing the removal brings the tile back closed and out of edit', async () => {
|
||||
const { user } = await mount()
|
||||
await startEdit(user, 'r4')
|
||||
act(() => {
|
||||
store
|
||||
.getState()
|
||||
.commit({ op: 'remove', key: { kind: 'reference', id: 'r4' } })
|
||||
})
|
||||
expect(order()).toEqual(['r1', 'r2', 'r3', 'r5'])
|
||||
act(() => {
|
||||
store.getState().undoStep()
|
||||
})
|
||||
expect(order()).toContain('r4')
|
||||
expect(header('r4')).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(
|
||||
within(header('r4').closest('li')!).queryByLabelText('Citation'),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -45,6 +45,9 @@ describe('Références', () => {
|
||||
await openReady()
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesTab {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une référence' }),
|
||||
)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user