test: replacement coverage for the deleted legacy suites (v3 schema rejections, appointment kinds, i18n keys and placeholders, pickLocaleLabel, region mapping, new report route); importer comment

This commit is contained in:
bchanot committed 2026-10-10 12:06:59 +02:00
1 parent 09d8b01a54
commit 06a2e86f3c
5 files changed
+242 -1

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import { describe, it, expect } from 'vitest'
import { fr } from '@/i18n/fr'
import { en } from '@/i18n/en'
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
const REQUIRED = [
'severity.mild',
'severity.moderate',
'severity.severe',
'severity.aria',
'home.import.error_invalid_pdf',
'home.import.error_no_attachment',
'home.import.error_generic',
'pdf.section.zones',
'pdf.section.findings_prefix',
'pdf.section.free_findings',
'pdf.section.severity',
'pdf.section.comment',
'pdf.view.general',
'pdf.view.detail_prefix',
'pdf.empty',
'sheet.status.draft',
'sheet.loading',
'vertebra.range_note',
]
const PLACEHOLDERS: Record<string, string> = {
'home.import.error_incompatible_version': '{version}',
'home.import.migrated': '{count}',
'vertebra.extend_to': '{max}',
}
describe.each([
['fr', fr],
['en', en],
])('i18n keys (%s)', (_name, dict) => {
it.each(REQUIRED)('has %s', (key) => {
expect(dict[key]).toBeTruthy()
})
it.each(Object.entries(PLACEHOLDERS))('%s carries %s', (key, ph) => {
expect(dict[key]).toContain(ph)
})
})
describe('pickLocaleLabel', () => {
it('returns the active locale label', () => {
expect(pickLocaleLabel('f', 'e', 'fr')).toBe('f')
expect(pickLocaleLabel('f', 'e', 'en')).toBe('e')
})
it('falls back to the other language when empty', () => {
expect(pickLocaleLabel('', 'e', 'fr')).toBe('e')
expect(pickLocaleLabel('f', '', 'en')).toBe('f')
})
it('returns the fallback when both are empty', () => {
expect(pickLocaleLabel('', '', 'fr', 'x')).toBe('x')
expect(pickLocaleLabel(undefined, undefined, 'en', 'x')).toBe('x')
})
})
@@ -0,0 +1,40 @@
/** The new-report form on the bundled sheet: species select, submit gate. */
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { cleanup, render, screen, waitFor } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import NewReportRoute from '@/app/routes/NewReportRoute'
import { useLocaleStore } from '@/state/localeStore'
import { fr } from '@/i18n/fr'
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
localStorage.clear()
})
afterEach(cleanup)
function mount() {
return render(
<MemoryRouter initialEntries={['/new']}>
<NewReportRoute />
</MemoryRouter>,
)
}
describe('NewReportRoute', () => {
it('selects equine and names it once the sheet is loaded', async () => {
mount()
const select = screen.getByLabelText(
fr['form.animal.species'],
) as HTMLSelectElement
await waitFor(() => {
expect(select.value).toBe('equine')
expect(select.selectedOptions[0]?.textContent).toBe('Cheval')
})
})
it('disables submit while the names are empty', async () => {
mount()
const button = screen.getByRole('button', { name: fr['new_report.submit'] })
await waitFor(() => expect(button).toBeDisabled())
})
})
@@ -77,6 +77,27 @@ describe('sheet index', () => {
expect(sheet.isSpine('head-trigger')).toBe(false)
})
it('maps spine annotations to their region codes on the main view', () => {
const codes = ['C', 'T', 'L', 'S', 'Cd']
for (const code of codes) {
const a = sheet.spineAnnotation(code, 'main')
expect(a, code).toBeDefined()
expect(a!.vertebral_region_code).toBe(code)
expect(sheet.isSpine(a!.id)).toBe(true)
}
const spineIds = sheet.sheet.document.annotations
.filter((a) => sheet.isSpine(a.id))
.map((a) => a.id)
expect(spineIds).toHaveLength(5)
const carried = sheet.sheet.document.annotations
.filter(isObservable)
.map((a) => a.vertebral_region_code)
.filter((c) => c !== null)
expect(sheet.regions().map((r) => r.code).sort()).toEqual(
[...carried].sort(),
)
})
it('resolves finding paths and reports absent ones', () => {
expect(
sheet.nodeAt('hip', [
+2 -1
View File
@@ -3,7 +3,8 @@ import type { Geometry } from '@faunosteo/domain'
import type { Anomaly } from './types'
/**
* Reads the annotation layer of a legacy SVG (docs/ANATOMY-SVG-CONVENTION.md).
* Reads the annotation layer of a legacy SVG (data-anno-* attributes of the
* historical files under supabase/seed/anatomical-sheets/equine/legacy-sources).
* Each annotation is drawn by one or two elements sharing a data-anno-id
* (hitbox first, visual marker second); the importer keeps one record per
* id, attributes and geometry taken from the first element.
+118
View File
@@ -0,0 +1,118 @@
import { describe, expect, it } from 'vitest'
import {
AnimalSchema,
FindingSchema,
LateralSideSchema,
ObservationSchema,
PractitionerSchema,
ReportSchema,
ReportZoneSchema,
SeveritySchema,
VertebraSchema,
} from '../src'
const finding = {
findingZoneId: 'z',
path: ['a'],
labelFrSnapshot: 'a',
labelEnSnapshot: 'a',
}
const observation = {
id: 'o1',
zones: [],
findings: [],
freeTextFindings: [],
comment: '',
}
const report = {
version: 3,
id: 'r1',
createdAt: '2026-10-01T00:00:00Z',
date: '2026-10-01',
practitioner: { name: 'P' },
animal: { speciesId: 'equine', name: 'A' },
owner: { name: 'O' },
sheet: { sheetId: 's', versionId: null, documentSha256: 'a'.repeat(64) },
observations: [],
conclusion: '',
recommendations: '',
}
describe('report v3 leaf schemas', () => {
it('FindingSchema rejects empty path and empty findingZoneId', () => {
expect(FindingSchema.safeParse(finding).success).toBe(true)
expect(FindingSchema.safeParse({ ...finding, path: [] }).success).toBe(
false,
)
expect(
FindingSchema.safeParse({ ...finding, findingZoneId: '' }).success,
).toBe(false)
})
it('LateralSideSchema rejects both and empty', () => {
expect(LateralSideSchema.safeParse('left').success).toBe(true)
expect(LateralSideSchema.safeParse('both').success).toBe(false)
expect(LateralSideSchema.safeParse('').success).toBe(false)
})
it('VertebraSchema rejects index 0 and non-integer index', () => {
expect(VertebraSchema.safeParse({ region: 'C', index: 1 }).success).toBe(
true,
)
expect(VertebraSchema.safeParse({ region: 'C', index: 0 }).success).toBe(
false,
)
expect(VertebraSchema.safeParse({ region: 'C', index: 1.5 }).success).toBe(
false,
)
})
it('ObservationSchema rejects an empty id', () => {
expect(ObservationSchema.safeParse(observation).success).toBe(true)
expect(ObservationSchema.safeParse({ ...observation, id: '' }).success).toBe(
false,
)
})
it('SeveritySchema accepts the three codes only', () => {
for (const c of ['mild', 'moderate', 'severe'])
expect(SeveritySchema.safeParse(c).success).toBe(true)
expect(SeveritySchema.safeParse('légère').success).toBe(false)
expect(SeveritySchema.safeParse('unknown').success).toBe(false)
})
it('ReportZoneSchema rejects an empty annotationId', () => {
const zone = { annotationId: 'a', viewId: 'main' }
expect(ReportZoneSchema.safeParse(zone).success).toBe(true)
expect(
ReportZoneSchema.safeParse({ ...zone, annotationId: '' }).success,
).toBe(false)
})
})
describe('report v3 document and identity', () => {
it('ReportSchema validates nextAppointment variants', () => {
const date = { kind: 'date', date: '2026-11-01' }
const period = { kind: 'period', text: 'dans 3 semaines' }
expect(
ReportSchema.safeParse({ ...report, nextAppointment: date }).success,
).toBe(true)
expect(
ReportSchema.safeParse({ ...report, nextAppointment: period }).success,
).toBe(true)
expect(
ReportSchema.safeParse({ ...report, nextAppointment: { kind: 'other' } })
.success,
).toBe(false)
})
it('PractitionerSchema rejects an empty name', () => {
expect(PractitionerSchema.safeParse({ name: '' }).success).toBe(false)
})
it('AnimalSchema rejects an empty speciesId', () => {
expect(AnimalSchema.safeParse({ speciesId: '', name: 'A' }).success).toBe(
false,
)
})
})