feat(app): application on the canonical sheet — report v3 store with v2 draft migration, bundled SheetProvider (SHEET_BUNDLE), annotation layer rendered from the document, zone interaction service, pickers and cards on the sheet index, PDF v3 export with v2 archive import; legacy registry, matchers, editors and assets removed
This commit is contained in:
1 parent
0a17e390cf
commit
ce2ec26112
114 files changed
+3560
-14637
No files matched your search
@@ -1,104 +1,87 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import {
|
||||
beforeAll,
|
||||
describe,
|
||||
expect,
|
||||
it,
|
||||
vi,
|
||||
afterEach,
|
||||
beforeEach,
|
||||
} from 'vitest'
|
||||
import { cleanup, render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import VertebraPicker from '@/components/observation/VertebraPicker'
|
||||
import { regionFromLabel } from '@/lib/spineZones'
|
||||
import { EQUINE_VERTEBRAL_FORMULA } from '@/domain/species/equine/vertebrae'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { loadTestSheet } from '../helpers/sheet'
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
let sheet: SheetIndex
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
})
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
afterEach(cleanup)
|
||||
|
||||
describe('VertebraPicker', () => {
|
||||
it('renders region tabs based on the formula', () => {
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => {}}
|
||||
onConfirm={() => {}}
|
||||
initial={[]}
|
||||
formula={EQUINE_VERTEBRAL_FORMULA}
|
||||
title="Vertèbres cervicales"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: /Cervicales/ })).toBeInTheDocument()
|
||||
expect(screen.getByRole('tab', { name: /Thoraciques/ })).toBeInTheDocument()
|
||||
})
|
||||
function mount(initialRegion?: string, onConfirm = vi.fn()) {
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => undefined}
|
||||
onConfirm={onConfirm}
|
||||
initial={[{ region: 'C', index: 3 }]}
|
||||
regions={sheet.regions()}
|
||||
title="Vertèbres"
|
||||
initialRegion={initialRegion}
|
||||
/>,
|
||||
)
|
||||
return onConfirm
|
||||
}
|
||||
|
||||
it('toggles a chip and confirms', async () => {
|
||||
const onConfirm = vi.fn()
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => {}}
|
||||
onConfirm={onConfirm}
|
||||
initial={[]}
|
||||
formula={EQUINE_VERTEBRAL_FORMULA}
|
||||
title="Vertèbres thoraciques"
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByRole('tab', { name: /Thoraciques/ }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'T12' }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Valider' }))
|
||||
expect(onConfirm).toHaveBeenCalledWith([{ region: 'T', index: 12 }])
|
||||
})
|
||||
|
||||
it('preselects the tab matching initialRegion', () => {
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => {}}
|
||||
onConfirm={() => {}}
|
||||
initial={[]}
|
||||
formula={EQUINE_VERTEBRAL_FORMULA}
|
||||
title="Vertèbres lombaires"
|
||||
initialRegion="L"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: /Lombaires/ })).toHaveAttribute(
|
||||
describe('VertebraPicker on the sheet regions', () => {
|
||||
it('shows one tab per region of the sheet, named from the document, opening on the asked region', () => {
|
||||
mount('L')
|
||||
const tabs = screen.getAllByRole('tab').map((t) => t.textContent)
|
||||
expect(tabs).toEqual([
|
||||
'Cervicales',
|
||||
'Thoraciques',
|
||||
'Lombaires',
|
||||
'Sacrales',
|
||||
'Caudales',
|
||||
])
|
||||
expect(screen.getByRole('tab', { name: 'Lombaires' })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
)
|
||||
expect(screen.getByText('L6')).toBeInTheDocument()
|
||||
expect(screen.queryByText('L7')).toBeNull()
|
||||
})
|
||||
|
||||
it('opens on initialRegion even when other regions are pre-selected', () => {
|
||||
render(
|
||||
<VertebraPicker
|
||||
open
|
||||
onClose={() => {}}
|
||||
onConfirm={() => {}}
|
||||
initial={[{ region: 'S', index: 2 }]}
|
||||
formula={EQUINE_VERTEBRAL_FORMULA}
|
||||
title="Vertèbres cervicales"
|
||||
initialRegion="C"
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByRole('tab', { name: /Cervicales/ })).toHaveAttribute(
|
||||
'aria-selected',
|
||||
'true',
|
||||
it('shows the usual count and extends to the documented maximum (D6)', async () => {
|
||||
const user = userEvent.setup()
|
||||
mount('Cd')
|
||||
expect(screen.getByText('Cd18')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Cd21')).toBeNull()
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: "Afficher jusqu'à 21" }),
|
||||
)
|
||||
expect(screen.getByText('Cd21')).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByText(/Nombre usuel : 18 ; variation documentée : 15 à 21/),
|
||||
).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('tab', { name: 'Cervicales' }))
|
||||
expect(screen.queryByRole('button', { name: /Afficher jusqu/ })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('regionFromLabel', () => {
|
||||
it('matches FR roots (accent-insensitive)', () => {
|
||||
expect(regionFromLabel('Vertèbres cervicales')).toBe('C')
|
||||
expect(regionFromLabel('Vertèbres thoraciques')).toBe('T')
|
||||
expect(regionFromLabel('Vertèbres lombaires')).toBe('L')
|
||||
expect(regionFromLabel('Vertèbres sacrales')).toBe('S')
|
||||
expect(regionFromLabel('Vertèbres caudales')).toBe('Cd')
|
||||
})
|
||||
|
||||
it('matches EN roots', () => {
|
||||
expect(regionFromLabel('Cervical Vertebrae')).toBe('C')
|
||||
expect(regionFromLabel('Thoracic Vertebrae')).toBe('T')
|
||||
expect(regionFromLabel('Lumbar Vertebrae')).toBe('L')
|
||||
expect(regionFromLabel('Coccygeal Vertebrae')).toBe('Cd')
|
||||
})
|
||||
|
||||
it('returns undefined when no root matches', () => {
|
||||
expect(regionFromLabel('Épaule')).toBeUndefined()
|
||||
expect(regionFromLabel('')).toBeUndefined()
|
||||
it('toggles vertebrae and confirms the selection across regions', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onConfirm = mount('C')
|
||||
await user.click(screen.getByText('C5'))
|
||||
await user.click(screen.getByRole('tab', { name: 'Thoraciques' }))
|
||||
await user.click(screen.getByText('T2'))
|
||||
await user.click(screen.getByRole('button', { name: 'Valider' }))
|
||||
expect(onConfirm).toHaveBeenCalledWith([
|
||||
{ region: 'C', index: 3 },
|
||||
{ region: 'C', index: 5 },
|
||||
{ region: 'T', index: 2 },
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user