Skip to content

Commit ad16c08

Browse files
committed
✅(test) adapt tests with updated dependencies
- update e2e tests to match changed function signatures - remove unused pdf-parse type definitions - fix type error in hocuspocusWS tests
1 parent 78a6307 commit ad16c08

File tree

8 files changed

+118
-191
lines changed

8 files changed

+118
-191
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-export.spec.ts

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import path from 'path';
22

33
import { expect, test } from '@playwright/test';
44
import cs from 'convert-stream';
5-
import { pdf } from 'pdf-parse';
5+
import { PDFParse } from 'pdf-parse';
66

77
import {
88
TestLanguage,
99
createDoc,
10-
randomName,
1110
verifyDocName,
1211
waitForLanguageSwitch,
1312
} from './utils-common';
@@ -86,11 +85,16 @@ test.describe('Doc Export', () => {
8685
expect(download.suggestedFilename()).toBe(`${randomDoc}.pdf`);
8786

8887
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
89-
const pdfData = await pdf(pdfBuffer);
90-
91-
expect(pdfData.total).toBe(2);
92-
expect(pdfData.text).toContain('Hello\n\nWorld\n\n'); // This is the doc text
93-
expect(pdfData.info?.Title).toBe(randomDoc);
88+
const pdfParse = new PDFParse({ data: pdfBuffer });
89+
const pdfInfo = await pdfParse.getInfo();
90+
const pdfText = await pdfParse.getText();
91+
92+
expect(pdfInfo.total).toBe(2);
93+
expect(pdfText.pages).toStrictEqual([
94+
{ text: 'Hello', num: 1 },
95+
{ text: 'World', num: 2 },
96+
]);
97+
expect(pdfInfo?.info.Title).toBe(randomDoc);
9498
});
9599

