diff --git a/.eslintrc.js b/.eslintrc.js index 7195bf9c036c34a5f76b7e01f0dab71503d9d750..2f4c522e66189a2febe623ad18950c04a278a676 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -83,9 +83,18 @@ module.exports = { }, { files: ['**/*.spec.{ts,tsx}'], - extends: ['plugin:jest/recommended'], + extends: ['plugin:jest/recommended', 'plugin:testing-library/react'], rules: { 'jest/no-mocks-import': 0, + + // Act warning -> should be fixed with "@testing-library/dom" v10 -> in another MR + 'testing-library/no-unnecessary-act': 0, + + // For testing View components which renders other components -> implementation tests ? + 'testing-library/no-container': 0, + + // Allows checking classes on containers -> could be fixed + 'testing-library/no-node-access': 0, }, }, ], diff --git a/package.json b/package.json index 5a0d5a05286700a59052dc34879ce290b0e509d7..05ae37a8cdfc4f544f291c7976243908171e3b1b 100644 --- a/package.json +++ b/package.json @@ -118,6 +118,7 @@ "eslint-plugin-prettier": "^5.0.0", "eslint-plugin-react": "7.37.1", "eslint-plugin-react-hooks": "^5.0.0", + "eslint-plugin-testing-library": "^6.4.0", "git-directory-deploy": "1.5.1", "jest-canvas-mock": "^2.4.0", "jest-junit": "^16.0.0", diff --git a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx index ed1789703e930b669c776175fc812a17f48beef9..08461a140dfbc447f5f3c4fb2f6410e0b76092d8 100644 --- a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx +++ b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx @@ -47,6 +47,6 @@ describe('ActionOnGoing component', () => { await act(async () => { await userEvent.click(screen.getByText('action.details')) }) - expect(screen.findByRole('dialog')).toBeTruthy() + expect(screen.getByRole('dialog')).toBeTruthy() }) }) diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx index a8611f6d0468ba324dd31caf734b0c6488dab2c5..422d746bbd8837ba8bdd1bd60720b0bdc630def1 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx @@ -100,8 +100,8 @@ describe('ElecHalfHourMonthlyAnalysis component', () => { <ElecHalfHourMonthlyAnalysis perfIndicator={mockPerfIndicator} /> </Provider> ) - await waitFor(() => - screen.getByLabelText('consumption.accessibility.button_previous_value') + await screen.findByLabelText( + 'consumption.accessibility.button_previous_value' ) await act(async () => { await userEvent.click( diff --git a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx index 99ed04a63287af471dcb82c5f20411a1bc1a5025..ac2f3a6cab54225ba47a8bc5579215a9e0631bbf 100644 --- a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx +++ b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx @@ -44,7 +44,7 @@ describe('ChallengeCardUnlocked component', () => { screen.getByText('challenge.card_unlocked.button_launch') ) }) - expect(screen.queryAllByRole('dialog').length).toBeTruthy() + expect(screen.getByRole('dialog')).toBeInTheDocument() }) it('should not display ChallengeNoFluidModal and update userChallenge when launching challenge with configured fluid', async () => { diff --git a/src/components/Connection/SGEConnect/StepAddress.spec.tsx b/src/components/Connection/SGEConnect/StepAddress.spec.tsx index 8ba9d944327c3f733a1d564b4d57d41c2e13c8fd..2c293656ea19209741e758188eb3268b36ed6c4d 100644 --- a/src/components/Connection/SGEConnect/StepAddress.spec.tsx +++ b/src/components/Connection/SGEConnect/StepAddress.spec.tsx @@ -15,12 +15,10 @@ describe('StepAddress component', () => { }) describe('should change inputs', () => { - beforeEach(() => { + it('should change address value', async () => { render( <StepAddress sgeState={mockSgeState} onChange={mockHandleChange} /> ) - }) - it('should change address value', async () => { const input = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.address', }) @@ -30,6 +28,9 @@ describe('StepAddress component', () => { expect(mockHandleChange).toHaveBeenCalledWith('address', 't') }) it('should change zipCode value', async () => { + render( + <StepAddress sgeState={mockSgeState} onChange={mockHandleChange} /> + ) const input = screen.getByRole('spinbutton', { name: 'auth.enedissgegrandlyon.zipCode', }) @@ -40,6 +41,9 @@ describe('StepAddress component', () => { }) it('should change city value', async () => { + render( + <StepAddress sgeState={mockSgeState} onChange={mockHandleChange} /> + ) const input = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.city', }) diff --git a/src/components/Consumption/WaterPricing/WaterPricing.spec.tsx b/src/components/Consumption/WaterPricing/WaterPricing.spec.tsx index 14ac6b98f94280ec7d37b1994496a85450c9d90e..52df0177446942fd653da9f5dc014996bd96d323 100644 --- a/src/components/Consumption/WaterPricing/WaterPricing.spec.tsx +++ b/src/components/Consumption/WaterPricing/WaterPricing.spec.tsx @@ -23,7 +23,7 @@ describe('WaterPricing component', () => { <WaterPricing /> </Provider> ) - userEvent.click(screen.getByRole('button')) + await userEvent.click(screen.getByRole('button')) expect(await screen.findByRole('dialog')).toBeInTheDocument() }) }) diff --git a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx index 8c97e6e22465d3046251099ac39e70f912b76a35..78eeccdb511db00c61fe7ef87e1d59c900e48674 100644 --- a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx +++ b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx @@ -25,7 +25,7 @@ describe('EcogestureInitModal component', () => { }) it('should not render the modal when open is false', () => { - const { queryByRole } = render( + render( <Provider store={store}> <EcogestureInitModal open={false} @@ -34,7 +34,7 @@ describe('EcogestureInitModal component', () => { /> </Provider> ) - expect(queryByRole('dialog')).toBeNull() + expect(screen.queryByRole('dialog')).toBeNull() }) it('should render correctly when open is true', () => { diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx index 5608a326dbb4161f40386bff9d8e374be2603b14..f16ad9ebe3cb38245bf2122ed0ecb53da6539755 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx @@ -20,25 +20,27 @@ describe('EcogestureSelectionDetail component', () => { }) describe('should click on buttons', () => { - let container: HTMLElement - beforeEach(async () => { - container = render( + it('should toggle more details', async () => { + render( <EcogestureSelectionDetail ecogesture={mockedEcogesturesData[0]} validate={mockValidate} title={mockedEcogesturesData[0].shortName} /> - ).container - await waitFor(() => null, { container }) - }) - - it('should toggle more details', async () => { + ) await act(async () => { await userEvent.click(screen.getByText('ecogesture_modal.show_more')) }) expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument() }) it('should call validate with objective to true', async () => { + render( + <EcogestureSelectionDetail + ecogesture={mockedEcogesturesData[0]} + validate={mockValidate} + title={mockedEcogesturesData[0].shortName} + /> + ) await act(async () => { await userEvent.click( screen.getByText('ecogesture_selection.button_objective') @@ -48,6 +50,13 @@ describe('EcogestureSelectionDetail component', () => { }) it('should call validate with doing to true', async () => { + render( + <EcogestureSelectionDetail + ecogesture={mockedEcogesturesData[0]} + validate={mockValidate} + title={mockedEcogesturesData[0].shortName} + /> + ) await act(async () => { await userEvent.click( screen.getByText('ecogesture_selection.button_doing') @@ -57,6 +66,13 @@ describe('EcogestureSelectionDetail component', () => { }) it('should call validate with objective and doing to false', async () => { + render( + <EcogestureSelectionDetail + ecogesture={mockedEcogesturesData[0]} + validate={mockValidate} + title={mockedEcogesturesData[0].shortName} + /> + ) await act(async () => { await userEvent.click( screen.getByText('ecogesture_selection.button_skip') diff --git a/src/components/Header/Header.spec.tsx b/src/components/Header/Header.spec.tsx index 5d50f14bff0361e403092469c586778eaa1489b0..2ce2ad0ad6c18cb997af2983b04980df8d14e8f4 100644 --- a/src/components/Header/Header.spec.tsx +++ b/src/components/Header/Header.spec.tsx @@ -54,12 +54,12 @@ describe('Header component', () => { }) it('should not display desktop title text when desktopTitleKey not provided', () => { - const { queryByText } = render( + render( <Provider store={desktopStore}> <Header desktopTitleKey="" /> </Provider> ) - expect(queryByText(/.+/)).not.toBeInTheDocument() + expect(screen.queryByText(/.+/)).not.toBeInTheDocument() }) it('should display title and back button when desktopTitle key provided and displayBackArrow is true', () => { diff --git a/src/components/WelcomeModal/WelcomeModal.spec.tsx b/src/components/WelcomeModal/WelcomeModal.spec.tsx index d05b9ee6d6fbae6ec6c4ea177bc63c33cd023b8b..e40b1823b6d96712906210e93cf24dcdd9c5f6c5 100644 --- a/src/components/WelcomeModal/WelcomeModal.spec.tsx +++ b/src/components/WelcomeModal/WelcomeModal.spec.tsx @@ -62,14 +62,12 @@ describe('WelcomeModal component', () => { }) describe('should test modal interactivity', () => { - beforeEach(() => { + it('should send mail and update profile when user click on the ok button', async () => { render( <Provider store={store}> <WelcomeModal open={true} /> </Provider> ) - }) - it('should send mail and update profile when user click on the ok button', async () => { await act(async () => { await userEvent.click( screen.getByText('onboarding.welcomeModal.button_valid') @@ -85,6 +83,11 @@ describe('WelcomeModal component', () => { }) it('should send mail and update profile when modal is closed by user', async () => { + render( + <Provider store={store}> + <WelcomeModal open={true} /> + </Provider> + ) await act(async () => { await userEvent.click( screen.getAllByLabelText( diff --git a/yarn.lock b/yarn.lock index 2d6d223904c6bc03b803a01048cdd4ff893f46f8..40a519faf77d3213b90797cbe190abc9132139da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3211,6 +3211,11 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== +"@types/json-schema@^7.0.9": + version "7.0.15" + resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" + integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== + "@types/lodash@^4.14.149", "@types/lodash@^4.14.170", "@types/lodash@^4.14.175": version "4.14.182" resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2" @@ -3334,6 +3339,11 @@ resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.23.0.tgz#0a6655b3e2708eaabca00b7372fafd7a792a7b09" integrity sha512-YIoDCTH3Af6XM5VuwGG/QL/CJqga1Zm3NkU3HZ4ZHK2fRMPYP1VczsTUqtsf43PH/iJNVlPHAo2oWX7BSdB2Hw== +"@types/semver@^7.3.12": + version "7.5.8" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" + integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== + "@types/semver@^7.5.0": version "7.5.3" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.3.tgz#9a726e116beb26c24f1ccd6850201e1246122e04" @@ -3412,6 +3422,14 @@ "@typescript-eslint/visitor-keys" "6.19.1" debug "^4.3.4" +"@typescript-eslint/scope-manager@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.62.0.tgz#d9457ccc6a0b8d6b37d0eb252a23022478c5460c" + integrity sha512-VXuvVvZeQCQb5Zgf4HAxc04q5j+WrNAtNh9OwCsCgpKqESMTu3tF/jhZ3xG6T4NZwWl65Bg8KuS2uEvhSfLl0w== + dependencies: + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/visitor-keys" "5.62.0" + "@typescript-eslint/scope-manager@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-6.19.1.tgz#2f527ee30703a6169a52b31d42a1103d80acd51b" @@ -3472,6 +3490,11 @@ debug "^4.3.4" ts-api-utils "^1.3.0" +"@typescript-eslint/types@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f" + integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ== + "@typescript-eslint/types@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-6.19.1.tgz#2d4c9d492a63ede15e7ba7d129bdf7714b77f771" @@ -3497,6 +3520,19 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-8.9.0.tgz#b733af07fb340b32e962c6c63b1062aec2dc0fe6" integrity sha512-SjgkvdYyt1FAPhU9c6FiYCXrldwYYlIQLkuc+LfAhCna6ggp96ACncdtlbn8FmnG72tUkXclrDExOpEYf1nfJQ== +"@typescript-eslint/typescript-estree@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.62.0.tgz#7d17794b77fabcac615d6a48fb143330d962eb9b" + integrity sha512-CmcQ6uY7b9y694lKdRB8FEel7JbU/40iSAPomu++SjLMntB+2Leay2LO6i8VnJk58MtE9/nQSFIH6jpyRWyYzA== + dependencies: + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/visitor-keys" "5.62.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/typescript-estree@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-6.19.1.tgz#796d88d88882f12e85bb33d6d82d39e1aea54ed1" @@ -3589,6 +3625,20 @@ "@typescript-eslint/types" "8.8.1" "@typescript-eslint/typescript-estree" "8.8.1" +"@typescript-eslint/utils@^5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.62.0.tgz#141e809c71636e4a75daa39faed2fb5f4b10df86" + integrity sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ== + dependencies: + "@eslint-community/eslint-utils" "^4.2.0" + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.62.0" + "@typescript-eslint/types" "5.62.0" + "@typescript-eslint/typescript-estree" "5.62.0" + eslint-scope "^5.1.1" + semver "^7.3.7" + "@typescript-eslint/utils@^6.0.0 || ^7.0.0 || ^8.0.0": version "8.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-8.9.0.tgz#748bbe3ea5bee526d9786d9405cf1b0df081c299" @@ -3599,6 +3649,14 @@ "@typescript-eslint/types" "8.9.0" "@typescript-eslint/typescript-estree" "8.9.0" +"@typescript-eslint/visitor-keys@5.62.0": + version "5.62.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.62.0.tgz#2174011917ce582875954ffe2f6912d5931e353e" + integrity sha512-07ny+LHRzQXepkGg6w0mFY41fVUNBrL2Roj/++7V1txKugfjm/Ci/qSND03r2RhlJhJYMcTn9AhhSSqQp0Ysyw== + dependencies: + "@typescript-eslint/types" "5.62.0" + eslint-visitor-keys "^3.3.0" + "@typescript-eslint/visitor-keys@6.19.1": version "6.19.1" resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-6.19.1.tgz#2164073ed4fc34a5ff3b5e25bb5a442100454c4c" @@ -8437,6 +8495,13 @@ eslint-plugin-react@7.37.1: string.prototype.matchall "^4.0.11" string.prototype.repeat "^1.0.0" +eslint-plugin-testing-library@^6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-6.4.0.tgz#1ba8a7422e3e31cc315a73ff17c34908f56f9838" + integrity sha512-yeWF+YgCgvNyPNI9UKnG0FjeE2sk93N/3lsKqcmR8dSfeXJwFT5irnWo7NjLf152HkRzfoFjh3LsBUrhvFz4eA== + dependencies: + "@typescript-eslint/utils" "^5.62.0" + eslint-plugin-vue@5.2.3: version "5.2.3" resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-5.2.3.tgz#3ee7597d823b5478804b2feba9863b1b74273961" @@ -16115,7 +16180,7 @@ semver@^7.3.6, semver@^7.5.4: dependencies: lru-cache "^6.0.0" -semver@^7.6.0, semver@^7.6.3: +semver@^7.3.7, semver@^7.6.0, semver@^7.6.3: version "7.6.3" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A== @@ -17599,7 +17664,7 @@ ts-pattern@^5.4.0: resolved "https://registry.yarnpkg.com/ts-pattern/-/ts-pattern-5.4.0.tgz#efbe74d1ffbb63b80298dbc89b6ec442eab095fa" integrity sha512-hgfOMfjlrARCnYtGD/xEAkFHDXuSyuqjzFSltyQCbN689uNvoQL20TVN2XFcLMjfNuwSsQGU+xtH6MrjIwhwUg== -tslib@^1.11.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.11.1, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: version "1.14.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== @@ -17614,6 +17679,13 @@ tslib@^2.6.2: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.3.tgz#0438f810ad7a9edcde7a241c3d80db693c8cbfe0" integrity sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ== +tsutils@^3.21.0: + version "3.21.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623" + integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA== + dependencies: + tslib "^1.8.1" + tty-browserify@0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"