U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.
R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
Références clicked -> no « Plus »; below 640 px five others -> Général,
Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
target place/section/key (vertebrae tab -> annotations/regions); consumed
context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
(key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
no_category text « (onglet Général) » -> « (Annotations, section
Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
+ place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
(edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
label « general tab » -> « categories section »; tab Références ->
openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry
Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
259 lines
9.3 KiB
TypeScript
259 lines
9.3 KiB
TypeScript
/** Lot F: Références 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 ReferencesPanel from '@/components/editor/references/ReferencesPanel'
|
|
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(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
|
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 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(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
|
const url = screen.getByLabelText('Adresse web (URL)', {
|
|
selector: '#reference-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.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 is refused with the citing findings listed; 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(<ReferencesPanel {...props} open onClose={vi.fn()} />)
|
|
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[0])
|
|
const refused = await screen.findByRole('dialog')
|
|
expect(within(refused).getByText(/cite cette référence/)).toBeTruthy()
|
|
expect(within(refused).getByText(/Boiterie/)).toBeTruthy()
|
|
await user.click(
|
|
within(refused).getAllByRole('button', { name: 'Fermer' }).at(-1)!,
|
|
)
|
|
await user.click(screen.getAllByRole('button', { name: 'Supprimer' })[1])
|
|
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 citations as text', async () => {
|
|
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
|
render(<ReferencesPanel {...props} open onClose={vi.fn()} readOnly />)
|
|
expect(screen.getByText('Alpha')).toBeTruthy()
|
|
expect(screen.queryByRole('textbox')).toBeNull()
|
|
expect(
|
|
screen.getAllByRole('button').map((b) => b.getAttribute('aria-label')),
|
|
).toEqual(['Fermer les références'])
|
|
})
|
|
})
|
|
|
|
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()
|
|
})
|
|
})
|