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,298 +1,112 @@
|
||||
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 type { Finding } from '@faunosteo/domain'
|
||||
import FindingsTreePicker from '@/components/observation/FindingsTreePicker'
|
||||
import type { ZoneFindings } from '@/domain/schema/findings'
|
||||
import type { Finding } from '@/domain/schema/observation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { loadTestSheet } from '../helpers/sheet'
|
||||
|
||||
beforeEach(() => {
|
||||
// Navigator-detected default may land on EN in happy-dom; force FR so the
|
||||
// FR-label assertions in this file remain stable regardless of the runner's
|
||||
// navigator.language.
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
let sheet: SheetIndex
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
})
|
||||
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
||||
afterEach(cleanup)
|
||||
|
||||
const TREE: ZoneFindings = {
|
||||
id: 'sphenoid',
|
||||
name_fr: 'Sphénoïde',
|
||||
name_en: 'Sphenoid',
|
||||
categories: [
|
||||
{
|
||||
id: 'dysfunctions',
|
||||
name_fr: 'Dysfonctions',
|
||||
name_en: 'Dysfunctions',
|
||||
children: [
|
||||
{
|
||||
id: 'flexion',
|
||||
name_fr: 'Flexion',
|
||||
name_en: 'Flexion',
|
||||
description_fr: 'Description test',
|
||||
},
|
||||
{
|
||||
id: 'extension',
|
||||
name_fr: 'Extension',
|
||||
name_en: 'Extension',
|
||||
requires_vet_referral: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe('FindingsTreePicker', () => {
|
||||
it('renders the zone name in the initial breadcrumb', () => {
|
||||
describe('FindingsTreePicker on a sheet finding zone', () => {
|
||||
it('drills down the hip zone and selects a leaf as a v3 finding with snapshots and side', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onChange = vi.fn()
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={[]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByText('Sphénoïde')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('drills into a category and shows leaves', async () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={[]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
expect(screen.getByLabelText('Flexion')).toBeInTheDocument()
|
||||
expect(screen.getByLabelText('Extension')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('emits a Finding with snapshot labels on leaf select', async () => {
|
||||
const onChange = vi.fn<(next: Finding[]) => void>()
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
zone={sheet.findingZone('hip')!}
|
||||
side="left"
|
||||
selected={[]}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
await userEvent.click(screen.getByLabelText('Flexion'))
|
||||
expect(onChange).toHaveBeenCalledTimes(1)
|
||||
expect(onChange.mock.calls[0][0]).toEqual([
|
||||
expect(screen.getByText('Hanche (coxo-fémorale)')).toBeInTheDocument()
|
||||
await user.click(
|
||||
screen.getByRole('button', {
|
||||
name: 'Ouvrir Dysfonctions ostéopathiques',
|
||||
}),
|
||||
)
|
||||
await user.click(
|
||||
screen.getByRole('button', {
|
||||
name: 'Ouvrir Restrictions de mobilité articulaire',
|
||||
}),
|
||||
)
|
||||
await user.click(
|
||||
screen.getByRole('checkbox', { name: 'Restriction en flexion' }),
|
||||
)
|
||||
expect(onChange).toHaveBeenCalledWith([
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['dysfunctions', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
findingZoneId: 'hip',
|
||||
path: ['hip-dysfunctions', 'articular', 'restriction-flexion'],
|
||||
labelFrSnapshot: 'Restriction en flexion',
|
||||
labelEnSnapshot: 'Flexion restriction',
|
||||
side: 'left',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('flags vet-referral leaves with requiresVetReferral on selection', async () => {
|
||||
const onChange = vi.fn<(next: Finding[]) => void>()
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={[]}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
await userEvent.click(screen.getByLabelText('Extension'))
|
||||
expect(onChange.mock.calls[0][0][0].requiresVetReferral).toBe(true)
|
||||
})
|
||||
|
||||
it('deselects a previously selected leaf', async () => {
|
||||
const onChange = vi.fn<(next: Finding[]) => void>()
|
||||
it('shows descriptions in the active locale, the vet marker, counts, and unselects', async () => {
|
||||
const user = userEvent.setup()
|
||||
useLocaleStore.setState({ locale: 'en' })
|
||||
const selected: Finding[] = [
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['dysfunctions', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
findingZoneId: 'hip',
|
||||
path: ['hip-dysfunctions', 'articular', 'hypermobility'],
|
||||
labelFrSnapshot: 'x',
|
||||
labelEnSnapshot: 'x',
|
||||
requiresVetReferral: true,
|
||||
},
|
||||
]
|
||||
const onChange = vi.fn()
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
zone={sheet.findingZone('hip')!}
|
||||
selected={selected}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
await userEvent.click(screen.getByLabelText('Flexion'))
|
||||
expect(screen.getByLabelText('1 finding selected')).toBeInTheDocument()
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Open Osteopathic dysfunctions' }),
|
||||
)
|
||||
await user.click(
|
||||
screen.getByRole('button', {
|
||||
name: 'Open Articular mobility restrictions',
|
||||
}),
|
||||
)
|
||||
expect(
|
||||
screen.getByText(/Perceived laxity may indicate a ligament injury/),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getAllByLabelText('Refer to a veterinarian').length,
|
||||
).toBeGreaterThan(0)
|
||||
const box = screen.getByRole('checkbox', {
|
||||
name: 'Hypermobility / perceived laxity',
|
||||
})
|
||||
expect(box).toBeChecked()
|
||||
await user.click(box)
|
||||
expect(onChange).toHaveBeenCalledWith([])
|
||||
})
|
||||
|
||||
it('navigates back to parent via the Retour button', async () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={[]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Back to previous level' }),
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
expect(screen.getByLabelText('Flexion')).toBeInTheDocument()
|
||||
await userEvent.click(screen.getByLabelText('Retour au niveau précédent'))
|
||||
expect(screen.getByLabelText('Ouvrir Dysfonctions')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
const DEEP_TREE: ZoneFindings = {
|
||||
id: 'atm',
|
||||
name_fr: 'ATM',
|
||||
name_en: 'TMJ',
|
||||
categories: [
|
||||
{
|
||||
id: 'dysf',
|
||||
name_fr: 'Dysfonctions ostéopathiques de l\'ATM',
|
||||
name_en: 'Osteopathic dysfunctions of the TMJ',
|
||||
children: [
|
||||
{
|
||||
id: 'tensions',
|
||||
name_fr: 'Tensions des muscles masticateurs',
|
||||
name_en: 'Masticatory muscle tensions',
|
||||
children: [
|
||||
{
|
||||
id: 'temporal',
|
||||
name_fr: 'Tension du temporal',
|
||||
name_en: 'Temporal tension',
|
||||
},
|
||||
{
|
||||
id: 'pterygo',
|
||||
name_fr: 'Tension des ptérygoïdiens',
|
||||
name_en: 'Pterygoid tension',
|
||||
},
|
||||
{
|
||||
id: 'masseter',
|
||||
name_fr: 'Tension des masséters',
|
||||
name_en: 'Masseter tension',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'capsule',
|
||||
name_fr: 'Dysfonction capsulaire',
|
||||
name_en: 'Capsular dysfunction',
|
||||
children: [
|
||||
{ id: 'cap-ant', name_fr: 'Antérieure', name_en: 'Anterior' },
|
||||
{ id: 'cap-post', name_fr: 'Postérieure', name_en: 'Posterior' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
describe('FindingsTreePicker selection counts on intermediate nodes', () => {
|
||||
const selected: Finding[] = [
|
||||
{
|
||||
zoneId: 'atm',
|
||||
path: ['dysf', 'tensions', 'temporal'],
|
||||
labelFrSnapshot: 'Tension du temporal',
|
||||
labelEnSnapshot: 'Temporal tension',
|
||||
},
|
||||
{
|
||||
zoneId: 'atm',
|
||||
path: ['dysf', 'tensions', 'pterygo'],
|
||||
labelFrSnapshot: 'Tension des ptérygoïdiens',
|
||||
labelEnSnapshot: 'Pterygoid tension',
|
||||
},
|
||||
]
|
||||
|
||||
it('shows a count badge of 2 on the top-level category when two descendant leaves are selected', () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="atm"
|
||||
tree={DEEP_TREE}
|
||||
selected={selected}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
// Root view: only the top-level "Dysfonctions..." category is visible.
|
||||
expect(
|
||||
screen.getByLabelText('2 constats sélectionnés'),
|
||||
screen.getByRole('button', {
|
||||
name: 'Open Articular mobility restrictions',
|
||||
}),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows a count badge of 2 on the sub-category one level deeper', async () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="atm"
|
||||
tree={DEEP_TREE}
|
||||
selected={selected}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(
|
||||
screen.getByLabelText('Ouvrir Dysfonctions ostéopathiques de l\'ATM'),
|
||||
)
|
||||
// Now we see "Tensions des muscles masticateurs" (2 leaves selected)
|
||||
// and "Dysfonction capsulaire" (0 leaves selected — no badge).
|
||||
expect(
|
||||
screen.getByLabelText('2 constats sélectionnés'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('does not show a badge for siblings without selected descendants', async () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="atm"
|
||||
tree={DEEP_TREE}
|
||||
selected={selected}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(
|
||||
screen.getByLabelText('Ouvrir Dysfonctions ostéopathiques de l\'ATM'),
|
||||
)
|
||||
// Capsular dysfunction has no selections — the button should not carry a badge label.
|
||||
const capsular = screen.getByLabelText('Ouvrir Dysfonction capsulaire')
|
||||
expect(capsular.textContent ?? '').not.toMatch(/\d/)
|
||||
})
|
||||
|
||||
it('shows a singular badge label for exactly one selection', () => {
|
||||
const oneSelected: Finding[] = [selected[0]]
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="atm"
|
||||
tree={DEEP_TREE}
|
||||
selected={oneSelected}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
expect(
|
||||
screen.getByLabelText('1 constat sélectionné'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('ignores selections from other zones when counting', () => {
|
||||
const cross: Finding[] = [
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['dysf', 'tensions', 'temporal'],
|
||||
labelFrSnapshot: 'Tension du temporal',
|
||||
labelEnSnapshot: 'Temporal tension',
|
||||
},
|
||||
]
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="atm"
|
||||
tree={DEEP_TREE}
|
||||
selected={cross}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
// No badge should appear on the ATM tree — the lone selected finding
|
||||
// belongs to a different zone.
|
||||
expect(
|
||||
screen.queryByLabelText(/constat sélectionné/),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user