User updated the clickable-zone convention in the source SVGs:
data-bone-id → data-anno-id
data-bone-fr → data-anno-name-fr
data-bone-en → data-anno-name-en
data-category → data-anno-category
data-opens-detail → data-anno-opens-detail
Bulk-renamed across:
- public/species/equine/Horse.svg + Horse_head.svg (86 anno-attrs each)
- src/anatomy/svgConvention.ts (parser + getBoneIdFromEvent)
- src/anatomy/types.ts (doc strings)
- src/components/canvas/AnatomyCanvas.tsx (querySelector + delegated click)
- src/styles/index.css (`[data-bone-id]` selectors → `[data-anno-id]`)
- src/domain/species/types.ts + schema/observation.ts (doc strings)
- docs/{ANATOMY-SVG-CONVENTION,ADDING-A-SPECIES,superpowers/specs,plans}.md
- CLAUDE.md + .claude/{memory/learnings,tasks/TODO}.md
- tests/unit/{anatomy.svgConvention,anatomy.svgLoader,components.AnatomyCanvas}.test.tsx
Internal TS type names and field names (Bone, boneId, parseSvgBones,
getBoneIdFromEvent) are kept intentionally — they're the application's
logical shape and the persisted JSON contract. ObservationZone.boneId is
the identifier seen in already-exported PDFs; renaming it would break
re-import of those PDFs. Only the SVG-side attribute names change.
90/90 tests pass, lint clean, build clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
86 lines
3.2 KiB
TypeScript
86 lines
3.2 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
parseSvgBones,
|
|
getBoneIdFromEvent,
|
|
isValidCategory,
|
|
} from '@/anatomy/svgConvention'
|
|
import { SvgConventionError } from '@/anatomy/types'
|
|
|
|
function svgFromString(s: string): SVGSVGElement {
|
|
const doc = new DOMParser().parseFromString(s, 'image/svg+xml')
|
|
return doc.documentElement as unknown as SVGSVGElement
|
|
}
|
|
|
|
const FIXTURE = `
|
|
<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
|
data-anno-category="articulation" class="bone osteo articulation hitbox bone-epaule" />
|
|
<circle data-anno-id="epaule" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
|
data-anno-category="articulation" class="bone osteo articulation visible bone-epaule" />
|
|
<polygon data-anno-id="cervical-vertebrae-spine-zone" data-anno-name-fr="Vertèbres cervicales"
|
|
data-anno-name-en="Cervical Vertebrae" data-anno-category="spine-zone"
|
|
class="bone osteo spine-zone bone-cervical-vertebrae" />
|
|
<polygon data-anno-id="zone-head" data-anno-name-fr="Crane" data-anno-name-en="Head"
|
|
data-anno-category="head" data-anno-opens-detail="head" />
|
|
</svg>`
|
|
|
|
describe('parseSvgBones', () => {
|
|
it('groups hitbox + visible by data-anno-id', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
const epaule = map.get('epaule')
|
|
expect(epaule).toBeDefined()
|
|
expect(epaule?.fr).toBe('Épaule')
|
|
expect(epaule?.category).toBe('articulation')
|
|
expect(epaule?.hitboxEls.length).toBe(1)
|
|
expect(epaule?.visibleEls.length).toBe(1)
|
|
})
|
|
|
|
it('captures opensDetail when present', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
expect(map.get('zone-head')?.opensDetail).toBe('head')
|
|
})
|
|
|
|
it('records spine-zone single-element bones', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
const bone = map.get('cervical-vertebrae-spine-zone')
|
|
expect(bone?.category).toBe('spine-zone')
|
|
})
|
|
})
|
|
|
|
describe('parseSvgBones validation', () => {
|
|
it('throws on missing data-anno-name-fr', () => {
|
|
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-anno-id="x" data-anno-name-en="X" data-anno-category="os" />
|
|
</svg>`
|
|
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
|
})
|
|
|
|
it('throws on unknown category', () => {
|
|
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-anno-id="x" data-anno-name-fr="X" data-anno-name-en="X" data-anno-category="bogus" />
|
|
</svg>`
|
|
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
|
})
|
|
})
|
|
|
|
describe('isValidCategory', () => {
|
|
it('accepts documented categories', () => {
|
|
expect(isValidCategory('articulation')).toBe(true)
|
|
expect(isValidCategory('spine-zone')).toBe(true)
|
|
expect(isValidCategory('cadran-crane')).toBe(true)
|
|
})
|
|
|
|
it('rejects unknown values', () => {
|
|
expect(isValidCategory('nope')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('getBoneIdFromEvent', () => {
|
|
it('returns null when no bone in ancestry', () => {
|
|
const div = document.createElement('div')
|
|
const evt = new Event('click')
|
|
Object.defineProperty(evt, 'target', { value: div })
|
|
expect(getBoneIdFromEvent(evt)).toBeNull()
|
|
})
|
|
})
|