feat(app): export and import through @faunosteo/pdf — snapshot, archived branding and labels, browser rasterizer, imported archive kept in session, explicit rebase with messages; legacy PDF modules removed
This commit is contained in:
1 parent
20dafc0b00
commit
9bd5173a9c
43 files changed
+1492
-1989
No files matched your search
@@ -1,15 +1,18 @@
|
||||
/**
|
||||
* Step 6 Phase 0 freeze (STEP6_PDF_ARCHIVE_ANALYSIS.md §17): the current PDF
|
||||
* pipeline recorded as goldens, per report × locale × logo mode. Generated
|
||||
* once with `MAKE_GOLDEN=1`; without the flag the same file asserts them.
|
||||
* Never regenerate without a user decision: the Step 6 engine must
|
||||
* reproduce these files.
|
||||
* Step 6 Phase 0 freeze (STEP6_PDF_ARCHIVE_ANALYSIS.md §17) replayed on the
|
||||
* application export path: `exportReportToPdf` now runs the engine with the
|
||||
* bundled sheet snapshotted, the branding fetched from `public/` and the
|
||||
* browser rasterizer (mocked to fixed PNGs, as the Phase 0 stub was). Text,
|
||||
* images and links goldens are asserted as frozen; `MAKE_GOLDEN=1` rewrites
|
||||
* them, never without a user decision. Never regenerate `report-v3.bare.pdf`:
|
||||
* it is the Step 5 bare export, an import fixture only.
|
||||
*/
|
||||
import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest'
|
||||
import { PDFDocument } from 'pdf-lib'
|
||||
import { readFileSync, writeFileSync } from 'node:fs'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import {
|
||||
buildSheetSnapshot,
|
||||
readReportDocument,
|
||||
ReportSchema,
|
||||
type Report,
|
||||
@@ -28,33 +31,22 @@ import {
|
||||
checkGolden,
|
||||
FIXTURES_DIR,
|
||||
installLogoFetch,
|
||||
MAKE_GOLDEN,
|
||||
ONE_PX_PNG,
|
||||
readGolden,
|
||||
readLinks,
|
||||
recordDrawing,
|
||||
snapshotViews,
|
||||
TWO_BY_ONE_PNG,
|
||||
type ImageEntry,
|
||||
type LinkEntry,
|
||||
type LogoMode,
|
||||
type TextEntry,
|
||||
type ViewSnapshot,
|
||||
} from '../helpers/goldens'
|
||||
|
||||
/** 1×1 PNG (nologos: the legacy stub) and 2×1 PNG (logos: deterministic partner logo width). */
|
||||
const ONE_PX_PNG = Uint8Array.from(
|
||||
Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==',
|
||||
'base64',
|
||||
),
|
||||
)
|
||||
const TWO_BY_ONE_PNG = Uint8Array.from(
|
||||
Buffer.from(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAIAAAB7QOjdAAAAD0lEQVR4nGPYEWX///9/AA0PBE/1T7nxAAAAAElFTkSuQmCC',
|
||||
'base64',
|
||||
),
|
||||
)
|
||||
|
||||
const raster = vi.hoisted(() => ({ png: new Uint8Array() }))
|
||||
vi.mock('@/pdf/render/svgToPng', () => ({
|
||||
rasterizeSvg: vi.fn(async () => raster.png),
|
||||
vi.mock('@/pdf/browserRasterizer', () => ({
|
||||
browserRasterizer: vi.fn(async () => raster.png),
|
||||
}))
|
||||
|
||||
const REPORTS = ['v2full', 'demo', 'v2unresolved'] as const
|
||||
@@ -184,20 +176,39 @@ describe.each(REPORTS)('goldens of %s', (name) => {
|
||||
}, 30_000)
|
||||
})
|
||||
|
||||
it('highlighted views', () => {
|
||||
checkGolden(`views.${name}.json`, snapshotViews(sheet, reports[name]))
|
||||
// Hidden markers are absent in the engine (the browser hid them with
|
||||
// display="none") and the layer <g> carries no data-* any more: `titles`
|
||||
// shrinks to the highlighted markers plus the asset's own, and
|
||||
// `dataAttributes` drops from 2 to 0. Everything else must match.
|
||||
it('highlighted views: same facts but titles and data attributes', () => {
|
||||
const snapshot = buildSheetSnapshot(sheet.sheet, reports[name])
|
||||
const actual = snapshotViews(snapshot, reports[name])
|
||||
const expected = readGolden<ViewSnapshot[]>(`views.${name}.json`)
|
||||
const comparable = (v: ViewSnapshot) => ({
|
||||
observationId: v.observationId,
|
||||
viewId: v.viewId,
|
||||
viewBox: v.viewBox,
|
||||
halo: v.halo,
|
||||
highlighted: v.highlighted,
|
||||
nonHighlightedVisible: v.nonHighlightedVisible,
|
||||
})
|
||||
expect(actual.map(comparable)).toEqual(expected.map(comparable))
|
||||
for (const view of actual) {
|
||||
expect(view.dataAttributes).toBe(0)
|
||||
expect(view.titles).toBeGreaterThanOrEqual(view.highlighted.length)
|
||||
}
|
||||
for (const view of expected) expect(view.dataAttributes).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('report-v3.bare.pdf', () => {
|
||||
it('is the demo report exported without logos and imports back unchanged', async () => {
|
||||
if (MAKE_GOLDEN) {
|
||||
const { bytes } = await exportWith(reports.demo, 'nologos', 'fr')
|
||||
writeFileSync(BARE_PDF, bytes)
|
||||
}
|
||||
it('is the demo report exported bare by Step 5 and imports with no archive', async () => {
|
||||
const bytes = new Uint8Array(readFileSync(BARE_PDF))
|
||||
const outcome = await importReportFromPdf(bytes, sheet.sheet.migrationMap)
|
||||
expect(outcome.origin).toBe('bare_v3')
|
||||
expect(outcome.migrated).toBe(false)
|
||||
expect(outcome.archive).toBeNull()
|
||||
expect(outcome.snapshotRejected).toBeUndefined()
|
||||
expect(outcome.report).toEqual(reports.demo)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user