import { DOMParser } from '@xmldom/xmldom' import { describe, expect, it } from 'vitest' import { overlayMarkers, renderReviewOverlay } from '../src' import { miniSheet } from './fixtures/mini-sheet' const DRAWING = '' + '' 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('') }) 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}"`, ) }) })