Skip to content

Commit a86aa1c

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 ef3da58 commit a86aa1c

File tree

3 files changed

+71
-8
lines changed

3 files changed

+71
-8
lines changed

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)