Files
faunosteo/tests/unit/components.PathologyPicker.test.tsx
T

58 lines
1.4 KiB
TypeScript

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'])
})
})