fix(pdf): bundle the branding assets into the app (no fetch at export), export returns its warnings and the editor reports missing elements

This commit is contained in:
bchanot committed 2026-10-11 16:09:39 +02:00
1 parent 80e95ca61d
commit 293a6e0b36
22 files changed
+199 -185

No files matched your search

@@ -1,8 +1,8 @@
/**
* Step 6 Phase 0 characterisation of the export flow on the editor route,
* with `exportReportToPdf` mocked: the call shape (store report, loaded
* index, locale), the download name and the failure alert. Phase 4 adapts
* only the mocked module path and the call-shape assertion.
* index, locale), the download name, the failure alert and the alert that
* names what the exported PDF lacks when the engine warned.
*/
import {
describe,
@@ -27,6 +27,7 @@ import { loadTestSheet, minimalReport } from '../helpers/sheet'
vi.mock('@/pdf/export', () => ({ exportReportToPdf: vi.fn() }))
const exportMock = vi.mocked(exportReportToPdf)
const PDF_BYTES = new Uint8Array([37, 80, 68, 70])
let sheet: SheetIndex
const downloads: string[] = []
@@ -74,7 +75,7 @@ async function mountAndExport(label: string): Promise<void> {
describe('EditorRoute export', () => {
it('calls exportReportToPdf with the store report, the loaded index and the FR locale', async () => {
exportMock.mockResolvedValue(new Uint8Array([37, 80, 68, 70]))
exportMock.mockResolvedValue({ pdf: PDF_BYTES, warnings: [] })
await mountAndExport(fr['editor.export']!)
await waitFor(() => expect(exportMock).toHaveBeenCalledTimes(1))
const [report, index, options] = exportMock.mock.calls[0]!
@@ -85,14 +86,14 @@ describe('EditorRoute export', () => {
it('passes the active locale (EN)', async () => {
useLocaleStore.setState({ locale: 'en' })
exportMock.mockResolvedValue(new Uint8Array([37, 80, 68, 70]))
exportMock.mockResolvedValue({ pdf: PDF_BYTES, warnings: [] })
await mountAndExport(en['editor.export']!)
await waitFor(() => expect(exportMock).toHaveBeenCalledTimes(1))
expect(exportMock.mock.calls[0]![2]).toEqual({ locale: 'en' })
})
it('downloads bilan-<animal>-<date>.pdf through a blob URL it then revokes', async () => {
exportMock.mockResolvedValue(new Uint8Array([37, 80, 68, 70]))
exportMock.mockResolvedValue({ pdf: PDF_BYTES, warnings: [] })
await mountAndExport(fr['editor.export']!)
await waitFor(() => expect(downloads).toHaveLength(1))
expect(downloads[0]).toBe('bilan-Mistral-2026-10-10.pdf')
@@ -103,6 +104,22 @@ describe('EditorRoute export', () => {
expect(window.alert).not.toHaveBeenCalled()
})
it('downloads then alerts editor.export_warnings naming the failed logo slots and views', async () => {
exportMock.mockResolvedValue({
pdf: PDF_BYTES,
warnings: [
{ kind: 'logo_failed', slot: 'headerLogo' },
{ kind: 'view_raster_failed', observationId: 'obs-1', viewId: 'head' },
],
})
await mountAndExport(fr['editor.export']!)
await waitFor(() => expect(window.alert).toHaveBeenCalledTimes(1))
expect(downloads).toEqual(['bilan-Mistral-2026-10-10.pdf'])
expect(window.alert).toHaveBeenCalledWith(
'PDF exporté avec des éléments manquants : headerLogo, head. Vérifiez la console du navigateur.',
)
})
it('alerts editor.export_failed when the export rejects', async () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined)
exportMock.mockRejectedValue(new Error('render exploded'))