/** * 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 type { Finding, Report } from '@faunosteo/core-wasm/types' import { exportReportToPdf } from '@/pdf/export' import { importAttachment, importReportFromPdf } from '../helpers/pdfImport' import type { SheetIndex } from '@/services/sheetIndex' import { findingNodeAt, loadTestSheet } from '../helpers/sheet' import { leavesAsV2Report, legacyLeaves, loadLegacyBaseline, } from '../helpers/legacyLeaves' // The factory runs when the engine first loads the adapter: fixed 1×1 PNG. vi.mock('@/pdf/browserRasterizer', async () => { const { ONE_PX_PNG } = await import('../helpers/goldens') return { browserRasterizer: 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) // Read as the application reads an attachment: the core migrates the v2 report. const outcome = importAttachment(v2, sheet).read 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 = findingNodeAt(sheet, f.findingZoneId, f.path) const where = `${f.findingZoneId}/${f.path.join('/')}` expect(sheet.hasNode(f.findingZoneId, f.path), where).toBe(!f.unresolved) 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 an archive PDF export and import', async () => { const { pdf } = await exportReportToPdf(report, sheet, { locale: 'fr' }) const bytes = new Uint8Array(await pdf.arrayBuffer()) const { read: back } = await importReportFromPdf(bytes) expect(back.migrated).toBe(false) expect(back.origin).toBe('envelope_v1') expect(back.archive).not.toBeNull() expect(back.report).toEqual(report) const again = back.report.observations.flatMap((o) => o.findings) expect(again.filter((f) => f.unresolved)).toHaveLength(29) }, 30_000) })