From 201d776d1b71aa399100c4347fe1f8212f2711a2 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 6 Jun 2024 12:12:45 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(frontend)=20doc=20title=20as?= =?UTF-8?q?=20title=20for=20pdf=20export?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our pdf export was named impress-document.pdf, now it is named after the document title. We sanitize the title by removing special characters, replacing spaces with underscores and putting it in lowercase. --- .../apps/e2e/__tests__/app-impress/pad-tools.spec.ts | 9 ++++----- .../src/features/pads/pad-tools/components/ModalPDF.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/frontend/apps/e2e/__tests__/app-impress/pad-tools.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/pad-tools.spec.ts index b529ee31..74e662b5 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/pad-tools.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/pad-tools.spec.ts @@ -14,11 +14,12 @@ test.describe('Pad Tools', () => { page, browserName, }) => { + const [randomPad] = await createPad(page, 'pad-editor', browserName, 1); + const downloadPromise = page.waitForEvent('download', (download) => { - return download.suggestedFilename().includes('impress-document.pdf'); + return download.suggestedFilename().includes(`${randomPad}.pdf`); }); - const [randomPad] = await createPad(page, 'pad-editor', browserName, 1); await expect(page.locator('h2').getByText(randomPad)).toBeVisible(); await page.locator('.ProseMirror.bn-editor').click(); @@ -38,13 +39,11 @@ test.describe('Pad Tools', () => { .click(); const download = await downloadPromise; - expect(download.suggestedFilename()).toBe('impress-document.pdf'); + expect(download.suggestedFilename()).toBe(`${randomPad}.pdf`); const pdfBuffer = await cs.toBuffer(await download.createReadStream()); const pdfText = (await pdf(pdfBuffer)).text; - expect(pdfText).toContain('Monsieur le Premier Ministre'); // This is the template text - expect(pdfText).toContain('La directrice'); // This is the template text expect(pdfText).toContain('Hello World'); // This is the pad text }); diff --git a/src/frontend/apps/impress/src/features/pads/pad-tools/components/ModalPDF.tsx b/src/frontend/apps/impress/src/features/pads/pad-tools/components/ModalPDF.tsx index 09984538..08ea4d3d 100644 --- a/src/frontend/apps/impress/src/features/pads/pad-tools/components/ModalPDF.tsx +++ b/src/frontend/apps/impress/src/features/pads/pad-tools/components/ModalPDF.tsx @@ -57,7 +57,14 @@ export const ModalPDF = ({ onClose, templateOptions, pad }: ModalPDFProps) => { return; } - downloadFile(pdf, 'impress-document.pdf'); + // normalize title + const title = pad.title + .toLowerCase() + .normalize('NFD') + .replace(/[\u0300-\u036f]/g, '') + .replace(/\s/g, '-'); + + downloadFile(pdf, `${title}.pdf`); toast(t('Your pdf was downloaded succesfully'), VariantType.SUCCESS);