Skip to content

Commit c1b12d1

Browse files
committed
✅(e2e) add test for accessible html export from export modal
checks generated zip contains html and embedded media files Signed-off-by: Cyril <[email protected]>
1 parent 3713f00 commit c1b12d1

File tree

5 files changed

+72
-54
lines changed

5 files changed

+72
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to
1616
- ⚡️(sw) stop to cache external resources likes videos #1655
1717
- 💥(frontend) upgrade to ui-kit v2
1818
- ⚡️(frontend) improve perf on upload and table of contents #1662
19+
- ⚡️Enhance/html copy to download #1669
20+
1921

2022
### Fixed
2123

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,64 @@ test.describe('Doc Export', () => {
187187
expect(download.suggestedFilename()).toBe(`${randomDoc}.odt`);
188188
});
189189

190+
test('it exports the doc to html zip', async ({ page, browserName }) => {
191+
const [randomDoc] = await createDoc(
192+
page,
193+
'doc-editor-html-zip',
194+
browserName,
195+
1,
196+
);
197+
198+
await verifyDocName(page, randomDoc);
199+
200+
// Add some content and at least one image so that the ZIP contains media files.
201+
await page.locator('.ProseMirror.bn-editor').click();
202+
await page.locator('.ProseMirror.bn-editor').fill('Hello HTML ZIP');
203+
204+
await page.keyboard.press('Enter');
205+
await page.locator('.bn-block-outer').last().fill('/');
206+
await page.getByText('Resizable image with caption').click();
207+
208+
const fileChooserPromise = page.waitForEvent('filechooser');
209+
await page.getByText('Upload image').click();
210+
211+
const fileChooser = await fileChooserPromise;
212+
await fileChooser.setFiles(path.join(__dirname, 'assets/test.svg'));
213+
214+
const image = page
215+
.locator('.--docs--editor-container img.bn-visual-media')
216+
.first();
217+
218+
await expect(image).toBeVisible();
219+
220+
await page
221+
.getByRole('button', {
222+
name: 'Export the document',
223+
})
224+
.click();
225+
226+
await page.getByRole('combobox', { name: 'Format' }).click();
227+
await page.getByRole('option', { name: 'HTML' }).click();
228+
229+
await expect(page.getByTestId('doc-export-download-button')).toBeVisible();
230+
231+
const downloadPromise = page.waitForEvent('download', (download) => {
232+
return download.suggestedFilename().includes(`${randomDoc}.zip`);
233+
});
234+
235+
void page.getByTestId('doc-export-download-button').click();
236+
237+
const download = await downloadPromise;
238+
expect(download.suggestedFilename()).toBe(`${randomDoc}.zip`);
239+
240+
const zipBuffer = await cs.toBuffer(await download.createReadStream());
241+
242+
// ZIP files start with "PK\x03\x04"
243+
expect(zipBuffer.length).toBeGreaterThan(4);
244+
expect(zipBuffer[0]).toBe(0x50);
245+
expect(zipBuffer[1]).toBe(0x4b);
246+
});
247+
190248
/**
191249
* This test tell us that the export to pdf is working with images
192250
* but it does not tell us if the images are being displayed correctly

src/frontend/apps/impress/src/features/docs/doc-export/__tests__/ExportMIT.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ describe('useModuleExport', () => {
1616
const Export = await import('@/features/docs/doc-export/');
1717

1818
expect(Export.default).toBeUndefined();
19-
}, 10000);
19+
}, 60000);
2020

2121
it('should load modules when NEXT_PUBLIC_PUBLISH_AS_MIT is false', async () => {
2222
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
2323
const Export = await import('@/features/docs/doc-export/');
2424

2525
expect(Export.default).toHaveProperty('ModalExport');
26-
});
26+
}, 60000);
2727
});
Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
import { render, screen } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
3-
import React, { Fragment } from 'react';
3+
import React from 'react';
44
import { beforeEach, describe, expect, vi } from 'vitest';
55

6-
import { AbstractAnalytic, Analytics } from '@/libs';
76
import { AppWrapper } from '@/tests/utils';
87

98
import { DocToolBox } from '../components/DocToolBox';
109

11-
let flag = true;
12-
class TestAnalytic extends AbstractAnalytic {
13-
public constructor() {
14-
super();
15-
}
16-
17-
public Provider() {
18-
return <Fragment />;
19-
}
20-
21-
public trackEvent() {}
22-
23-
public isFeatureFlagActivated(flagName: string): boolean {
24-
if (flagName === 'CopyAsHTML') {
25-
return flag;
26-
}
27-
28-
return true;
29-
}
30-
}
31-
3210
vi.mock('next/router', async () => ({
3311
...(await vi.importActual('next/router')),
3412
useRouter: () => ({
@@ -45,42 +23,21 @@ const doc = {
4523
};
4624

4725
beforeEach(() => {
48-
Analytics.clearAnalytics();
4926
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
5027
});
5128

52-
describe('DocToolBox "Copy as HTML" option', () => {
53-
test('renders "Copy as HTML" option when feature flag is enabled', async () => {
54-
new TestAnalytic();
55-
29+
describe('DocToolBox options', () => {
30+
test('shows "Copy as Markdown" option and no longer shows "Copy as HTML"', async () => {
5631
render(<DocToolBox doc={doc as any} />, {
5732
wrapper: AppWrapper,
5833
});
34+
5935
const optionsButton = await screen.findByLabelText(
6036
'Open the document options',
6137
);
6238
await userEvent.click(optionsButton);
63-
expect(await screen.findByText('Copy as HTML')).toBeInTheDocument();
64-
});
6539

66-
test('does not render "Copy as HTML" option when feature flag is disabled', async () => {
67-
flag = false;
68-
new TestAnalytic();
69-
70-
render(<DocToolBox doc={doc as any} />, {
71-
wrapper: AppWrapper,
72-
});
73-
const optionsButton = screen.getByLabelText('Open the document options');
74-
await userEvent.click(optionsButton);
40+
expect(await screen.findByText('Copy as Markdown')).toBeInTheDocument();
7541
expect(screen.queryByText('Copy as HTML')).not.toBeInTheDocument();
7642
});
77-
78-
test('render "Copy as HTML" option when we did not add analytics', async () => {
79-
render(<DocToolBox doc={doc as any} />, {
80-
wrapper: AppWrapper,
81-
});
82-
const optionsButton = screen.getByLabelText('Open the document options');
83-
await userEvent.click(optionsButton);
84-
expect(screen.getByText('Copy as HTML')).toBeInTheDocument();
85-
});
8643
});

src/frontend/apps/impress/src/features/docs/doc-header/__tests__/DocToolBoxLicence.spec.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ describe('DocToolBox - Licence', () => {
4242
});
4343
const optionsButton = await screen.findByLabelText('Export the document');
4444
await userEvent.click(optionsButton);
45+
46+
// Wait for the export modal to be visible, then assert on its content text.
47+
await screen.findByTestId('modal-export-title');
4548
expect(
46-
await screen.findByText(
47-
'Download your document in a .docx, .odt or .pdf format.',
48-
),
49+
screen.getByText(/Download your document in a .docx, .odt.*format\./i),
4950
).toBeInTheDocument();
50-
}, 10000);
51+
}, 60000);
5152

5253
test('The export button is not rendered when MIT version is activated', async () => {
5354
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'true';

0 commit comments

Comments
 (0)