-
Notifications
You must be signed in to change notification settings - Fork 4
feat(test): add jest and testing library react test environnement #467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev-react
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds Jest and Testing Library support for React, replacing Vitest and introducing new tests for key components and utilities.
- Switched testing framework from Vitest to Jest and updated related scripts and configuration.
- Added test utilities (renderWithProviders) and new unit tests for FolderModal, ModalProvider, and isEnterPressed utility.
- Updated build scripts and minor UI tweaks in FolderModal.
Reviewed Changes
Copilot reviewed 11 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| formulaire/frontend/src/tests/testUtils.tsx | Added a custom renderWithProviders for wrapping tests with app context. |
| formulaire/frontend/src/tests/mocks/uiMocks.tsx | Created module mocks for UI components from @cgi-learning-hub/ui. |
| formulaire/frontend/src/tests/mocks/edificeReact.tsx | Provided no-op mocks for EdificeClientProvider / EdificeThemeProvider. |
| formulaire/frontend/src/tests/mocks/cgiTheme.tsx | Added a simplified ThemeProvider mock for tests. |
| formulaire/frontend/src/tests/jestSetup.tsx | Configured jest setup and i18n mock. |
| formulaire/frontend/src/providers/ModalProvider/tests/ModalProvider.spec.tsx | Added tests to validate modal context behavior and error handling. |
| formulaire/frontend/src/core/tests/utils.spec.ts | Tested the isEnterPressed utility. |
| formulaire/frontend/src/containers/FolderModal/index.tsx | Simplified DialogTitle usage in FolderModal. |
| formulaire/frontend/src/containers/FolderModal/tests/FolderModal.spec.tsx | Added tests for FolderModal actions in both CREATE and RENAME modes. |
| formulaire/frontend/jest.config.ts | Updated Jest configuration for transforms, coverage, and module mappings. |
Files not reviewed (3)
- build.sh: Language not supported
- formulaire/frontend/package.json: Language not supported
- formulaire/frontend/tsconfig.app.json: Language not supported
Comments suppressed due to low confidence (1)
formulaire/frontend/src/containers/FolderModal/index.tsx:79
- Ensure that the DialogTitle component accepts the 'fontWeight' prop directly; if not, consider using the sx prop (e.g., <DialogTitle sx={{ fontWeight: 'bold' }}>...) to apply the styling.
<DialogTitle fontWeight="bold">{t(currentConfig.i18nTitle)}</DialogTitle>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces Vitest with Jest as the testing framework and improves the test infrastructure by adding mocks, a custom render helper, and new unit tests for several components and utilities.
- Replaced Vitest with Jest and updated configuration/scripts
- Introduced a custom render helper (renderWithProviders) and added relevant test mocks
- Added new tests for FolderModal, ModalProvider, and the isEnterPressed utility
Reviewed Changes
Copilot reviewed 12 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/testUtils.tsx | Added renderWithProviders helper with app providers for Jest tests |
| src/tests/mocks/uiMocks.tsx | Provided mocks for UI components from MUI |
| src/tests/mocks/edificeReact.tsx | Provided no‑op implementations for Edifice providers |
| src/tests/mocks/cgiTheme.tsx | Provided a no‑op ThemeProvider for testing |
| src/tests/jestSetup.tsx | Set up Jest-related test configuration and mocks |
| providers/ModalProvider/tests/ModalProvider.spec.tsx | Added tests to verify proper functioning of ModalProvider |
| src/core/tests/utils.spec.ts | Added tests covering the isEnterPressed utility function |
| containers/FolderModal/index.tsx | Simplified the DialogTitle structure in FolderModal |
| containers/FolderModal/tests/FolderModal.spec.tsx | Added tests for FolderModal behaviors in both CREATE and RENAME modes |
| jest.config.ts | Introduced a Jest configuration file for overall test setup |
Files not reviewed (3)
- build.sh: Language not supported
- formulaire/frontend/package.json: Language not supported
- formulaire/frontend/tsconfig.app.json: Language not supported
3c41394 to
62e480b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR transitions the testing framework from Vitest to Jest, adds extensive unit tests for various components and utilities, and includes several minor tweaks to UI components and build configurations.
- Introduces Jest configuration and polyfills.
- Adds new unit tests for ModalProvider, FolderModal, FormPropModal, and various utility functions.
- Implements minor refactors such as simplified DialogTitle usage and updates to ESLint and workflow files.
Reviewed Changes
Copilot reviewed 26 out of 28 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| formulaire/frontend/src/tests/jest/jest.polyfills.js | Adds polyfills to support Jest in the frontend tests. |
| formulaire/frontend/src/providers/ModalProvider/tests/ModalProvider.spec.tsx | Provides tests for modal provider behavior and error boundaries. |
| formulaire/frontend/src/core/models/form/utils.ts | Updates utility functions, including changes to distribution functions and form status logic. |
| formulaire/frontend/src/core/models/form/tests/IForm.spec.ts | Adds unit tests covering form-related utilities. |
| formulaire/frontend/src/core/models/distribution/utils.ts | Adds getLatestResponsedDistribution and refactors getLatestDistribution and getFirstDistribution. |
| formulaire/frontend/src/core/models/distribution/tests/IDistribution.spec.ts | Introduces tests verifying distribution utility functions. |
| formulaire/frontend/src/core/constants.ts | Updates the DEFAULT_PAGINATION_LIMIT value. |
| formulaire/frontend/src/core/tests/utils.spec.ts | Includes tests for the isEnterPressed utility function. |
| formulaire/frontend/src/containers/HomeMainFormsTable/index.tsx | Wraps table content with an explicit Table component and updates pagination conditions. |
| formulaire/frontend/src/containers/HomeMainFormsTable/tests/HomeMainFormsTable.spec.tsx | Adds tests for table rendering, pagination behavior, and checkbox selection. |
| formulaire/frontend/src/containers/FormPropModal/index.tsx | Refactors DialogTitle usage using Fragment for keying and simplifies markup. |
| formulaire/frontend/src/containers/FormPropModal/tests/FormPropModal.spec.tsx | Provides tests for form modal interactions in both CREATE and UPDATE modes. |
| formulaire/frontend/src/containers/FolderModal/index.tsx | Simplifies the DialogTitle component for the folder modal. |
| formulaire/frontend/src/containers/FolderModal/tests/FolderModal.spec.tsx | Includes tests for folder creation and renaming functionality. |
| formulaire/frontend/src/components/RgpdInfoBox/test/RgpdInfoBox.spec.tsx | Adds tests for rendering RGPD information with interpolated values. |
| formulaire/frontend/jest.config.ts | Establishes Jest configuration with coverage settings and module mappings. |
| formulaire/frontend/eslint.config.js | Updates the ignore list to include additional test polyfill files. |
| .github/workflows/dev-check-repository.yml | Refines workflow step names for running tests across different frameworks. |
Files not reviewed (2)
- build.sh: Language not supported
- formulaire/frontend/package.json: Language not supported
Comments suppressed due to low confidence (2)
formulaire/frontend/src/core/models/form/utils.ts:77
- In isFormFilled, getNbFinishedDistrib is applied to the full distributions array rather than the filtered formDistributions. It should likely use formDistributions to correctly reflect the form's response status.
return getNbFinishedDistrib(distributions) > 0;
formulaire/frontend/src/core/constants.ts:40
- Changing DEFAULT_PAGINATION_LIMIT from 10 to 1 may impact UI pagination behavior. Please confirm if this change is intentional.
export const DEFAULT_PAGINATION_LIMIT = 1;
* chore(react): [#FOR-868] add React * chore(react): [#FOR-868] update git worflow * chore(react): [#FOR-868] add React and improve build.sh files * chore(angular): [#FOR-868] fix build.sh * chore(react): [#FOR-868] link react to the app * chore(lint): [#FOR-868] fix pipeline git * fix(JekinsFile): [#FOR-868] fix JenkinsFile for future delivery
* feat: add HomeView component and folder API service * refactor: simplify Folder interface and clean up folderApi endpoints
* feat(): [#FOR-869] add Header * feat(header): [#FOR-869] retours PR * lint
* feat: implement HomeTabs component and update folder modal functionality * feat(sidebar) : mainlayout+sidebarlayout+treeview-impl+tab * fix: update Box import source in HomeMainLayout * fix(form): fix review
* feat(FormPropModal): add modal component with create/update functionality and localization * feat(FormPropModal): enhance modal with image upload, date selection, and improved localization * wip * feat(FormPropModal): refactor date handling and improve checkbox state management * feat(Form): refactor form model and API integration; update folder imports and improve state management * feat(RgpdInfoBox, FormPropModal): fix review
* feat(toaster): implement toaster component with button actions and state management * refactor(toaster): simplify button actions
* fix(return): #FOR-880 fix remind modal return * wip * fix(return): #FOR-880 add badge for number of responders * wip * wip
* fix(return) : fix return for remind modal, export modal, tabs * wip
Describe your changes
jest.config.ts, updated scripts/dependencies).renderWithProvidershelper.FolderModalcomponent,ModalProvider, and theisEnterPressedutility.build.shwith atestFormulaireReacttarget to run React tests.DialogTitleinFolderModaland enabledesModuleInterop/allowSyntheticDefaultImportsintsconfig.app.json.Checklist tests
Issue ticket number and link
Checklist before requesting a review (magic string, indentation, comment/documentation...)