Skip to content

Commit 7c47786

Browse files
committed
✅(frontend) fix vitest tests
We upgraded vitest recently, we need to adapt some of our tests to the new version. We brought some modules improvments as well, problemes that was highlighted by the new version of vitest.
1 parent fc80322 commit 7c47786

14 files changed

Lines changed: 50 additions & 84 deletions

File tree

src/frontend/apps/impress/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@
106106
"stylelint-config-standard": "39.0.1",
107107
"stylelint-prettier": "5.0.3",
108108
"typescript": "*",
109-
"vite-tsconfig-paths": "6.1.1",
110109
"vitest": "4.1.0",
111110
"webpack": "5.105.4",
112111
"workbox-webpack-plugin": "7.1.0"

src/frontend/apps/impress/src/features/docs/doc-editor/hook/useSaveDoc.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useCallback, useEffect, useState } from 'react';
33
import * as Y from 'yjs';
44

55
import { useUpdateDoc } from '@/docs/doc-management/';
6-
import { KEY_LIST_DOC_VERSIONS } from '@/docs/doc-versioning';
6+
import { KEY_LIST_DOC_VERSIONS } from '@/docs/doc-versioning/api/useDocVersions';
77
import { toBase64 } from '@/utils/string';
88
import { isFirefox } from '@/utils/userAgent';
99

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest';
2+
3+
vi.mock('@/docs/doc-export/components/ModalExport', () => ({
4+
ModalExport: vi.fn(),
5+
}));
6+
27
const originalEnv = process.env.NEXT_PUBLIC_PUBLISH_AS_MIT;
38

49
describe('useModuleExport', () => {
@@ -16,12 +21,12 @@ describe('useModuleExport', () => {
1621
const Export = await import('@/features/docs/doc-export/');
1722

1823
expect(Export.default).toBeUndefined();
19-
}, 15000);
24+
});
2025

2126
it('should load modules when NEXT_PUBLIC_PUBLISH_AS_MIT is false', async () => {
2227
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'false';
2328
const Export = await import('@/features/docs/doc-export/');
2429

2530
expect(Export.default).toHaveProperty('ModalExport');
26-
}, 15000);
31+
});
2732
});

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { render, screen } from '@testing-library/react';
2-
import userEvent from '@testing-library/user-event';
3-
import React from 'react';
42
import { afterAll, beforeEach, describe, expect, vi } from 'vitest';
53

64
import { AppWrapper } from '@/tests/utils';
@@ -40,17 +38,11 @@ describe('DocToolBox - Licence', () => {
4038
render(<DocToolBox doc={doc as any} />, {
4139
wrapper: AppWrapper,
4240
});
43-
const optionsButton = await screen.findByLabelText('Export the document');
44-
await userEvent.click(optionsButton);
4541

46-
// Wait for the export modal to be visible, then assert on its content text.
47-
await screen.findByTestId('modal-export-title');
4842
expect(
49-
screen.getByText(
50-
'Export your document to print or download in .docx, .odt, .pdf or .html(zip) format.',
51-
),
43+
await screen.findByLabelText('Export the document'),
5244
).toBeInTheDocument();
53-
}, 10000);
45+
}, 15000);
5446

5547
test('The export button is not rendered when MIT version is activated', async () => {
5648
process.env.NEXT_PUBLIC_PUBLISH_AS_MIT = 'true';
@@ -68,5 +60,5 @@ describe('DocToolBox - Licence', () => {
6860
expect(
6961
screen.queryByLabelText('Export the document'),
7062
).not.toBeInTheDocument();
71-
});
63+
}, 15000);
7264
});

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Button, useModal } from '@gouvfr-lasuite/cunningham-react';
22
import { useTreeContext } from '@gouvfr-lasuite/ui-kit';
3-
import { useQueryClient } from '@tanstack/react-query';
43
import dynamic from 'next/dynamic';
54
import { useRouter } from 'next/router';
6-
import { useEffect, useState } from 'react';
5+
import { useState } from 'react';
76
import { useTranslation } from 'react-i18next';
87
import { css } from 'styled-components';
98

@@ -39,7 +38,6 @@ import {
3938
useDocUtils,
4039
useDuplicateDoc,
4140
} from '@/docs/doc-management';
42-
import { KEY_LIST_DOC_VERSIONS } from '@/docs/doc-versioning';
4341
import { useFocusStore, useResponsiveStore } from '@/stores';
4442

