Skip to content

Commit 64f967c

Browse files
committed
✅(frontend) assert DocToolBox depends the licence
Thanks to Vitest we can now assert more complicated parts of the code without too much mocking.
1 parent 1eee24d commit 64f967c

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test.describe('Doc Export', () => {
2525
await createDoc(page, 'doc-editor', browserName, 1);
2626
await page
2727
.getByRole('button', {
28-
name: 'download',
28+
name: 'Export the document',
2929
})
3030
.click();
3131

@@ -78,8 +78,7 @@ test.describe('Doc Export', () => {
7878

7979
await page
8080
.getByRole('button', {
81-
name: 'download',
82-
exact: true,
81+
name: 'Export the document',
8382
})
8483
.click();
8584

@@ -130,8 +129,7 @@ test.describe('Doc Export', () => {
130129

131130
await page
132131
.getByRole('button', {
133-
name: 'download',
134-
exact: true,
132+
name: 'Export the document',
135133
})
136134
.click();
137135

@@ -200,7 +198,7 @@ test.describe('Doc Export', () => {
200198

201199
await page
202200
.getByRole('button', {
203-
name: 'download',
201+
name: 'Export the document',
204202
})
205203
.click();
206204

@@ -277,7 +275,7 @@ test.describe('Doc Export', () => {
277275

278276
await page
279277
.getByRole('button', {
280-
name: 'download',
278+
name: 'Export the document',
281279
})
282280
.click();
283281

@@ -327,8 +325,7 @@ test.describe('Doc Export', () => {
327325

328326
await page
329327
.getByRole('button', {
330-
name: 'download',
331-
exact: true,
328+
name: 'Export the document',
332329
})
333330
.click();
334331

@@ -390,8 +387,7 @@ test.describe('Doc Export', () => {
390387

391388
await page
392389
.getByRole('button', {
393-
name: 'download',
394-
exact: true,
390+
name: 'Export the document',
395391
})
396392
.click();
397393

@@ -465,8 +461,7 @@ test.describe('Doc Export', () => {
465461

466462
await page
467463
.getByRole('button', {
468-
name: 'download',
469-
exact: true,
464+
name: 'Export the document',
470465
})
471466
.click();
472467

@@ -537,8 +532,7 @@ test.describe('Doc Export', () => {
537532

538533
await page
539534
.getByRole('button', {
540-
name: 'download',
541-
exact: true,
535+
name: 'Export the document',
542536
})
543537
.click();
544538

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ test.describe('Doc Header', () => {
4444

4545
await expect(card.getByText('Owner ·')).toBeVisible();
4646
await expect(page.getByRole('button', { name: 'Share' })).toBeVisible();
47-
await expect(page.getByRole('button', { name: 'download' })).toBeVisible();
47+
await expect(
48+
page.getByRole('button', { name: 'Export the document' }),
49+
).toBeVisible();
4850
await expect(
4951
page.getByRole('button', { name: 'Open the document options' }),
5052
).toBeVisible();
@@ -115,7 +117,9 @@ test.describe('Doc Header', () => {
115117

116118
await goToGridDoc(page);
117119

118-
await expect(page.getByRole('button', { name: 'download' })).toBeVisible();
120+
await expect(
121+
page.getByRole('button', { name: 'Export the document' }),
122+
).toBeVisible();
119123

120124
await page.getByLabel('Open the document options').click();
121125

@@ -185,7 +189,9 @@ test.describe('Doc Header', () => {
185189

186190
await goToGridDoc(page);
187191

188-
await expect(page.getByRole('button', { name: 'download' })).toBeVisible();
192+
await expect(
193+
page.getByRole('button', { name: 'Export the document' }),
194+
).toBeVisible();
189195
await page.getByLabel('Open the document options').click();
190196

191197
await expect(page.getByLabel('Delete document')).toBeDisabled();
@@ -245,7 +251,9 @@ test.describe('Doc Header', () => {
245251

246252
await goToGridDoc(page);
247253

248-
await expect(page.getByRole('button', { name: 'download' })).toBeVisible();
254+
await expect(
255+
page.getByRole('button', { name: 'Export the document' }),
256+
).toBeVisible();
249257
await page.getByLabel('Open the document options').click();
250258

251259
await expect(page.getByLabel('Delete document')).toBeDisabled();

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest';
22
const originalEnv = process.env.NEXT_PUBLIC_PUBLISH_AS_MIT;
33

4-
vi.mock('@/features/docs/doc-export/utils', () => ({
5-
anything: true,
6-
}));
7-
vi.mock('@/features/docs/doc-export/components/ModalExport', () => ({
8-
ModalExport: () => <span>ModalExport</span>,
9-
}));
10-
114
describe('useModuleExport', () => {
125
afterAll(() => {
136
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv;
@@ -23,7 +16,7 @@ describe('useModuleExport', () => {
2316
const Export = await import('@/features/docs/doc-export/');
2417

2518
expect(Export.default).toBeUndefined();
26-
});
19+
}, 10000);
2720

2821
it('should load modules when NEXT_PUBLIC_PUBLISH_AS_MIT is false', async () => {
2922
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import React from 'react';
4+
import { afterAll, beforeEach, describe, expect, vi } from 'vitest';
5+
6+
import { AppWrapper } from '@/tests/utils';
7+
8+
const originalEnv = process.env.NEXT_PUBLIC_PUBLISH_AS_MIT;
9+
10+
vi.mock('next/router', async () => ({
11+
...(await vi.importActual('next/router')),
12+
useRouter: () => ({
13+
push: vi.fn(),
14+
}),
15+
}));
16+
17+
const doc = {
18+
nb_accesses: 1,
19+
abilities: {
20+
versions_list: true,
21+
destroy: true,
22+
},
23+
};
24+
25+
describe('DocToolBox - Licence', () => {
26+
afterAll(() => {
27+
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = originalEnv;
28+
});
29+
30+
beforeEach(() => {
31+
vi.clearAllMocks();
32+
vi.resetModules();
33+
});
34+
35+
test('The export button is rendered when MIT version is deactivated', async () => {
36+
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
37+
38+
const { DocToolBox } = await import('../components/DocToolBox');
39+
40+
render(<DocToolBox doc={doc as any} />, {
41+
wrapper: AppWrapper,
42+
});
43+
const optionsButton = await screen.findByLabelText('Export the document');
44+
await userEvent.click(optionsButton);
45+
expect(
46+
await screen.findByText(
47+
'Download your document in a .docx or .pdf format.',
48+
),
49+
).toBeInTheDocument();
50+
}, 10000);
51+
52+
test('The export button is not rendered when MIT version is activated', async () => {
53+
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'true';
54+
55+
const { DocToolBox } = await import('../components/DocToolBox');
56+
57+
render(<DocToolBox doc={doc as any} />, {
58+
wrapper: AppWrapper,
59+
});
60+
61+
expect(
62+
screen.getByLabelText('Open the document options'),
63+
).toBeInTheDocument();
64+
65+
expect(
66+
screen.queryByLabelText('Export the document'),
67+
).not.toBeInTheDocument();
68+
});
69+
});

src/frontend/apps/impress/src/features/docs/doc-header/components/DocToolBox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
241241
setIsModalExportOpen(true);
242242
}}
243243
size={isSmallMobile ? 'small' : 'medium'}
244+
aria-label={t('Export the document')}
244245
/>
245246
)}
246247
<DropdownMenu options={options}>

0 commit comments

Comments
 (0)