Files
faunosteo/packages/anatomy/tests/importer.counts.test.ts
T

104 lines
3.5 KiB
TypeScript

import type { FindingNodeInput } from '@faunosteo/domain'
import { EQUINE_SOURCE_PATHS, type ImportResult } from '../src'
import { legacyAnnoIds, runImport } from './helpers'
let result: ImportResult
beforeAll(async () => {
result = await runImport()
})
describe('equine import volumes', () => {
it('imports 27 annotations, 26 linked to a finding zone', () => {
const annotations = result.document.annotations
expect(annotations).toHaveLength(27)
const linked = annotations.filter(
(a) => a.kind !== 'detail_trigger' && a.finding_zone_id !== null,
)
expect(linked).toHaveLength(26)
})
it('has two views and one trigger opening head from main', () => {
expect(result.document.views.map((v) => v.id)).toEqual(['main', 'head'])
const triggers = result.document.annotations.filter(
(a) => a.kind === 'detail_trigger',
)
expect(triggers).toHaveLength(1)
expect(triggers[0]).toMatchObject({
view_id: 'main',
opens_view_id: 'head',
})
})
it('codes exactly the five zone-colonne polygons with C, T, L, S, Cd', () => {
const coded = result.document.annotations.filter(
(a) => a.kind !== 'detail_trigger' && a.vertebral_region_code !== null,
)
expect(coded).toHaveLength(5)
expect(new Set(coded.map((a) => a.kind))).toEqual(new Set(['zone']))
expect(new Set(coded.map((a) => a.category_id))).toEqual(
new Set(['zone-colonne']),
)
const codes = coded.map((a) =>
a.kind === 'detail_trigger' ? null : a.vertebral_region_code,
)
expect(new Set(codes)).toEqual(new Set(['C', 'T', 'L', 'S', 'Cd']))
})
it('counts 9 bilateral annotations', () => {
const bilateral = result.document.annotations.filter(
(a) => a.laterality === 'bilateral',
)
expect(bilateral).toHaveLength(9)
})
it('writes 792 nodes, 612 leaves, 41 vet referrals in the document', () => {
const counts = { nodes: 0, leaves: 0, vet: 0 }
const walk = (nodes: readonly FindingNodeInput[]): void => {
for (const node of nodes) {
counts.nodes += 1
if (!node.children?.length) counts.leaves += 1
if (node.requires_vet_referral === true) counts.vet += 1
walk(node.children ?? [])
}
}
for (const zone of result.document.finding_zones) {
counts.nodes += zone.categories.length
for (const category of zone.categories) walk(category.children)
}
expect(counts).toEqual({ nodes: 792, leaves: 612, vet: 41 })
})
it('reports the input side from the sources: 27 ids, 26 zones, 792/612/41', () => {
expect(result.document.finding_zones).toHaveLength(26)
expect(result.stats).toMatchObject({
legacyAnnotations: 27,
findingZones: 26,
nodes: 792,
leaves: 612,
vetReferrals: 41,
})
})
it('maps every data-anno-id of both SVGs', async () => {
const ids = [
...(await legacyAnnoIds(EQUINE_SOURCE_PATHS.mainSvg)),
...(await legacyAnnoIds(EQUINE_SOURCE_PATHS.headSvg)),
]
expect(ids).toHaveLength(27)
expect(Object.keys(result.legacyIdMap.annotations).sort()).toEqual(
ids.sort(),
)
})
it('places the nine head annotations in view head', async () => {
const headIds = await legacyAnnoIds(EQUINE_SOURCE_PATHS.headSvg)
const newIds = new Set(
headIds.map((id) => result.legacyIdMap.annotations[id]),
)
const inHead = result.document.annotations.filter((a) => newIds.has(a.id))
expect(inHead).toHaveLength(9)
expect(inHead.every((a) => a.view_id === 'head')).toBe(true)
})
})