Board 23 / 24 / 27 tiles: closed (citation on two lines, type, « Citée
{n} fois » / « Non citée »), open (Type, DOI, URL as safe links, the
citers with « famille » badge and « Aller à »), edit (« Terminer » with a
leave guard re-committing every changed field; a refusal keeps edit
and focuses the field). A cited reference shows the deletion hint, an
uncited one keeps « Supprimer ». Read-only keeps DOI, URL, « Aller à ».
« Terminer » keeps focus in the field on press, so a refusal message
can no longer move the button under the pointer.
Gates: typecheck, lint, test:run (app 1419), build, e2e:ui 251;
e2e:shell 16 specs on db:sandbox (editor-equine never listed): 111
passed / 99 skipped / 3 failed in the new editor-references.spec (two
test bugs, one app bug), fixed and rerun: 5 passed / 4 skipped; full-row
guard: no pre-existing row changed in any table.
## R-24 (removed or rewritten assertions)
| file | old | new |
|---|---|---|
| editor-citations.test.ts | `citationCounts` counts 2/1/0, memoised, empty | `citersOf`: ordered citers (Cat, Node), family flag, trail from zone, key, memoised, empty |
| editor-references-tab.test.tsx | cards say « citée N fois » (ref-a 1, ref-c 0) | « Citée 2 fois » (fixture gains a node citing ref-a), « Citée 1 fois », « Non citée » |
| same | ids `#tab-reference-ref-a-citation` exist when closed | header id `#tab-reference-0-ref-a-header`; field ids only inside an open edit tile |
| same | ↑/↓ on every card | in open tiles only, absent under a search |
| same | Ctrl+Z on an always-visible field | open tile, Modifier, then same assertion on `#tab-reference-0-ref-a-citation` |
| same | « Aller à » focuses the card (`listitem` count 3, focus key) | tile opened (aria-expanded true), header focused, 3 tiles |
| same | add: `getByText('Nouvelle source')` | tile header named « Nouvelle source » |
| same | read-only: no Supprimer / add | same after opening every tile |
| editor-tabs-lists.test.tsx | edit on blur and arrows on always-open cards | open tile, Modifier, blur applies, Terminer, Monter on opened tile |
| same | cited reference deletion refused in a dialog listing citers | REMOVED: no Supprimer on a cited tile (hint asserted, citer listed); uncited delete kept. The dialog's blocked path stays covered by `DeleteDialog`'s own tests |
| same | read-only: no button at all | read-only: facts shown, no Modifier / Supprimer / Citation textbox (header buttons exist now) |
| editor-keep-alive.test.tsx:~330 | tab-click commit of `#tab-reference-ref-1-citation` | opens tile + Modifier first, id `#tab-reference-0-ref-1-citation` |
| editor-keep-alive.test.tsx:~350,367 | `#panel-reference-ref-1-citation` | `#panel-reference-0-ref-1-citation` |
| editor-references-panel.test.tsx | « citée 2 fois / 1 fois » | « Citée 2 fois / 1 fois » |
| same | `#panel-reference-ref-a-citation`; no `#tab-reference-ref-a-citation` | `#panel-reference-0-ref-a-citation`; no `[id^="tab-reference-"]` while the tab tiles are closed |
| same | ids unique, tab and panel field ids present | tab tile opened in edit first; `tab-reference-0-ref-a-citation` and `panel-reference-0-ref-a-citation` unique |
| e2e editor-structures.spec.ts:~88-110 | citation inputs count 3/1/2, « citée 0 fois » x2, « citée 1 fois », move via row buttons | tile headers count, « Non citée » x2, « Citée 1 fois », tile opened before Monter/Supprimer, `tiles.nth(1)` contains the moved text (saved-list assertion unchanged) |
## i18n (fr / en)
Changed (in place, P18): `editor.references.cited_one|other`: « citée {count} fois » -> « Citée {count} fois »; « cited {count} time(s) » -> « Cited {count} time(s) ».
Added: `editor.references.uncited` Non citée / Not cited; `citers_one|other` « Citée {count} fois, par : » / « Cited {count} time(s), by: »; `no_citers` « Aucun constat ni aucune famille ne cite cette référence. » / « No finding or family cites this reference. »; `family` famille / family; `go_to` Aller à / Go to; `edit` Modifier / Edit; `done` Terminer / Done; `edit_title` Modifier la référence / Edit the reference; `url_label` URL / URL; `none_doi` Aucun / None; `none_url` Aucune / None; `new_tab` (nouvel onglet) / (new tab) (sr-only); `delete_hint` (REVUE wording, fr and en).
Removed: none. R10 grep (src, tests, e2e incl. editor-equine) found no reader of the old lowercase wording left.
262 lines
9.6 KiB
TypeScript
262 lines
9.6 KiB
TypeScript
/** Lot F: the Références tab and Vertèbres. */
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { cleanup, render, screen, within } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
|
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
|
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
|
import { useLocaleStore } from '@/state/localeStore'
|
|
import { edit, insert, point } from '../helpers/editorFixtures'
|
|
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(),
|
|
}))
|
|
|
|
const props = { readOnly: false, navigate: vi.fn(), reloadSheet: vi.fn() }
|
|
const doc = (): AnatomicalSheetDocument =>
|
|
JSON.parse(store.getState().documentText)
|
|
|
|
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
|
afterEach(() => {
|
|
cleanup()
|
|
resetStore()
|
|
})
|
|
|
|
const reference = (id: string, citation: string) =>
|
|
({
|
|
kind: 'reference',
|
|
value: { id, type: 'book', citation, url: null, doi: null },
|
|
}) as const
|
|
|
|
describe('Références', () => {
|
|
it('adds a reference only with a type and a citation', async () => {
|
|
await openReady()
|
|
const user = userEvent.setup()
|
|
render(<ReferencesTab {...props} />)
|
|
await user.click(
|
|
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
|
)
|
|
expect(screen.getByRole('alert')).toHaveTextContent('Choisissez un type')
|
|
expect(doc().references).toEqual([])
|
|
await user.selectOptions(screen.getByLabelText('Type'), 'web')
|
|
await user.type(screen.getByLabelText('Citation'), 'Anatomie du cheval')
|
|
await user.click(
|
|
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
|
)
|
|
expect(doc().references).toHaveLength(1)
|
|
expect(doc().references[0]).toMatchObject({
|
|
type: 'web',
|
|
citation: 'Anatomie du cheval',
|
|
url: null,
|
|
doi: null,
|
|
})
|
|
expect(doc().references[0].id).toMatch(/^ref-[a-z2-7]{10}$/)
|
|
})
|
|
|
|
it('edits a field in a tile, applies it on blur, and reorders with the arrows', async () => {
|
|
const text = insert(
|
|
insert(baseText(), reference('ref-a', 'Alpha')),
|
|
reference('ref-b', 'Beta'),
|
|
)
|
|
await openReady({ text })
|
|
const user = userEvent.setup()
|
|
render(<ReferencesTab {...props} />)
|
|
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
|
await user.click(screen.getByRole('button', { name: 'Modifier' }))
|
|
const url = screen.getByLabelText('Adresse web (URL)', {
|
|
selector: '#tab-reference-0-ref-a-url',
|
|
})
|
|
await user.type(url, 'https://example.org')
|
|
await user.tab()
|
|
expect(doc().references[0].url).toBe('https://example.org')
|
|
await user.click(screen.getByRole('button', { name: 'Terminer' }))
|
|
await user.click(screen.getByRole('button', { name: /^Beta/ }))
|
|
await user.click(screen.getAllByRole('button', { name: 'Monter' })[1])
|
|
expect(doc().references.map((r) => r.id)).toEqual(['ref-b', 'ref-a'])
|
|
expect(screen.getAllByRole('button', { name: 'Monter' })[0]).toBeDisabled()
|
|
})
|
|
|
|
it('a cited reference offers no deletion, only the hint; an uncited one is deleted', async () => {
|
|
let text = insert(
|
|
insert(baseText(), reference('ref-a', 'Alpha')),
|
|
reference('ref-b', 'Beta'),
|
|
)
|
|
text = insert(text, {
|
|
kind: 'zone',
|
|
value: { id: 'zone-a', name: { fr: 'Z', en: 'Z' }, categories: [] },
|
|
})
|
|
text = edit(text, {
|
|
op: 'insert',
|
|
parent: { kind: 'zone', id: 'zone-a' },
|
|
element: {
|
|
kind: 'finding_category',
|
|
value: {
|
|
id: 'fcat-a',
|
|
kind: 'dysfunction',
|
|
name: { fr: 'Boiterie', en: 'Lameness' },
|
|
description: {},
|
|
reference_ids: ['ref-a'],
|
|
review_status: 'to_confirm',
|
|
children: [],
|
|
},
|
|
},
|
|
})
|
|
await openReady({ text })
|
|
const user = userEvent.setup()
|
|
render(<ReferencesTab {...props} />)
|
|
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
|
expect(screen.queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
|
expect(screen.getByText(/Pour supprimer cette référence/)).toBeTruthy()
|
|
expect(screen.getByText('Boiterie')).toBeTruthy()
|
|
await user.click(screen.getByRole('button', { name: /^Beta/ }))
|
|
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
|
const asked = await screen.findByRole('dialog')
|
|
await user.click(within(asked).getByRole('button', { name: 'Supprimer' }))
|
|
expect(doc().references.map((r) => r.id)).toEqual(['ref-a'])
|
|
})
|
|
|
|
it('read-only shows the facts and no control that changes the draft', async () => {
|
|
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
|
const user = userEvent.setup()
|
|
render(<ReferencesTab {...props} readOnly />)
|
|
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
|
expect(screen.getByText('Aucun')).toBeTruthy()
|
|
expect(screen.queryByRole('textbox', { name: 'Citation' })).toBeNull()
|
|
expect(screen.queryByRole('button', { name: 'Modifier' })).toBeNull()
|
|
expect(screen.queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
|
})
|
|
})
|
|
|
|
const region = (code: string, count: number) =>
|
|
({
|
|
kind: 'region',
|
|
value: {
|
|
code,
|
|
name: { fr: `R ${code}`, en: `R ${code}` },
|
|
count,
|
|
count_range: null,
|
|
},
|
|
}) as const
|
|
|
|
describe('Vertèbres', () => {
|
|
it('adds a region with a typed code; a bad count or half range never reaches the core', async () => {
|
|
await openReady()
|
|
const user = userEvent.setup()
|
|
render(<RegionsSection {...props} />)
|
|
await user.type(screen.getByLabelText('Code'), 'C')
|
|
await user.type(screen.getByLabelText('Nom (FR)'), 'Cervicales')
|
|
await user.type(screen.getByLabelText('Nom (EN)'), 'Cervical')
|
|
await user.type(screen.getByLabelText('Nombre de vertèbres'), 'sept')
|
|
await user.click(screen.getByRole('button', { name: 'Ajouter la région' }))
|
|
expect(screen.getByRole('alert')).toHaveTextContent('nombre entier')
|
|
await user.clear(screen.getByLabelText('Nombre de vertèbres'))
|
|
await user.type(screen.getByLabelText('Nombre de vertèbres'), '7')
|
|
await user.type(screen.getByLabelText('Plage : minimum'), '6')
|
|
await user.click(screen.getByRole('button', { name: 'Ajouter la région' }))
|
|
expect(screen.getByRole('alert')).toHaveTextContent('les deux bornes')
|
|
expect(doc().vertebral_config.regions).toEqual([])
|
|
await user.type(screen.getByLabelText('Plage : maximum'), '8')
|
|
await user.click(screen.getByRole('button', { name: 'Ajouter la région' }))
|
|
expect(doc().vertebral_config.regions).toEqual([
|
|
{
|
|
code: 'C',
|
|
name: { fr: 'Cervicales', en: 'Cervical' },
|
|
count: 7,
|
|
count_range: { min: 6, max: 8 },
|
|
},
|
|
])
|
|
})
|
|
|
|
it('edits the count, applies and clears a range, reorders', async () => {
|
|
const text = insert(insert(baseText(), region('C', 7)), region('T', 18))
|
|
await openReady({ text })
|
|
const user = userEvent.setup()
|
|
render(<RegionsSection {...props} />)
|
|
const count = screen.getByLabelText('Nombre de vertèbres', {
|
|
selector: '#region-T-count',
|
|
})
|
|
await user.clear(count)
|
|
await user.type(count, '17')
|
|
await user.tab()
|
|
expect(doc().vertebral_config.regions[1].count).toBe(17)
|
|
await user.type(
|
|
screen.getByLabelText('Plage : minimum', {
|
|
selector: '#region-T-range-min',
|
|
}),
|
|
'17',
|
|
)
|
|
await user.type(
|
|
screen.getByLabelText('Plage : maximum', {
|
|
selector: '#region-T-range-max',
|
|
}),
|
|
'19',
|
|
)
|
|
await user.click(
|
|
screen.getAllByRole('button', { name: 'Appliquer la plage' })[1],
|
|
)
|
|
expect(doc().vertebral_config.regions[1].count_range).toEqual({
|
|
min: 17,
|
|
max: 19,
|
|
})
|
|
await user.clear(
|
|
screen.getByLabelText('Plage : minimum', {
|
|
selector: '#region-T-range-min',
|
|
}),
|
|
)
|
|
await user.clear(
|
|
screen.getByLabelText('Plage : maximum', {
|
|
selector: '#region-T-range-max',
|
|
}),
|
|
)
|
|
await user.click(
|
|
screen.getAllByRole('button', { name: 'Appliquer la plage' })[1],
|
|
)
|
|
expect(doc().vertebral_config.regions[1].count_range).toBeNull()
|
|
await user.click(screen.getAllByRole('button', { name: 'Monter' })[1])
|
|
expect(doc().vertebral_config.regions.map((r) => r.code)).toEqual([
|
|
'T',
|
|
'C',
|
|
])
|
|
})
|
|
|
|
it('a region used by an annotation is refused with that annotation listed', async () => {
|
|
const used = point('anno-v', 20, 20, 3)
|
|
const value = {
|
|
...used.value,
|
|
vertebral_region_code: 'C',
|
|
} as typeof used.value
|
|
const text = insert(insert(baseText(), region('C', 7)), {
|
|
kind: 'annotation',
|
|
value,
|
|
})
|
|
await openReady({ text })
|
|
const user = userEvent.setup()
|
|
render(<RegionsSection {...props} />)
|
|
await user.click(screen.getByRole('button', { name: 'Supprimer' }))
|
|
const dialog = await screen.findByRole('dialog')
|
|
expect(
|
|
within(dialog).getByText(/utilise cette région vertébrale/),
|
|
).toBeTruthy()
|
|
expect(doc().vertebral_config.regions).toHaveLength(1)
|
|
})
|
|
|
|
it('read-only has no control', async () => {
|
|
await openReady({ text: insert(baseText(), region('C', 7)) })
|
|
render(<RegionsSection {...props} readOnly />)
|
|
expect(screen.queryByRole('textbox')).toBeNull()
|
|
expect(screen.queryByRole('button')).toBeNull()
|
|
})
|
|
})
|