refactor(anatomy): category becomes free-form string, no enum / no auto-trigger

User asked that the app interact with anything carrying data-anno-*
attributes without hardcoding any specific category, id, or name. Future
SVGs may introduce new categories, and the existing SVGs may be updated.

Changes:
- `BoneCategory` is now `type BoneCategory = string`. The closed union
  is gone; the parser accepts any non-empty value. New categories don't
  require code changes.
- `VALID_CATEGORIES` and `isValidCategory()` removed from
  svgConvention.ts. `validateBoneElement()` now only enforces presence
  of `data-anno-id` and `data-anno-category`.
- EditorRoute no longer auto-triggers the vertebra picker when the
  clicked annotation is `zone-colonne`. Any zone is added the same way
  to the active observation regardless of category.
- ObservationCard shows a "Vertèbres…" link on every zone badge (was
  conditional on `category === 'zone-colonne'`). The praticien picks
  vertebrae only when relevant — the UI no longer knows or cares which
  zones are spinal.
- Tests rewritten: removed the `isValidCategory` enum assertions and
  the "rejects unknown category" branch. New test demonstrates that
  parseSvgBones accepts a completely novel category string.

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

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bastien ChanotandClaude Opus 4.7 committed 2026-05-19 04:10:54 +02:00
1 parent cad94a49db
commit 21b678c3d5
5 files changed
+41 -76

No files matched your search

+11 -26
View File
@@ -2,7 +2,6 @@ import { describe, it, expect } from 'vitest'
import {
parseSvgBones,
getBoneIdFromEvent,
isValidCategory,
} from '@/anatomy/svgConvention'
import { SvgConventionError } from '@/anatomy/types'
@@ -20,6 +19,8 @@ const FIXTURE = `
<polygon data-anno-id="zone-cervical" data-anno-name-fr="Vertèbres cervicales"
data-anno-name-en="Cervical Vertebrae" data-anno-category="zone-colonne" />
<polygon data-anno-id="zone-head" data-anno-category="os" data-anno-opens-detail="head" />
<polygon data-anno-id="zone-future" data-anno-name-fr="Catégorie inédite"
data-anno-category="something-new-the-parser-has-never-seen" />
</svg>`
describe('parseSvgBones', () => {
@@ -38,19 +39,19 @@ describe('parseSvgBones', () => {
expect(map.get('zone-head')?.opensDetail).toBe('head')
})
it('records zone-colonne single-element annotations', () => {
const map = parseSvgBones(svgFromString(FIXTURE))
const bone = map.get('zone-cervical')
expect(bone?.category).toBe('zone-colonne')
expect(bone?.els.length).toBe(1)
})
it('allows annotations without data-anno-name-fr/en (trigger-only zones)', () => {
const map = parseSvgBones(svgFromString(FIXTURE))
const trigger = map.get('zone-head')
expect(trigger?.fr).toBe('')
expect(trigger?.en).toBe('')
})
it('accepts any string as data-anno-category (no hardcoded enum)', () => {
const map = parseSvgBones(svgFromString(FIXTURE))
expect(map.get('zone-future')?.category).toBe(
'something-new-the-parser-has-never-seen',
)
})
})
describe('parseSvgBones validation', () => {
@@ -61,30 +62,14 @@ describe('parseSvgBones validation', () => {
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
})
it('throws on unknown category', () => {
it('throws on empty data-anno-id', () => {
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
<circle data-anno-id="x" data-anno-category="bogus" />
<circle data-anno-id="" data-anno-category="anything" />
</svg>`
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
})
})
describe('isValidCategory', () => {
it('accepts documented categories', () => {
expect(isValidCategory('articulations')).toBe(true)
expect(isValidCategory('zone-colonne')).toBe(true)
expect(isValidCategory('cadrans-du-cr-ne')).toBe(true)
expect(isValidCategory('charni-res-vert-brales')).toBe(true)
expect(isValidCategory('os')).toBe(true)
})
it('rejects unknown values', () => {
expect(isValidCategory('nope')).toBe(false)
expect(isValidCategory('articulation')).toBe(false) // old singular form
expect(isValidCategory('spine-zone')).toBe(false) // old name
})
})
describe('getBoneIdFromEvent', () => {
it('returns null when no anno in ancestry', () => {
const div = document.createElement('div')