test(anatomy,app): every legacy catalog leaf (612) and annotation (27) through the v2 to v3 migration against the draft document, the sheet index and a PDF roundtrip
This commit is contained in:
1 parent
e7f4167ada
commit
1e0491f3bc
3 files changed
+436
No files matched your search
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* The 612 legacy leaves through the application itself: migrated with the
|
||||
* bundled sheet's map, resolved by the sheet index the editor and the PDF
|
||||
* use, exported to a v3 PDF and read back without loss.
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll } from 'vitest'
|
||||
import {
|
||||
readReportDocument,
|
||||
type Finding,
|
||||
type Report,
|
||||
} from '@faunosteo/domain'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import { importReportFromPdf } from '@/pdf/import'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { loadTestSheet } from '../helpers/sheet'
|
||||
import {
|
||||
leavesAsV2Report,
|
||||
legacyLeaves,
|
||||
loadLegacyBaseline,
|
||||
} from '../helpers/legacyLeaves'
|
||||
|
||||
const ONE_PX_PNG = Uint8Array.from(
|
||||
Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==',
|
||||
'base64',
|
||||
),
|
||||
)
|
||||
vi.mock('@/pdf/render/svgToPng', () => ({
|
||||
rasterizeSvg: vi.fn(async () => ONE_PX_PNG),
|
||||
}))
|
||||
|
||||
let sheet: SheetIndex
|
||||
let report: Report
|
||||
let findings: Finding[]
|
||||
let unresolvedFindings: number
|
||||
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
const leaves = legacyLeaves(loadLegacyBaseline())
|
||||
const v2 = leavesAsV2Report(leaves)
|
||||
const outcome = readReportDocument(v2, sheet.sheet.migrationMap)
|
||||
report = outcome.report
|
||||
findings = report.observations.flatMap((o) => o.findings)
|
||||
unresolvedFindings = outcome.unresolvedFindings
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
})
|
||||
|
||||
describe('the 612 legacy leaves in the application', () => {
|
||||
it('resolves every migrated leaf to a leaf node of the bundled sheet', () => {
|
||||
expect(findings).toHaveLength(612)
|
||||
expect(unresolvedFindings).toBe(29)
|
||||
for (const f of findings) {
|
||||
const node = sheet.nodeAt(f.findingZoneId, f.path)
|
||||
const where = `${f.findingZoneId}/${f.path.join('/')}`
|
||||
if (f.unresolved) expect(node, where).toBeUndefined()
|
||||
else {
|
||||
expect(node, where).toBeDefined()
|
||||
expect(node!.children, where).toHaveLength(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('keeps every finding, resolved or not, through a v3 PDF export and import', async () => {
|
||||
const bytes = await exportReportToPdf(report, sheet, { locale: 'fr' })
|
||||
const back = await importReportFromPdf(bytes, sheet.sheet.migrationMap)
|
||||
expect(back.migrated).toBe(false)
|
||||
expect(back.report).toEqual(report)
|
||||
const again = back.report.observations.flatMap((o) => o.findings)
|
||||
expect(again.filter((f) => f.unresolved)).toHaveLength(29)
|
||||
}, 30_000)
|
||||
})
|
||||
Reference in new issue
Block a user