96100
test('it exports the doc to docx', async ({ page, browserName }) => {
@@ -219,10 +223,10 @@ test.describe('Doc Export', () => {
219223
expect(download.suggestedFilename()).toBe(`${randomDoc}.pdf`);
220224

221225
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
222-
const pdfExport = await pdf(pdfBuffer);
223-
const pdfText = pdfExport.text;
224226

225-
expect(pdfText).toContain('Hello World');
227+
const pdfParse = new PDFParse({ data: pdfBuffer });
228+
const pdfText = await pdfParse.getText();
229+
expect(pdfText.text).toContain('Hello World');
226230
});
227231

228232
test('it exports the doc with quotes', async ({ page, browserName }) => {
@@ -265,9 +269,9 @@ test.describe('Doc Export', () => {
265269
expect(download.suggestedFilename()).toBe(`${randomDoc}.pdf`);
266270

267271
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
268-
const pdfData = await pdf(pdfBuffer);
269-
270-
expect(pdfData.text).toContain('Hello World'); // This is the pdf text
272+
const pdfParse = new PDFParse({ data: pdfBuffer });
273+
const pdfText = await pdfParse.getText();
274+
expect(pdfText.text).toContain('Hello World');
271275
});
272276

273277
test('it exports the doc with multi columns', async ({
@@ -320,46 +324,33 @@ test.describe('Doc Export', () => {
320324
expect(download.suggestedFilename()).toBe(`${randomDoc}.pdf`);
321325

322326
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
323-
const pdfData = await pdf(pdfBuffer);
324-
expect(pdfData.text).toContain('Column 1');
325-
expect(pdfData.text).toContain('Column 2');
326-
expect(pdfData.text).toContain('Column 3');
327+
const pdfParse = new PDFParse({ data: pdfBuffer });
328+
const pdfText = await pdfParse.getText();
329+
expect(pdfText.text).toContain('Column 1');
330+
expect(pdfText.text).toContain('Column 2');
331+
expect(pdfText.text).toContain('Column 3');
327332
});
328333

329334
test('it injects the correct language attribute into PDF export', async ({
330335
page,
331336
browserName,
332337
}) => {
333-
await waitForLanguageSwitch(page, TestLanguage.French);
334-
335-
// Wait for the page to be ready after language switch
336-
await page.waitForLoadState('domcontentloaded');
337-
338-
const header = page.locator('header').first();
339-
await header.locator('h1').getByText('Docs').click();
340-
341-
const randomDocFrench = randomName(
338+
const [randomDocFrench] = await createDoc(
339+
page,
342340
'doc-language-export-french',
343341
browserName,
344342
1,
345-
)[0];
343+
);
346344

347-
await page
348-
.getByRole('button', {
349-
name: 'Nouveau doc',
350-
})
351-
.click();
345+
await waitForLanguageSwitch(page, TestLanguage.French);
352346

353-
const input = page.getByRole('textbox', { name: 'Titre du document' });
354-
await expect(input).toBeVisible();
355-
await expect(input).toHaveText('', { timeout: 10000 });
356-
await input.click();
357-
await input.fill(randomDocFrench);
358-
await input.blur();
347+
// Wait for the page to be ready after language switch
348+
await page.waitForLoadState('domcontentloaded');
359349

360-
const editor = page.locator('.ProseMirror.bn-editor');
361-
await editor.click();
362-
await editor.fill('Contenu de test pour export en français');
350+
await writeInEditor({
351+
page,
352+
text: 'Contenu de test pour export en français',
353+
});
363354

364355
await page
365356
.getByRole('button', {
@@ -447,8 +438,8 @@ test.describe('Doc Export', () => {
447438
expect(download.suggestedFilename()).toBe(`${docChild}.pdf`);
448439

449440
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
450-
const pdfData = await pdf(pdfBuffer);
451-
452-
expect(pdfData.text).toContain(randomDoc);
441+
const pdfParse = new PDFParse({ data: pdfBuffer });
442+
const pdfText = await pdfParse.getText();
443+
expect(pdfText.text).toContain(randomDoc);
453444
});
454445
});

src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, test } from '@playwright/test';
22

3-
import { createDoc, getGridRow } from './utils-common';
3+
import { createDoc, getGridRow, verifyDocName } from './utils-common';
4+
import { addNewMember, connectOtherUserToDoc } from './utils-share';
45

56
type SmallDoc = {
67
id: string;
@@ -11,7 +12,7 @@ test.describe('Documents Grid mobile', () => {
1112
test.use({ viewport: { width: 500, height: 1200 } });
1213

1314
test('it checks the grid when mobile', async ({ page }) => {
14-
await page.route('**/documents/**', async (route) => {
15+
await page.route(/.*\/documents\/.*/, async (route) => {
1516
const request = route.request();
1617
if (request.method().includes('GET') && request.url().includes('page=')) {
1718
await route.fulfill({
@@ -161,7 +162,7 @@ test.describe('Document grid item options', () => {
161162
test("it checks if the delete option is disabled if we don't have the destroy capability", async ({
162163
page,
163164
}) => {
164-
await page.route('*/**/api/v1.0/documents/?page=1', async (route) => {
165+
await page.route(/.*\/api\/v1.0\/documents\/\?page=1/, async (route) => {
165166
await route.fulfill({
166167
json: {
167168
results: [
@@ -192,90 +193,68 @@ test.describe('Document grid item options', () => {
192193
});
193194
await page.goto('/');
194195

195-
const button = page.getByTestId(
196-
`docs-grid-actions-button-mocked-document-id`,
197-
);
196+
const button = page
197+
.getByTestId(`docs-grid-actions-button-mocked-document-id`)
198+
.first();
198199
await expect(button).toBeVisible();
199200
await button.click();
200-
const removeButton = page.getByTestId(
201-
`docs-grid-actions-remove-mocked-document-id`,
202-
);
201+
const removeButton = page
202+
.getByTestId(`docs-grid-actions-remove-mocked-document-id`)
203+
.first();
203204
await expect(removeButton).toBeVisible();
204205
await removeButton.isDisabled();
205206
});
206207
});
207208

208209
test.describe('Documents filters', () => {
209-
test('it checks the prebuild left panel filters', async ({ page }) => {
210+
test('it checks the left panel filters', async ({ page, browserName }) => {
210211
void page.goto('/');
211212

212-
// All Docs
213-
const response = await page.waitForResponse(
214-
(response) =>
215-
response.url().endsWith('documents/?page=1') &&
216-
response.status() === 200,
217-
);
218-
const result = await response.json();
219-
const allCount = result.count as number;
220-
await expect(page.getByTestId('grid-loader')).toBeHidden();
213+
// Create my doc
214+
const [docName] = await createDoc(page, 'my-doc', browserName, 1);
215+
await verifyDocName(page, docName);
216+
217+
// Another user create a doc and share it with me
218+
const { cleanup, otherPage, otherBrowserName } =
219+
await connectOtherUserToDoc({
220+
browserName,
221+
docUrl: '/',
222+
});
221223

222-
const allDocs = page.getByLabel('All docs');
223-
const myDocs = page.getByLabel('My docs');
224-
const sharedWithMe = page.getByLabel('Shared with me');
224+
const [docShareName] = await createDoc(
225+
otherPage,
226+
'my-share-doc',
227+
otherBrowserName,
228+
1,
229+
);
225230

226-
// Initial state
227-
await expect(allDocs).toBeVisible();
228-
await expect(allDocs).toHaveAttribute('aria-current', 'page');
231+
await verifyDocName(otherPage, docShareName);
229232

230-
await expect(myDocs).toBeVisible();
231-
await expect(myDocs).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
232-
await expect(myDocs).not.toHaveAttribute('aria-current');
233+
await otherPage.getByRole('button', { name: 'Share' }).click();
233234

234-
await expect(sharedWithMe).toBeVisible();
235-
await expect(sharedWithMe).toHaveCSS(
236-
'background-color',
237-
'rgba(0, 0, 0, 0)',
238-
);
239-
await expect(sharedWithMe).not.toHaveAttribute('aria-current');
235+
await addNewMember(otherPage, 0, 'Editor', browserName);
240236

241-
await allDocs.click();
237+
// Let's check the filters
238+
await page.getByRole('button', { name: 'Back to homepage' }).click();
242239

243-
await page.waitForURL('**/?target=all_docs');
240+
const row = await getGridRow(page, docName);
241+
const rowShare = await getGridRow(page, docShareName);
244242

245-
let url = new URL(page.url());
246-
let target = url.searchParams.get('target');
247-
expect(target).toBe('all_docs');
243+
// All Docs
244+
await expect(row).toBeVisible();
245+
await expect(rowShare).toBeVisible();
248246

249-
// My docs
250-
await myDocs.click();
251-
url = new URL(page.url());
252-
target = url.searchParams.get('target');
253-
expect(target).toBe('my_docs');
254-
const responseMyDocs = await page.waitForResponse(
255-
(response) =>
256-
response.url().endsWith('documents/?page=1&is_creator_me=true') &&
257-
response.status() === 200,
258-
);
259-
const resultMyDocs = await responseMyDocs.json();
260-
const countMyDocs = resultMyDocs.count as number;
261-
await expect(page.getByTestId('grid-loader')).toBeHidden();
262-
expect(countMyDocs).toBeLessThanOrEqual(allCount);
247+
// My Docs
248+
await page.getByRole('link', { name: 'My docs' }).click();
249+
await expect(row).toBeVisible();
250+
await expect(rowShare).toBeHidden();
263251

264252
// Shared with me
265-
await sharedWithMe.click();
266-
url = new URL(page.url());
267-
target = url.searchParams.get('target');
268-
expect(target).toBe('shared_with_me');
269-
const responseSharedWithMe = await page.waitForResponse(
270-
(response) =>
271-
response.url().includes('documents/?page=1&is_creator_me=false') &&
272-
response.status() === 200,
273-
);
274-
const resultSharedWithMe = await responseSharedWithMe.json();
275-
const countSharedWithMe = resultSharedWithMe.count as number;
276-
await expect(page.getByTestId('grid-loader')).toBeHidden();
277-
expect(countSharedWithMe).toBeLessThanOrEqual(allCount);
278-
expect(countSharedWithMe + countMyDocs).toEqual(allCount);
253+
await page.getByRole('link', { name: 'Shared with me' }).click();
254+
await expect(row).toBeHidden();
255+
await expect(rowShare).toBeVisible();
256+
257+
await cleanup();
279258
});
280259
});
281260

src/frontend/apps/e2e/__tests__/app-impress/doc-member-list.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ test.describe('Document list members', () => {
3131
return cleanUrl.split('/').pop() || '';
3232
})();
3333

34-
await page.route('**/documents/**/accesses/', async (route) => {
34+
await page.route(/.*\/documents\/.*\/accesses\//, async (route) => {
3535
const request = route.request();
3636
const url = new URL(request.url());
3737
const pageId = url.searchParams.get('page') ?? '1';

src/frontend/apps/e2e/__tests__/app-impress/types/pdf-parse.d.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/frontend/apps/e2e/__tests__/app-impress/utils-common.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const overrideConfig = async (
3131
page: Page,
3232
newConfig: { [_K in keyof typeof CONFIG]?: unknown },
3333
) =>
34-
await page.route('**/api/v1.0/config/', async (route) => {
34+
await page.route(/.*\/api\/v1.0\/config\/.*/, async (route) => {
3535
const request = route.request();
3636
if (request.method().includes('GET')) {
3737
await route.fulfill({
@@ -204,7 +204,7 @@ export const waitForResponseCreateDoc = (page: Page) => {
204204
};
205205

206206
export const mockedDocument = async (page: Page, data: object) => {
207-
await page.route('**/documents/**/', async (route) => {
207+
await page.route(/\**\/documents\/\**/, async (route) => {
208208
const request = route.request();
209209
if (
210210
request.method().includes('GET') &&
@@ -256,7 +256,7 @@ export const mockedDocument = async (page: Page, data: object) => {
256256
};
257257

258258
export const mockedListDocs = async (page: Page, data: object[] = []) => {
259-
await page.route('**/documents/**/', async (route) => {
259+
await page.route(/\**\/documents\/\**/, async (route) => {
260260
const request = route.request();
261261
if (request.method().includes('GET') && request.url().includes('page=')) {
262262
await route.fulfill({
@@ -301,7 +301,7 @@ export async function waitForLanguageSwitch(
301301
page: Page,
302302
lang: TestLanguageValue,
303303
) {
304-
await page.route('**/api/v1.0/users/**', async (route, request) => {
304+
await page.route(/\**\/api\/v1.0\/users\/\**/, async (route, request) => {
305305
if (request.method().includes('PATCH')) {
306306
await route.fulfill({
307307
json: {

0 commit comments

Comments
 (0)