Skip to content

Commit fe24c00

Browse files
committed
♻️(frontend) adapt custom blocks to new implementation
Last release of Blocknote introduced breaking changes for custom blocks. We adapted our custom blocks to the new implementation. "code-block" is considered as a block now, we update the way to import and use it. The custom blocks should be now more tiptap friendly.
1 parent aca334f commit fe24c00

File tree

30 files changed

+1772
-3118
lines changed

30 files changed

+1772
-3118
lines changed

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to
88

99
### Changed
1010

11+
- ♻️(frontend) adapt custom blocks to new implementation #1375
1112
- ♻️(backend) increase user short_name field length
1213

1314
### Fixed
@@ -42,10 +43,6 @@ and this project adheres to
4243
- ✨(frontend) add pdf block to the editor #1293
4344
- ✨List and restore deleted docs #1450
4445

45-
### Fixed
46-
47-
- 🐛(frontend) show full nested doc names with ajustable bar #1456
48-
4946
### Changed
5047

5148
- ♻️(frontend) Refactor Auth component for improved redirection logic #1461

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,9 @@ test.describe('Doc Editor', () => {
676676

677677
await calloutBlock.locator('.inline-content').fill('example text');
678678

679-
await expect(page.locator('.bn-block').first()).toHaveAttribute(
680-
'data-background-color',
681-
'yellow',
682-
);
679+
await expect(
680+
page.locator('.bn-block-content[data-content-type="callout"]').first(),
681+
).toHaveAttribute('data-background-color', 'yellow');
683682

684683
const emojiButton = calloutBlock.getByRole('button');
685684
await expect(emojiButton).toHaveText('💡');
@@ -703,10 +702,9 @@ test.describe('Doc Editor', () => {
703702
await page.locator('.mantine-Menu-dropdown > button').last().click();
704703
await page.locator('.bn-color-picker-dropdown > button').last().click();
705704

706-
await expect(page.locator('.bn-block').first()).toHaveAttribute(
707-
'data-background-color',
708-
'pink',
709-
);
705+
await expect(
706+
page.locator('.bn-block-content[data-content-type="callout"]').first(),
707+
).toHaveAttribute('data-background-color', 'pink');
710708
});
711709

712710
test('it checks interlink feature', async ({ page, browserName }) => {
@@ -844,10 +842,10 @@ test.describe('Doc Editor', () => {
844842

845843
await expect(pdfBlock).toBeVisible();
846844

847-
await page.getByText('Add PDF').click();
845+
await page.getByText(/Add (PDF|file)/).click();
848846
const fileChooserPromise = page.waitForEvent('filechooser');
849847
const downloadPromise = page.waitForEvent('download');
850-
await page.getByText('Upload file').click();
848+
await page.getByText(/Upload (PDF|file)/).click();
851849
const fileChooser = await fileChooserPromise;
852850

853851
await fileChooser.setFiles(path.join(__dirname, 'assets/test-pdf.pdf'));

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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 { pdf } from 'pdf-parse';
66

77
import {
88
TestLanguage,
@@ -59,20 +59,16 @@ test.describe('Doc Export', () => {
5959

6060
await verifyDocName(page, randomDoc);
6161

62-
const editor = page.locator('.ProseMirror.bn-editor');
63-
64-
await editor.click();
65-
await editor.locator('.bn-block-outer').last().fill('Hello');
66-
62+
const editor = await writeInEditor({ page, text: 'Hello' });
6763
await page.keyboard.press('Enter');
68-
await editor.locator('.bn-block-outer').last().fill('/');
64+
await openSuggestionMenu({ page });
6965
await page.getByText('Page Break').click();
7066

71-
await expect(editor.locator('.bn-page-break')).toBeVisible();
72-
73-
await page.keyboard.press('Enter');
67+
await expect(
68+
editor.locator('div[data-content-type="pageBreak"]'),
69+
).toBeVisible();
7470

75-
await editor.locator('.bn-block-outer').last().fill('World');
71+
await writeInEditor({ page, text: 'World' });
7672

7773
await page
7874
.getByRole('button', {
@@ -92,9 +88,9 @@ test.describe('Doc Export', () => {
9288
const pdfBuffer = await cs.toBuffer(await download.createReadStream());
9389
const pdfData = await pdf(pdfBuffer);
9490

95-
expect(pdfData.numpages).toBe(2);
96-
expect(pdfData.text).toContain('\n\nHello\n\nWorld'); // This is the doc text
97-
expect(pdfData.info.Title).toBe(randomDoc);
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);
9894
});
9995

10096
test('it exports the doc to docx', async ({ page, browserName }) => {

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
randomName,
88
verifyDocName,
99
} from './utils-common';
10+
import { writeInEditor } from './utils-editor';
1011
import { connectOtherUserToDoc, updateRoleUser } from './utils-share';
1112
import { createRootSubPage } from './utils-sub-pages';
1213

@@ -240,11 +241,7 @@ test.describe('Document create member', () => {
240241

241242
await verifyDocName(page, docTitle);
242243

243-
await page
244-
.locator('.ProseMirror')
245-
.locator('.bn-block-outer')
246-
.last()
247-
.fill('Hello World');
244+
await writeInEditor({ page, text: 'Hello World' });
248245

249246
const docUrl = page.url();
250247

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
mockedDocument,
1010
verifyDocName,
1111
} from './utils-common';
12+
import { writeInEditor } from './utils-editor';
1213
import { createRootSubPage } from './utils-sub-pages';
1314

1415
test.describe('Doc Routing', () => {
@@ -58,16 +59,23 @@ test.describe('Doc Routing', () => {
5859

5960
await createRootSubPage(page, browserName, '401-doc-child');
6061

61-
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
62+
await writeInEditor({ page, text: 'Hello World' });
6263

6364
const responsePromise = page.route(
6465
/.*\/documents\/.*\/$|users\/me\/$/,
6566
async (route) => {
6667
const request = route.request();
6768

69+
// When we quit a document, a PATCH request is sent to save the document.
70+
// We intercept this request to simulate a 401 error from the backend.
71+
// The GET request to users/me is also intercepted to simulate the user
72+
// being logged out when trying to fetch user info.
73+
// This way we can test the 401 error handling when saving the document
6874
if (
69-
request.method().includes('PATCH') ||
70-
request.method().includes('GET')
75+
(request.url().includes('/documents/') &&
76+
request.method().includes('PATCH')) ||
77+
(request.url().includes('/users/me/') &&
78+
request.method().includes('GET'))
7179
) {
7280
await route.fulfill({
7381
status: 401,

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ test.describe('Doc Visibility: Restricted', () => {
175175
await addNewMember(page, 0, 'Reader', otherBrowserName);
176176

177177
await otherPage.reload();
178-
await expect(otherPage.getByText('Hello World')).toBeVisible();
178+
await expect(otherPage.getByText('Hello World')).toBeVisible({
179+
timeout: 10000,
180+
});
179181
});
180182
});
181183

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

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

33
import { TestLanguage, createDoc, waitForLanguageSwitch } from './utils-common';
4+
import { openSuggestionMenu } from './utils-editor';
45

56
test.describe('Language', () => {
67
test.beforeEach(async ({ page }) => {
@@ -51,6 +52,7 @@ test.describe('Language', () => {
5152
await expect(page.locator('html')).toHaveAttribute('lang', 'en');
5253
await expect(languagePicker).toContainText('English');
5354
});
55+
5456
test('can switch language using only keyboard', async ({ page }) => {
5557
await page.goto('/');
5658
await waitForLanguageSwitch(page, TestLanguage.English);
@@ -106,18 +108,18 @@ test.describe('Language', () => {
106108
}) => {
107109
await createDoc(page, 'doc-toolbar', browserName, 1);
108110

109-
const editor = page.locator('.ProseMirror');
110-
111-
// Trigger slash menu to show english menu
112-
await editor.click();
113-
await editor.fill('/');
111+
const editor = await openSuggestionMenu({ page });
114112
await expect(page.getByText('Headings', { exact: true })).toBeVisible();
115113

114+
await editor.click(); // close the menu
115+
116+
await expect(page.getByText('Headings', { exact: true })).toBeHidden();
117+
116118
// Change language to French
117119
await waitForLanguageSwitch(page, TestLanguage.French);
118120

119121
// Trigger slash menu to show french menu
120-
await editor.locator('.bn-block-outer').last().fill('/');
122+
await openSuggestionMenu({ page });
121123
await expect(page.getByText('Titres', { exact: true })).toBeVisible();
122124
});
123125
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Type definitions for pdf-parse library
3+
* The library doesn't export complete type definitions for the parsed PDF data
4+
*/
5+
6+
declare module 'pdf-parse' {
7+
export interface PdfInfo {
8+
Title?: string;
9+
Author?: string;
10+
Subject?: string;
11+
Keywords?: string;
12+
Creator?: string;
13+
Producer?: string;
14+
CreationDate?: string;
15+
ModDate?: string;
16+
[key: string]: unknown;
17+
}
18+
19+
export interface PdfData {
20+
/** Total number of pages */
21+
numpages: number;
22+
/** Alias for numpages */
23+
total?: number;
24+
/** Extracted text content from the PDF */
25+
text: string;
26+
/** PDF metadata information */
27+
info?: PdfInfo;
28+
/** PDF metadata (alternative structure) */
29+
metadata?: unknown;
30+
/** PDF version */
31+
version?: string;
32+
}
33+
34+
export function pdf(buffer: Buffer): Promise<PdfData>;
35+
36+
export default pdf;
37+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getEditor = async ({ page }: { page: Page }) => {
99
export const openSuggestionMenu = async ({ page }: { page: Page }) => {
1010
const editor = await getEditor({ page });
1111
await editor.click();
12-
await page.locator('.bn-block-outer').last().fill('/');
12+
await writeInEditor({ page, text: '/' });
1313

1414
return editor;
1515
};
@@ -22,6 +22,6 @@ export const writeInEditor = async ({
2222
text: string;
2323
}) => {
2424
const editor = await getEditor({ page });
25-
await editor.locator('.bn-block-outer').last().fill(text);
25+
await editor.locator('.bn-block-outer .bn-inline-content').last().fill(text);
2626
return editor;
2727
};

src/frontend/apps/impress/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@
3636
"@gouvfr-lasuite/integration": "1.0.3",
3737
"@gouvfr-lasuite/ui-kit": "0.16.2",
3838
"@hocuspocus/provider": "2.15.2",
39+
"@mantine/core": "8.3.4",
40+
"@mantine/hooks": "8.3.4",
3941
"@openfun/cunningham-react": "3.2.3",
4042
"@react-pdf/renderer": "4.3.1",
4143
"@sentry/nextjs": "10.17.0",
4244
"@tanstack/react-query": "5.90.2",
45+
"@tiptap/extensions": "3.4.4",
4346
"canvg": "4.0.3",
4447
"clsx": "2.1.1",
4548
"cmdk": "1.1.1",
4649
"crisp-sdk-web": "1.0.25",
47-
"docx": "9.5.0",
50+
"docx": "*",
4851
"emoji-datasource-apple": "16.0.0",
4952
"emoji-mart": "5.6.0",
5053
"emoji-regex": "10.5.0",

0 commit comments

Comments
 (0)