Files
faunosteo/tests/unit/anatomy.horse.test.ts
Bastien ChanotandClaude Opus 4.7 cad94a49db refactor(anatomy): adapt parser to new SVG convention (categories + single-element)
User dropped new Horse.svg / Horse_head.svg that follow a simpler
convention:

- Categories renamed to longer human strings:
    articulation       → articulations
    charniere          → charni-res-vert-brales
    spine-zone         → zone-colonne
    cadran-crane       → cadrans-du-cr-ne
    head, os-overlay   → dropped (head zone is now category="os" + data-anno-opens-detail)
    os                 → unchanged
- No more hitbox / visible class split; multiple elements may still share
  the same data-anno-id but they all carry the same role.
- Trigger-only zones (`data-anno-opens-detail="head"`) may omit
  `data-anno-name-fr/en`.

Changes:
- `Bone` now exposes a single `els: Element[]` instead of `hitboxEls +
  visibleEls`.
- `parseSvgBones` accepts annotations without fr/en labels (defaults to
  empty string) but still rejects unknown or missing categories.
- The "interactive vs decorative" filter is gone — every parsed
  annotation is interactive, since the new SVGs only annotate the
  clickable zones.
- Vertebra-picker trigger: `bone.category === 'zone-colonne'`
  (EditorRoute + ObservationCard).
- PDF colorisation in `observationPage.colorizedSvgString` writes the
  accent fill to every `els[]` entry (no more hitbox dual-pass).
- Dead `src/components/observation/ObservationEditor.tsx` removed (its
  body lives inside ObservationCard since the accordion refactor).
- Tests rewritten for the new vocabulary; synthetic fixture uses the new
  categories, real-SVG test asserts 18 + 9 unique zones.

92/92 tests pass, lint clean, build clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 04:06:26 +02:00

73 lines
2.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { dirname, resolve } from 'node:path'
import { parseSvgBones } from '@/anatomy/svgConvention'
const HERE = dirname(fileURLToPath(import.meta.url))
const HORSE_PATH = resolve(HERE, '../../public/species/equine/Horse.svg')
const HEAD_PATH = resolve(HERE, '../../public/species/equine/Horse_head.svg')
function loadSvg(path: string): SVGSVGElement {
const raw = readFileSync(path, 'utf8')
const doc = new DOMParser().parseFromString(raw, 'image/svg+xml')
return doc.documentElement as unknown as SVGSVGElement
}
describe('real Horse.svg', () => {
const map = parseSvgBones(loadSvg(HORSE_PATH))
it('parses 18 unique annotations', () => {
expect(map.size).toBe(18)
})
it('contains 5 zone-colonne annotations (cervical / thoracic / lumbar / sacral / caudal)', () => {
const spine = [...map.values()].filter(
(b) => b.category === 'zone-colonne',
)
expect(spine.length).toBe(5)
})
it('contains exactly one opens-detail trigger pointing at the head SVG', () => {
const triggers = [...map.values()].filter((b) => b.opensDetail === 'head')
expect(triggers.length).toBe(1)
})
it('contains 9 articulations', () => {
const arts = [...map.values()].filter(
(b) => b.category === 'articulations',
)
expect(arts.length).toBe(9)
})
it('contains 3 vertebral hinges', () => {
const ch = [...map.values()].filter(
(b) => b.category === 'charni-res-vert-brales',
)
expect(ch.length).toBe(3)
})
})
describe('real Horse_head.svg', () => {
const map = parseSvgBones(loadSvg(HEAD_PATH))
it('parses 9 unique annotations', () => {
expect(map.size).toBe(9)
})
it('contains 5 cadrans-du-cr-ne annotations', () => {
const cadrans = [...map.values()].filter(
(b) => b.category === 'cadrans-du-cr-ne',
)
expect(cadrans.length).toBe(5)
})
it('contains 2 articulations (ATM + SSB equivalents)', () => {
const arts = [...map.values()].filter(
(b) => b.category === 'articulations',
)
expect(arts.length).toBe(2)
})
})