✅(e2e) test the pdf export of the impress app
Add a test to check the pdf export of the impress app. It intercept the download of the PDF and read its content. We can assert that the template is correctly rendered, and that the pad text is present as well.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import cs from 'convert-stream';
|
||||
import pdf from 'pdf-parse';
|
||||
|
||||
import { keyCloakSignIn } from './common';
|
||||
|
||||
@@ -42,4 +44,30 @@ test.describe('Pad Editor', () => {
|
||||
const typeCases = ['publish', 'subscribe', 'unsubscribe', 'ping'];
|
||||
expect(typeCases.includes(payload.type)).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it converts the pad to pdf with a template integrated', async ({
|
||||
page,
|
||||
}) => {
|
||||
const downloadPromise = page.waitForEvent('download', (download) => {
|
||||
return download.suggestedFilename().includes('impress-document.pdf');
|
||||
});
|
||||
|
||||
await page.getByText('My mocked pad').first().click();
|
||||
await expect(page.locator('h2').getByText('My mocked pad')).toBeVisible();
|
||||
|
||||
await page.locator('.ProseMirror.bn-editor').click();
|
||||
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
|
||||
|
||||
await page.getByText('Print the pad').first().click();
|
||||
|
||||
const download = await downloadPromise;
|
||||
expect(download.suggestedFilename()).toBe('impress-document.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
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
"devDependencies": {
|
||||
"@playwright/test": "1.42.1",
|
||||
"@types/node": "*",
|
||||
"@types/pdf-parse": "1.1.4",
|
||||
"eslint-config-impress": "*",
|
||||
"typescript": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"convert-stream": "1.0.2",
|
||||
"pdf-parse": "^1.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
},
|
||||
"include": ["**/*.ts"],
|
||||
"include": ["**/*.ts", "**/*.d.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
5
src/frontend/apps/e2e/type/convert-stream.d.ts
vendored
Normal file
5
src/frontend/apps/e2e/type/convert-stream.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
declare module 'convert-stream' {
|
||||
export function toBuffer(
|
||||
readableStream: NodeJS.ReadableStream,
|
||||
): Promise<Buffer>;
|
||||
}
|
||||
Reference in New Issue
Block a user