feat(editor): findings tree picker + scope disclaimer + PDF render
Replaces the flat PathologyPicker with FindingsTreePicker — breadcrumb navigation, drill into intermediate categories, toggle leaves, optional vet-referral badge, optional description rendering. One picker per zone that has a catalog entry; zones without a tree fall back to the free-text input (renamed FreeTextFindingInput to match the new vocabulary). EditorRoute now loads SpeciesFindings instead of a Pathology[] and shows the scope_disclaimer once per session via a sessionStorage flag so the practitioner is reminded of the legal perimeter the first time. PDF observationPage renders findings via the snapshotted FR label and prefixes ⚠ on vet-referral items, keeping the existing layout pipeline intact (LRN-007/008/009 still apply). Also drops the unused Toast and ZoneTooltip stubs, refreshes the CLAUDE.md folder map, and adds a FindingsTreePicker test covering navigation, leaf toggle, vet-referral flag, and back-out. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
d08d773d74
commit
b67f4cd82b
12 files changed
+473
-186
No files matched your search
@@ -0,0 +1,137 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import FindingsTreePicker from '@/components/observation/FindingsTreePicker'
|
||||
import type { ZoneFindings } from '@/domain/schema/findings'
|
||||
import type { Finding } from '@/domain/schema/observation'
|
||||
|
||||
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', () => {
|
||||
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}
|
||||
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([
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['dysfunctions', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
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>()
|
||||
const selected: Finding[] = [
|
||||
{
|
||||
zoneId: 'sphenoid',
|
||||
path: ['dysfunctions', 'flexion'],
|
||||
labelFrSnapshot: 'Flexion',
|
||||
labelEnSnapshot: 'Flexion',
|
||||
},
|
||||
]
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={selected}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Ouvrir Dysfonctions'))
|
||||
await userEvent.click(screen.getByLabelText('Flexion'))
|
||||
expect(onChange).toHaveBeenCalledWith([])
|
||||
})
|
||||
|
||||
it('navigates back to parent via the Retour button', async () => {
|
||||
render(
|
||||
<FindingsTreePicker
|
||||
zoneId="sphenoid"
|
||||
tree={TREE}
|
||||
selected={[]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -1,57 +0,0 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import PathologyPicker from '@/components/observation/PathologyPicker'
|
||||
import type { Pathology } from '@/domain/schema/pathology'
|
||||
|
||||
const POOL: Pathology[] = [
|
||||
{
|
||||
id: 'a',
|
||||
labelFr: 'Aïe',
|
||||
description: '',
|
||||
category: 'osseux',
|
||||
speciesIds: ['equine'],
|
||||
boneIds: ['epaule'],
|
||||
sources: [{ type: 'manual', citation: 'X' }],
|
||||
},
|
||||
{
|
||||
id: 'b',
|
||||
labelFr: 'Aïe-aïe',
|
||||
description: '',
|
||||
category: 'osseux',
|
||||
speciesIds: ['equine'],
|
||||
boneIds: ['hanche'],
|
||||
sources: [{ type: 'manual', citation: 'X' }],
|
||||
},
|
||||
]
|
||||
|
||||
describe('PathologyPicker', () => {
|
||||
it('shows only pathologies matching zones', () => {
|
||||
render(
|
||||
<PathologyPicker
|
||||
pool={POOL}
|
||||
speciesId="equine"
|
||||
boneIds={['epaule']}
|
||||
selected={[]}
|
||||
onChange={() => {}}
|
||||
/>,
|
||||
)
|
||||
expect(screen.getByLabelText('Aïe')).toBeInTheDocument()
|
||||
expect(screen.queryByLabelText('Aïe-aïe')).toBeNull()
|
||||
})
|
||||
|
||||
it('toggles selection', async () => {
|
||||
const onChange = vi.fn()
|
||||
render(
|
||||
<PathologyPicker
|
||||
pool={POOL}
|
||||
speciesId="equine"
|
||||
boneIds={['epaule']}
|
||||
selected={[]}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
)
|
||||
await userEvent.click(screen.getByLabelText('Aïe'))
|
||||
expect(onChange).toHaveBeenCalledWith(['a'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user