Files
faunosteo/tests/unit/components.FindingsTreePicker.test.tsx
T
Bastien ChanotandClaude Opus 4.7 b67f4cd82b 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>
2026-05-20 03:49:11 +02:00

138 lines
3.9 KiB
TypeScript

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()
})
})