Files
faunosteo/apps/app/tests/unit/char.i18nSpecies.test.tsx
T
bchanot 8673475293 chore(workspace): move the app to apps/app under a pnpm workspace (step 2)
144 files moved with git mv (pure renames). Root package.json delegates
dev/typecheck/test:run/lint/build to the packages; Node 24 LTS and
pnpm 10.13.1 pinned (.nvmrc, .node-version, engines, packageManager,
root devDependency, engine-strict). Dockerfile builds @faunosteo/app on
node:24-alpine and copies apps/app/dist; nginx and runtime config
unchanged. CI workflow for Gitea Actions. packages/ reserved (README only).
Docs synced: WORKSPACE.md, CLAUDE.md, README, DEPLOY, CHANGELOG, plan.
271/271 tests, typecheck, lint, build green from the root.
2026-10-08 21:51:13 +02:00

128 lines
5.2 KiB
TypeScript

/**
* Characterisation (Step 1): dictionary keys the runtime builds dynamically
* (severity.<fr value>, vertebra.region.<code>, import error kinds, PDF
* section labels), label fallbacks, the species registry and the
* scaffold script quirks (audit 12 §1).
*/
import { describe, it, expect, beforeEach } from 'vitest'
import { render, screen } from '@testing-library/react'
import { MemoryRouter } from 'react-router-dom'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
import { fr } from '@/i18n/fr'
import { en } from '@/i18n/en'
import { pickLocaleLabel } from '@/i18n/pickLocaleLabel'
import { boneLabel } from '@/anatomy/labels'
import { SeveritySchema, VertebralRegionSchema } from '@/domain/schema/observation'
import { getAllSpecies, getSpecies, speciesLabel } from '@/domain/species/registry'
import { EQUINE_VERTEBRAL_FORMULA } from '@/domain/species/equine/vertebrae'
import NewReportRoute from '@/app/routes/NewReportRoute'
import { useLocaleStore } from '@/state/localeStore'
const HERE = dirname(fileURLToPath(import.meta.url))
describe('dynamic dictionary keys', () => {
it('has a severity.* key for every stored severity value, in both dicts', () => {
for (const s of SeveritySchema.options) {
expect(fr[`severity.${s}`]).toBeTruthy()
expect(en[`severity.${s}`]).toBeTruthy()
}
})
it('has a vertebra.region.* key for every region code', () => {
for (const r of VertebralRegionSchema.options) {
expect(fr[`vertebra.region.${r}`]).toBeTruthy()
expect(en[`vertebra.region.${r}`]).toBeTruthy()
}
})
it('has one message per ImportError kind plus a generic one, with a {version} placeholder', () => {
for (const k of ['invalid_pdf', 'no_attachment', 'incompatible_version', 'generic']) {
expect(fr[`home.import.error_${k}`]).toBeTruthy()
expect(en[`home.import.error_${k}`]).toBeTruthy()
}
expect(fr['home.import.error_incompatible_version']).toContain('{version}')
expect(en['home.import.error_incompatible_version']).toContain('{version}')
})
it('exposes the PDF section and view labels used by the renderer', () => {
for (const k of [
'pdf.section.zones', 'pdf.section.findings_prefix', 'pdf.section.free_findings',
'pdf.section.severity', 'pdf.section.comment', 'pdf.section.conclusion',
'pdf.section.recommendations', 'pdf.section.next_appointment', 'pdf.view.general',
'pdf.view.detail_prefix', 'pdf.empty', 'pdf.title.suffix.bilan', 'pdf.subject',
]) {
expect(fr[k], k).toBeTruthy()
expect(en[k], k).toBeTruthy()
}
expect(fr['pdf.section.findings_prefix']).toBe('CONSTATS — ')
})
it('carries 71 svg_editor.* keys that die with the SVG editor', () => {
expect(Object.keys(fr).filter((k) => k.startsWith('svg_editor.'))).toHaveLength(71)
})
})
describe('label fallbacks', () => {
it('pickLocaleLabel falls back to the other language, then to the fallback', () => {
expect(pickLocaleLabel('FR', 'EN', 'fr')).toBe('FR')
expect(pickLocaleLabel('', 'EN', 'fr')).toBe('EN')
expect(pickLocaleLabel('FR', '', 'en')).toBe('FR')
expect(pickLocaleLabel('', '', 'en', 'id')).toBe('id')
expect(pickLocaleLabel(undefined, undefined, 'fr')).toBe('')
})
it('boneLabel returns the raw fallback for an unknown bone', () => {
expect(boneLabel(undefined, 'fr', 'point-x')).toBe('point-x')
})
})
describe('species registry', () => {
it('registers exactly one species, equine, with the committed manifest values', () => {
expect(getAllSpecies().map((s) => s.id)).toEqual(['equine'])
const eq = getSpecies('equine')!
expect(speciesLabel(eq, 'fr')).toBe('Cheval')
expect(speciesLabel(eq, 'en')).toBe('Horse')
expect(eq.vertebralFormula).toEqual({ C: 7, T: 18, L: 6, S: 5, Cd: 18 })
expect(EQUINE_VERTEBRAL_FORMULA).toEqual(eq.vertebralFormula)
})
it('the catalog loader resolves the same species id as the manifest', async () => {
const m = await getSpecies('equine')!.findings()
expect(m.default.species.id).toBe('equine')
})
it('NewReportRoute defaults the species select to equine', () => {
useLocaleStore.setState({ locale: 'fr' })
render(
<MemoryRouter>
<NewReportRoute />
</MemoryRouter>,
)
const select = screen.getByRole('combobox') as HTMLSelectElement
expect(select.value).toBe('equine')
expect(select.options).toHaveLength(1)
})
})
describe('scaffold script quirks (audit 12 §1, kept as-is, script slated for removal)', () => {
const src = readFileSync(resolve(HERE, '../../scripts/scaffold-species.mjs'), 'utf8')
it("writes schema_version '1.1' while the horse catalog is at '2.0'", () => {
expect(src).toContain("schema_version: '1.1'")
})
it('defaults the vertebral formula to C7 T13 L6 S5 Cd18 (mixed canine/equine)', () => {
expect(src).toMatch(/askPositiveInt\('\s*cervical \(C\)', 7\)/)
expect(src).toMatch(/askPositiveInt\('\s*thoracic \(T\)', 13\)/)
expect(src).toMatch(/askPositiveInt\('\s*lumbar \(L\)', 6\)/)
expect(src).toMatch(/askPositiveInt\('\s*sacral \(S\)', 5\)/)
expect(src).toMatch(/askPositiveInt\('\s*caudal \(Cd\)', 18\)/)
})
})
beforeEach(() => {
useLocaleStore.setState({ locale: 'fr' })
})