113 lines
3.3 KiB
TypeScript
113 lines
3.3 KiB
TypeScript
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 { useLocaleStore } from '@/state/localeStore'
|
|
import type { SheetIndex } from '@/services/sheetIndex'
|
|
import { loadTestSheet } from '../helpers/sheet'
|
|
|
|
let sheet: SheetIndex
|
|
beforeAll(async () => {
|
|
sheet = await loadTestSheet()
|
|
})
|
|
beforeEach(() => useLocaleStore.setState({ locale: 'fr' }))
|
|
afterEach(cleanup)
|
|
|
|
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
|
|
zone={sheet.findingZone('hip')!}
|
|
side="left"
|
|
selected={[]}
|
|
onChange={onChange}
|
|
/>,
|
|
)
|
|
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([
|
|
{
|
|
findingZoneId: 'hip',
|
|
path: ['hip-dysfunctions', 'articular', 'restriction-flexion'],
|
|
labelFrSnapshot: 'Restriction en flexion',
|
|
labelEnSnapshot: 'Flexion restriction',
|
|
side: 'left',
|
|
},
|
|
])
|
|
})
|
|
|
|
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[] = [
|
|
{
|
|
findingZoneId: 'hip',
|
|
path: ['hip-dysfunctions', 'articular', 'hypermobility'],
|
|
labelFrSnapshot: 'x',
|
|
labelEnSnapshot: 'x',
|
|
requiresVetReferral: true,
|
|
},
|
|
]
|
|
const onChange = vi.fn()
|
|
render(
|
|
<FindingsTreePicker
|
|
zone={sheet.findingZone('hip')!}
|
|
selected={selected}
|
|
onChange={onChange}
|
|
/>,
|
|
)
|
|
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([])
|
|
await user.click(
|
|
screen.getByRole('button', { name: 'Back to previous level' }),
|
|
)
|
|
expect(
|
|
screen.getByRole('button', {
|
|
name: 'Open Articular mobility restrictions',
|
|
}),
|
|
).toBeInTheDocument()
|
|
})
|
|
})
|