feat(anatomy): before/after review drawings per view, questions of every level in the report, tests on the real changeset

This commit is contained in:
bchanot committed 2026-10-10 01:53:10 +02:00
1 parent 6870d87910
commit 1a96a1555c
7 files changed
+348 -10

No files matched your search

@@ -0,0 +1,83 @@
import { DOMParser } from '@xmldom/xmldom'
import { describe, expect, it } from 'vitest'
import { overlayMarkers, renderReviewOverlay } from '../src'
import { miniSheet } from './fixtures/mini-sheet'
const DRAWING =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="10">' +
'<path d="M0 0h10"/></svg>'
function moved() {
const after = miniSheet()
const hip = after.annotations.find((a) => a.id === 'hip')!
hip.geometry = { type: 'circle', cx: 50, cy: 60, r: 3 }
after.annotations.push({
...hip,
id: 'knee',
geometry: {
type: 'polygon',
points: [
[0, 0],
[10, 0],
[5, 5],
],
},
})
return after
}
describe('review overlay', () => {
it('marks moved annotations with their previous position', () => {
const markers = overlayMarkers(miniSheet(), moved(), 'main')
const byId = (id: string) => markers.filter((m) => m.id === id)
expect(byId('hip').map((m) => m.status)).toEqual(['moved', 'removed'])
expect(byId('knee').map((m) => m.status)).toEqual(['added'])
expect(markers.every((m) => m.geometry !== null)).toBe(true)
})
it('reports an annotation dropped by the changeset', () => {
const after = miniSheet()
after.annotations = after.annotations.filter((a) => a.id !== 'hip')
const markers = overlayMarkers(miniSheet(), after, 'main')
expect(markers.find((m) => m.id === 'hip')?.status).toBe('removed')
})
it('renders a framed SVG with one group per marker and a legend', () => {
const svg = renderReviewOverlay({
cleanedSvg: DRAWING,
before: miniSheet(),
after: moved(),
viewId: 'main',
})
const root = new DOMParser().parseFromString(
svg,
'image/svg+xml',
).documentElement!
expect(root.getAttribute('width')).toBeNull()
const groups = Array.from(root.getElementsByTagName('g')).filter((g) =>
g.hasAttribute('data-review-id'),
)
expect(groups.map((g) => g.getAttribute('data-review-status'))).toEqual([
'moved',
'removed',
'added',
])
expect(svg).toContain('stroke-dasharray')
expect(svg).toContain('inchangé')
expect(svg).toContain('<path d="M0 0h10"/>')
})
it('frames a detail view on its view box', () => {
const after = moved()
const svg = renderReviewOverlay({
cleanedSvg: DRAWING,
before: miniSheet(),
after,
viewId: after.views[1]!.id,
})
const box = after.views[1]!.view_box!
expect(svg).toContain(
`viewBox="${box.min_x} ${box.min_y} ${box.width} ${box.height}"`,
)
})
})
@@ -46,9 +46,7 @@ describe('equine working draft (real sources + committed curation)', () => {
expect(draft.sheetId).toBe(result.sheetId)
})
it('keeps the catalog volumes and carries one drawing', () => {
expect(draft.statsAfter.nodes).toBe(draft.statsBefore.nodes)
expect(draft.statsAfter.leaves).toBe(draft.statsBefore.leaves)
it('carries one drawing and the curated content', () => {
expect(draft.statsBefore.assets).toBe(2)
expect(draft.statsAfter.assets).toBe(1)
expect(draft.assets).toHaveLength(1)
@@ -62,13 +60,22 @@ describe('equine working draft (real sources + committed curation)', () => {
(r) => r.code === 'Cd',
)
expect(cd!.count_range).toEqual({ min: 15, max: 21 })
// Carpus zone added, linked from its annotation (CHG carpus_zone).
const carpus = draft.document.annotations.find((a) => a.id === 'carpus')
expect(carpus).toMatchObject({ finding_zone_id: 'carpus', kind: 'point' })
expect(draft.document.finding_zones.some((z) => z.id === 'carpus')).toBe(
true,
)
// Node volume: 792 legacy − SSB duplicates − absent sutures + carpus & flags.
expect(draft.statsAfter.nodes).toBe(811)
expect(draft.statsAfter.descriptionsFrOnly).toBe(0)
})
it('lists CHG-000 and CHG-001 in the CHANGELOG', () => {
it('lists CHG-000 and the Cd range change in the CHANGELOG', () => {
const changelog = artifacts['CHANGELOG.md']!
expect(changelog).toContain('## Comparaison quantitative')
expect(changelog).toMatch(/\| `CHG-000` .*`view:head\.view_box`/)
expect(changelog).toMatch(/\| `CHG-001` .*`region:Cd\.count_range`/)
expect(changelog).toMatch(/\| `CHG-\d{3}` .*`region:Cd\.count_range`/)
})
it('writes the ten review sections in order', () => {
+12 -4
View File
@@ -27,11 +27,19 @@ const CHANGE = {
describe('curation schemas', () => {
it('parse the committed curation files', async () => {
const changeset = ChangesetSchema.parse(await committed('changes.json'))
expect(changeset.changes.map((c) => [c.id, c.priority])).toEqual([
['CHG-001', 'medium'],
])
const ids = changeset.changes.map((c) => c.id)
expect(ids[0]).toBe('CHG-001')
expect(ids).toEqual([...ids].sort())
expect(new Set(ids).size).toBe(ids.length)
expect(changeset.changes.every((c) => c.level !== 'C' || c.question)).toBe(
true,
)
const refs = ReferencesFileSchema.parse(await committed('references.json'))
expect(refs.references.map((r) => r.id)).toEqual(['legacy-catalog'])
const refIds = refs.references.map((r) => r.id)
expect(refIds).toContain('legacy-catalog')
expect(new Set(refIds).size).toBe(refIds.length)
const cited = new Set(changeset.changes.flatMap((c) => c.reference_ids))
for (const id of cited) expect(refIds).toContain(id)
})
it.each([