72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
/**
|
||
* 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'
|
||
|
||
// 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)
|
||
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 an archive PDF export and import', async () => {
|
||
const { pdf: bytes } = await exportReportToPdf(report, sheet, {
|
||
locale: 'fr',
|
||
})
|
||
const back = await importReportFromPdf(bytes, sheet.sheet.migrationMap)
|
||
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)
|
||
})
|