From fa3eb51394f5f45a98086ae320818eca73ef48dd Mon Sep 17 00:00:00 2001 From: Bastien Chanot Date: Wed, 20 May 2026 07:12:05 +0200 Subject: [PATCH] test(pdf): cover roundtrip under locale=fr and locale=en MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3 new cases: - exports with locale=fr roundtrips - exports with locale=en roundtrips - both produce non-empty byte streams and the imported JSON payloads match (locale lives outside the Report, so finding labelFr/EnSnapshot are byte-identical between exports — only the static dict labels rendered into the PDF differ, verified manually since pdf-lib font subsets make byte-grep unreliable per LRN-016) 154/154 tests pass. Co-Authored-By: Claude Opus 4.7 --- tests/unit/pdf.roundtrip.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unit/pdf.roundtrip.test.ts b/tests/unit/pdf.roundtrip.test.ts index 8bfbf5d1..ddb79baf 100644 --- a/tests/unit/pdf.roundtrip.test.ts +++ b/tests/unit/pdf.roundtrip.test.ts @@ -32,6 +32,35 @@ describe('PDF roundtrip', () => { expect(imported.version).toBe(2) }) + it('roundtrips a report exported with locale=fr', async () => { + const bytes = await exportReportToPdf(report, { locale: 'fr' }) + const imported = await importReportFromPdf(bytes) + expect(imported.animal.name).toBe('Mistral') + expect(imported.version).toBe(2) + }) + + it('roundtrips a report exported with locale=en', async () => { + const bytes = await exportReportToPdf(report, { locale: 'en' }) + const imported = await importReportFromPdf(bytes) + expect(imported.animal.name).toBe('Mistral') + expect(imported.version).toBe(2) + }) + + it('FR and EN exports both produce non-empty byte streams', async () => { + // pdf-lib subsets fonts (LRN-016), so plain-text grep over the bytes + // is unreliable. The imported JSON is the strongest invariant — the + // locale lives outside the Report, so both imports return the same + // payload while the static label snapshots differ inside the PDF. + const fr = await exportReportToPdf(report, { locale: 'fr' }) + const en = await exportReportToPdf(report, { locale: 'en' }) + expect(fr.byteLength).toBeGreaterThan(0) + expect(en.byteLength).toBeGreaterThan(0) + const frImported = await importReportFromPdf(fr) + const enImported = await importReportFromPdf(en) + expect(frImported.animal.name).toBe(enImported.animal.name) + expect(frImported.version).toBe(enImported.version) + }) + it('rejects a legacy v1 PDF with a version-specific message', async () => { const doc = await PDFDocument.create() doc.addPage()