/** * ObservationCard on the bundled sheet: one findings picker per (finding * zone, side), unresolved findings and zones, zone removal and the vertebra * picker entry point. */ import { describe, it, expect, vi, beforeAll, beforeEach, afterEach, } from 'vitest' import { render, screen, cleanup } from '@testing-library/react' import userEvent from '@testing-library/user-event' import type { Observation } from '@faunosteo/core-wasm/types' import ObservationCard from '@/components/observation/ObservationCard' import { useLocaleStore } from '@/state/localeStore' import { fr } from '@/i18n/fr' import type { SheetIndex } from '@/services/sheetIndex' import { emptyObservation, loadTestSheet } from '../helpers/sheet' let sheet: SheetIndex beforeAll(async () => { sheet = await loadTestSheet() }) beforeEach(() => useLocaleStore.setState({ locale: 'fr' })) afterEach(cleanup) function mount(observation: Observation) { const handlers = { onChange: vi.fn(), onRemoveZone: vi.fn(), onOpenVertebraPicker: vi.fn(), } render( , ) return handlers } const HIP = 'Hanche (coxo-fémorale)' describe('ObservationCard', () => { it('renders one findings picker per (finding zone, side), none for the head trigger', () => { mount({ ...emptyObservation(), zones: [ { annotationId: 'hip', viewId: 'main', side: 'left' }, { annotationId: 'hip', viewId: 'main', side: 'right' }, { annotationId: 'c7-t1', viewId: 'main' }, { annotationId: 'head-trigger', viewId: 'main' }, ], }) const headers = screen .getAllByRole('button', { expanded: false }) .filter((b) => b.getAttribute('aria-controls')?.startsWith('findings-zone-'), ) .map((b) => b.textContent?.replace('▼', '')) expect(headers).toEqual([ `${HIP} (Gauche)`, `${HIP} (Droite)`, 'Charnière C7-T1 (cervico-thoracique)', ]) }) it('lists unresolved findings and removes one without touching the zones', async () => { const user = userEvent.setup() const zones = [{ annotationId: 'c7-t1', viewId: 'main' }] const observation: Observation = { ...emptyObservation(), zones, findings: [ { findingZoneId: 'ssb', path: ['ssb-dysfunctions', 'sutures', 'sphenozygomatic'], labelFrSnapshot: 'Suture sphéno-zygomatique', labelEnSnapshot: 'Sphenozygomatic suture', unresolved: true, }, ], } const { onChange } = mount(observation) expect( screen.getByText(fr['observation.findings_unresolved_label']!), ).toBeInTheDocument() expect(screen.getByText('Suture sphéno-zygomatique')).toBeInTheDocument() await user.click( screen.getByRole('button', { name: `${fr['common.delete']} Suture sphéno-zygomatique`, }), ) expect(onChange).toHaveBeenCalledWith({ ...observation, findings: [] }) expect(onChange.mock.calls[0]![0].zones).toBe(zones) }) it('removes a zone by index', async () => { const user = userEvent.setup() const { onRemoveZone } = mount({ ...emptyObservation(), zones: [ { annotationId: 'c7-t1', viewId: 'main' }, { annotationId: 'hip', viewId: 'main', side: 'left' }, ], }) await user.click( screen.getByRole('button', { name: `${fr['observation.remove_zone']} ${HIP}`, }), ) expect(onRemoveZone).toHaveBeenCalledWith(1) }) it('offers the vertebrae button on spine zones only', async () => { const user = userEvent.setup() const { onOpenVertebraPicker } = mount({ ...emptyObservation(), zones: [ { annotationId: 'c7-t1', viewId: 'main' }, { annotationId: 'cervical', viewId: 'main' }, ], }) const buttons = screen.getAllByText(fr['observation.vertebrae_button']!) expect(buttons).toHaveLength(1) await user.click(buttons[0]!) expect(onOpenVertebraPicker).toHaveBeenCalledWith(1) }) it('shows the snapshot and the unresolved marker for a zone unknown to the sheet', () => { mount({ ...emptyObservation(), zones: [ { annotationId: 'point-gone', viewId: 'main', unresolved: true, labelFrSnapshot: 'Point disparu', labelEnSnapshot: 'Gone point', }, ], }) expect(screen.getByText(/Point disparu/)).toBeInTheDocument() expect( screen.getByText(fr['observation.unresolved_short']!), ).toBeInTheDocument() }) })