ObservationSchema now carries a hierarchical Finding (zoneId + path + labelFrSnapshot + labelEnSnapshot + requiresVetReferral?) plus a renamed freeTextFindings list, replacing the flat pathologyIds / freeTextPathologies pair. Snapshot labels keep already-exported reports readable if the catalog is later edited. ReportSchema.version bumped from 1 → 2. PDF import surfaces a distinct, French-language error message on legacy v1 attachments instead of the generic "not an osteo PDF" line, via a new IncompatibleReportVersionError detected before the strict Zod parse runs. Store seed and tests updated for the new shape. The standalone Pathology Zod schema and its test are removed — the new findings tree is the single source of truth for what an observation can carry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
121 lines
3.9 KiB
TypeScript
121 lines
3.9 KiB
TypeScript
import { describe, it, expect, beforeEach } from 'vitest'
|
|
import { useReportStore } from '@/state/reportStore'
|
|
|
|
const draft = {
|
|
date: '2026-05-18',
|
|
practitioner: { name: 'Dr. Dupont' },
|
|
animal: { speciesId: 'equine', name: 'Mistral' },
|
|
owner: { name: 'Jean Martin' },
|
|
observations: [],
|
|
conclusion: '',
|
|
recommendations: '',
|
|
}
|
|
|
|
beforeEach(() => {
|
|
useReportStore.getState().reset()
|
|
})
|
|
|
|
describe('reportStore.initReport', () => {
|
|
it('sets a report with version=2, id, and createdAt', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
const r = useReportStore.getState().report!
|
|
expect(r.version).toBe(2)
|
|
expect(r.id.length).toBeGreaterThan(0)
|
|
expect(r.createdAt).toMatch(/^\d{4}-\d{2}-\d{2}T/)
|
|
expect(r.practitioner.name).toBe('Dr. Dupont')
|
|
})
|
|
|
|
it('seeds a single empty observation when the draft has none', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
const r = useReportStore.getState().report!
|
|
expect(r.observations.length).toBe(1)
|
|
expect(r.observations[0].zones).toEqual([])
|
|
expect(r.observations[0].comment).toBe('')
|
|
})
|
|
|
|
it('resets activeObservationIndex to 0', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
expect(useReportStore.getState().activeObservationIndex).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe('reportStore.reset', () => {
|
|
it('clears the report', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
useReportStore.getState().reset()
|
|
expect(useReportStore.getState().report).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('reportStore.addObservation', () => {
|
|
it('appends an empty observation and sets it active', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
useReportStore.getState().addObservation()
|
|
const s = useReportStore.getState()
|
|
expect(s.report!.observations.length).toBe(2)
|
|
expect(s.activeObservationIndex).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('reportStore.updateObservation', () => {
|
|
it('replaces the observation at the given index', () => {
|
|
useReportStore.getState().initReport(draft)
|
|
useReportStore.getState().addObservation()
|
|
const next = {
|
|
...useReportStore.getState().report!.observations[0],
|
|
comment: 'patate',
|
|
}
|
|
useReportStore.getState().updateObservation(0, next)
|
|
expect(useReportStore.getState().report!.observations[0].comment).toBe('patate')
|
|
})
|
|
})
|
|
|
|
describe('reportStore.removeObservation', () => {
|
|
it('drops the observation at the given index', () => {
|
|
const store = useReportStore.getState()
|
|
store.initReport(draft) // seeds 1
|
|
store.addObservation()
|
|
store.addObservation()
|
|
store.removeObservation(0)
|
|
expect(useReportStore.getState().report!.observations.length).toBe(2)
|
|
})
|
|
|
|
it('clamps activeObservationIndex within bounds', () => {
|
|
const store = useReportStore.getState()
|
|
store.initReport(draft) // seeds 1
|
|
store.addObservation()
|
|
store.addObservation() // total 3
|
|
store.setActiveObservation(2)
|
|
store.removeObservation(2)
|
|
expect(useReportStore.getState().activeObservationIndex).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('reportStore.move up/down', () => {
|
|
it('moveObservationUp swaps with previous', () => {
|
|
const s = useReportStore.getState()
|
|
s.initReport(draft)
|
|
s.addObservation()
|
|
s.addObservation()
|
|
const idA = useReportStore.getState().report!.observations[0].id
|
|
const idB = useReportStore.getState().report!.observations[1].id
|
|
s.moveObservationUp(1)
|
|
const after = useReportStore.getState().report!.observations
|
|
expect(after[0].id).toBe(idB)
|
|
expect(after[1].id).toBe(idA)
|
|
})
|
|
|
|
it('moveObservationDown swaps with next', () => {
|
|
const s = useReportStore.getState()
|
|
s.initReport(draft)
|
|
s.addObservation()
|
|
s.addObservation()
|
|
const idA = useReportStore.getState().report!.observations[0].id
|
|
const idB = useReportStore.getState().report!.observations[1].id
|
|
s.moveObservationDown(0)
|
|
const after = useReportStore.getState().report!.observations
|
|
expect(after[0].id).toBe(idB)
|
|
expect(after[1].id).toBe(idA)
|
|
})
|
|
})
|