4543
import { useCopyCurrentEditorToClipboard } from '../hooks/useCopyCurrentEditorToClipboard';
@@ -88,7 +86,6 @@ interface DocToolBoxProps {
8886
export const DocToolBox = ({ doc }: DocToolBoxProps) => {
8987
const { t } = useTranslation();
9088
const treeContext = useTreeContext<Doc>();
91-
const queryClient = useQueryClient();
9289
const router = useRouter();
9390
const { isChild, isTopRoot } = useDocUtils(doc);
9491

@@ -114,16 +111,6 @@ export const DocToolBox = ({ doc }: DocToolBoxProps) => {
114111
listInvalidQueries: [KEY_LIST_DOC, KEY_DOC, KEY_LIST_FAVORITE_DOC],
115112
});
116113

117-
useEffect(() => {
118-
if (selectHistoryModal.isOpen) {
119-
return;
120-
}
121-
122-
void queryClient.resetQueries({
123-
queryKey: [KEY_LIST_DOC_VERSIONS],
124-
});
125-
}, [selectHistoryModal.isOpen, queryClient]);
126-
127114
// Emoji Management
128115
const { emoji } = getEmojiAndTitle(doc.title ?? '');
129116
const { updateDocEmoji } = useDocTitleUpdate();

src/frontend/apps/impress/src/features/docs/doc-header/hooks/useCopyCurrentEditorToClipboard.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '@gouvfr-lasuite/cunningham-react';
55
import { useTranslation } from 'react-i18next';
66

7-
import { useEditorStore } from '../../doc-editor';
7+
import { useEditorStore } from '@/docs/doc-editor/stores/useEditorStore';
88

99
export const useCopyCurrentEditorToClipboard = () => {
1010
const { editor } = useEditorStore();
@@ -21,8 +21,8 @@ export const useCopyCurrentEditorToClipboard = () => {
2121
try {
2222
const editorContentFormatted =
2323
asFormat === 'html'
24-
? await editor.blocksToHTMLLossy()
25-
: await editor.blocksToMarkdownLossy();
24+
? editor.blocksToHTMLLossy()
25+
: editor.blocksToMarkdownLossy();
2626
await navigator.clipboard.writeText(editorContentFormatted);
2727
const successMessage =
2828
asFormat === 'markdown'

src/frontend/apps/impress/src/features/docs/doc-management/hooks/__tests__/useDocTitleUpdate.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ vi.mock('@/stores', () => ({
1414
}),
1515
}));
1616

17+
vi.mock('@gouvfr-lasuite/ui-kit', async () => ({
18+
...(await vi.importActual('@gouvfr-lasuite/ui-kit')),
19+
useTreeContext: () => null,
20+
}));
21+
1722
describe('useDocTitleUpdate', () => {
1823
beforeEach(() => {
1924
vi.clearAllMocks();

src/frontend/apps/impress/src/features/docs/doc-versioning/components/DocVersionEditor.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { useEffect, useState } from 'react';
44
import * as Y from 'yjs';
55

66
import { Box, Text, TextErrors } from '@/components';
7-
import { BlockNoteReader, DocEditorContainer } from '@/docs/doc-editor/';
7+
import { BlockNoteReader } from '@/docs/doc-editor/components/BlockNoteEditor';
8+
import { DocEditorContainer } from '@/docs/doc-editor/components/DocEditor';
89
import { Doc, base64ToBlocknoteXmlFragment } from '@/docs/doc-management';
9-
import { Versions, useDocVersion } from '@/docs/doc-versioning/';
10+
11+
import { useDocVersion } from '../api/useDocVersion';
12+
import { Versions } from '../types';
1013

1114
import { DocVersionHeader } from './DocVersionHeader';
1215

src/frontend/apps/impress/src/features/docs/doc-versioning/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Doc } from '../doc-management';
1+
import { Doc } from '../doc-management/types';
22

33
export interface APIListVersions {
44
count: number;

src/frontend/apps/impress/src/features/docs/docs-grid/components/__tests__/DocsGridItemDate.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen, waitFor } from '@testing-library/react';
1+
import { act, render, screen, waitFor } from '@testing-library/react';
22
import fetchMock from 'fetch-mock';
33
import i18next from 'i18next';
44
import { DateTime } from 'luxon';
@@ -73,7 +73,9 @@ describe('DocsGridItemDate', () => {
7373
});
7474

7575
it(`should render rendered the updated_at field in the correct language`, async () => {
76-
await i18next.changeLanguage('fr');
76+
await act(async () => {
77+
await i18next.changeLanguage('fr');
78+
});
7779

7880
render(
7981
<DocsGridItemDate
@@ -90,7 +92,9 @@ describe('DocsGridItemDate', () => {
9092

9193
expect(screen.getByText('il y a 5 jours')).toBeInTheDocument();
9294

93-
await i18next.changeLanguage('en');
95+
await act(async () => {
96+
await i18next.changeLanguage('en');
97+
});
9498
});
9599

96100
[

0 commit comments

Comments
 (0)