Three coupled bugs in zone interaction: 1. Clicks inside the head detail popup were ignored — EditorRoute looked up the clicked id in the main-SVG bones map only, so detail-only ids (point-mpbykomv et al.) returned undefined. 2. Spine zones did not open VertebraPicker on click; the picker was only reachable via the per-zone "Vertèbres…" button. 3. The new SVG hint data-anno-special="vertebral-precision" was present in Horse.svg but unread by the parser/UI. Parser now reads data-anno-special into Bone.special. EditorRoute parses the detail SVG on open and falls back to detailBones for id lookups. When bone.special === 'vertebral-precision', clicking adds the zone (if absent) and opens VertebraPicker for that zone index; toggle-off via main click is disabled for these zones (use ✕). The "Vertèbres…" button in ObservationCard is now shown only on zones that support it. Convention doc updated. Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import {
|
|
parseSvgBones,
|
|
getBoneIdFromEvent,
|
|
} 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="point-shoulder" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
|
data-anno-category="articulations" />
|
|
<circle data-anno-id="point-shoulder" data-anno-name-fr="Épaule" data-anno-name-en="Shoulder"
|
|
data-anno-category="articulations" />
|
|
<polygon data-anno-id="zone-cervical" data-anno-name-fr="Vertèbres cervicales"
|
|
data-anno-name-en="Cervical Vertebrae" data-anno-category="zone-colonne"
|
|
data-anno-special="vertebral-precision" />
|
|
<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', () => {
|
|
it('groups multiple elements sharing the same data-anno-id', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
const shoulder = map.get('point-shoulder')
|
|
expect(shoulder).toBeDefined()
|
|
expect(shoulder?.fr).toBe('Épaule')
|
|
expect(shoulder?.en).toBe('Shoulder')
|
|
expect(shoulder?.category).toBe('articulations')
|
|
expect(shoulder?.els.length).toBe(2)
|
|
})
|
|
|
|
it('captures opensDetail when present', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
expect(map.get('zone-head')?.opensDetail).toBe('head')
|
|
})
|
|
|
|
it('captures data-anno-special when present', () => {
|
|
const map = parseSvgBones(svgFromString(FIXTURE))
|
|
expect(map.get('zone-cervical')?.special).toBe('vertebral-precision')
|
|
expect(map.get('point-shoulder')?.special).toBeUndefined()
|
|
})
|
|
|
|
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', () => {
|
|
it('throws on missing data-anno-category', () => {
|
|
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-anno-id="x" />
|
|
</svg>`
|
|
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
|
})
|
|
|
|
it('throws on empty data-anno-id', () => {
|
|
const bad = `<svg xmlns="http://www.w3.org/2000/svg">
|
|
<circle data-anno-id="" data-anno-category="anything" />
|
|
</svg>`
|
|
expect(() => parseSvgBones(svgFromString(bad))).toThrow(SvgConventionError)
|
|
})
|
|
})
|
|
|
|
describe('getBoneIdFromEvent', () => {
|
|
it('returns null when no anno in ancestry', () => {
|
|
const div = document.createElement('div')
|
|
const evt = new Event('click')
|
|
Object.defineProperty(evt, 'target', { value: div })
|
|
expect(getBoneIdFromEvent(evt)).toBeNull()
|
|
})
|
|
})
|