From f6334e73c667dbb0f2a114e52e4b67ca1af740c9 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Wed, 30 Aug 2023 14:36:57 +0000 Subject: [PATCH] refactor(tests): setup common mocks --- .vscode/settings.json | 1 + jest.config.js | 2 +- package.json | 1 + .../Action/ActionBegin/ActionBegin.spec.tsx | 28 +- .../__snapshots__/ActionBegin.spec.tsx.snap | 6 +- .../Action/ActionCard/ActionCard.spec.tsx | 18 +- .../Action/ActionChoose/ActionChoose.spec.tsx | 14 +- .../Action/ActionDone/ActionDone.spec.tsx | 22 +- .../Action/ActionList/ActionList.spec.tsx | 22 +- .../Action/ActionModal/ActionModal.spec.tsx | 17 +- .../ActionOnGoing/ActionOnGoing.spec.tsx | 14 - src/components/Action/ActionView.spec.tsx | 10 - src/components/Analysis/AnalysisView.spec.tsx | 10 +- .../ElecHalfHourChart.spec.tsx | 13 +- .../ElecHalfHourMonthlyAnalysis.spec.tsx | 37 +- .../ElecInfoModal.spec.tsx | 6 - .../IncompleteDataWarning.spec.tsx | 6 - .../MaxConsumptionCard.spec.tsx | 24 +- .../Analysis/MonthlyAnalysis.spec.tsx | 11 - .../ProfileComparator.spec.tsx | 46 +- .../ProfileComparatorRow.spec.tsx | 6 - .../TotalAnalysisChart/PieChart.spec.tsx | 6 - .../TotalAnalysisChart.spec.tsx | 5 - .../ChallengeCard/ChallengeCard.spec.tsx | 6 - .../ChallengeCardDone.spec.tsx | 31 +- .../ChallengeCardDone.spec.tsx.snap | 7 +- .../ChallengeCardLast.spec.tsx | 6 - .../ChallengeCardLocked.spec.tsx | 6 - .../ChallengeCardUnlocked.spec.tsx | 27 +- .../ChallengeNoFluidModal.spec.tsx | 6 - .../Challenge/ChallengeView.spec.tsx | 10 +- src/components/Charts/AxisBottom.spec.tsx | 3 - src/components/Charts/AxisRight.spec.tsx | 6 - src/components/Charts/Bar.spec.tsx | 10 - .../CommonKit/ErrorPage/ErrorPage.spec.tsx | 14 +- .../__snapshots__/ErrorPage.spec.tsx.snap | 284 +++++----- .../FormNavigation/FormNavigation.spec.tsx | 27 +- src/components/Connection/Connection.spec.tsx | 23 +- .../ExpiredConsentModal.spec.tsx | 8 +- .../DeleteGRDFAccountModal.spec.tsx | 6 - .../SGEConnect/SgeConnectView.spec.tsx | 10 - .../Connection/SGEConnect/SgeInit.spec.tsx | 5 - .../SGEConnect/SgeModalHint.spec.tsx | 6 - .../SGEConnect/StepAddress.spec.tsx | 5 - .../SGEConnect/StepConsent.spec.tsx | 5 - .../SGEConnect/StepIdentityAndPdl.spec.tsx | 5 - .../__snapshots__/Connection.spec.tsx.snap | 8 +- .../ConsumptionDetails.spec.tsx | 10 +- .../Consumption/ConsumptionView.spec.tsx | 24 +- .../FluidButtons/FluidButton.spec.tsx | 14 - .../FluidButtons/FluidButtons.spec.tsx | 14 - .../DataloadConsumptionVisualizer.spec.tsx | 22 +- .../DataloadNoValue.spec.tsx | 5 - .../DataloadSection.spec.tsx | 6 - .../DataloadSectionDetail.spec.tsx | 6 - .../DataloadSectionValue.spec.tsx | 6 - .../EstimatedConsumptionModal.spec.tsx | 14 +- .../InfoDataConsumptionVisualizer.spec.tsx | 9 - .../NoDataModal.spec.tsx | 6 - .../CustomPopup/CustomPopupModal.spec.tsx | 6 - .../DateNavigator/DateNavigator.spec.tsx | 6 - .../Duel/DuelError/DuelError.spec.tsx | 12 - .../Duel/DuelOngoing/DuelOngoing.spec.tsx | 36 +- .../DuelResultModal/DuelResultModal.spec.tsx | 21 - .../DuelResultModal.spec.tsx.snap | 14 +- .../Duel/DuelUnlocked/DuelUnlocked.spec.tsx | 38 +- src/components/Duel/DuelView.spec.tsx | 9 +- .../Duel/LastDuelModal/lastDuelModal.spec.tsx | 6 - .../EcogestureCard/EcogestureCard.spec.tsx | 19 - .../EcogestureCard.spec.tsx.snap | 206 ++++++- .../EcogestureEmptyList.spec.tsx | 7 +- .../EcogestureInitModal.spec.tsx | 21 - .../EcogestureList/EcogestureList.spec.tsx | 5 - .../EcogestureModal/EcogestureModal.spec.tsx | 14 - .../EcogestureReinitModal.spec.tsx | 14 - .../Ecogesture/EcogestureTabsView.spec.tsx | 62 +- .../EfficiencyRating.spec.tsx | 6 - .../Ecogesture/SingleEcogestureView.spec.tsx | 38 +- .../SingleEcogestureView.spec.tsx.snap | 532 +++++++++--------- .../EcogestureFormEquipment.spec.tsx | 13 +- .../EcogestureFormSingleChoice.spec.tsx | 14 - .../EcogestureFormView.spec.tsx | 17 +- .../EcogestureLaunchFormModal.spec.tsx | 6 - .../EquipmentIcon/EquipmentIcon.spec.tsx | 15 - .../__snapshots__/EquipmentIcon.spec.tsx.snap | 4 +- .../EcogestureSelectionDetail.spec.tsx | 22 - .../EcogestureSelectionDetail.spec.tsx.snap | 6 +- .../EcogestureSelectionEnd.spec.tsx | 7 +- .../EcogestureSelectionModal.spec.tsx | 6 - .../EcogestureSelectionRestart.spec.tsx | 10 - .../EcogestureSelectionView.spec.tsx | 36 +- .../Exploration/ExplorationError.spec.tsx | 12 - .../Exploration/ExplorationFinished.spec.tsx | 11 - .../Exploration/ExplorationOngoing.spec.tsx | 24 +- .../Exploration/ExplorationView.spec.tsx | 11 - .../Feedback/FeedbackModal.spec.tsx | 14 +- .../HalfHourNoData/HalfHourNoData.spec.tsx | 6 - .../TimeStepSelector.spec.tsx | 5 - src/components/Header/CozyBar.spec.tsx | 6 - src/components/Header/Header.spec.tsx | 6 - .../ConnectionNotFound.spec.tsx | 6 - .../Konnector/KonnectorModal.spec.tsx | 13 +- .../Konnector/KonnectorModalFooter.spec.tsx | 20 +- .../Konnector/KonnectorViewerList.spec.tsx | 8 - .../KonnectorModalFooter.spec.tsx.snap | 1 - src/components/Loader/Loader.spec.tsx | 6 - src/components/Navbar/Navbar.spec.tsx | 6 - .../Options/ExportData/ExportData.spec.tsx | 21 +- .../Modals/exportDoneModal.spec.tsx | 9 - .../Modals/exportLoadingModal.spec.tsx | 12 +- .../Modals/exportStartModal.spec.tsx | 9 - .../Options/GCU/GCUContent.spec.tsx | 20 - src/components/Options/GCU/GCULink.spec.tsx | 6 - .../__snapshots__/GCUContent.spec.tsx.snap | 289 +--------- .../LegalNotice/LegalNoticeContent.spec.tsx | 6 - .../LegalNotice/LegalNoticeLink.spec.tsx | 6 - .../MatomoOptOut/MatomoOptOut.spec.tsx | 6 - .../ProfileTypeOptions.spec.tsx | 11 - .../ReportOptions/ReportOptions.spec.tsx | 17 +- .../Unsubscribe/UnSubscribeView.spec.tsx | 16 +- .../PartnerIssue/PartnerIssueModal.spec.tsx | 6 - .../ProfileTypeFinished.spec.tsx | 18 +- .../ProfileTypeFormMultiChoice.spec.tsx | 22 +- .../ProfileTypeFormNumber.spec.tsx | 21 +- .../ProfileTypeFormNumberSelection.spec.tsx | 21 +- .../ProfileTypeFormSingleChoice.spec.tsx | 21 +- .../ProfileType/ProfileTypeView.spec.tsx | 14 - .../Quiz/QuizBegin/QuizBegin.spec.tsx | 14 +- .../Quiz/QuizFinish/QuizFinish.spec.tsx | 14 +- .../Quiz/QuizQuestion/QuizQuestion.spec.tsx | 14 - .../QuizQuestion/QuizQuestionContent.spec.tsx | 22 +- .../QuizQuestionContentCustom.spec.tsx | 24 +- src/components/Quiz/QuizView.spec.tsx | 11 - src/components/Splash/SplashRoot.spec.tsx | 6 - src/components/Splash/SplashScreen.spec.tsx | 6 - .../Splash/SplashScreenError.spec.tsx | 6 - src/components/Terms/CGUModal.spec.tsx | 6 - .../Terms/DataShareConsentContent.spec.tsx | 6 - .../Terms/LegalNoticeModal.spec.tsx | 6 - .../Terms/MinorUpdateContent.spec.tsx | 6 - src/components/Terms/TermsView.spec.tsx | 29 +- .../TotalConsumption.spec.tsx | 6 - .../WelcomeModal/WelcomeModal.spec.tsx | 45 +- src/migrations/migration.service.spec.ts | 4 +- src/migrations/migration.spec.ts | 2 +- src/services/account.service.spec.ts | 10 +- src/services/action.service.spec.ts | 70 +-- src/services/challenge.service.spec.ts | 35 +- src/services/connection.service.spec.ts | 26 +- src/services/consumption.service.spec.ts | 21 +- src/services/customPopup.service.test.ts | 10 +- src/services/duel.service.spec.ts | 20 +- src/services/ecogesture.service.spec.ts | 2 +- .../enedisMonthlyAnalysisData.service.spec.ts | 2 +- src/services/exploration.service.spec.ts | 2 +- src/services/fluid.service.spec.ts | 38 +- src/services/fluidsPrices.service.spec.ts | 2 +- src/services/initialization.service.spec.ts | 155 ++--- src/services/konnector.service.spec.ts | 12 +- src/services/konnectorStatus.service.spec.ts | 10 +- src/services/mail.service.spec.ts | 2 +- src/services/partnersInfo.service.spec.ts | 10 +- src/services/profile.service.spec.ts | 2 +- .../profileEcogesture.service.spec.ts | 2 +- src/services/profileType.service.spec.ts | 2 +- .../profileTypeEntity.service.spec.ts | 2 +- src/services/queryRunner.service.spec.ts | 2 +- src/services/quiz.service.spec.ts | 12 +- src/services/terms.service.spec.ts | 2 +- src/services/triggers.service.spec.ts | 10 +- src/services/usageEvent.service.spec.ts | 2 +- .../profileEcogesture.action.spec.ts | 10 +- tests/__mocks__/{client.ts => client.mock.ts} | 0 tests/__mocks__/store/store.ts | 2 +- tests/jestLib/setup.js | 37 -- tests/jestLib/setupTests.ts | 24 + yarn.lock | 15 + 177 files changed, 1066 insertions(+), 2631 deletions(-) rename tests/__mocks__/{client.ts => client.mock.ts} (100%) delete mode 100644 tests/jestLib/setup.js create mode 100644 tests/jestLib/setupTests.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 744ba2f95..44149075f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -52,6 +52,7 @@ "camelcase", "cicid", "CONSO", + "cozybar", "cozycloud", "d’éco", "dacc", diff --git a/jest.config.js b/jest.config.js index cbbdcfe6b..6358f0010 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,7 +2,7 @@ const config = { testURL: 'http://localhost/', moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'styl'], - setupFiles: ['<rootDir>/tests/jestLib/setup.js'], + setupFiles: ['<rootDir>/tests/jestLib/setupTests.ts'], moduleDirectories: ['<rootDir>', 'node_modules'], modulePaths: ['<rootDir>/src'], moduleNameMapper: { diff --git a/package.json b/package.json index b7f05b0d2..8ba4fe897 100644 --- a/package.json +++ b/package.json @@ -91,6 +91,7 @@ "@types/classnames": "^2.2.10", "@types/d3": "^6.0.0", "@types/enzyme": "^3.10.8", + "@types/enzyme-adapter-react-16": "^1.0.6", "@types/file-saver": "^2.0.5", "@types/history": "^5.0.0", "@types/jest": "^29.4.0", diff --git a/src/components/Action/ActionBegin/ActionBegin.spec.tsx b/src/components/Action/ActionBegin/ActionBegin.spec.tsx index 2abec2163..2c05f3c11 100644 --- a/src/components/Action/ActionBegin/ActionBegin.spec.tsx +++ b/src/components/Action/ActionBegin/ActionBegin.spec.tsx @@ -18,29 +18,14 @@ import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionModal from '../ActionModal/ActionModal' import ActionBegin from './ActionBegin' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockgetCustomActions = jest.fn() const mockgetDefaultActions = jest.fn() jest.mock('services/action.service', () => { - return jest.fn(() => { - return { - getCustomActions: mockgetCustomActions, - getDefaultActions: mockgetDefaultActions, - } - }) -}) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } + return jest.fn(() => ({ + getCustomActions: mockgetCustomActions, + getDefaultActions: mockgetDefaultActions, + })) }) describe('ActionBegin component', () => { @@ -49,7 +34,6 @@ describe('ActionBegin component', () => { global: { ...mockGlobalState, fluidTypes: [0, 1, 2] }, profile: mockProfileState, }) - mockImportIconById.mockReturnValue('') const wrapper = mount( <Provider store={store}> @@ -69,7 +53,6 @@ describe('ActionBegin component', () => { AllEcogestureData[5], AllEcogestureData[2], ]) - mockImportIconById.mockReturnValue('') const store = createMockEcolyoStore({ global: { ...mockGlobalState, fluidTypes: [0, 1, 2] }, profile: { ...mockProfileState, isProfileTypeCompleted: true }, @@ -91,7 +74,6 @@ describe('ActionBegin component', () => { global: { ...mockGlobalState, fluidTypes: [0, 1, 2] }, profile: mockProfileState, }) - mockImportIconById.mockReturnValue('') const wrapper = mount( <Provider store={store}> @@ -110,7 +92,6 @@ describe('ActionBegin component', () => { global: { ...mockGlobalState, fluidTypes: [0, 1, 2] }, profile: mockProfileState, }) - mockImportIconById.mockReturnValue('') const wrapper = mount( <Provider store={store}> @@ -131,7 +112,6 @@ describe('ActionBegin component', () => { global: { ...mockGlobalState, fluidTypes: [0, 1, 2] }, profile: mockProfileState, }) - mockImportIconById.mockReturnValue('') const wrapper = mount( <Provider store={store}> diff --git a/src/components/Action/ActionBegin/__snapshots__/ActionBegin.spec.tsx.snap b/src/components/Action/ActionBegin/__snapshots__/ActionBegin.spec.tsx.snap index bc15c7476..72c90f35e 100644 --- a/src/components/Action/ActionBegin/__snapshots__/ActionBegin.spec.tsx.snap +++ b/src/components/Action/ActionBegin/__snapshots__/ActionBegin.spec.tsx.snap @@ -203,13 +203,13 @@ exports[`ActionBegin component should render correctly 1`] = ` > <StyledIcon className="action-icon" - icon="" + icon="test-file-stub" size={100} > <Icon aria-hidden={true} className="action-icon" - icon="" + icon="test-file-stub" size={100} spin={false} > @@ -228,7 +228,7 @@ exports[`ActionBegin component should render correctly 1`] = ` width={100} > <use - xlinkHref="#" + xlinkHref="#test-file-stub" /> </svg> </Component> diff --git a/src/components/Action/ActionCard/ActionCard.spec.tsx b/src/components/Action/ActionCard/ActionCard.spec.tsx index 6b41863f9..fee4477b8 100644 --- a/src/components/Action/ActionCard/ActionCard.spec.tsx +++ b/src/components/Action/ActionCard/ActionCard.spec.tsx @@ -1,5 +1,4 @@ import { Button } from '@material-ui/core' -import defaultIcon from 'assets/icons/visu/duel/default.svg' import EcogestureModal from 'components/Ecogesture/EcogestureModal/EcogestureModal' import { mount } from 'enzyme' import toJson from 'enzyme-to-json' @@ -11,20 +10,6 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionCard from './ActionCard' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockImportIconById = jest.fn(() => defaultIcon) -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) describe('ActionCard component', () => { const store = createMockEcolyoStore({ challenge: { @@ -44,7 +29,7 @@ describe('ActionCard component', () => { await waitForComponentToPaint(wrapper) expect(toJson(wrapper)).toMatchSnapshot() }) - it('should open modal', () => { + it('should open modal', async () => { const wrapper = mount( <Provider store={store}> <ActionCard @@ -54,6 +39,7 @@ describe('ActionCard component', () => { /> </Provider> ) + await waitForComponentToPaint(wrapper) wrapper.find(Button).first().simulate('click') expect(wrapper.find(EcogestureModal).exists()).toBeTruthy() }) diff --git a/src/components/Action/ActionChoose/ActionChoose.spec.tsx b/src/components/Action/ActionChoose/ActionChoose.spec.tsx index ab20ba7b2..93f2bcdac 100644 --- a/src/components/Action/ActionChoose/ActionChoose.spec.tsx +++ b/src/components/Action/ActionChoose/ActionChoose.spec.tsx @@ -12,19 +12,11 @@ import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionBegin from '../ActionBegin/ActionBegin' import ActionChoose from './ActionChoose' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockGetEcogesturesByIds = jest.fn(() => []) jest.mock('services/ecogesture.service', () => { - return jest.fn(() => { - return { - getEcogesturesByIds: mockGetEcogesturesByIds, - } - }) + return jest.fn(() => ({ + getEcogesturesByIds: mockGetEcogesturesByIds, + })) }) describe('ActionChoose component', () => { diff --git a/src/components/Action/ActionDone/ActionDone.spec.tsx b/src/components/Action/ActionDone/ActionDone.spec.tsx index b48eee510..0716cc3b7 100644 --- a/src/components/Action/ActionDone/ActionDone.spec.tsx +++ b/src/components/Action/ActionDone/ActionDone.spec.tsx @@ -10,27 +10,15 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionDone from './ActionDone' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('services/usageEvent.service') const mockAddEvent = jest.fn() UsageEventService.addEvent = mockAddEvent -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) -const mockupdateUserChallenge = jest.fn() +const mockUpdateUserChallenge = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockupdateUserChallenge, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUpdateUserChallenge, + })) }) describe('ActionDone component', () => { @@ -49,7 +37,7 @@ describe('ActionDone component', () => { challengeActions, 'updateUserChallengeList' ) - mockupdateUserChallenge.mockResolvedValueOnce(userChallengeData[1]) + mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1]) const wrapper = mount( <Provider store={store}> <ActionDone currentChallenge={userChallengeData[1]} /> diff --git a/src/components/Action/ActionList/ActionList.spec.tsx b/src/components/Action/ActionList/ActionList.spec.tsx index a0237a2bc..e243a3a28 100644 --- a/src/components/Action/ActionList/ActionList.spec.tsx +++ b/src/components/Action/ActionList/ActionList.spec.tsx @@ -10,27 +10,19 @@ import { import ActionCard from '../ActionCard/ActionCard' import ActionList from './ActionList' -const mockgetCustomActions = jest.fn() -const mockgetDefaultActions = jest.fn() +const mockGetCustomActions = jest.fn() +const mockGetDefaultActions = jest.fn() jest.mock('services/action.service', () => { - return jest.fn(() => { - return { - getCustomActions: mockgetCustomActions, - getDefaultActions: mockgetDefaultActions, - } - }) + return jest.fn(() => ({ + getCustomActions: mockGetCustomActions, + getDefaultActions: mockGetDefaultActions, + })) }) -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ActionList component', () => { it('should be rendered correctly', () => { - mockgetDefaultActions.mockResolvedValueOnce(defaultEcogestureData) + mockGetDefaultActions.mockResolvedValueOnce(defaultEcogestureData) const store = createMockEcolyoStore({ challenge: { ...mockChallengeState }, global: { fluidTypes: [0, 1, 2] }, diff --git a/src/components/Action/ActionModal/ActionModal.spec.tsx b/src/components/Action/ActionModal/ActionModal.spec.tsx index 64b0d9209..9f54ea0a1 100644 --- a/src/components/Action/ActionModal/ActionModal.spec.tsx +++ b/src/components/Action/ActionModal/ActionModal.spec.tsx @@ -11,18 +11,11 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionModal from './ActionModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockupdateUserChallenge = jest.fn() +const mockUpdateUserChallenge = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockupdateUserChallenge, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUpdateUserChallenge, + })) }) jest.mock('services/usageEvent.service') const mockAddEvent = jest.fn() @@ -49,7 +42,7 @@ describe('ActionModal component', () => { challengeActions, 'updateUserChallengeList' ) - mockupdateUserChallenge.mockResolvedValueOnce(userChallengeData[1]) + mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1]) const wrapper = mount( <Provider store={store}> diff --git a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx index 3f2f8f492..de69a0814 100644 --- a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx +++ b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx @@ -12,20 +12,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import ActionOnGoing from './ActionOnGoing' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) - describe('ActionOnGoing component', () => { const store = createMockEcolyoStore() const userAction: UserAction = { diff --git a/src/components/Action/ActionView.spec.tsx b/src/components/Action/ActionView.spec.tsx index e34726252..8f8936c0d 100644 --- a/src/components/Action/ActionView.spec.tsx +++ b/src/components/Action/ActionView.spec.tsx @@ -11,16 +11,6 @@ import ActionChoose from './ActionChoose/ActionChoose' import ActionDone from './ActionDone/ActionDone' import ActionOnGoing from './ActionOnGoing/ActionOnGoing' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') diff --git a/src/components/Analysis/AnalysisView.spec.tsx b/src/components/Analysis/AnalysisView.spec.tsx index 1481e2c88..6045ccf90 100644 --- a/src/components/Analysis/AnalysisView.spec.tsx +++ b/src/components/Analysis/AnalysisView.spec.tsx @@ -12,11 +12,6 @@ import { mockProfileState, } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') @@ -40,10 +35,7 @@ const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') describe('AnalysisView component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - mockAppDispatch.mockClear() - toggleAnalysisNotificationSpy.mockClear() - updateProfileSpy.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', () => { diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourChart.spec.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourChart.spec.tsx index f0756b7ec..16f33ebce 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourChart.spec.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourChart.spec.tsx @@ -7,17 +7,10 @@ import { dataLoadArray } from 'tests/__mocks__/chartData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' import ElecHalfHourChart from './ElecHalfHourChart' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('services/dateChart.service', () => { - return jest.fn(() => { - return { - compareStepDate: jest.fn(), - } - }) + return jest.fn(() => ({ + compareStepDate: jest.fn(), + })) }) describe('ElecHalfHourChart component', () => { diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx index 72b8d6d0a..88c4aa8ec 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx @@ -13,11 +13,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import ElecHalfHourMonthlyAnalysis from './ElecHalfHourMonthlyAnalysis' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('components/Hooks/useExploration', () => { return () => ['', jest.fn()] }) @@ -33,21 +28,17 @@ jest.mock( const mockCheckDoctypeEntries = jest.fn() jest.mock('services/consumption.service', () => { - return jest.fn(() => { - return { - checkDoctypeEntries: mockCheckDoctypeEntries, - } - }) + return jest.fn(() => ({ + checkDoctypeEntries: mockCheckDoctypeEntries, + })) }) const mockGetEnedisMonthlyAnalysisByDate = jest.fn() const mockAggregateValuesToDataLoad = jest.fn() jest.mock('services/enedisMonthlyAnalysisData.service', () => { - return jest.fn(() => { - return { - getEnedisMonthlyAnalysisByDate: mockGetEnedisMonthlyAnalysisByDate, - aggregateValuesToDataLoad: mockAggregateValuesToDataLoad, - } - }) + return jest.fn(() => ({ + getEnedisMonthlyAnalysisByDate: mockGetEnedisMonthlyAnalysisByDate, + aggregateValuesToDataLoad: mockAggregateValuesToDataLoad, + })) }) const mockPerfIndicator: PerformanceIndicator = { value: 10, @@ -57,20 +48,16 @@ const mockPerfIndicator: PerformanceIndicator = { } const mockGetPrices = jest.fn() jest.mock('services/fluidsPrices.service', () => { - return jest.fn(() => { - return { - getPrices: mockGetPrices, - } - }) + return jest.fn(() => ({ + getPrices: mockGetPrices, + })) }) describe('ElecHalfHourMonthlyAnalysis component', () => { + const store = createMockEcolyoStore() beforeEach(() => { - mockCheckDoctypeEntries.mockClear() - mockGetEnedisMonthlyAnalysisByDate.mockClear() - mockAggregateValuesToDataLoad.mockClear() + jest.clearAllMocks() }) - const store = createMockEcolyoStore() it('should be rendered correctly when isHalfHourActivated is false', async () => { mockCheckDoctypeEntries.mockResolvedValueOnce(false) diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecInfoModal.spec.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecInfoModal.spec.tsx index 7dba81723..952434809 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecInfoModal.spec.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecInfoModal.spec.tsx @@ -3,12 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import ElecInfoModal from './ElecInfoModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ElecInfoModal component', () => { it('should be rendered correctly', () => { const component = mount( diff --git a/src/components/Analysis/IncompleteDataWarning/IncompleteDataWarning.spec.tsx b/src/components/Analysis/IncompleteDataWarning/IncompleteDataWarning.spec.tsx index c833c8c14..85a452c6d 100644 --- a/src/components/Analysis/IncompleteDataWarning/IncompleteDataWarning.spec.tsx +++ b/src/components/Analysis/IncompleteDataWarning/IncompleteDataWarning.spec.tsx @@ -3,12 +3,6 @@ import { mount } from 'enzyme' import React from 'react' import IncompleteDataWarning from './IncompleteDataWarning' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('IncompleteDataWarning', () => { it('renders component correctly', () => { const incompleteFluidTypes = [FluidType.ELECTRICITY, FluidType.GAS] diff --git a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx index 7b7e0363f..8dda88193 100644 --- a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx +++ b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx @@ -4,33 +4,17 @@ import toJson from 'enzyme-to-json' import React from 'react' import { Provider } from 'react-redux' import { graphData } from 'tests/__mocks__/chartData.mock' -import mockClient from 'tests/__mocks__/client' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import MaxConsumptionCard from './MaxConsumptionCard' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockGetMaxLoad = jest.fn(() => 0) const mockGetGraphData = jest.fn(() => graphData) jest.mock('services/consumption.service', () => { - return jest.fn(() => { - return { - getMaxLoad: mockGetMaxLoad, - getGraphData: mockGetGraphData, - } - }) -}) -jest.mock('cozy-client', () => { - return { - useClient: jest.fn(() => { - return mockClient - }), - } + return jest.fn(() => ({ + getMaxLoad: mockGetMaxLoad, + getGraphData: mockGetGraphData, + })) }) jest.mock('components/Charts/BarChart', () => 'mock-BarChart') diff --git a/src/components/Analysis/MonthlyAnalysis.spec.tsx b/src/components/Analysis/MonthlyAnalysis.spec.tsx index 243264d3a..b6f18e546 100644 --- a/src/components/Analysis/MonthlyAnalysis.spec.tsx +++ b/src/components/Analysis/MonthlyAnalysis.spec.tsx @@ -5,20 +5,9 @@ import { PerformanceIndicator } from 'models' import React from 'react' import { Provider } from 'react-redux' import { BrowserRouter } from 'react-router-dom' -import mockClient from 'tests/__mocks__/client' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -jest.mock('cozy-client', () => ({ - useClient: () => mockClient, -})) - const mockPI: PerformanceIndicator[] = [ { value: 5, compareValue: 10, percentageVariation: 50 }, { value: 5, compareValue: 10, percentageVariation: 50 }, diff --git a/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx b/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx index f8b37f957..6f8997cf4 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx @@ -15,39 +15,29 @@ import { createMockEcolyoStore, mockAnalysisState } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import ProfileComparator from './ProfileComparator' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: () => mockedNavigate, })) -const mockgetMonthlyForecast = jest.fn() +const mockGetMonthlyForecast = jest.fn() jest.mock('services/profileType.service', () => { - return jest.fn(() => { - return { - getMonthlyForecast: mockgetMonthlyForecast, - } - }) + return jest.fn(() => ({ + getMonthlyForecast: mockGetMonthlyForecast, + })) }) -const mockgetProfileTypeData = jest.fn() +const mockGetProfileTypeData = jest.fn() jest.mock('services/profileTypeEntity.service', () => { - return jest.fn(() => { - return { - getProfileType: mockgetProfileTypeData, - } - }) + return jest.fn(() => ({ + getProfileType: mockGetProfileTypeData, + })) }) jest.mock( 'components/Analysis/ProfileComparator/ProfileComparatorRow', - () => () => <div id="profilecomparatorrow" /> + () => 'mock-profileComparatorRow' ) const modifiedProfile = { ...profileData, isProfileTypeCompleted: true } @@ -93,7 +83,7 @@ describe('AnalysisConsumption component', () => { ) await waitForComponentToPaint(wrapper) expect(wrapper.find(Accordion).exists()).toBeTruthy() - expect(wrapper.find('#profilecomparatorrow').length).toBe(4) + expect(wrapper.find('mock-profileComparatorRow').length).toBe(4) }) it('should be rendered correctly with no profil set', async () => { @@ -132,7 +122,7 @@ describe('AnalysisConsumption component', () => { ) await waitForComponentToPaint(wrapper) expect(wrapper.find(Accordion).exists()).toBeTruthy() - expect(wrapper.find('#profilecomparatorrow').length).toBe(4) + expect(wrapper.find('mock-profileComparatorRow').length).toBe(4) }) it('should be rendered correctly without fluid', async () => { @@ -147,7 +137,7 @@ describe('AnalysisConsumption component', () => { ) await waitForComponentToPaint(wrapper) expect( - wrapper.find('#profilecomparatorrow').first().parent().prop('fluid') + wrapper.find('mock-profileComparatorRow').first().prop('fluid') ).toBe(FluidType.MULTIFLUID) }) @@ -163,7 +153,7 @@ describe('AnalysisConsumption component', () => { analysisMonth: profileData.monthlyAnalysisDate, }, }) - mockgetMonthlyForecast.mockReturnValue( + mockGetMonthlyForecast.mockReturnValue( mockMonthlyForecastJanuaryTestProfile1 ) const wrapper = mount( @@ -176,11 +166,11 @@ describe('AnalysisConsumption component', () => { </Provider> ) await waitForComponentToPaint(wrapper) - expect(mockgetMonthlyForecast).toHaveBeenCalledWith( + expect(mockGetMonthlyForecast).toHaveBeenCalledWith( profileData.monthlyAnalysisDate.month - 1 ) expect( - wrapper.find('#profilecomparatorrow').first().parent().prop('fluid') + wrapper.find('mock-profileComparatorRow').first().prop('fluid') ).toBe(FluidType.MULTIFLUID) }) @@ -190,7 +180,7 @@ describe('AnalysisConsumption component', () => { global: { fluidTypes: [FluidType.ELECTRICITY, FluidType.WATER] }, analysis: { analysisMonth: profileData.monthlyAnalysisDate }, }) - mockgetMonthlyForecast.mockReturnValue( + mockGetMonthlyForecast.mockReturnValue( mockMonthlyForecastJanuaryTestProfile1 ) const wrapper = mount( @@ -203,11 +193,11 @@ describe('AnalysisConsumption component', () => { </Provider> ) await waitForComponentToPaint(wrapper) - expect(mockgetMonthlyForecast).toHaveBeenCalledWith( + expect(mockGetMonthlyForecast).toHaveBeenCalledWith( profileData.monthlyAnalysisDate.month - 1 ) expect( - wrapper.find('#profilecomparatorrow').first().parent().prop('fluid') + wrapper.find('mock-profileComparatorRow').first().prop('fluid') ).toBe(FluidType.MULTIFLUID) }) diff --git a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx index 6c008806c..bf62f7867 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx @@ -5,12 +5,6 @@ import React from 'react' import { mockMonthlyForecastJanuaryTestProfile1 } from 'tests/__mocks__/profileType.mock' import ProfileComparatorRow from './ProfileComparatorRow' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('AnalysisConsumptionRow component', () => { const userPriceConsumption = 20 const homePriceConsumption = 18 diff --git a/src/components/Analysis/TotalAnalysisChart/PieChart.spec.tsx b/src/components/Analysis/TotalAnalysisChart/PieChart.spec.tsx index 064408f84..c866cabdf 100644 --- a/src/components/Analysis/TotalAnalysisChart/PieChart.spec.tsx +++ b/src/components/Analysis/TotalAnalysisChart/PieChart.spec.tsx @@ -5,12 +5,6 @@ import { DataloadValueDetail } from 'models' import React from 'react' import PieChart from './PieChart' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('PieChart component', () => { const mockDataloadValueDetailArray: DataloadValueDetail[] = [ { value: 10, state: DataloadState.VALID }, diff --git a/src/components/Analysis/TotalAnalysisChart/TotalAnalysisChart.spec.tsx b/src/components/Analysis/TotalAnalysisChart/TotalAnalysisChart.spec.tsx index 21effece2..4bcfcc3a6 100644 --- a/src/components/Analysis/TotalAnalysisChart/TotalAnalysisChart.spec.tsx +++ b/src/components/Analysis/TotalAnalysisChart/TotalAnalysisChart.spec.tsx @@ -10,11 +10,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import TotalAnalysisChart from './TotalAnalysisChart' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockGetGraphData = jest.fn() jest.mock('services/consumption.service', () => { return jest.fn(() => ({ diff --git a/src/components/Challenge/ChallengeCard/ChallengeCard.spec.tsx b/src/components/Challenge/ChallengeCard/ChallengeCard.spec.tsx index 51fdf9afc..9c4a0a2f2 100644 --- a/src/components/Challenge/ChallengeCard/ChallengeCard.spec.tsx +++ b/src/components/Challenge/ChallengeCard/ChallengeCard.spec.tsx @@ -6,12 +6,6 @@ import ChallengeCardOnGoing from '../ChallengeCardOnGoing/ChallengeCardOnGoing' import ChallengeCardUnlocked from '../ChallengeCardUnlocked/ChallengeCardUnlocked' import ChallengeCard from './ChallengeCard' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockMoveToSlide = jest.fn() describe('ChallengeCard component', () => { diff --git a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx index 73bf140fa..22af2203e 100644 --- a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx +++ b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx @@ -9,33 +9,11 @@ import * as storeHooks from 'store/hooks' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockFormatNumberValues = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => null), - formatNumberValues: jest.fn(() => mockFormatNumberValues), - getChallengeTitleWithLineReturn: jest.fn(() => 'Challenge 1'), - } -}) - -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - const mockUpdateUserChallenge = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUpdateUserChallenge, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUpdateUserChallenge, + })) }) const mockStore = configureStore([]) @@ -60,8 +38,7 @@ describe('ChallengeCardDone component', () => { describe('Reset final challenge', () => { beforeEach(() => { - mockUpdateUserChallenge.mockClear() - mockDispatch.mockClear() + jest.clearAllMocks() }) it('should reset challenge if no other challenge is on going', async () => { mockAppDispatch.mockImplementationOnce(() => mockDispatch) diff --git a/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap b/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap index 4065b79a9..5395d8e19 100644 --- a/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap +++ b/src/components/Challenge/ChallengeCardDone/__snapshots__/ChallengeCardDone.spec.tsx.snap @@ -164,7 +164,8 @@ exports[`ChallengeCardDone component should be rendered correctly 1`] = ` <div className="challengeName text-22-bold" > - Challenge 1 + Simone +VEILLE </div> <div className="iconResult" @@ -218,9 +219,7 @@ exports[`ChallengeCardDone component should be rendered correctly 1`] = ` <span className="text-18-bold" > - function () { - return fn.apply(this, arguments); - } + 0,00 € </span> <br /> diff --git a/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx b/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx index 027b0268a..b711bf01d 100644 --- a/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx +++ b/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx @@ -6,12 +6,6 @@ import ChallengeCardLast from './ChallengeCardLast' // Value coming from jest.config declare let __SAU_IDEA_DIRECT_LINK__: string -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ChallengeCardLast component', () => { it('should be rendered correctly', async () => { const wrapper = mount(<ChallengeCardLast />) diff --git a/src/components/Challenge/ChallengeCardLocked/ChallengeCardLocked.spec.tsx b/src/components/Challenge/ChallengeCardLocked/ChallengeCardLocked.spec.tsx index 08dfd9aa5..0cf83e9a1 100644 --- a/src/components/Challenge/ChallengeCardLocked/ChallengeCardLocked.spec.tsx +++ b/src/components/Challenge/ChallengeCardLocked/ChallengeCardLocked.spec.tsx @@ -3,12 +3,6 @@ import React from 'react' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ChallengeCardLocked from './ChallengeCardLocked' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ChallengeCardLocked component', () => { it('should be rendered correctly', () => { const component = shallow( diff --git a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx index 6fadd106a..04014cf96 100644 --- a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx +++ b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx @@ -1,5 +1,4 @@ import { Button } from '@material-ui/core' -import defaultIcon from 'assets/icons/visu/challenge/challengeLocked.svg' import { FluidType } from 'enums' import { mount } from 'enzyme' import React from 'react' @@ -15,27 +14,13 @@ import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ChallengeNoFluidModal from '../ChallengeNoFluidModal/ChallengeNoFluidModal' import ChallengeCardUnlocked from './ChallengeCardUnlocked' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockStartUserChallenge = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - startUserChallenge: mockStartUserChallenge, - } - }) -}) -const mockImportIconById = jest.fn(() => defaultIcon) -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => mockImportIconById), - getChallengeTitleWithLineReturn: jest.fn(() => 'Challenge 1'), - } + return jest.fn(() => ({ + startUserChallenge: mockStartUserChallenge, + })) }) + jest.mock('services/usageEvent.service') const mockAddEvent = jest.fn() UsageEventService.addEvent = mockAddEvent @@ -48,9 +33,7 @@ describe('ChallengeCardUnlocked component', () => { <ChallengeCardUnlocked userChallenge={userChallengeData[0]} /> </Provider> ) - expect(wrapper.find('.challengeTitle').text()).toEqual( - userChallengeData[0].title - ) + expect(wrapper.find('.challengeTitle').text()).toEqual('Simone\nVEILLE') expect(wrapper.find('.btn-duel-active').exists()).toBeTruthy() expect(wrapper.find(ChallengeNoFluidModal).exists()).toBeTruthy() expect(wrapper.find(ChallengeNoFluidModal).prop('open')).toBeFalsy() diff --git a/src/components/Challenge/ChallengeNoFluidModal/ChallengeNoFluidModal.spec.tsx b/src/components/Challenge/ChallengeNoFluidModal/ChallengeNoFluidModal.spec.tsx index e223c20f9..310572994 100644 --- a/src/components/Challenge/ChallengeNoFluidModal/ChallengeNoFluidModal.spec.tsx +++ b/src/components/Challenge/ChallengeNoFluidModal/ChallengeNoFluidModal.spec.tsx @@ -2,12 +2,6 @@ import { shallow } from 'enzyme' import React from 'react' import ChallengeNoFluidModal from './ChallengeNoFluidModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ChallengeNoFluidModal component', () => { it('should be rendered correctly opened', () => { const handleClose = jest.fn() diff --git a/src/components/Challenge/ChallengeView.spec.tsx b/src/components/Challenge/ChallengeView.spec.tsx index a28970ae9..1d8f8cb1a 100644 --- a/src/components/Challenge/ChallengeView.spec.tsx +++ b/src/components/Challenge/ChallengeView.spec.tsx @@ -6,12 +6,6 @@ import { Provider } from 'react-redux' import { challengeStateDataFull } from 'tests/__mocks__/challengeStateData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') @@ -19,6 +13,10 @@ jest.mock( 'components/Challenge/ChallengeCard/ChallengeCard', () => 'mock-challengecard' ) +jest.mock( + 'components/Challenge/ChallengeCard/ChallengeCard', + () => 'mock-challengecard' +) describe('ChallengeView component', () => { const store = createMockEcolyoStore({ diff --git a/src/components/Charts/AxisBottom.spec.tsx b/src/components/Charts/AxisBottom.spec.tsx index da25e6dc0..c10ede15c 100644 --- a/src/components/Charts/AxisBottom.spec.tsx +++ b/src/components/Charts/AxisBottom.spec.tsx @@ -29,9 +29,6 @@ describe('AxisBottom component test', () => { }), }, }) - beforeEach(() => { - store.clearActions() - }) it('should correctly render YEAR format of AxisBottom', () => { const wrapper = mount( diff --git a/src/components/Charts/AxisRight.spec.tsx b/src/components/Charts/AxisRight.spec.tsx index 1e3c9eb39..0ff617522 100644 --- a/src/components/Charts/AxisRight.spec.tsx +++ b/src/components/Charts/AxisRight.spec.tsx @@ -4,12 +4,6 @@ import { mount } from 'enzyme' import React from 'react' import AxisRight from './AxisRight' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockProps = { yScale: scaleLinear(), fluidType: FluidType.ELECTRICITY, diff --git a/src/components/Charts/Bar.spec.tsx b/src/components/Charts/Bar.spec.tsx index 83f0718f5..5c3056586 100644 --- a/src/components/Charts/Bar.spec.tsx +++ b/src/components/Charts/Bar.spec.tsx @@ -33,18 +33,8 @@ const mockParam = { } const setSelectedDateSpy = jest.spyOn(chartActions, 'setSelectedDate') -const setCurrentDatachartIndexSpy = jest.spyOn( - chartActions, - 'setCurrentDataChartIndex' -) describe('Bar component test', () => { - beforeEach(() => { - store.clearActions() - setSelectedDateSpy.mockClear() - setCurrentDatachartIndexSpy.mockClear() - }) - const store = createMockEcolyoStore({ chart: { selectedDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { diff --git a/src/components/CommonKit/ErrorPage/ErrorPage.spec.tsx b/src/components/CommonKit/ErrorPage/ErrorPage.spec.tsx index 685b0f43c..f14822572 100644 --- a/src/components/CommonKit/ErrorPage/ErrorPage.spec.tsx +++ b/src/components/CommonKit/ErrorPage/ErrorPage.spec.tsx @@ -5,23 +5,15 @@ import toJson from 'enzyme-to-json' import React from 'react' import ErrorPage from './ErrorPage' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: () => mockedNavigate, })) -jest.mock('components/Header/Header', () => () => <div id="Header" />) -jest.mock('components/Header/CozyBar', () => () => <div id="CozyBar" />) -// eslint-disable-next-line @typescript-eslint/no-explicit-any -jest.mock('components/Content/Content', () => (props: any) => ( - <div id="content">{props.children}</div> -)) +jest.mock('components/Header/Header', () => 'mock-header') +jest.mock('components/Header/CozyBar', () => 'mock-cozybar') +jest.mock('components/Content/Content', () => 'mock-content') describe('ErrorPage component', () => { it('should be rendered correctly', async () => { diff --git a/src/components/CommonKit/ErrorPage/__snapshots__/ErrorPage.spec.tsx.snap b/src/components/CommonKit/ErrorPage/__snapshots__/ErrorPage.spec.tsx.snap index e8c666f6a..f49c1b48e 100644 --- a/src/components/CommonKit/ErrorPage/__snapshots__/ErrorPage.spec.tsx.snap +++ b/src/components/CommonKit/ErrorPage/__snapshots__/ErrorPage.spec.tsx.snap @@ -5,122 +5,128 @@ exports[`ErrorPage component should be rendered correctly 1`] = ` returnPage="ecogestures" text="test" > - <Component + <mock-cozybar titleKey="error_page.main" - > - <div - id="CozyBar" - /> - </Component> - <Component + /> + <mock-header desktopTitleKey="error_page.main" setHeaderHeight={[Function]} - > - <div - id="Header" - /> - </Component> - <Component + /> + <mock-content heightOffset={0} > <div - id="content" + className="error-container" > - <div - className="error-container" + <StyledIcon + className="profile-icon" + icon="test-file-stub" + size={250} > - <StyledIcon + <Icon + aria-hidden={true} className="profile-icon" icon="test-file-stub" size={250} + spin={false} > - <Icon + <Component aria-hidden={true} - className="profile-icon" - icon="test-file-stub" - size={250} - spin={false} + className="profile-icon styles__icon___23x3R" + height={250} + style={Object {}} + width={250} > - <Component + <svg aria-hidden={true} className="profile-icon styles__icon___23x3R" height={250} style={Object {}} width={250} > - <svg - aria-hidden={true} - className="profile-icon styles__icon___23x3R" - height={250} - style={Object {}} - width={250} - > - <use - xlinkHref="#test-file-stub" - /> - </svg> - </Component> - </Icon> - </StyledIcon> - <div - className="text-18-bold head" - > - test - </div> - <WithStyles(ForwardRef(Button)) + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> + <div + className="text-18-bold head" + > + test + </div> + <WithStyles(ForwardRef(Button)) + aria-label="error_page.back" + classes={ + Object { + "label": "text-18-bold", + "root": "btn-highlight", + } + } + onClick={[Function]} + type="submit" + variant="contained" + > + <ForwardRef(Button) aria-label="error_page.back" classes={ Object { - "label": "text-18-bold", - "root": "btn-highlight", + "colorInherit": "MuiButton-colorInherit", + "contained": "MuiButton-contained", + "containedPrimary": "MuiButton-containedPrimary", + "containedSecondary": "MuiButton-containedSecondary", + "containedSizeLarge": "MuiButton-containedSizeLarge", + "containedSizeSmall": "MuiButton-containedSizeSmall", + "disableElevation": "MuiButton-disableElevation", + "disabled": "Mui-disabled", + "endIcon": "MuiButton-endIcon", + "focusVisible": "Mui-focusVisible", + "fullWidth": "MuiButton-fullWidth", + "iconSizeLarge": "MuiButton-iconSizeLarge", + "iconSizeMedium": "MuiButton-iconSizeMedium", + "iconSizeSmall": "MuiButton-iconSizeSmall", + "label": "MuiButton-label text-18-bold", + "outlined": "MuiButton-outlined", + "outlinedPrimary": "MuiButton-outlinedPrimary", + "outlinedSecondary": "MuiButton-outlinedSecondary", + "outlinedSizeLarge": "MuiButton-outlinedSizeLarge", + "outlinedSizeSmall": "MuiButton-outlinedSizeSmall", + "root": "MuiButton-root btn-highlight", + "sizeLarge": "MuiButton-sizeLarge", + "sizeSmall": "MuiButton-sizeSmall", + "startIcon": "MuiButton-startIcon", + "text": "MuiButton-text", + "textPrimary": "MuiButton-textPrimary", + "textSecondary": "MuiButton-textSecondary", + "textSizeLarge": "MuiButton-textSizeLarge", + "textSizeSmall": "MuiButton-textSizeSmall", } } onClick={[Function]} type="submit" variant="contained" > - <ForwardRef(Button) + <WithStyles(ForwardRef(ButtonBase)) aria-label="error_page.back" - classes={ - Object { - "colorInherit": "MuiButton-colorInherit", - "contained": "MuiButton-contained", - "containedPrimary": "MuiButton-containedPrimary", - "containedSecondary": "MuiButton-containedSecondary", - "containedSizeLarge": "MuiButton-containedSizeLarge", - "containedSizeSmall": "MuiButton-containedSizeSmall", - "disableElevation": "MuiButton-disableElevation", - "disabled": "Mui-disabled", - "endIcon": "MuiButton-endIcon", - "focusVisible": "Mui-focusVisible", - "fullWidth": "MuiButton-fullWidth", - "iconSizeLarge": "MuiButton-iconSizeLarge", - "iconSizeMedium": "MuiButton-iconSizeMedium", - "iconSizeSmall": "MuiButton-iconSizeSmall", - "label": "MuiButton-label text-18-bold", - "outlined": "MuiButton-outlined", - "outlinedPrimary": "MuiButton-outlinedPrimary", - "outlinedSecondary": "MuiButton-outlinedSecondary", - "outlinedSizeLarge": "MuiButton-outlinedSizeLarge", - "outlinedSizeSmall": "MuiButton-outlinedSizeSmall", - "root": "MuiButton-root btn-highlight", - "sizeLarge": "MuiButton-sizeLarge", - "sizeSmall": "MuiButton-sizeSmall", - "startIcon": "MuiButton-startIcon", - "text": "MuiButton-text", - "textPrimary": "MuiButton-textPrimary", - "textSecondary": "MuiButton-textSecondary", - "textSizeLarge": "MuiButton-textSizeLarge", - "textSizeSmall": "MuiButton-textSizeSmall", - } - } + className="MuiButton-root btn-highlight MuiButton-contained" + component="button" + disabled={false} + focusRipple={true} + focusVisibleClassName="Mui-focusVisible" onClick={[Function]} type="submit" - variant="contained" > - <WithStyles(ForwardRef(ButtonBase)) + <ForwardRef(ButtonBase) aria-label="error_page.back" className="MuiButton-root btn-highlight MuiButton-contained" + classes={ + Object { + "disabled": "Mui-disabled", + "focusVisible": "Mui-focusVisible", + "root": "MuiButtonBase-root", + } + } component="button" disabled={false} focusRipple={true} @@ -128,82 +134,64 @@ exports[`ErrorPage component should be rendered correctly 1`] = ` onClick={[Function]} type="submit" > - <ForwardRef(ButtonBase) + <button aria-label="error_page.back" - className="MuiButton-root btn-highlight MuiButton-contained" - classes={ - Object { - "disabled": "Mui-disabled", - "focusVisible": "Mui-focusVisible", - "root": "MuiButtonBase-root", - } - } - component="button" + className="MuiButtonBase-root MuiButton-root btn-highlight MuiButton-contained" disabled={false} - focusRipple={true} - focusVisibleClassName="Mui-focusVisible" + onBlur={[Function]} onClick={[Function]} + onDragLeave={[Function]} + onFocus={[Function]} + onKeyDown={[Function]} + onKeyUp={[Function]} + onMouseDown={[Function]} + onMouseLeave={[Function]} + onMouseUp={[Function]} + onTouchEnd={[Function]} + onTouchMove={[Function]} + onTouchStart={[Function]} + tabIndex={0} type="submit" > - <button - aria-label="error_page.back" - className="MuiButtonBase-root MuiButton-root btn-highlight MuiButton-contained" - disabled={false} - onBlur={[Function]} - onClick={[Function]} - onDragLeave={[Function]} - onFocus={[Function]} - onKeyDown={[Function]} - onKeyUp={[Function]} - onMouseDown={[Function]} - onMouseLeave={[Function]} - onMouseUp={[Function]} - onTouchEnd={[Function]} - onTouchMove={[Function]} - onTouchStart={[Function]} - tabIndex={0} - type="submit" + <span + className="MuiButton-label text-18-bold" > - <span - className="MuiButton-label text-18-bold" - > - error_page.back - </span> - <WithStyles(memo) + error_page.back + </span> + <WithStyles(memo) + center={false} + > + <ForwardRef(TouchRipple) center={false} - > - <ForwardRef(TouchRipple) - center={false} - classes={ - Object { - "child": "MuiTouchRipple-child", - "childLeaving": "MuiTouchRipple-childLeaving", - "childPulsate": "MuiTouchRipple-childPulsate", - "ripple": "MuiTouchRipple-ripple", - "ripplePulsate": "MuiTouchRipple-ripplePulsate", - "rippleVisible": "MuiTouchRipple-rippleVisible", - "root": "MuiTouchRipple-root", - } + classes={ + Object { + "child": "MuiTouchRipple-child", + "childLeaving": "MuiTouchRipple-childLeaving", + "childPulsate": "MuiTouchRipple-childPulsate", + "ripple": "MuiTouchRipple-ripple", + "ripplePulsate": "MuiTouchRipple-ripplePulsate", + "rippleVisible": "MuiTouchRipple-rippleVisible", + "root": "MuiTouchRipple-root", } + } + > + <span + className="MuiTouchRipple-root" > - <span - className="MuiTouchRipple-root" - > - <TransitionGroup - childFactory={[Function]} - component={null} - exit={true} - /> - </span> - </ForwardRef(TouchRipple)> - </WithStyles(memo)> - </button> - </ForwardRef(ButtonBase)> - </WithStyles(ForwardRef(ButtonBase))> - </ForwardRef(Button)> - </WithStyles(ForwardRef(Button))> - </div> + <TransitionGroup + childFactory={[Function]} + component={null} + exit={true} + /> + </span> + </ForwardRef(TouchRipple)> + </WithStyles(memo)> + </button> + </ForwardRef(ButtonBase)> + </WithStyles(ForwardRef(ButtonBase))> + </ForwardRef(Button)> + </WithStyles(ForwardRef(Button))> </div> - </Component> + </mock-content> </ErrorPage> `; diff --git a/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx b/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx index 8703cfe9d..27cd6d1ee 100644 --- a/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx +++ b/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx @@ -6,33 +6,18 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import FormNavigation from './FormNavigation' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('FormNavigation component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { - const mockhandlePrevious = jest.fn() - const mockhandleNext = jest.fn() + const mockHandlePrevious = jest.fn() + const mockHandleNext = jest.fn() const wrapper = mount( <Provider store={store}> <FormNavigation step={ProfileTypeStepForm.COOKING_FLUID} - handlePrevious={mockhandlePrevious} - handleNext={mockhandleNext} + handlePrevious={mockHandlePrevious} + handleNext={mockHandleNext} disableNextButton={false} /> </Provider> @@ -41,7 +26,7 @@ describe('FormNavigation component', () => { wrapper.find(Button).at(1).simulate('click') expect(wrapper.find('profile-navigation')).toBeTruthy() expect(wrapper.find(Button)).toBeTruthy() - expect(mockhandlePrevious.mock.calls.length).toEqual(1) - expect(mockhandleNext.mock.calls.length).toEqual(1) + expect(mockHandlePrevious.mock.calls.length).toEqual(1) + expect(mockHandleNext.mock.calls.length).toEqual(1) }) }) diff --git a/src/components/Connection/Connection.spec.tsx b/src/components/Connection/Connection.spec.tsx index c1fd7f53c..c5915516a 100644 --- a/src/components/Connection/Connection.spec.tsx +++ b/src/components/Connection/Connection.spec.tsx @@ -6,28 +6,9 @@ import { Provider } from 'react-redux' import { fluidStatusConnectedData } from 'tests/__mocks__/fluidStatusData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' -jest.mock('components/Connection/EPGLConnect/EpglInit', () => { - return jest.fn(() => { - return <div id="EpglInit" /> - }) -}) - -jest.mock('components/Connection/GRDFConnect/GrdfInit', () => { - return jest.fn(() => { - return <div id="GrdfInit" /> - }) -}) +jest.mock('components/Connection/EPGLConnect/EpglInit', () => 'mock-EpglInit') -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +jest.mock('components/Connection/GRDFConnect/GrdfInit', () => 'mock-GrdfInit') describe('Connection component test', () => { const store = createMockEcolyoStore() diff --git a/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx b/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx index b03a29c2a..de738abe4 100644 --- a/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx +++ b/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx @@ -9,11 +9,6 @@ import { fluidStatusConnectedData } from 'tests/__mocks__/fluidStatusData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' import ExpiredConsentModal from './ExpiredConsentModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -26,8 +21,7 @@ const mockHandleCloseClick = jest.fn() describe('ExpiredConsentModal component', () => { const store = createMockEcolyoStore() beforeEach(() => { - mockedNavigate.mockReset() - mockAppDispatch.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', () => { const component = mount( diff --git a/src/components/Connection/GRDFDeleteAccountModal/DeleteGRDFAccountModal.spec.tsx b/src/components/Connection/GRDFDeleteAccountModal/DeleteGRDFAccountModal.spec.tsx index 93cea948d..ea7676933 100644 --- a/src/components/Connection/GRDFDeleteAccountModal/DeleteGRDFAccountModal.spec.tsx +++ b/src/components/Connection/GRDFDeleteAccountModal/DeleteGRDFAccountModal.spec.tsx @@ -4,12 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import DeleteGRDFAccountModal from './DeleteGRDFAccountModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('DeleteGRDFAccountModal component', () => { it('should be rendered correctly', () => { const component = mount( diff --git a/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx b/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx index 0c577af1b..30d79f957 100644 --- a/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx +++ b/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx @@ -7,16 +7,6 @@ import * as storeHooks from 'store/hooks' import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import SgeConnectView from './SgeConnectView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) jest.mock('components/Content/Content', () => 'mock-content') jest.mock('components/Header/CozyBar', () => 'mock-cozybar') diff --git a/src/components/Connection/SGEConnect/SgeInit.spec.tsx b/src/components/Connection/SGEConnect/SgeInit.spec.tsx index 3f1b2bc7d..840893b54 100644 --- a/src/components/Connection/SGEConnect/SgeInit.spec.tsx +++ b/src/components/Connection/SGEConnect/SgeInit.spec.tsx @@ -11,11 +11,6 @@ import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import SgeInit from './SgeInit' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/src/components/Connection/SGEConnect/SgeModalHint.spec.tsx b/src/components/Connection/SGEConnect/SgeModalHint.spec.tsx index 316d9e0f3..eab06f6c6 100644 --- a/src/components/Connection/SGEConnect/SgeModalHint.spec.tsx +++ b/src/components/Connection/SGEConnect/SgeModalHint.spec.tsx @@ -5,12 +5,6 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import SgeModalHint from './SgeModalHint' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('SgeModalHint component', () => { it('should be rendered correctly', () => { const mockClose = jest.fn() diff --git a/src/components/Connection/SGEConnect/StepAddress.spec.tsx b/src/components/Connection/SGEConnect/StepAddress.spec.tsx index 500aa61c3..785ca968a 100644 --- a/src/components/Connection/SGEConnect/StepAddress.spec.tsx +++ b/src/components/Connection/SGEConnect/StepAddress.spec.tsx @@ -5,11 +5,6 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import StepAddress from './StepAddress' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockHandleChange = jest.fn() describe('StepAddress component', () => { diff --git a/src/components/Connection/SGEConnect/StepConsent.spec.tsx b/src/components/Connection/SGEConnect/StepConsent.spec.tsx index f1e6c7136..c2ca84554 100644 --- a/src/components/Connection/SGEConnect/StepConsent.spec.tsx +++ b/src/components/Connection/SGEConnect/StepConsent.spec.tsx @@ -5,11 +5,6 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import StepConsent from './StepConsent' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockHandleChange = jest.fn() describe('StepConsent component', () => { diff --git a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx index 9e92e0205..562541f5d 100644 --- a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx +++ b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx @@ -5,11 +5,6 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import StepIdentityAndPdl from './StepIdentityAndPdl' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockHandleChange = jest.fn() describe('StepIdentityAndPdl component', () => { diff --git a/src/components/Connection/__snapshots__/Connection.spec.tsx.snap b/src/components/Connection/__snapshots__/Connection.spec.tsx.snap index 16d66b146..3579c54ab 100644 --- a/src/components/Connection/__snapshots__/Connection.spec.tsx.snap +++ b/src/components/Connection/__snapshots__/Connection.spec.tsx.snap @@ -447,7 +447,7 @@ exports[`Connection component test should call GrdfInit 1`] = ` <div className="konnector-form" > - <mockConstructor + <mock-GrdfInit fluidStatus={ Object { "connection": Object { @@ -473,11 +473,7 @@ exports[`Connection component test should call GrdfInit 1`] = ` } } onSuccess={[Function]} - > - <div - id="GrdfInit" - /> - </mockConstructor> + /> </div> </Connection> </Provider> diff --git a/src/components/Consumption/ConsumptionDetails/ConsumptionDetails.spec.tsx b/src/components/Consumption/ConsumptionDetails/ConsumptionDetails.spec.tsx index b711a5769..6268e2f34 100644 --- a/src/components/Consumption/ConsumptionDetails/ConsumptionDetails.spec.tsx +++ b/src/components/Consumption/ConsumptionDetails/ConsumptionDetails.spec.tsx @@ -7,17 +7,9 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import ConsumptionDetails from './ConsumptionDetails' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ConsumptionDetails component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) + it('should be rendered correctly', async () => { const wrapper = mount( <Provider store={store}> diff --git a/src/components/Consumption/ConsumptionView.spec.tsx b/src/components/Consumption/ConsumptionView.spec.tsx index 7c2a6f0cb..bb036742c 100644 --- a/src/components/Consumption/ConsumptionView.spec.tsx +++ b/src/components/Consumption/ConsumptionView.spec.tsx @@ -18,24 +18,12 @@ import { } from 'tests/__mocks__/store' import ConsumptionView from './ConsumptionView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockUpdateProfile = jest.fn() jest.mock('services/profile.service', () => { - return jest.fn(() => { - return { - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + updateProfile: mockUpdateProfile, + })) }) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') @@ -77,12 +65,6 @@ mockFluidStatus[FluidType.ELECTRICITY].status = FluidState.DONE const mockChartStateShowOffline = { ...mockChartState, showOfflineData: true } describe('ConsumptionView component', () => { - const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - setCurrentTimeStepSpy.mockClear() - }) - it('should be rendered correctly', async () => { const store = createMockEcolyoStore({ chart: { diff --git a/src/components/Consumption/FluidButtons/FluidButton.spec.tsx b/src/components/Consumption/FluidButtons/FluidButton.spec.tsx index 04ed871e4..28699710e 100644 --- a/src/components/Consumption/FluidButtons/FluidButton.spec.tsx +++ b/src/components/Consumption/FluidButtons/FluidButton.spec.tsx @@ -9,22 +9,8 @@ import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import FluidButton from './FluidButton' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('FluidButton component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/Consumption/FluidButtons/FluidButtons.spec.tsx b/src/components/Consumption/FluidButtons/FluidButtons.spec.tsx index 50cf24a07..4517997e1 100644 --- a/src/components/Consumption/FluidButtons/FluidButtons.spec.tsx +++ b/src/components/Consumption/FluidButtons/FluidButtons.spec.tsx @@ -7,22 +7,8 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import FluidButtons from './FluidButtons' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('FluidButtons component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.spec.tsx b/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.spec.tsx index 55db7ace8..35226df5e 100644 --- a/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadConsumptionVisualizer.spec.tsx @@ -11,19 +11,11 @@ import { createMockEcolyoStore, mockChartState } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import DataloadConsumptionVisualizer from './DataloadConsumptionVisualizer' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockGetAllLastPrices = jest.fn() jest.mock('services/fluidsPrices.service', () => { - return jest.fn(() => { - return { - getAllLastPrices: mockGetAllLastPrices, - } - }) + return jest.fn(() => ({ + getAllLastPrices: mockGetAllLastPrices, + })) }) const mockChartStateLoaded = { ...mockChartState, loading: false } @@ -131,11 +123,9 @@ describe('Dataload consumption visualizer component', () => { }) const mockLoadToEuro = jest.fn() jest.mock('services/converter.service', () => { - return jest.fn(() => { - return { - LoadToEuro: mockLoadToEuro, - } - }) + return jest.fn(() => ({ + LoadToEuro: mockLoadToEuro, + })) }) const wrapper = mount( diff --git a/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx b/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx index 2b0e5ab96..28f63e557 100644 --- a/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx @@ -6,11 +6,6 @@ import React from 'react' import { baseDataLoad } from 'tests/__mocks__/chartData.mock' import DataloadNoValue from './DataloadNoValue' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockSetActive = jest.fn() describe('DataloadNoValue component', () => { diff --git a/src/components/ConsumptionVisualizer/DataloadSection.spec.tsx b/src/components/ConsumptionVisualizer/DataloadSection.spec.tsx index 84ab4e32d..aef6fc33e 100644 --- a/src/components/ConsumptionVisualizer/DataloadSection.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSection.spec.tsx @@ -6,12 +6,6 @@ import React from 'react' import { baseDataLoad } from 'tests/__mocks__/chartData.mock' import DataloadSection from './DataloadSection' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - jest.mock( 'components/ConsumptionVisualizer/DataloadSectionValue', () => 'mock-dataloadsectionvalue' diff --git a/src/components/ConsumptionVisualizer/DataloadSectionDetail.spec.tsx b/src/components/ConsumptionVisualizer/DataloadSectionDetail.spec.tsx index fd38a9ca2..144cbc4d6 100644 --- a/src/components/ConsumptionVisualizer/DataloadSectionDetail.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSectionDetail.spec.tsx @@ -6,12 +6,6 @@ import React from 'react' import { baseDataLoad } from 'tests/__mocks__/chartData.mock' import DataloadSectionDetail from './DataloadSectionDetail' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('DataloadSectionDetail component', () => { const mockDataload: Dataload = baseDataLoad diff --git a/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx b/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx index c20320527..799209817 100644 --- a/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx @@ -9,12 +9,6 @@ import { } from 'tests/__mocks__/chartData.mock' import DataloadSectionValue from './DataloadSectionValue' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockToggleEstimationModal = jest.fn() describe('DataloadSectionValue component', () => { diff --git a/src/components/ConsumptionVisualizer/EstimatedConsumptionModal.spec.tsx b/src/components/ConsumptionVisualizer/EstimatedConsumptionModal.spec.tsx index 250e959f5..b7e025619 100644 --- a/src/components/ConsumptionVisualizer/EstimatedConsumptionModal.spec.tsx +++ b/src/components/ConsumptionVisualizer/EstimatedConsumptionModal.spec.tsx @@ -3,19 +3,11 @@ import toJson from 'enzyme-to-json' import React from 'react' import EstimatedConsumptionModal from './EstimatedConsumptionModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockGetAllLastPrices = jest.fn() jest.mock('services/fluidsPrices.service', () => { - return jest.fn(() => { - return { - getAllLastPrices: mockGetAllLastPrices, - } - }) + return jest.fn(() => ({ + getAllLastPrices: mockGetAllLastPrices, + })) }) describe('EstimatedConsumptionModal component', () => { diff --git a/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx b/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx index 6f230b8b3..8dd1a1c77 100644 --- a/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx +++ b/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx @@ -11,12 +11,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import InfoDataConsumptionVisualizer from './InfoDataConsumptionVisualizer' import NoDataModal from './NoDataModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch') describe('InfoDataConsumptionVisualizer component', () => { @@ -26,9 +20,6 @@ describe('InfoDataConsumptionVisualizer component', () => { const mockDataload: Dataload = baseDataLoad const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should render correctly when data valid', () => { const wrapper = mount( diff --git a/src/components/ConsumptionVisualizer/NoDataModal.spec.tsx b/src/components/ConsumptionVisualizer/NoDataModal.spec.tsx index 44fa9239f..3f79b27a9 100644 --- a/src/components/ConsumptionVisualizer/NoDataModal.spec.tsx +++ b/src/components/ConsumptionVisualizer/NoDataModal.spec.tsx @@ -3,12 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import NoDataModal from './NoDataModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('NoDataModal component', () => { it('should render correctly', async () => { const wrapper = mount( diff --git a/src/components/CustomPopup/CustomPopupModal.spec.tsx b/src/components/CustomPopup/CustomPopupModal.spec.tsx index b16023eb1..5c7a807be 100644 --- a/src/components/CustomPopup/CustomPopupModal.spec.tsx +++ b/src/components/CustomPopup/CustomPopupModal.spec.tsx @@ -9,12 +9,6 @@ import { } from 'tests/__mocks__/customPopup.mock' import CustomPopupModal from './CustomPopupModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() describe('CustomPopupModal component', () => { diff --git a/src/components/DateNavigator/DateNavigator.spec.tsx b/src/components/DateNavigator/DateNavigator.spec.tsx index b9dedb9d2..8cd2494ef 100644 --- a/src/components/DateNavigator/DateNavigator.spec.tsx +++ b/src/components/DateNavigator/DateNavigator.spec.tsx @@ -7,12 +7,6 @@ import React from 'react' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import DateNavigator from './DateNavigator' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - jest.mock( 'components/DateNavigator/DateNavigatorFormat', () => 'mock-date-navigator-format' diff --git a/src/components/Duel/DuelError/DuelError.spec.tsx b/src/components/Duel/DuelError/DuelError.spec.tsx index 38538b7fc..c8763df63 100644 --- a/src/components/Duel/DuelError/DuelError.spec.tsx +++ b/src/components/Duel/DuelError/DuelError.spec.tsx @@ -2,18 +2,6 @@ import { shallow } from 'enzyme' import React from 'react' import DuelError from './DuelError' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('DuelError component', () => { it('should be rendered correctly', () => { const component = shallow(<DuelError />).getElement() diff --git a/src/components/Duel/DuelOngoing/DuelOngoing.spec.tsx b/src/components/Duel/DuelOngoing/DuelOngoing.spec.tsx index 7345593c2..2f9eb9c8d 100644 --- a/src/components/Duel/DuelOngoing/DuelOngoing.spec.tsx +++ b/src/components/Duel/DuelOngoing/DuelOngoing.spec.tsx @@ -10,42 +10,15 @@ import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import DuelResultModal from '../DuelResultModal/DuelResultModal' import DuelOngoing from './DuelOngoing' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockUserChallengeUpdateFlag = jest.fn() const mockIsChallengeDone = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - isChallengeDone: mockIsChallengeDone, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + isChallengeDone: mockIsChallengeDone, + })) }) -const mockHistoryPush = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => ({ - push: mockHistoryPush, - }), -})) -const mockImportIconById = jest.fn() -const mockFormatNumberValues = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - formatNumberValues: jest.fn(() => { - return mockFormatNumberValues - }), - } -}) jest.mock('components/Duel/DuelChart/DuelChart', () => 'mock-duelchart') jest.mock( 'components/Duel/DuelResultModal/DuelResultModal', @@ -60,7 +33,6 @@ describe('DuelOngoing component', () => { isWin: false, isEmpty: false, }) - mockFormatNumberValues.mockReturnValue('20') const wrapper = mount( <Provider store={store}> <DuelOngoing userChallenge={userChallengeData[0]} /> diff --git a/src/components/Duel/DuelResultModal/DuelResultModal.spec.tsx b/src/components/Duel/DuelResultModal/DuelResultModal.spec.tsx index 6e6836060..4a73f4cf3 100644 --- a/src/components/Duel/DuelResultModal/DuelResultModal.spec.tsx +++ b/src/components/Duel/DuelResultModal/DuelResultModal.spec.tsx @@ -5,27 +5,8 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import DuelResultModal from './DuelResultModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -const mockFormatNumberValues = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - formatNumberValues: jest.fn(() => { - return mockFormatNumberValues - }), - } -}) - describe('DuelResultModal component', () => { it('should render correctly', async () => { - mockImportIconById.mockReturnValue('') const wrapper = mount( <DuelResultModal open={true} @@ -38,8 +19,6 @@ describe('DuelResultModal component', () => { expect(toJson(wrapper)).toMatchSnapshot() }) it('should render a loss modal', async () => { - mockImportIconById.mockReturnValue('') - const wrapper = mount( <DuelResultModal open={true} diff --git a/src/components/Duel/DuelResultModal/__snapshots__/DuelResultModal.spec.tsx.snap b/src/components/Duel/DuelResultModal/__snapshots__/DuelResultModal.spec.tsx.snap index 4a87bdd34..99029ebbc 100644 --- a/src/components/Duel/DuelResultModal/__snapshots__/DuelResultModal.spec.tsx.snap +++ b/src/components/Duel/DuelResultModal/__snapshots__/DuelResultModal.spec.tsx.snap @@ -573,7 +573,7 @@ exports[`DuelResultModal component should render correctly 1`] = ` width="180" > <use - xlink:href="#" + xlink:href="#test-file-stub" /> </svg> </div> @@ -585,9 +585,7 @@ exports[`DuelResultModal component should render correctly 1`] = ` <div class="text-18-normal" > - duel_result_modal.sucess.message1function () { - return fn.apply(this, arguments); - } € + duel_result_modal.sucess.message10,00 € </div> <div class="text-18-normal" @@ -854,7 +852,7 @@ exports[`DuelResultModal component should render correctly 1`] = ` </Icon> <Icon className="imgResult" - icon="" + icon="test-file-stub" size={180} spin={false} > @@ -871,7 +869,7 @@ exports[`DuelResultModal component should render correctly 1`] = ` width={180} > <use - xlinkHref="#" + xlinkHref="#test-file-stub" /> </svg> </Component> @@ -885,9 +883,7 @@ exports[`DuelResultModal component should render correctly 1`] = ` <div className="text-18-normal" > - duel_result_modal.sucess.message1function () { - return fn.apply(this, arguments); - } € + duel_result_modal.sucess.message10,00 € </div> <div className="text-18-normal" diff --git a/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx b/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx index 4ef56d048..822eff26b 100644 --- a/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx +++ b/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx @@ -1,56 +1,26 @@ import Button from '@material-ui/core/Button' -import defaultIcon from 'assets/icons/visu/duel/default.svg' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import { FluidType, UserChallengeUpdateFlag } from 'enums' import { mount } from 'enzyme' import React from 'react' import { Provider } from 'react-redux' -import UsageEventService from 'services/usageEvent.service' import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import { formatNumberValues } from 'utils/utils' import DuelUnlocked from './DuelUnlocked' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn(() => defaultIcon) -const mockFormatNumberValues = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - formatNumberValues: jest.fn(() => { - return mockFormatNumberValues - }), - } -}) const mockUserChallengeUpdateFlag = jest.fn() const mockGetUserChallengeDataload = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - getUserChallengeDataload: mockGetUserChallengeDataload, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + getUserChallengeDataload: mockGetUserChallengeDataload, + })) }) -const mockAddEvent = jest.fn() jest.mock('services/usageEvent.service') -UsageEventService.addEvent = mockAddEvent describe('DuelUnlocked component', () => { - beforeAll(() => { - jest.useFakeTimers() - }) - - afterAll(() => { - jest.useRealTimers() - }) const store = createMockEcolyoStore() it('should be rendered correctly', () => { diff --git a/src/components/Duel/DuelView.spec.tsx b/src/components/Duel/DuelView.spec.tsx index f590ca9f3..80a35498f 100644 --- a/src/components/Duel/DuelView.spec.tsx +++ b/src/components/Duel/DuelView.spec.tsx @@ -14,18 +14,11 @@ jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') -const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ useLocation: () => ({ search: '?id=CHALLENGE0002', }), - useNavigate: () => mockedNavigate, -})) - -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), + useNavigate: () => jest.fn(), })) describe('DuelView component', () => { diff --git a/src/components/Duel/LastDuelModal/lastDuelModal.spec.tsx b/src/components/Duel/LastDuelModal/lastDuelModal.spec.tsx index f1f88b608..ed1f8b01b 100644 --- a/src/components/Duel/LastDuelModal/lastDuelModal.spec.tsx +++ b/src/components/Duel/LastDuelModal/lastDuelModal.spec.tsx @@ -4,12 +4,6 @@ import React from 'react' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import LastDuelModal from './lastDuelModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('lastDuelModal component', () => { it('should render correctly', async () => { const wrapper = mount( diff --git a/src/components/Ecogesture/EcogestureCard/EcogestureCard.spec.tsx b/src/components/Ecogesture/EcogestureCard/EcogestureCard.spec.tsx index 074a0c972..836668c81 100644 --- a/src/components/Ecogesture/EcogestureCard/EcogestureCard.spec.tsx +++ b/src/components/Ecogesture/EcogestureCard/EcogestureCard.spec.tsx @@ -7,26 +7,8 @@ import { BrowserRouter } from 'react-router-dom' import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -jest.mock('components/CommonKit/Icon/StyledIcon', () => () => ( - <div id="StyledIcon" /> -)) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) - describe('EcogestureCard component', () => { it('should be rendered correctly', async () => { - mockImportIconById.mockReturnValueOnce('') const wrapper = mount( <BrowserRouter> <EcogestureCard ecogesture={mockedEcogesturesData[0]} /> @@ -36,7 +18,6 @@ describe('EcogestureCard component', () => { expect(toJson(wrapper)).toMatchSnapshot() }) it('should be with default icon', async () => { - mockImportIconById.mockReturnValue(undefined) const wrapper = mount( <BrowserRouter> <EcogestureCard ecogesture={mockedEcogesturesData[0]} /> diff --git a/src/components/Ecogesture/EcogestureCard/__snapshots__/EcogestureCard.spec.tsx.snap b/src/components/Ecogesture/EcogestureCard/__snapshots__/EcogestureCard.spec.tsx.snap index 5a91aa831..56a97459a 100644 --- a/src/components/Ecogesture/EcogestureCard/__snapshots__/EcogestureCard.spec.tsx.snap +++ b/src/components/Ecogesture/EcogestureCard/__snapshots__/EcogestureCard.spec.tsx.snap @@ -292,15 +292,39 @@ exports[`EcogestureCard component should be rendered correctly 1`] = ` <div className="ec-content" > - <Component + <StyledIcon className="Icon" - icon="" + icon="test-file-stub" size={50} > - <div - id="StyledIcon" - /> - </Component> + <Icon + aria-hidden={true} + className="Icon" + icon="test-file-stub" + size={50} + spin={false} + > + <Component + aria-hidden={true} + className="Icon styles__icon___23x3R" + height={50} + style={Object {}} + width={50} + > + <svg + aria-hidden={true} + className="Icon styles__icon___23x3R" + height={50} + style={Object {}} + width={50} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> <div className="ec-content-short-name text-15-bold" > @@ -312,56 +336,176 @@ exports[`EcogestureCard component should be rendered correctly 1`] = ` <div className="thunder" > - <Component + <StyledIcon className="star" icon="test-file-stub" key="1" size={15} > - <div - id="StyledIcon" - /> - </Component> - <Component + <Icon + aria-hidden={true} + className="star" + icon="test-file-stub" + size={15} + spin={false} + > + <Component + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <svg + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> + <StyledIcon className="star" icon="test-file-stub" key="2" size={15} > - <div - id="StyledIcon" - /> - </Component> - <Component + <Icon + aria-hidden={true} + className="star" + icon="test-file-stub" + size={15} + spin={false} + > + <Component + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <svg + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> + <StyledIcon className="star" icon="test-file-stub" key="3" size={15} > - <div - id="StyledIcon" - /> - </Component> - <Component + <Icon + aria-hidden={true} + className="star" + icon="test-file-stub" + size={15} + spin={false} + > + <Component + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <svg + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> + <StyledIcon className="star" icon="test-file-stub" key="4" size={15} > - <div - id="StyledIcon" - /> - </Component> - <Component + <Icon + aria-hidden={true} + className="star" + icon="test-file-stub" + size={15} + spin={false} + > + <Component + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <svg + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> + <StyledIcon className="star" icon="test-file-stub" key="5" size={15} > - <div - id="StyledIcon" - /> - </Component> + <Icon + aria-hidden={true} + className="star" + icon="test-file-stub" + size={15} + spin={false} + > + <Component + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <svg + aria-hidden={true} + className="star styles__icon___23x3R" + height={15} + style={Object {}} + width={15} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + </StyledIcon> </div> </EfficiencyRating> </div> diff --git a/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx b/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx index e6d11ab23..d2cdc4121 100644 --- a/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx +++ b/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx @@ -4,16 +4,11 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureEmptyList from './EcogestureEmptyList' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) +const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: () => mockedNavigate, })) -const mockedNavigate = jest.fn() const mockChangeTab = jest.fn() const mockHandleClick = jest.fn() diff --git a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx index 47c4af897..9f527a984 100644 --- a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx +++ b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx @@ -4,27 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureInitModal from './EcogestureInitModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) -const mockHistoryPush = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => ({ - push: mockHistoryPush, - }), -})) - const mockHandleClose = jest.fn() const mockHandleLaunchForm = jest.fn() describe('EcogestureInitModal component', () => { diff --git a/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx b/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx index cc90f64a6..e51a18972 100644 --- a/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx +++ b/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx @@ -10,11 +10,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureList from './EcogestureList' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock( 'components/Ecogesture/EcogestureCard/EcogestureCard', () => 'mock-ecogesturecard' diff --git a/src/components/Ecogesture/EcogestureModal/EcogestureModal.spec.tsx b/src/components/Ecogesture/EcogestureModal/EcogestureModal.spec.tsx index f877e968e..8cfd17faf 100644 --- a/src/components/Ecogesture/EcogestureModal/EcogestureModal.spec.tsx +++ b/src/components/Ecogesture/EcogestureModal/EcogestureModal.spec.tsx @@ -6,20 +6,6 @@ import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) - describe('EcogestureModal component', () => { it('should be rendered correctly', async () => { const store = createMockEcolyoStore() diff --git a/src/components/Ecogesture/EcogestureReinitModal/EcogestureReinitModal.spec.tsx b/src/components/Ecogesture/EcogestureReinitModal/EcogestureReinitModal.spec.tsx index 9bb6ec44b..5f9148b03 100644 --- a/src/components/Ecogesture/EcogestureReinitModal/EcogestureReinitModal.spec.tsx +++ b/src/components/Ecogesture/EcogestureReinitModal/EcogestureReinitModal.spec.tsx @@ -3,20 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureReinitModal from './EcogestureReinitModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) - describe('EcogestureReinitModal component', () => { it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/Ecogesture/EcogestureTabsView.spec.tsx b/src/components/Ecogesture/EcogestureTabsView.spec.tsx index 17d8c832f..f9eb724da 100644 --- a/src/components/Ecogesture/EcogestureTabsView.spec.tsx +++ b/src/components/Ecogesture/EcogestureTabsView.spec.tsx @@ -1,6 +1,5 @@ import { IconButton, Tab } from '@material-ui/core' import EcogestureTabsView from 'components/Ecogesture/EcogestureTabsView' -import { Season } from 'enums' import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' @@ -12,32 +11,23 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureEmptyList from './EcogestureEmptyList/EcogestureEmptyList' import EcogestureInitModal from './EcogestureInitModal/EcogestureInitModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockGetAllEcogestures = jest.fn() -const mockGetEcogestureListByProfile = jest.fn() -const mockInitEcogesture = jest.fn() +const mockGetEcogestureListByProfile = jest.fn().mockResolvedValue([]) +const mockInitEcogesture = jest.fn().mockResolvedValue(mockedEcogesturesData) jest.mock('services/ecogesture.service', () => { - return jest.fn(() => { - return { - getAllEcogestures: mockGetAllEcogestures, - getEcogestureListByProfile: mockGetEcogestureListByProfile, - initEcogesture: mockInitEcogesture, - } - }) + return jest.fn(() => ({ + getAllEcogestures: mockGetAllEcogestures, + getEcogestureListByProfile: mockGetEcogestureListByProfile, + initEcogesture: mockInitEcogesture, + })) }) const mockGetProfile = jest.fn() const mockUpdateProfile = jest.fn() jest.mock('services/profile.service', () => { - return jest.fn(() => { - return { - getProfile: mockGetProfile, - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + getProfile: mockGetProfile, + updateProfile: mockUpdateProfile, + })) }) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') @@ -47,37 +37,17 @@ jest.mock( () => 'mock-ecogesturelist' ) jest.mock('components/Content/Content', () => 'mock-content') -const mockGetSeason = jest.fn() -jest.mock('utils/utils', () => { - return { - getSeason: jest.fn(() => { - return mockGetSeason - }), - } -}) -const mockedNavigate = jest.fn() + jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), - useLocation: () => { - return { - search: '', - } - }, - useNavigate: () => mockedNavigate, + useLocation: () => ({ + search: '', + }), + useNavigate: () => jest.fn(), })) describe('EcogestureView component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - mockGetSeason.mockClear() - mockGetAllEcogestures.mockClear() - mockGetEcogestureListByProfile.mockClear() - - mockInitEcogesture.mockResolvedValue(mockedEcogesturesData) - mockGetSeason.mockReturnValue(Season.WINTER) - mockGetEcogestureListByProfile.mockResolvedValue([]) - }) it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/Ecogesture/EfficiencyRating/EfficiencyRating.spec.tsx b/src/components/Ecogesture/EfficiencyRating/EfficiencyRating.spec.tsx index 35690f5f2..0ac6b73e5 100644 --- a/src/components/Ecogesture/EfficiencyRating/EfficiencyRating.spec.tsx +++ b/src/components/Ecogesture/EfficiencyRating/EfficiencyRating.spec.tsx @@ -3,12 +3,6 @@ import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('EfficiencyRating component', () => { it('should be rendered correctly', () => { const wrapper = mount(<EfficiencyRating result={3} />) diff --git a/src/components/Ecogesture/SingleEcogestureView.spec.tsx b/src/components/Ecogesture/SingleEcogestureView.spec.tsx index 09315002e..3dca815a0 100644 --- a/src/components/Ecogesture/SingleEcogestureView.spec.tsx +++ b/src/components/Ecogesture/SingleEcogestureView.spec.tsx @@ -8,11 +8,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import SingleEcogestureView from './SingleEcogestureView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ @@ -24,34 +19,22 @@ jest.mock('react-router-dom', () => ({ state: { selectionCompleted: true }, }), })) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: () => mockImportIconById, - } -}) jest.mock( 'components/Ecogesture/EfficiencyRating/EfficiencyRating', - () => () => <div id="EfficiencyRating" /> + () => 'mock-EfficiencyRating' ) -jest.mock('components/Header/Header', () => () => <div id="Header" />) -jest.mock('components/Header/CozyBar', () => () => <div id="CozyBar" />) -jest.mock('components/Loader/Loader', () => () => <div id="spinner" />) -// eslint-disable-next-line @typescript-eslint/no-explicit-any -jest.mock('components/Content/Content', () => (props: any) => ( - <div id="content">{props.children}</div> -)) +jest.mock('components/Header/CozyBar', () => 'mock-cozybar') +jest.mock('components/Header/Header', () => 'mock-header') +jest.mock('components/Content/Content', () => 'mock-content') const mockGetEcogesturesByIds = jest.fn() const mockUpdateEcogesture = jest.fn() jest.mock('services/ecogesture.service', () => { - return jest.fn(() => { - return { - getEcogesturesByIds: mockGetEcogesturesByIds, - updateEcogesture: mockUpdateEcogesture, - } - }) + return jest.fn(() => ({ + getEcogesturesByIds: mockGetEcogesturesByIds, + updateEcogesture: mockUpdateEcogesture, + })) }) describe('SingleEcogesture component', () => { @@ -69,7 +52,7 @@ describe('SingleEcogesture component', () => { it('should change doing status', async () => { mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]]) - mockImportIconById.mockReturnValue('') + const updatedEcogesture = { ...mockedEcogesturesData[0], doing: true } mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture) const wrapper = mount( @@ -84,7 +67,7 @@ describe('SingleEcogesture component', () => { }) it('should change objective status', async () => { mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]]) - mockImportIconById.mockReturnValue('icontest') + const updatedEcogesture = { ...mockedEcogesturesData[0], objective: true } mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture) @@ -100,7 +83,6 @@ describe('SingleEcogesture component', () => { }) it('should toggle more details', async () => { mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]]) - mockImportIconById.mockReturnValue(undefined) const wrapper = mount( <Provider store={store}> diff --git a/src/components/Ecogesture/__snapshots__/SingleEcogestureView.spec.tsx.snap b/src/components/Ecogesture/__snapshots__/SingleEcogestureView.spec.tsx.snap index 73666bc89..80927a48f 100644 --- a/src/components/Ecogesture/__snapshots__/SingleEcogestureView.spec.tsx.snap +++ b/src/components/Ecogesture/__snapshots__/SingleEcogestureView.spec.tsx.snap @@ -14,354 +14,372 @@ exports[`SingleEcogesture component should be rendered correctly 1`] = ` } > <SingleEcogestureView> - <Component + <mock-cozybar displayBackArrow={true} titleKey="common.title_ecogesture" - > - <div - id="CozyBar" - /> - </Component> - <Component + /> + <mock-header desktopTitleKey="common.title_ecogesture" displayBackArrow={true} setHeaderHeight={[Function]} - > - <div - id="Header" - /> - </Component> - <Component + /> + <mock-content heightOffset={0} > <div - id="content" + className="single-ecogesture" > <div - className="single-ecogesture" + className="icon-container" > - <div - className="icon-container" - /> - <div - className="details" + <StyledIcon + className="icon-big" + icon="test-file-stub" + size={220} > - <div - className="text-22 title" + <Icon + aria-hidden={true} + className="icon-big" + icon="test-file-stub" + size={220} + spin={false} > - Bonhomme de neige - </div> - <div - className="efficiency" - > - <span - className="text text-14-normal" - > - ecogesture_modal.efficiency - </span> <Component - result={4} + aria-hidden={true} + className="icon-big styles__icon___23x3R" + height={220} + style={Object {}} + width={220} > - <div - id="EfficiencyRating" - /> + <svg + aria-hidden={true} + className="icon-big styles__icon___23x3R" + height={220} + style={Object {}} + width={220} + > + <use + xlinkHref="#test-file-stub" + /> + </svg> </Component> - </div> + </Icon> + </StyledIcon> + </div> + <div + className="details" + > + <div + className="text-22 title" + > + Bonhomme de neige </div> <div - className="styled-container" + className="efficiency" > - <div - className="long-name text-18-bold" - > - Je baisse le chauffage en mode hors gel lorsque je m'absente plus de 2 jours. - </div> - <div - className="toggle-text text-15-normal" - onClick={[Function]} - role="button" + <span + className="text text-14-normal" > - ecogesture_modal.show_more - </div> - <div - className="description text-16-normal-150" - > - On se demande parfois si cela vaut le coup de "couper le chauffage" quand on s’absente… dès qu’il s’agit d’un week-end la réponse est « oui sûrement » ! Attention cependant au retour à ne pas faire de la surchauffe ! L’idéal est bien évidemment de régler sa programmation pour que le chauffage se relance quelques heures avant votre retour… - </div> + ecogesture_modal.efficiency + </span> + <mock-EfficiencyRating + result={4} + /> + </div> + </div> + <div + className="styled-container" + > + <div + className="long-name text-18-bold" + > + Je baisse le chauffage en mode hors gel lorsque je m'absente plus de 2 jours. </div> <div - className="buttons-selection" + className="toggle-text text-15-normal" + onClick={[Function]} + role="button" > - <WithStyles(ForwardRef(IconButton)) + ecogesture_modal.show_more + </div> + <div + className="description text-16-normal-150" + > + On se demande parfois si cela vaut le coup de "couper le chauffage" quand on s’absente… dès qu’il s’agit d’un week-end la réponse est « oui sûrement » ! Attention cependant au retour à ne pas faire de la surchauffe ! L’idéal est bien évidemment de régler sa programmation pour que le chauffage se relance quelques heures avant votre retour… + </div> + </div> + <div + className="buttons-selection" + > + <WithStyles(ForwardRef(IconButton)) + aria-label="ecogesture.objective" + classes={ + Object { + "label": "text-15-normal", + "root": "btn-secondary-negative objective-btn false", + } + } + onClick={[Function]} + > + <ForwardRef(IconButton) aria-label="ecogesture.objective" classes={ Object { - "label": "text-15-normal", - "root": "btn-secondary-negative objective-btn false", + "colorInherit": "MuiIconButton-colorInherit", + "colorPrimary": "MuiIconButton-colorPrimary", + "colorSecondary": "MuiIconButton-colorSecondary", + "disabled": "Mui-disabled", + "edgeEnd": "MuiIconButton-edgeEnd", + "edgeStart": "MuiIconButton-edgeStart", + "label": "MuiIconButton-label text-15-normal", + "root": "MuiIconButton-root btn-secondary-negative objective-btn false", + "sizeSmall": "MuiIconButton-sizeSmall", } } onClick={[Function]} > - <ForwardRef(IconButton) + <WithStyles(ForwardRef(ButtonBase)) aria-label="ecogesture.objective" - classes={ - Object { - "colorInherit": "MuiIconButton-colorInherit", - "colorPrimary": "MuiIconButton-colorPrimary", - "colorSecondary": "MuiIconButton-colorSecondary", - "disabled": "Mui-disabled", - "edgeEnd": "MuiIconButton-edgeEnd", - "edgeStart": "MuiIconButton-edgeStart", - "label": "MuiIconButton-label text-15-normal", - "root": "MuiIconButton-root btn-secondary-negative objective-btn false", - "sizeSmall": "MuiIconButton-sizeSmall", - } - } + centerRipple={true} + className="MuiIconButton-root btn-secondary-negative objective-btn false" + disabled={false} + focusRipple={true} onClick={[Function]} > - <WithStyles(ForwardRef(ButtonBase)) + <ForwardRef(ButtonBase) aria-label="ecogesture.objective" centerRipple={true} className="MuiIconButton-root btn-secondary-negative objective-btn false" + classes={ + Object { + "disabled": "Mui-disabled", + "focusVisible": "Mui-focusVisible", + "root": "MuiButtonBase-root", + } + } disabled={false} focusRipple={true} onClick={[Function]} > - <ForwardRef(ButtonBase) + <button aria-label="ecogesture.objective" - centerRipple={true} - className="MuiIconButton-root btn-secondary-negative objective-btn false" - classes={ - Object { - "disabled": "Mui-disabled", - "focusVisible": "Mui-focusVisible", - "root": "MuiButtonBase-root", - } - } + className="MuiButtonBase-root MuiIconButton-root btn-secondary-negative objective-btn false" disabled={false} - focusRipple={true} + onBlur={[Function]} onClick={[Function]} + onDragLeave={[Function]} + onFocus={[Function]} + onKeyDown={[Function]} + onKeyUp={[Function]} + onMouseDown={[Function]} + onMouseLeave={[Function]} + onMouseUp={[Function]} + onTouchEnd={[Function]} + onTouchMove={[Function]} + onTouchStart={[Function]} + tabIndex={0} + type="button" > - <button - aria-label="ecogesture.objective" - className="MuiButtonBase-root MuiIconButton-root btn-secondary-negative objective-btn false" - disabled={false} - onBlur={[Function]} - onClick={[Function]} - onDragLeave={[Function]} - onFocus={[Function]} - onKeyDown={[Function]} - onKeyUp={[Function]} - onMouseDown={[Function]} - onMouseLeave={[Function]} - onMouseUp={[Function]} - onTouchEnd={[Function]} - onTouchMove={[Function]} - onTouchStart={[Function]} - tabIndex={0} - type="button" + <span + className="MuiIconButton-label text-15-normal" > - <span - className="MuiIconButton-label text-15-normal" + <Icon + className="status-icon" + icon="test-file-stub" + size={40} + spin={false} > - <Icon - className="status-icon" - icon="test-file-stub" - size={40} - spin={false} + <Component + className="status-icon styles__icon___23x3R" + height={40} + style={Object {}} + width={40} > - <Component + <svg className="status-icon styles__icon___23x3R" height={40} style={Object {}} width={40} > - <svg - className="status-icon styles__icon___23x3R" - height={40} - style={Object {}} - width={40} - > - <use - xlinkHref="#test-file-stub" - /> - </svg> - </Component> - </Icon> - <span> - ecogesture.objective - </span> + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + <span> + ecogesture.objective </span> - <WithStyles(memo) + </span> + <WithStyles(memo) + center={true} + > + <ForwardRef(TouchRipple) center={true} - > - <ForwardRef(TouchRipple) - center={true} - classes={ - Object { - "child": "MuiTouchRipple-child", - "childLeaving": "MuiTouchRipple-childLeaving", - "childPulsate": "MuiTouchRipple-childPulsate", - "ripple": "MuiTouchRipple-ripple", - "ripplePulsate": "MuiTouchRipple-ripplePulsate", - "rippleVisible": "MuiTouchRipple-rippleVisible", - "root": "MuiTouchRipple-root", - } + classes={ + Object { + "child": "MuiTouchRipple-child", + "childLeaving": "MuiTouchRipple-childLeaving", + "childPulsate": "MuiTouchRipple-childPulsate", + "ripple": "MuiTouchRipple-ripple", + "ripplePulsate": "MuiTouchRipple-ripplePulsate", + "rippleVisible": "MuiTouchRipple-rippleVisible", + "root": "MuiTouchRipple-root", } + } + > + <span + className="MuiTouchRipple-root" > - <span - className="MuiTouchRipple-root" - > - <TransitionGroup - childFactory={[Function]} - component={null} - exit={true} - /> - </span> - </ForwardRef(TouchRipple)> - </WithStyles(memo)> - </button> - </ForwardRef(ButtonBase)> - </WithStyles(ForwardRef(ButtonBase))> - </ForwardRef(IconButton)> - </WithStyles(ForwardRef(IconButton))> - <WithStyles(ForwardRef(IconButton)) + <TransitionGroup + childFactory={[Function]} + component={null} + exit={true} + /> + </span> + </ForwardRef(TouchRipple)> + </WithStyles(memo)> + </button> + </ForwardRef(ButtonBase)> + </WithStyles(ForwardRef(ButtonBase))> + </ForwardRef(IconButton)> + </WithStyles(ForwardRef(IconButton))> + <WithStyles(ForwardRef(IconButton)) + aria-label="ecogesture.doing" + classes={ + Object { + "label": "text-15-normal", + "root": "btn-secondary-negative doing-btn false", + } + } + onClick={[Function]} + > + <ForwardRef(IconButton) aria-label="ecogesture.doing" classes={ Object { - "label": "text-15-normal", - "root": "btn-secondary-negative doing-btn false", + "colorInherit": "MuiIconButton-colorInherit", + "colorPrimary": "MuiIconButton-colorPrimary", + "colorSecondary": "MuiIconButton-colorSecondary", + "disabled": "Mui-disabled", + "edgeEnd": "MuiIconButton-edgeEnd", + "edgeStart": "MuiIconButton-edgeStart", + "label": "MuiIconButton-label text-15-normal", + "root": "MuiIconButton-root btn-secondary-negative doing-btn false", + "sizeSmall": "MuiIconButton-sizeSmall", } } onClick={[Function]} > - <ForwardRef(IconButton) + <WithStyles(ForwardRef(ButtonBase)) aria-label="ecogesture.doing" - classes={ - Object { - "colorInherit": "MuiIconButton-colorInherit", - "colorPrimary": "MuiIconButton-colorPrimary", - "colorSecondary": "MuiIconButton-colorSecondary", - "disabled": "Mui-disabled", - "edgeEnd": "MuiIconButton-edgeEnd", - "edgeStart": "MuiIconButton-edgeStart", - "label": "MuiIconButton-label text-15-normal", - "root": "MuiIconButton-root btn-secondary-negative doing-btn false", - "sizeSmall": "MuiIconButton-sizeSmall", - } - } + centerRipple={true} + className="MuiIconButton-root btn-secondary-negative doing-btn false" + disabled={false} + focusRipple={true} onClick={[Function]} > - <WithStyles(ForwardRef(ButtonBase)) + <ForwardRef(ButtonBase) aria-label="ecogesture.doing" centerRipple={true} className="MuiIconButton-root btn-secondary-negative doing-btn false" + classes={ + Object { + "disabled": "Mui-disabled", + "focusVisible": "Mui-focusVisible", + "root": "MuiButtonBase-root", + } + } disabled={false} focusRipple={true} onClick={[Function]} > - <ForwardRef(ButtonBase) + <button aria-label="ecogesture.doing" - centerRipple={true} - className="MuiIconButton-root btn-secondary-negative doing-btn false" - classes={ - Object { - "disabled": "Mui-disabled", - "focusVisible": "Mui-focusVisible", - "root": "MuiButtonBase-root", - } - } + className="MuiButtonBase-root MuiIconButton-root btn-secondary-negative doing-btn false" disabled={false} - focusRipple={true} + onBlur={[Function]} onClick={[Function]} + onDragLeave={[Function]} + onFocus={[Function]} + onKeyDown={[Function]} + onKeyUp={[Function]} + onMouseDown={[Function]} + onMouseLeave={[Function]} + onMouseUp={[Function]} + onTouchEnd={[Function]} + onTouchMove={[Function]} + onTouchStart={[Function]} + tabIndex={0} + type="button" > - <button - aria-label="ecogesture.doing" - className="MuiButtonBase-root MuiIconButton-root btn-secondary-negative doing-btn false" - disabled={false} - onBlur={[Function]} - onClick={[Function]} - onDragLeave={[Function]} - onFocus={[Function]} - onKeyDown={[Function]} - onKeyUp={[Function]} - onMouseDown={[Function]} - onMouseLeave={[Function]} - onMouseUp={[Function]} - onTouchEnd={[Function]} - onTouchMove={[Function]} - onTouchStart={[Function]} - tabIndex={0} - type="button" + <span + className="MuiIconButton-label text-15-normal" > - <span - className="MuiIconButton-label text-15-normal" + <Icon + className="status-icon" + icon="test-file-stub" + size={40} + spin={false} > - <Icon - className="status-icon" - icon="test-file-stub" - size={40} - spin={false} + <Component + className="status-icon styles__icon___23x3R" + height={40} + style={Object {}} + width={40} > - <Component + <svg className="status-icon styles__icon___23x3R" height={40} style={Object {}} width={40} > - <svg - className="status-icon styles__icon___23x3R" - height={40} - style={Object {}} - width={40} - > - <use - xlinkHref="#test-file-stub" - /> - </svg> - </Component> - </Icon> - <span> - ecogesture.doing - </span> + <use + xlinkHref="#test-file-stub" + /> + </svg> + </Component> + </Icon> + <span> + ecogesture.doing </span> - <WithStyles(memo) + </span> + <WithStyles(memo) + center={true} + > + <ForwardRef(TouchRipple) center={true} - > - <ForwardRef(TouchRipple) - center={true} - classes={ - Object { - "child": "MuiTouchRipple-child", - "childLeaving": "MuiTouchRipple-childLeaving", - "childPulsate": "MuiTouchRipple-childPulsate", - "ripple": "MuiTouchRipple-ripple", - "ripplePulsate": "MuiTouchRipple-ripplePulsate", - "rippleVisible": "MuiTouchRipple-rippleVisible", - "root": "MuiTouchRipple-root", - } + classes={ + Object { + "child": "MuiTouchRipple-child", + "childLeaving": "MuiTouchRipple-childLeaving", + "childPulsate": "MuiTouchRipple-childPulsate", + "ripple": "MuiTouchRipple-ripple", + "ripplePulsate": "MuiTouchRipple-ripplePulsate", + "rippleVisible": "MuiTouchRipple-rippleVisible", + "root": "MuiTouchRipple-root", } + } + > + <span + className="MuiTouchRipple-root" > - <span - className="MuiTouchRipple-root" - > - <TransitionGroup - childFactory={[Function]} - component={null} - exit={true} - /> - </span> - </ForwardRef(TouchRipple)> - </WithStyles(memo)> - </button> - </ForwardRef(ButtonBase)> - </WithStyles(ForwardRef(ButtonBase))> - </ForwardRef(IconButton)> - </WithStyles(ForwardRef(IconButton))> - </div> + <TransitionGroup + childFactory={[Function]} + component={null} + exit={true} + /> + </span> + </ForwardRef(TouchRipple)> + </WithStyles(memo)> + </button> + </ForwardRef(ButtonBase)> + </WithStyles(ForwardRef(ButtonBase))> + </ForwardRef(IconButton)> + </WithStyles(ForwardRef(IconButton))> </div> </div> - </Component> + </mock-content> </SingleEcogestureView> </Provider> `; diff --git a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx index b586ef080..102b0d4b3 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx @@ -8,20 +8,9 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureFormEquipment from './EcogestureFormEquipment' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockSetPreviousStep = jest.fn() const mockSetNextStep = jest.fn() -const mockHistoryPush = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => ({ - push: mockHistoryPush, - }), -})) + jest.mock('../EquipmentIcon/EquipmentIcon', () => 'mock-equipment-icon') describe('EcogestureFormEquipment component', () => { diff --git a/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx b/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx index 502f657b4..3d97bafc6 100644 --- a/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx @@ -11,17 +11,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureFormSingleChoice from './EcogestureFormSingleChoice' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - jest.mock( 'components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal', () => 'mock-ecogesturelaunchmodal' @@ -31,9 +20,6 @@ const mockHandleNextStep = jest.fn() const mockHandlePreviousStep = jest.fn() describe('EcogestureFormSingleChoice component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/EcogestureForm/EcogestureFormView.spec.tsx b/src/components/EcogestureForm/EcogestureFormView.spec.tsx index 717d72343..77256f6dc 100644 --- a/src/components/EcogestureForm/EcogestureFormView.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormView.spec.tsx @@ -10,12 +10,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureFormView from './EcogestureFormView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock( @@ -28,18 +22,15 @@ const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: () => mockedNavigate, - useLocation: () => { - return { - search: '', - } - }, + useLocation: () => ({ + search: '', + }), })) describe('EcogestureFormView component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - mockAppDispatch.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', async () => { diff --git a/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx b/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx index 1f0289958..1efe25a5e 100644 --- a/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx +++ b/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx @@ -4,12 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureLaunchFormModal from './EcogestureLaunchFormModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() describe('EcogestureLaunchFormModal component', () => { it('should be rendered correctly', () => { diff --git a/src/components/EcogestureForm/EquipmentIcon/EquipmentIcon.spec.tsx b/src/components/EcogestureForm/EquipmentIcon/EquipmentIcon.spec.tsx index cf1ebcde7..6d248173c 100644 --- a/src/components/EcogestureForm/EquipmentIcon/EquipmentIcon.spec.tsx +++ b/src/components/EcogestureForm/EquipmentIcon/EquipmentIcon.spec.tsx @@ -6,22 +6,8 @@ import React from 'react' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EquipmentIcon from './EquipmentIcon' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) describe('EcogestureFormSingleChoice component', () => { it('should be rendered correctly', async () => { - mockImportIconById.mockReturnValue('') const wrapper = mount( <EquipmentIcon equipment={EquipmentType.BOILER} isChecked={false} /> ) @@ -29,7 +15,6 @@ describe('EcogestureFormSingleChoice component', () => { expect(toJson(wrapper)).toMatchSnapshot() }) it('should render checked icon', async () => { - mockImportIconById.mockReturnValue('') const wrapper = mount( <EquipmentIcon equipment={EquipmentType.BOILER} isChecked={true} /> ) diff --git a/src/components/EcogestureForm/EquipmentIcon/__snapshots__/EquipmentIcon.spec.tsx.snap b/src/components/EcogestureForm/EquipmentIcon/__snapshots__/EquipmentIcon.spec.tsx.snap index bded38e56..8909ac3fb 100644 --- a/src/components/EcogestureForm/EquipmentIcon/__snapshots__/EquipmentIcon.spec.tsx.snap +++ b/src/components/EcogestureForm/EquipmentIcon/__snapshots__/EquipmentIcon.spec.tsx.snap @@ -10,7 +10,7 @@ exports[`EcogestureFormSingleChoice component should be rendered correctly 1`] = > <Icon className="equipmentIcon " - icon="" + icon="test-file-stub" size={40} spin={false} > @@ -27,7 +27,7 @@ exports[`EcogestureFormSingleChoice component should be rendered correctly 1`] = width={40} > <use - xlinkHref="#" + xlinkHref="#test-file-stub" /> </svg> </Component> diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx index 3b81ac7bd..0ccba339a 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx @@ -6,29 +6,10 @@ import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureSelectionDetail from './EcogestureSelectionDetail' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockImportIconById = jest.fn() -jest.mock('utils/utils', () => { - return { - importIconById: jest.fn(() => { - return mockImportIconById - }), - } -}) const mockValidate = jest.fn() describe('EcogestureSelectionDetail component', () => { - beforeEach(() => { - mockImportIconById.mockClear() - mockValidate.mockClear() - }) - it('should be rendered correctly', async () => { - mockImportIconById.mockReturnValueOnce('testIcon') const wrapper = mount( <EcogestureSelectionDetail ecogesture={mockedEcogesturesData[0]} @@ -41,7 +22,6 @@ describe('EcogestureSelectionDetail component', () => { }) it('should call validate with objective to true', async () => { - mockImportIconById.mockReturnValueOnce('testIcon') const wrapper = mount( <EcogestureSelectionDetail ecogesture={mockedEcogesturesData[0]} @@ -55,7 +35,6 @@ describe('EcogestureSelectionDetail component', () => { }) it('should call validate with doing to true', async () => { - mockImportIconById.mockReturnValueOnce('testIcon') const wrapper = mount( <EcogestureSelectionDetail ecogesture={mockedEcogesturesData[0]} @@ -69,7 +48,6 @@ describe('EcogestureSelectionDetail component', () => { }) it('should call validate with objective and doing to false', async () => { - mockImportIconById.mockReturnValueOnce('testIcon') const wrapper = mount( <EcogestureSelectionDetail ecogesture={mockedEcogesturesData[0]} diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap b/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap index 13d309ddf..a25ce5445 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap @@ -46,13 +46,13 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] = > <StyledIcon className="icon" - icon="testIcon" + icon="test-file-stub" size={240} > <Icon aria-hidden={true} className="icon" - icon="testIcon" + icon="test-file-stub" size={240} spin={false} > @@ -71,7 +71,7 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] = width={240} > <use - xlinkHref="#testIcon" + xlinkHref="#test-file-stub" /> </svg> </Component> diff --git a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx index 4af3daef4..b6359dd88 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx @@ -4,11 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureSelectionEnd from './EcogestureSelectionEnd' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -17,7 +12,7 @@ jest.mock('react-router-dom', () => ({ describe('EcogestureSelectionEnd component', () => { beforeEach(() => { - mockedNavigate.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', () => { diff --git a/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx index 7f83daeea..b2f3141ca 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx @@ -4,12 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureSelectionModal from './EcogestureSelectionModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() describe('EcogestureInitModal component', () => { it('should be rendered correctly', () => { diff --git a/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx index ded77ef64..08bc2048c 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx @@ -4,11 +4,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import EcogestureSelectionRestart from './EcogestureSelectionRestart' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -17,11 +12,6 @@ jest.mock('react-router-dom', () => ({ const mockRestart = jest.fn() describe('EcogestureSelectionRestart component', () => { - beforeEach(() => { - mockedNavigate.mockClear() - mockRestart.mockClear() - }) - it('should be rendered correctly', () => { const wrapper = mount( <EcogestureSelectionRestart listLength={10} restart={mockRestart} /> diff --git a/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx index 11ca91568..234ba798c 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx @@ -3,43 +3,16 @@ import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' import { Provider } from 'react-redux' -import mockClient from 'tests/__mocks__/client' import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureSelectionView from './EcogestureSelectionView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -jest.mock('cozy-client', () => { - return { - useClient: jest.fn(() => { - return mockClient - }), - } -}) -const mockHistoryGoBack = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useLocation: () => { - return { - search: '', - } - }, - useNavigate: () => ({ - push: mockHistoryGoBack, - }), -})) const mockGetEcogestureListByProfile = jest.fn() jest.mock('services/ecogesture.service', () => { - return jest.fn(() => { - return { - getEcogestureListByProfile: mockGetEcogestureListByProfile, - } - }) + return jest.fn(() => ({ + getEcogestureListByProfile: mockGetEcogestureListByProfile, + })) }) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') @@ -65,8 +38,7 @@ jest.mock( describe('EcogestureSelection component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - mockGetEcogestureListByProfile.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', async () => { diff --git a/src/components/Exploration/ExplorationError.spec.tsx b/src/components/Exploration/ExplorationError.spec.tsx index 389ed334e..4ea8699db 100644 --- a/src/components/Exploration/ExplorationError.spec.tsx +++ b/src/components/Exploration/ExplorationError.spec.tsx @@ -2,18 +2,6 @@ import ExplorationError from 'components/Exploration/ExplorationError' import { shallow } from 'enzyme' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('ExplorationError component', () => { it('should be rendered correctly', () => { const component = shallow(<ExplorationError />).getElement diff --git a/src/components/Exploration/ExplorationFinished.spec.tsx b/src/components/Exploration/ExplorationFinished.spec.tsx index e78072219..8daffa84a 100644 --- a/src/components/Exploration/ExplorationFinished.spec.tsx +++ b/src/components/Exploration/ExplorationFinished.spec.tsx @@ -7,17 +7,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ExplorationFinished from './ExplorationFinished' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('ExplorationFinished', () => { const store = createMockEcolyoStore() it('should be rendered correctly', () => { diff --git a/src/components/Exploration/ExplorationOngoing.spec.tsx b/src/components/Exploration/ExplorationOngoing.spec.tsx index 4267bb61c..fd468838a 100644 --- a/src/components/Exploration/ExplorationOngoing.spec.tsx +++ b/src/components/Exploration/ExplorationOngoing.spec.tsx @@ -5,31 +5,15 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockUserChallengeUpdateFlag = jest.fn() const mockIsChallengeDone = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - isChallengeDone: mockIsChallengeDone, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + isChallengeDone: mockIsChallengeDone, + })) }) -const mockHistoryPush = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => ({ - push: mockHistoryPush, - }), -})) - describe('ExplorationOngoing component', () => { it('should be rendered correctly', () => { const store = createMockEcolyoStore() diff --git a/src/components/Exploration/ExplorationView.spec.tsx b/src/components/Exploration/ExplorationView.spec.tsx index 3b64f2ffe..ee403e980 100644 --- a/src/components/Exploration/ExplorationView.spec.tsx +++ b/src/components/Exploration/ExplorationView.spec.tsx @@ -10,17 +10,6 @@ import ExplorationFinished from './ExplorationFinished' import ExplorationOngoing from './ExplorationOngoing' import ExplorationView from './ExplorationView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => jest.fn(), -})) - jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') diff --git a/src/components/Feedback/FeedbackModal.spec.tsx b/src/components/Feedback/FeedbackModal.spec.tsx index 5ce641f8b..9d92f7ab0 100644 --- a/src/components/Feedback/FeedbackModal.spec.tsx +++ b/src/components/Feedback/FeedbackModal.spec.tsx @@ -9,18 +9,10 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' // Value coming from jest.config declare let __SAU_LINK__: string -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - jest.mock('services/environment.service', () => { - return jest.fn(() => { - return { - isProduction: () => true, - } - }) + return jest.fn(() => ({ + isProduction: () => true, + })) }) jest.mock('components/Hooks/useExploration', () => () => ['', jest.fn()]) diff --git a/src/components/FluidChart/HalfHourNoData/HalfHourNoData.spec.tsx b/src/components/FluidChart/HalfHourNoData/HalfHourNoData.spec.tsx index a5c625607..5b817591b 100644 --- a/src/components/FluidChart/HalfHourNoData/HalfHourNoData.spec.tsx +++ b/src/components/FluidChart/HalfHourNoData/HalfHourNoData.spec.tsx @@ -2,12 +2,6 @@ import { mount } from 'enzyme' import React from 'react' import HalfHourNoData from './HalfHourNoData' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('HalfHourNoData component', () => { it('should render correctly HalfHourNoData', () => { const component = mount(<HalfHourNoData />) diff --git a/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx b/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx index e0e0a6c02..2264ab476 100644 --- a/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx +++ b/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx @@ -11,11 +11,6 @@ import * as chartActions from 'store/chart/chart.slice' import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('services/usageEvent.service') const mockAddEvent = jest.fn() UsageEventService.addEvent = mockAddEvent diff --git a/src/components/Header/CozyBar.spec.tsx b/src/components/Header/CozyBar.spec.tsx index ea48ce7a0..274a14b02 100644 --- a/src/components/Header/CozyBar.spec.tsx +++ b/src/components/Header/CozyBar.spec.tsx @@ -19,12 +19,6 @@ jest.mock('utils/cozyBar', () => { } }) -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/src/components/Header/Header.spec.tsx b/src/components/Header/Header.spec.tsx index 074620e9a..8bd279a70 100644 --- a/src/components/Header/Header.spec.tsx +++ b/src/components/Header/Header.spec.tsx @@ -6,12 +6,6 @@ import { Provider } from 'react-redux' import * as ModalAction from 'store/modal/modal.slice' import { createMockEcolyoStore } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), diff --git a/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx b/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx index 595f02a28..b156f88bd 100644 --- a/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx +++ b/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx @@ -3,12 +3,6 @@ import { mount, shallow } from 'enzyme' import React from 'react' import ConnectionNotFound from './ConnectionNotFound' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('ConnectionNotFound component test', () => { const konnectorSlug = 'enedissgegrandlyon' diff --git a/src/components/Konnector/KonnectorModal.spec.tsx b/src/components/Konnector/KonnectorModal.spec.tsx index 2d4d38d18..d837f1ecb 100644 --- a/src/components/Konnector/KonnectorModal.spec.tsx +++ b/src/components/Konnector/KonnectorModal.spec.tsx @@ -8,24 +8,13 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import KonnectorModal from './KonnectorModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +const mockHandleCloseClick = jest.fn() describe('KonnectorModal component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() jest.clearAllMocks() }) - const mockHandleCloseClick = jest.fn() it('should be rendered correctly', () => { const wrapper = mount( <Provider store={store}> diff --git a/src/components/Konnector/KonnectorModalFooter.spec.tsx b/src/components/Konnector/KonnectorModalFooter.spec.tsx index 8f232344e..9cae90897 100644 --- a/src/components/Konnector/KonnectorModalFooter.spec.tsx +++ b/src/components/Konnector/KonnectorModalFooter.spec.tsx @@ -1,6 +1,6 @@ import { Button } from '@material-ui/core' import { ERROR_EVENT } from 'cozy-harvest-lib/dist/models/flowEvents' -import { FluidType, KonnectorError } from 'enums' +import { KonnectorError } from 'enums' import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' @@ -10,11 +10,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import KonnectorModalFooter from './KonnectorModalFooter' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -25,10 +20,7 @@ const mockDelete = jest.fn() describe('KonnectorModalFooter component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - mockDelete.mockClear() - mockClose.mockClear() - mockedNavigate.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', () => { @@ -37,7 +29,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={null} error={null} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} @@ -54,7 +45,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.USER_ACTION_NEEDED} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} @@ -73,7 +63,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.LOGIN_FAILED} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} @@ -90,7 +79,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.TERMS_VERSION_MISMATCH} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} @@ -108,7 +96,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.LOGIN_FAILED} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} @@ -125,7 +112,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.TERMS_VERSION_MISMATCH} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={accountsData[0]} @@ -144,7 +130,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.TERMS_VERSION_MISMATCH} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={accountsData[0]} @@ -163,7 +148,6 @@ describe('KonnectorModalFooter component', () => { <KonnectorModalFooter state={ERROR_EVENT} error={KonnectorError.TERMS_VERSION_MISMATCH} - fluidType={FluidType.ELECTRICITY} handleCloseClick={mockClose} handleAccountDeletion={mockDelete} account={null} diff --git a/src/components/Konnector/KonnectorViewerList.spec.tsx b/src/components/Konnector/KonnectorViewerList.spec.tsx index 47a2973bb..505bc5610 100644 --- a/src/components/Konnector/KonnectorViewerList.spec.tsx +++ b/src/components/Konnector/KonnectorViewerList.spec.tsx @@ -6,11 +6,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import KonnectorViewerList from './KonnectorViewerList' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -19,9 +14,6 @@ jest.mock('react-router-dom', () => ({ describe('KonnectorViewerList component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', async () => { const wrapper = mount( diff --git a/src/components/Konnector/__snapshots__/KonnectorModalFooter.spec.tsx.snap b/src/components/Konnector/__snapshots__/KonnectorModalFooter.spec.tsx.snap index 729e3c5d1..c54c118d7 100644 --- a/src/components/Konnector/__snapshots__/KonnectorModalFooter.spec.tsx.snap +++ b/src/components/Konnector/__snapshots__/KonnectorModalFooter.spec.tsx.snap @@ -16,7 +16,6 @@ exports[`KonnectorModalFooter component should be rendered correctly 1`] = ` <KonnectorModalFooter account={null} error={null} - fluidType={0} handleAccountDeletion={[MockFunction]} handleCloseClick={[MockFunction]} isUpdating={false} diff --git a/src/components/Loader/Loader.spec.tsx b/src/components/Loader/Loader.spec.tsx index 7fbb634fe..91618983d 100644 --- a/src/components/Loader/Loader.spec.tsx +++ b/src/components/Loader/Loader.spec.tsx @@ -3,12 +3,6 @@ import { mount } from 'enzyme' import React from 'react' import Loader from './Loader' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('Loader component', () => { it('should render base Loader', () => { const wrapper = mount(<Loader />) diff --git a/src/components/Navbar/Navbar.spec.tsx b/src/components/Navbar/Navbar.spec.tsx index dad8e7e21..b457828e3 100644 --- a/src/components/Navbar/Navbar.spec.tsx +++ b/src/components/Navbar/Navbar.spec.tsx @@ -5,12 +5,6 @@ import { Provider } from 'react-redux' import { BrowserRouter } from 'react-router-dom' import { createMockEcolyoStore } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('Navbar component', () => { it('should be rendered correctly with 5 navlink', () => { const store = createMockEcolyoStore() diff --git a/src/components/Options/ExportData/ExportData.spec.tsx b/src/components/Options/ExportData/ExportData.spec.tsx index 34e6a2069..3afe225ce 100644 --- a/src/components/Options/ExportData/ExportData.spec.tsx +++ b/src/components/Options/ExportData/ExportData.spec.tsx @@ -1,28 +1,15 @@ import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' -import mockClient from 'tests/__mocks__/client' - import ExportData from './ExportData' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('services/consumption.service', () => { - return jest.fn(() => { - return { - fetchAllFirstDateData: jest.fn(() => [null, null, null]), - getFluidsWithData: jest.fn(() => []), - } - }) + return jest.fn(() => ({ + fetchAllFirstDateData: jest.fn(() => [null, null, null]), + getFluidsWithData: jest.fn(() => []), + })) }) -jest.mock('cozy-client', () => ({ - useClient: () => mockClient, -})) - describe('exportOptions component', () => { it('should be rendered correctly', async () => { const wrapper = mount(<ExportData />) diff --git a/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx b/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx index 604f3b94e..6cb90a0e0 100644 --- a/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx @@ -6,19 +6,10 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import ExportDoneModal from './exportDoneModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() describe('exportDoneModal component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { const wrapper = mount( diff --git a/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx b/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx index fcfd0a73a..c25414ec7 100644 --- a/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx @@ -1,4 +1,5 @@ import { Button } from '@material-ui/core' +import { FluidType } from 'enums' import { mount } from 'enzyme' import toJson from 'enzyme-to-json' import React from 'react' @@ -6,21 +7,12 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import ExportLoadingModal from './exportLoadingModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() const mockHandleDone = jest.fn() -const mockSelectedFluids: Array<any> = [0, 1, 2] +const mockSelectedFluids: FluidType[] = [0, 1, 2] describe('ExportLoadingModal component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { const wrapper = mount( diff --git a/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx b/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx index 8630ed7db..2857c5f12 100644 --- a/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx @@ -6,20 +6,11 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import ExportStartModal from './exportStartModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() const mockHandleDownloadClick = jest.fn() describe('exportStartModal component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { const wrapper = mount( diff --git a/src/components/Options/GCU/GCUContent.spec.tsx b/src/components/Options/GCU/GCUContent.spec.tsx index f7480cd76..2bc41f57b 100644 --- a/src/components/Options/GCU/GCUContent.spec.tsx +++ b/src/components/Options/GCU/GCUContent.spec.tsx @@ -2,29 +2,9 @@ import GCUContent from 'components/Options/GCU/GCUContent' import { shallow } from 'enzyme' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => { - return { - useI18n: jest.fn(() => { - return { - t: (str: string) => { - if (str === 'gcu.content.part9_4_content') { - return 'test <a href="link.com">link</a>fin test' - } else { - return str - } - }, - } - }), - } -}) - describe('GCUContent component', () => { it('should be rendered correctly', () => { const component = shallow(<GCUContent />).getElement() expect(component).toMatchSnapshot() }) - it('should display a link when translation contains <a href=""></a>', () => { - const component = shallow(<GCUContent />).getElement() - expect(component).toMatchSnapshot() - }) }) diff --git a/src/components/Options/GCU/GCULink.spec.tsx b/src/components/Options/GCU/GCULink.spec.tsx index acbae4f38..f3cb6b4f3 100644 --- a/src/components/Options/GCU/GCULink.spec.tsx +++ b/src/components/Options/GCU/GCULink.spec.tsx @@ -2,12 +2,6 @@ import LegalNoticeLink from 'components/Options/LegalNotice/LegalNoticeLink' import { shallow } from 'enzyme' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('LegalNoticeLink component', () => { it('should be rendered correctly', () => { const component = shallow(<LegalNoticeLink />).getElement() diff --git a/src/components/Options/GCU/__snapshots__/GCUContent.spec.tsx.snap b/src/components/Options/GCU/__snapshots__/GCUContent.spec.tsx.snap index ea98b5c5b..93d8846db 100644 --- a/src/components/Options/GCU/__snapshots__/GCUContent.spec.tsx.snap +++ b/src/components/Options/GCU/__snapshots__/GCUContent.spec.tsx.snap @@ -266,294 +266,7 @@ exports[`GCUContent component should be rendered correctly 1`] = ` <span dangerouslySetInnerHTML={ Object { - "__html": "test <a href=\\"link.com\\">link</a>fin test", - } - } - /> - </p> - <p - className="text-14-normal" - > - <span - className="text-14-bold" - > - gcu.content.part9_5_title - </span> - <span> - gcu.content.part9_5_content - </span> - </p> - </div> -</div> -`; - -exports[`GCUContent component should display a link when translation contains <a href=""></a> 1`] = ` -<div - className="gcu-content-root" -> - <div - className="gcu-content-wrapper" - > - <p - className="text-14-normal version" - > - gcu.version - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title1 - </div> - <p - className="text-14-normal" - > - gcu.content.part1_1 - </p> - <p - className="text-14-normal" - > - gcu.content.part1_2 - </p> - <p - className="text-14-normal" - > - gcu.content.part1_3 - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title2 - </div> - <p - className="text-14-normal" - > - gcu.content.part2_1 - </p> - <p - className="text-14-normal" - > - gcu.content.part2_2 - </p> - <ul - className="text-14-normal" - > - <li> - gcu.content.part2_2_list1 - </li> - <li> - gcu.content.part2_2_list2 - </li> - <li> - gcu.content.part2_2_list3 - </li> - </ul> - <p - className="text-14-normal" - > - gcu.content.part2_3 - </p> - <p - className="text-14-normal" - > - gcu.content.part2_4 - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title3 - </div> - <p - className="text-14-normal" - > - gcu.content.part3_1 - </p> - <p - className="text-14-normal" - > - gcu.content.part3_2 - </p> - <p - className="text-14-normal" - > - gcu.content.part3_3 - </p> - <p - className="text-14-normal" - > - gcu.content.part3_4 - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title4 - </div> - <p - className="text-14-normal" - > - gcu.content.part4_1 - </p> - <p - className="text-14-normal" - dangerouslySetInnerHTML={ - Object { - "__html": "gcu.content.part4_2", - } - } - /> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title5 - </div> - <p - className="text-14-normal" - > - gcu.content.part5_1 - </p> - <p - className="text-14-normal" - > - gcu.content.part5_2 - </p> - <p - className="text-14-normal" - > - gcu.content.part5_3 - </p> - <ul - className="text-14-normal" - > - <li> - gcu.content.part5_3_list1 - </li> - <li> - gcu.content.part5_3_list2 - </li> - </ul> - <p - className="text-14-normal" - > - gcu.content.part5_4 - </p> - <p - className="text-14-normal" - > - gcu.content.part5_5 - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title6 - </div> - <p - className="text-14-normal" - > - gcu.content.part6_1 - </p> - <p - className="text-14-normal" - > - gcu.content.part6_2 - </p> - <p - className="text-14-normal" - > - gcu.content.part6_3 - </p> - <ul - className="text-14-normal" - > - <li> - gcu.content.part6_3_list1 - </li> - <li> - gcu.content.part6_3_list2 - </li> - <li> - gcu.content.part6_3_list3 - </li> - </ul> - <p - className="text-14-normal" - > - gcu.content.part6_4 - </p> - <p - className="text-14-normal" - > - gcu.content.part6_5 - </p> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title8 - </div> - <p - className="text-14-normal" - > - gcu.content.part8_1 - </p> - <p - className="text-14-normal" - dangerouslySetInnerHTML={ - Object { - "__html": "gcu.content.part8_2", - } - } - /> - <div - className="gcu-content-part-title text-15-normal" - > - gcu.content.title9 - </div> - <p - className="text-14-normal" - > - <span - className="text-14-bold" - > - gcu.content.part9_1_title - </span> - <span> - gcu.content.part9_1_content - </span> - </p> - <p - className="text-14-normal" - > - <span - className="text-14-bold" - > - gcu.content.part9_2_title - </span> - <span> - gcu.content.part9_2_content - </span> - </p> - <p - className="text-14-normal" - > - <span - className="text-14-bold" - > - gcu.content.part9_3_title - </span> - <span> - gcu.content.part9_3_content - </span> - </p> - <p - className="text-14-normal" - > - <span - className="text-14-bold" - > - gcu.content.part9_4_title - </span> - <span - dangerouslySetInnerHTML={ - Object { - "__html": "test <a href=\\"link.com\\">link</a>fin test", + "__html": "gcu.content.part9_4_content", } } /> diff --git a/src/components/Options/LegalNotice/LegalNoticeContent.spec.tsx b/src/components/Options/LegalNotice/LegalNoticeContent.spec.tsx index 4316fa7b4..55cbffee7 100644 --- a/src/components/Options/LegalNotice/LegalNoticeContent.spec.tsx +++ b/src/components/Options/LegalNotice/LegalNoticeContent.spec.tsx @@ -2,12 +2,6 @@ import LegalNoticeContent from 'components/Options/LegalNotice/LegalNoticeConten import { shallow } from 'enzyme' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('LegalNoticeContent component', () => { it('should be rendered correctly', () => { const component = shallow(<LegalNoticeContent />).getElement() diff --git a/src/components/Options/LegalNotice/LegalNoticeLink.spec.tsx b/src/components/Options/LegalNotice/LegalNoticeLink.spec.tsx index e4cc40d63..190508b0a 100644 --- a/src/components/Options/LegalNotice/LegalNoticeLink.spec.tsx +++ b/src/components/Options/LegalNotice/LegalNoticeLink.spec.tsx @@ -2,12 +2,6 @@ import GCULink from 'components/Options/GCU/GCULink' import { shallow } from 'enzyme' import React from 'react' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('GCULink component', () => { it('should be rendered correctly', () => { const component = shallow(<GCULink />).getElement() diff --git a/src/components/Options/MatomoOptOut/MatomoOptOut.spec.tsx b/src/components/Options/MatomoOptOut/MatomoOptOut.spec.tsx index 31f4ab7bb..ad9864f10 100644 --- a/src/components/Options/MatomoOptOut/MatomoOptOut.spec.tsx +++ b/src/components/Options/MatomoOptOut/MatomoOptOut.spec.tsx @@ -2,12 +2,6 @@ import { shallow } from 'enzyme' import React from 'react' import MatomoOptOut from './MatomoOptOut' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('MatomoOptOut component', () => { it('should be rendered correctly', () => { const component = shallow(<MatomoOptOut />).getElement() diff --git a/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx b/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx index 6a40244d5..6bbdb5dc3 100644 --- a/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx +++ b/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx @@ -18,17 +18,6 @@ import { mockProfileState, } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - describe('ProfileTypeOptions component', () => { const store = createMockEcolyoStore() it('should be rendered correctly', () => { diff --git a/src/components/Options/ReportOptions/ReportOptions.spec.tsx b/src/components/Options/ReportOptions/ReportOptions.spec.tsx index 070689330..7453ae580 100644 --- a/src/components/Options/ReportOptions/ReportOptions.spec.tsx +++ b/src/components/Options/ReportOptions/ReportOptions.spec.tsx @@ -11,19 +11,11 @@ import { mockInitialEcolyoState, } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockUpdateProfile = jest.fn() jest.mock('services/profile.service', () => { - return jest.fn(() => { - return { - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + updateProfile: mockUpdateProfile, + })) }) const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') @@ -31,8 +23,7 @@ const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') describe('ReportOptions component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - updateProfileSpy.mockClear() + jest.clearAllMocks() }) it('should be rendered with sendAnalysisNotification to true', () => { diff --git a/src/components/Options/Unsubscribe/UnSubscribeView.spec.tsx b/src/components/Options/Unsubscribe/UnSubscribeView.spec.tsx index f5534ba25..55ada4892 100644 --- a/src/components/Options/Unsubscribe/UnSubscribeView.spec.tsx +++ b/src/components/Options/Unsubscribe/UnSubscribeView.spec.tsx @@ -7,22 +7,15 @@ import * as profileActions from 'store/profile/profile.slice' import { createMockEcolyoStore } from 'tests/__mocks__/store' import UnSubscribeView from './UnSubscribeView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') const mockUpdateProfile = jest.fn() jest.mock('services/profile.service', () => { - return jest.fn(() => { - return { - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + updateProfile: mockUpdateProfile, + })) }) const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') const mockedNavigate = jest.fn() @@ -34,8 +27,7 @@ jest.mock('react-router-dom', () => ({ describe('UnSubscribe component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() - updateProfileSpy.mockClear() + jest.clearAllMocks() }) it('should be rendered correctly', () => { diff --git a/src/components/PartnerIssue/PartnerIssueModal.spec.tsx b/src/components/PartnerIssue/PartnerIssueModal.spec.tsx index ff2e62e9b..4aaf2652d 100644 --- a/src/components/PartnerIssue/PartnerIssueModal.spec.tsx +++ b/src/components/PartnerIssue/PartnerIssueModal.spec.tsx @@ -5,12 +5,6 @@ import React from 'react' import { mockInitialEcolyoState } from 'tests/__mocks__/store' import PartnerIssueModal from './PartnerIssueModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHandleClose = jest.fn() describe('PartnerIssueModal component', () => { it('should render correctly', () => { diff --git a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx index afe8e36dc..efaf28189 100644 --- a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx @@ -8,7 +8,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import ProfileTypeFinished from './ProfileTypeFinished' const mockedNavigate = jest.fn() - jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useLocation: () => ({ @@ -16,11 +15,7 @@ jest.mock('react-router-dom', () => ({ }), useNavigate: () => mockedNavigate, })) -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) + const mockAddEvent = jest.fn() jest.mock('services/usageEvent.service') UsageEventService.addEvent = mockAddEvent @@ -28,18 +23,15 @@ UsageEventService.addEvent = mockAddEvent const mockGetAllProfileTypes = jest.fn() const mockDeleteProfileTypes = jest.fn() jest.mock('services/profileTypeEntity.service', () => { - return jest.fn(() => { - return { - getAllProfileTypes: mockGetAllProfileTypes, - deleteProfileTypes: mockDeleteProfileTypes, - } - }) + return jest.fn(() => ({ + getAllProfileTypes: mockGetAllProfileTypes, + deleteProfileTypes: mockDeleteProfileTypes, + })) }) describe('ProfileTypeFinished component', () => { const store = createMockEcolyoStore() beforeEach(() => { - store.clearActions() jest.clearAllMocks() }) diff --git a/src/components/ProfileType/ProfileTypeFormMultiChoice/ProfileTypeFormMultiChoice.spec.tsx b/src/components/ProfileType/ProfileTypeFormMultiChoice/ProfileTypeFormMultiChoice.spec.tsx index 1bf3e9ddb..4abad2652 100644 --- a/src/components/ProfileType/ProfileTypeFormMultiChoice/ProfileTypeFormMultiChoice.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFormMultiChoice/ProfileTypeFormMultiChoice.spec.tsx @@ -9,27 +9,13 @@ import { import { createMockEcolyoStore } from 'tests/__mocks__/store' import ProfileTypeFormMultiChoice from './ProfileTypeFormMultiChoice' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +const mockHandlePrevious = jest.fn() +const mockHandleNext = jest.fn() describe('ProfileTypeFormMultiChoice component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { - const mockhandlePrevious = jest.fn() - const mockhandleNext = jest.fn() const wrapper = mount( <Provider store={store}> <ProfileTypeFormMultiChoice @@ -37,8 +23,8 @@ describe('ProfileTypeFormMultiChoice component', () => { viewedStep={ProfileTypeStepForm.AREA} currentProfileType={mockProfileType} answerType={mockProfileTypeAnswers[1]} - setNextStep={mockhandlePrevious} - setPreviousStep={mockhandleNext} + setNextStep={mockHandlePrevious} + setPreviousStep={mockHandleNext} /> </Provider> ) diff --git a/src/components/ProfileType/ProfileTypeFormNumber/ProfileTypeFormNumber.spec.tsx b/src/components/ProfileType/ProfileTypeFormNumber/ProfileTypeFormNumber.spec.tsx index 9d5265440..f272691bb 100644 --- a/src/components/ProfileType/ProfileTypeFormNumber/ProfileTypeFormNumber.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumber/ProfileTypeFormNumber.spec.tsx @@ -9,26 +9,13 @@ import { import { createMockEcolyoStore } from 'tests/__mocks__/store' import ProfileTypeFormNumber from './ProfileTypeFormNumber' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +const mockHandlePrevious = jest.fn() +const mockHandleNext = jest.fn() describe('ProfileTypeFormNumber component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { - const mockhandlePrevious = jest.fn() - const mockhandleNext = jest.fn() const wrapper = mount( <Provider store={store}> <ProfileTypeFormNumber @@ -36,8 +23,8 @@ describe('ProfileTypeFormNumber component', () => { viewedStep={ProfileTypeStepForm.AREA} currentProfileType={mockProfileType} answerType={mockProfileTypeAnswers[1]} - setNextStep={mockhandlePrevious} - setPreviousStep={mockhandleNext} + setNextStep={mockHandlePrevious} + setPreviousStep={mockHandleNext} /> </Provider> ) diff --git a/src/components/ProfileType/ProfileTypeFormNumberSelection/ProfileTypeFormNumberSelection.spec.tsx b/src/components/ProfileType/ProfileTypeFormNumberSelection/ProfileTypeFormNumberSelection.spec.tsx index 891f30ff4..c575f170d 100644 --- a/src/components/ProfileType/ProfileTypeFormNumberSelection/ProfileTypeFormNumberSelection.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFormNumberSelection/ProfileTypeFormNumberSelection.spec.tsx @@ -9,26 +9,13 @@ import { import { createMockEcolyoStore } from 'tests/__mocks__/store' import ProfileTypeFormNumberSelection from './ProfileTypeFormNumberSelection' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +const mockHandlePrevious = jest.fn() +const mockHandleNext = jest.fn() describe('ProfileTypeFormNumberSelection component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { - const mockhandlePrevious = jest.fn() - const mockhandleNext = jest.fn() const wrapper = mount( <Provider store={store}> <ProfileTypeFormNumberSelection @@ -36,8 +23,8 @@ describe('ProfileTypeFormNumberSelection component', () => { viewedStep={ProfileTypeStepForm.AREA} currentProfileType={mockProfileType} answerType={mockProfileTypeAnswers[3]} - setNextStep={mockhandlePrevious} - setPreviousStep={mockhandleNext} + setNextStep={mockHandleNext} + setPreviousStep={mockHandlePrevious} /> </Provider> ) diff --git a/src/components/ProfileType/ProfileTypeFormSingleChoice/ProfileTypeFormSingleChoice.spec.tsx b/src/components/ProfileType/ProfileTypeFormSingleChoice/ProfileTypeFormSingleChoice.spec.tsx index e0370e717..5ee630d39 100644 --- a/src/components/ProfileType/ProfileTypeFormSingleChoice/ProfileTypeFormSingleChoice.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFormSingleChoice/ProfileTypeFormSingleChoice.spec.tsx @@ -9,26 +9,13 @@ import { import { createMockEcolyoStore } from 'tests/__mocks__/store' import ProfileTypeFormSingleChoice from './ProfileTypeFormSingleChoice' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) +const mockHandlePrevious = jest.fn() +const mockHandleNext = jest.fn() describe('ProfileTypeFormSingleChoice component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { - const mockhandlePrevious = jest.fn() - const mockhandleNext = jest.fn() const wrapper = mount( <Provider store={store}> <ProfileTypeFormSingleChoice @@ -36,8 +23,8 @@ describe('ProfileTypeFormSingleChoice component', () => { viewedStep={ProfileTypeStepForm.AREA} currentProfileType={mockProfileType} answerType={mockProfileTypeAnswers[1]} - setNextStep={mockhandlePrevious} - setPreviousStep={mockhandleNext} + setNextStep={mockHandleNext} + setPreviousStep={mockHandlePrevious} /> </Provider> ) diff --git a/src/components/ProfileType/ProfileTypeView.spec.tsx b/src/components/ProfileType/ProfileTypeView.spec.tsx index 04bfc3bd5..a2192fa89 100644 --- a/src/components/ProfileType/ProfileTypeView.spec.tsx +++ b/src/components/ProfileType/ProfileTypeView.spec.tsx @@ -4,26 +4,12 @@ import React from 'react' import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) - jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') describe('ProfileTypeView component', () => { const store = createMockEcolyoStore() - beforeEach(() => { - store.clearActions() - }) it('should be rendered correctly', () => { const wrapper = mount( diff --git a/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx b/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx index 4dfc32037..8ad0f7374 100644 --- a/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx +++ b/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx @@ -8,19 +8,11 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizBegin from './QuizBegin' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockUserChallengeUpdateFlag = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + })) }) describe('QuizBegin component', () => { diff --git a/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx b/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx index 6b9038e26..1329a7fd3 100644 --- a/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx +++ b/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx @@ -9,19 +9,11 @@ import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizFinish from './QuizFinish' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockUserChallengeUpdateFlag = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + })) }) const mockedNavigate = jest.fn() diff --git a/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx index d849881ac..1421e6ce3 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestion.spec.tsx @@ -7,20 +7,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizQuestion from './QuizQuestion' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -const mockHistoryPush = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => ({ - push: mockHistoryPush, - }), -})) - const mockgetCustomQuestion = jest.fn() jest.mock('services/quiz.service', () => { return jest.fn(() => { diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx index 269720464..e30abb302 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx @@ -5,12 +5,6 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizQuestionContent from './QuizQuestionContent' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockedNavigate = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -19,20 +13,16 @@ jest.mock('react-router-dom', () => ({ const mockUpdateUserQuiz = jest.fn() jest.mock('services/quiz.service', () => { - return jest.fn(() => { - return { - updateUserQuiz: mockUpdateUserQuiz, - } - }) + return jest.fn(() => ({ + updateUserQuiz: mockUpdateUserQuiz, + })) }) const mockUserChallengeUpdateFlag = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + })) }) describe('QuizQuestionContent component', () => { diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx index 9b42e7b32..b05a3a8f6 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx @@ -9,12 +9,6 @@ import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import QuizExplanationModal from '../QuizExplanationModal/QuizExplanationModal' import QuizQuestionContentCustom from './QuizQuestionContentCustom' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockHistoryPush = jest.fn() jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), @@ -26,21 +20,17 @@ jest.mock('react-router-dom', () => ({ const mockUpdateUserQuiz = jest.fn() const mockGetCustomQuestion = jest.fn() jest.mock('services/quiz.service', () => { - return jest.fn(() => { - return { - updateUserQuiz: mockUpdateUserQuiz, - getCustomQuestion: mockGetCustomQuestion, - } - }) + return jest.fn(() => ({ + updateUserQuiz: mockUpdateUserQuiz, + getCustomQuestion: mockGetCustomQuestion, + })) }) const mockUserChallengeUpdateFlag = jest.fn() jest.mock('services/challenge.service', () => { - return jest.fn(() => { - return { - updateUserChallenge: mockUserChallengeUpdateFlag, - } - }) + return jest.fn(() => ({ + updateUserChallenge: mockUserChallengeUpdateFlag, + })) }) describe('QuizCustomQuestionContent component', () => { diff --git a/src/components/Quiz/QuizView.spec.tsx b/src/components/Quiz/QuizView.spec.tsx index 7ad781c8a..40f0962f0 100644 --- a/src/components/Quiz/QuizView.spec.tsx +++ b/src/components/Quiz/QuizView.spec.tsx @@ -11,17 +11,6 @@ import QuizBegin from './QuizBegin/QuizBegin' import QuizFinish from './QuizFinish/QuizFinish' import QuizQuestion from './QuizQuestion/QuizQuestion' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => jest.fn(), -})) - jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Content/Content', () => 'mock-content') diff --git a/src/components/Splash/SplashRoot.spec.tsx b/src/components/Splash/SplashRoot.spec.tsx index cffe3f6e0..55bce081c 100644 --- a/src/components/Splash/SplashRoot.spec.tsx +++ b/src/components/Splash/SplashRoot.spec.tsx @@ -11,12 +11,6 @@ jest.mock('@sentry/react', () => ({ startTransaction: () => ({ finish: jest.fn() }), })) -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('SplashRoot component', () => { it('should be rendered correctly', async () => { const store = createMockEcolyoStore() diff --git a/src/components/Splash/SplashScreen.spec.tsx b/src/components/Splash/SplashScreen.spec.tsx index 98c55a3c2..2277171e6 100644 --- a/src/components/Splash/SplashScreen.spec.tsx +++ b/src/components/Splash/SplashScreen.spec.tsx @@ -4,12 +4,6 @@ import { InitSteps } from 'models/initialisationSteps.model' import React from 'react' import SplashScreen from './SplashScreen' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('SplashScreen component', () => { it('should be rendered correctly', () => { const component = mount(<SplashScreen initStep={InitSteps.CONSENT} />) diff --git a/src/components/Splash/SplashScreenError.spec.tsx b/src/components/Splash/SplashScreenError.spec.tsx index aa759feb5..2f3837093 100644 --- a/src/components/Splash/SplashScreenError.spec.tsx +++ b/src/components/Splash/SplashScreenError.spec.tsx @@ -5,12 +5,6 @@ import { InitStepsErrors } from 'models/initialisationSteps.model' import React from 'react' import SplashScreenError from './SplashScreenError' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('SplashScreenError component', () => { const reload = window.location.reload diff --git a/src/components/Terms/CGUModal.spec.tsx b/src/components/Terms/CGUModal.spec.tsx index 3cbbcf8a5..8e54916bc 100644 --- a/src/components/Terms/CGUModal.spec.tsx +++ b/src/components/Terms/CGUModal.spec.tsx @@ -3,12 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import CGUModal from './CGUModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('CGUModal component', () => { it('should be rendered correctly', () => { const component = mount( diff --git a/src/components/Terms/DataShareConsentContent.spec.tsx b/src/components/Terms/DataShareConsentContent.spec.tsx index 1e856af6e..e2653b92a 100644 --- a/src/components/Terms/DataShareConsentContent.spec.tsx +++ b/src/components/Terms/DataShareConsentContent.spec.tsx @@ -5,12 +5,6 @@ import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' import DataShareConsentContent from './DataShareConsentContent' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('DataShareConsentContent component', () => { it('should be rendered correctly with first connexion text', () => { const store = createMockEcolyoStore({ diff --git a/src/components/Terms/LegalNoticeModal.spec.tsx b/src/components/Terms/LegalNoticeModal.spec.tsx index ccc09d963..1c8144711 100644 --- a/src/components/Terms/LegalNoticeModal.spec.tsx +++ b/src/components/Terms/LegalNoticeModal.spec.tsx @@ -3,12 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import LegalNoticeModal from './LegalNoticeModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('LegalNoticeModal component', () => { it('should be rendered correctly', () => { const component = mount( diff --git a/src/components/Terms/MinorUpdateContent.spec.tsx b/src/components/Terms/MinorUpdateContent.spec.tsx index ac15474dd..01cc23253 100644 --- a/src/components/Terms/MinorUpdateContent.spec.tsx +++ b/src/components/Terms/MinorUpdateContent.spec.tsx @@ -3,12 +3,6 @@ import toJson from 'enzyme-to-json' import React from 'react' import MinorUpdateContent from './MinorUpdateContent' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - describe('Minor update content component', () => { it('should be rendered correctly', () => { const component = mount(<MinorUpdateContent />) diff --git a/src/components/Terms/TermsView.spec.tsx b/src/components/Terms/TermsView.spec.tsx index cc905cb48..f615514e3 100644 --- a/src/components/Terms/TermsView.spec.tsx +++ b/src/components/Terms/TermsView.spec.tsx @@ -8,37 +8,22 @@ import { createMockEcolyoStore } from 'tests/__mocks__/store' import { mockUpToDateTerm } from 'tests/__mocks__/termsData.mock' import TermsView from './TermsView' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockCreateTerm = jest.fn() const mockGetTermsVersionType = jest.fn() jest.mock('services/terms.service', () => { - return jest.fn(() => { - return { - createTerm: mockCreateTerm, - getTermsVersionType: mockGetTermsVersionType, - } - }) + return jest.fn(() => ({ + createTerm: mockCreateTerm, + getTermsVersionType: mockGetTermsVersionType, + })) }) -const mockedNavigate = jest.fn() -jest.mock('react-router-dom', () => ({ - ...jest.requireActual('react-router-dom'), - useNavigate: () => mockedNavigate, -})) const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch') const mockUpdateProfile = jest.fn() jest.mock('services/profile.service', () => { - return jest.fn(() => { - return { - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + updateProfile: mockUpdateProfile, + })) }) describe('TermsView component', () => { diff --git a/src/components/TotalConsumption/TotalConsumption.spec.tsx b/src/components/TotalConsumption/TotalConsumption.spec.tsx index 3a80eab66..a427bd1ca 100644 --- a/src/components/TotalConsumption/TotalConsumption.spec.tsx +++ b/src/components/TotalConsumption/TotalConsumption.spec.tsx @@ -7,12 +7,6 @@ import { createMockEcolyoStore, mockChartState } from 'tests/__mocks__/store' import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import TotalConsumption from './TotalConsumption' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) - const mockChartStore = createMockEcolyoStore({ chart: { ...mockChartState, diff --git a/src/components/WelcomeModal/WelcomeModal.spec.tsx b/src/components/WelcomeModal/WelcomeModal.spec.tsx index 8bce59cfc..9d6706a61 100644 --- a/src/components/WelcomeModal/WelcomeModal.spec.tsx +++ b/src/components/WelcomeModal/WelcomeModal.spec.tsx @@ -4,20 +4,9 @@ import toJson from 'enzyme-to-json' import React from 'react' import { Provider } from 'react-redux' import * as profileActions from 'store/profile/profile.slice' -import mockClient from 'tests/__mocks__/client' import { createMockEcolyoStore } from 'tests/__mocks__/store' import WelcomeModal from './WelcomeModal' -jest.mock('cozy-ui/transpiled/react/I18n', () => ({ - useI18n: jest.fn(() => ({ - t: (str: string) => str, - })), -})) -jest.mock('cozy-client', () => { - return { - useClient: jest.fn(() => mockClient), - } -}) jest.mock('components/Hooks/useUserInstanceSettings', () => { return jest.fn(() => ({ data: { @@ -27,33 +16,25 @@ jest.mock('components/Hooks/useUserInstanceSettings', () => { })) }) jest.mock('services/environment.service', () => { - return jest.fn(() => { - return { - getPublicURL: () => 'https://ecolyo-agent-rec.grandlyon.com', - } - }) + return jest.fn(() => ({ + getPublicURL: () => 'https://ecolyo-agent-rec.grandlyon.com', + })) }) const mockSendMail = jest.fn() jest.mock('services/mail.service', () => { - return jest.fn(() => { - return { - SendMail: mockSendMail, - } - }) + return jest.fn(() => ({ + SendMail: mockSendMail, + })) }) jest.mock('notifications/welcome.hbs', () => { - return jest.fn(() => { - return { - welcomeTemplate: jest.fn(), - } - }) + return jest.fn(() => ({ + welcomeTemplate: jest.fn(), + })) }) jest.mock('mjml-browser', () => { - return jest.fn(() => { - return { - mjml2html: jest.fn(), - } - }) + return jest.fn(() => ({ + mjml2html: jest.fn(), + })) }) jest.mock('services/profile.service') @@ -61,7 +42,7 @@ const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') describe('WelcomeModal component', () => { beforeEach(() => { - updateProfileSpy.mockClear() + jest.clearAllMocks() }) const store = createMockEcolyoStore() diff --git a/src/migrations/migration.service.spec.ts b/src/migrations/migration.service.spec.ts index 4474c7db3..af4ee1112 100644 --- a/src/migrations/migration.service.spec.ts +++ b/src/migrations/migration.service.spec.ts @@ -3,7 +3,7 @@ import { PROFILE_DOCTYPE } from 'doctypes' import { Profile } from 'models' import { Notes } from 'models/releaseNotes.model' import { Schema } from 'models/schema.models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import * as Migrate from './migration' import { MIGRATION_RESULT_FAILED } from './migration.data' import { MigrationService } from './migration.service' @@ -17,7 +17,7 @@ describe('Migration service', () => { description: '', } beforeEach(() => { - migrateSpy.mockClear() + jest.clearAllMocks() }) it('should run migrations', async () => { const schema: Schema = { _id: '1', version: 0 } diff --git a/src/migrations/migration.spec.ts b/src/migrations/migration.spec.ts index c07a3181a..f316279e7 100644 --- a/src/migrations/migration.spec.ts +++ b/src/migrations/migration.spec.ts @@ -2,7 +2,7 @@ import { QueryResult } from 'cozy-client' import { FLUIDSPRICES_DOCTYPE, PROFILE_DOCTYPE } from 'doctypes' import { FluidPrice, Profile } from 'models' import { Schema } from 'models/schema.models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { mockProfileState } from 'tests/__mocks__/store' import { migrate, migrationLog } from './migration' import { diff --git a/src/services/account.service.spec.ts b/src/services/account.service.spec.ts index fea058abf..e43bb207e 100644 --- a/src/services/account.service.spec.ts +++ b/src/services/account.service.spec.ts @@ -3,7 +3,7 @@ import { QueryResult } from 'cozy-client' import * as harvestLibAccounts from 'cozy-harvest-lib/dist/connections/accounts' import { Account, AccountAuthData } from 'models' import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { konnectorsData } from 'tests/__mocks__/konnectorsData.mock' import { triggersEnedisData } from 'tests/__mocks__/triggersData.mock' import AccountService from './account.service' @@ -15,11 +15,9 @@ const mockHavestLibAccounts = harvestLibAccounts as jest.Mocked< const mockGetTriggerForAccount = jest.fn() jest.mock('./triggers.service', () => { - return jest.fn(() => { - return { - getTriggerForAccount: mockGetTriggerForAccount, - } - }) + return jest.fn(() => ({ + getTriggerForAccount: mockGetTriggerForAccount, + })) }) describe('Account service', () => { diff --git a/src/services/action.service.spec.ts b/src/services/action.service.spec.ts index df7b19a1f..ea0ca3a00 100644 --- a/src/services/action.service.spec.ts +++ b/src/services/action.service.spec.ts @@ -6,45 +6,45 @@ import { defaultEcogestureData, ecogestureDefault, } from 'tests/__mocks__/actionData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' -import * as utils from 'utils/utils' import ActionService from './action.service' -const mockgetAllUserChallengeEntities = jest.fn() +const mockGetAllUserChallengeEntities = jest.fn() jest.mock('./challenge.service', () => { - return jest.fn(() => { - return { - getAllUserChallengeEntities: mockgetAllUserChallengeEntities, - } - }) + return jest.fn(() => ({ + getAllUserChallengeEntities: mockGetAllUserChallengeEntities, + })) }) -const mockgetAllEcogestures = jest.fn() -const mockgetEcogesturesByIds = jest.fn() +const mockGetAllEcogestures = jest.fn() +const mockGetEcogesturesByIds = jest.fn() jest.mock('./ecogesture.service', () => { - return jest.fn(() => { - return { - getAllEcogestures: mockgetAllEcogestures, - getEcogesturesByIds: mockgetEcogesturesByIds, - } - }) + return jest.fn(() => ({ + getAllEcogestures: mockGetAllEcogestures, + getEcogesturesByIds: mockGetEcogesturesByIds, + })) }) +const mockGetSeason = jest.fn() +jest.mock('utils/utils', () => ({ + getSeason: () => mockGetSeason(), +})) + describe('Action Service', () => { const actionService = new ActionService(mockClient) it('should return the default actions', async () => { - mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) - mockgetEcogesturesByIds.mockResolvedValueOnce(defaultEcogestureData) + mockGetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) + mockGetEcogesturesByIds.mockResolvedValueOnce(defaultEcogestureData) const result: Ecogesture[] = await actionService.getDefaultActions() expect(result).toEqual(defaultEcogestureData) }) it('should return the Available Action List', async () => { - mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) - mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) - mockgetEcogesturesByIds.mockResolvedValueOnce([ + mockGetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) + mockGetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) + mockGetEcogesturesByIds.mockResolvedValueOnce([ AllEcogestureData[2], AllEcogestureData[3], AllEcogestureData[4], @@ -58,7 +58,7 @@ describe('Action Service', () => { ]) }) it('should return winter ecogestures', () => { - jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) + mockGetSeason.mockReturnValueOnce(Season.WINTER) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) expect(result).toEqual([ AllEcogestureData[0], @@ -67,13 +67,13 @@ describe('Action Service', () => { ]) }) it('should return no season ecogestures', () => { - jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.NONE) + mockGetSeason.mockReturnValueOnce(Season.NONE) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) expect(result).toEqual([AllEcogestureData[3], AllEcogestureData[4]]) }) it('should return summer ecogestures', () => { - jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.SUMMER) + mockGetSeason.mockReturnValueOnce(Season.SUMMER) const result: Ecogesture[] = actionService.filterBySeason(AllEcogestureData) expect(result).toEqual([ @@ -100,7 +100,7 @@ describe('Action Service', () => { expect(result).toEqual(UserActionDefault) }) it('complete list if < 3', async () => { - mockgetEcogesturesByIds.mockResolvedValueOnce([ + mockGetEcogesturesByIds.mockResolvedValueOnce([ AllEcogestureData[2], AllEcogestureData[3], AllEcogestureData[4], @@ -119,10 +119,10 @@ describe('Action Service', () => { describe('getCustomActions function', () => { it('should return filtered and sorted ecogestures and not complete the list', async () => { - jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) - mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) - mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) - mockgetEcogesturesByIds.mockResolvedValueOnce([ + mockGetSeason.mockReturnValueOnce(Season.WINTER) + mockGetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) + mockGetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) + mockGetEcogesturesByIds.mockResolvedValueOnce([ AllEcogestureData[0], AllEcogestureData[1], AllEcogestureData[2], @@ -139,17 +139,17 @@ describe('Action Service', () => { ]) }) it('should return filtered and sorted ecogestures and complete the list with default ecogesture', async () => { - jest.spyOn(utils, 'getSeason').mockReturnValueOnce(Season.WINTER) - mockgetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) - mockgetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) - mockgetEcogesturesByIds.mockResolvedValueOnce([ + mockGetSeason.mockReturnValueOnce(Season.WINTER) + mockGetAllUserChallengeEntities.mockResolvedValueOnce(userChallengeData) + mockGetAllEcogestures.mockResolvedValueOnce(AllEcogestureData) + mockGetEcogesturesByIds.mockResolvedValueOnce([ AllEcogestureData[0], AllEcogestureData[1], AllEcogestureData[2], AllEcogestureData[3], ]) - mockgetEcogesturesByIds.mockClear() - mockgetEcogesturesByIds.mockResolvedValueOnce([ + mockGetEcogesturesByIds.mockClear() + mockGetEcogesturesByIds.mockResolvedValueOnce([ defaultEcogestureData[0], defaultEcogestureData[1], defaultEcogestureData[2], diff --git a/src/services/challenge.service.spec.ts b/src/services/challenge.service.spec.ts index 2b5c19152..a683a391b 100644 --- a/src/services/challenge.service.spec.ts +++ b/src/services/challenge.service.spec.ts @@ -23,7 +23,7 @@ import { challengeEntityData, } from 'tests/__mocks__/challengeEntity.mock' import { graphData } from 'tests/__mocks__/chartData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allDuelEntity, duelData, @@ -55,37 +55,28 @@ const mockGetExplorationEntityById = jest.fn() const mockParseExplorationEntityToUserExploration = jest.fn() const mockGetUserExplorationFromExplorationEntities = jest.fn() jest.mock('./exploration.service', () => { - return jest.fn(() => { - return { - getExplorationEntityById: mockGetExplorationEntityById, - parseExplorationEntityToUserExploration: - mockParseExplorationEntityToUserExploration, - getUserExplorationfromExplorationEntities: - mockGetUserExplorationFromExplorationEntities, - } - }) + return jest.fn(() => ({ + getExplorationEntityById: mockGetExplorationEntityById, + parseExplorationEntityToUserExploration: + mockParseExplorationEntityToUserExploration, + getUserExplorationfromExplorationEntities: + mockGetUserExplorationFromExplorationEntities, + })) }) const mockGetGraphData = jest.fn() const mockCalculatePerformanceIndicatorValue = jest.fn() jest.mock('./consumption.service', () => { - return jest.fn(() => { - return { - getGraphData: mockGetGraphData, - calculatePerformanceIndicatorValue: - mockCalculatePerformanceIndicatorValue, - } - }) + return jest.fn(() => ({ + getGraphData: mockGetGraphData, + calculatePerformanceIndicatorValue: mockCalculatePerformanceIndicatorValue, + })) }) describe('Challenge service', () => { const challengeService = new ChallengeService(mockClient) beforeEach(() => { - mockGetExplorationEntityById.mockClear() - mockParseExplorationEntityToUserExploration.mockClear() - mockGetUserExplorationFromExplorationEntities.mockClear() - mockGetGraphData.mockClear() - mockCalculatePerformanceIndicatorValue.mockClear() + jest.clearAllMocks() }) describe('unLockCurrentUserChallenge method', () => { diff --git a/src/services/connection.service.spec.ts b/src/services/connection.service.spec.ts index ae41efe92..445efa37f 100644 --- a/src/services/connection.service.spec.ts +++ b/src/services/connection.service.spec.ts @@ -1,35 +1,29 @@ import { AccountAuthData } from 'models' import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { konnectorsData } from 'tests/__mocks__/konnectorsData.mock' import { triggersData } from 'tests/__mocks__/triggersData.mock' import ConnectionService from './connection.service' const mockGetKonnector = jest.fn() jest.mock('./konnector.service', () => { - return jest.fn(() => { - return { - getKonnector: mockGetKonnector, - } - }) + return jest.fn(() => ({ + getKonnector: mockGetKonnector, + })) }) const mockCreateAccount = jest.fn() jest.mock('./account.service', () => { - return jest.fn(() => { - return { - createAccount: mockCreateAccount, - } - }) + return jest.fn(() => ({ + createAccount: mockCreateAccount, + })) }) const mockCreateTrigger = jest.fn() jest.mock('./triggers.service', () => { - return jest.fn(() => { - return { - createTrigger: mockCreateTrigger, - } - }) + return jest.fn(() => ({ + createTrigger: mockCreateTrigger, + })) }) const mockEGLAuthData: AccountAuthData = { diff --git a/src/services/consumption.service.spec.ts b/src/services/consumption.service.spec.ts index f402858a3..ba675a859 100644 --- a/src/services/consumption.service.spec.ts +++ b/src/services/consumption.service.spec.ts @@ -10,7 +10,7 @@ import { FluidStatus, TimePeriod, } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { fetchDayDataComplete, fetchDayDataIncomplete, @@ -26,15 +26,13 @@ const mockGetFirstDateData = jest.fn() const mockGetLastDateData = jest.fn() const mockGetEntries = jest.fn() jest.mock('./queryRunner.service', () => { - return jest.fn(() => { - return { - fetchFluidData: mockFetchFluidData, - fetchFluidMaxData: mockFetchFluidMaxData, - getFirstDateData: mockGetFirstDateData, - getLastDateData: mockGetLastDateData, - getEntries: mockGetEntries, - } - }) + return jest.fn(() => ({ + fetchFluidData: mockFetchFluidData, + fetchFluidMaxData: mockFetchFluidMaxData, + getFirstDateData: mockGetFirstDateData, + getLastDateData: mockGetLastDateData, + getEntries: mockGetEntries, + })) }) describe('Consumption service', () => { @@ -78,9 +76,6 @@ describe('Consumption service', () => { ] describe('getGraphData method', () => { - beforeEach(() => { - mockFetchFluidData.mockClear() - }) it('should return null', async () => { const result = await consumptionDataManager.getGraphData( mockTimePeriod, diff --git a/src/services/customPopup.service.test.ts b/src/services/customPopup.service.test.ts index fbd69e543..6808d6cef 100644 --- a/src/services/customPopup.service.test.ts +++ b/src/services/customPopup.service.test.ts @@ -1,13 +1,11 @@ -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { mockCustomPopup } from 'tests/__mocks__/customPopup.mock' import CustomPopupService from './customPopup.service' jest.mock('services/environment.service', () => { - return jest.fn(() => { - return { - isProduction: () => true, - } - }) + return jest.fn(() => ({ + isProduction: () => true, + })) }) describe('PartnersInfo service', () => { diff --git a/src/services/duel.service.spec.ts b/src/services/duel.service.spec.ts index 86db4ddc4..f50bf5e4a 100644 --- a/src/services/duel.service.spec.ts +++ b/src/services/duel.service.spec.ts @@ -4,7 +4,7 @@ import { DateTime, Duration } from 'luxon' import { DuelEntity, UserDuel } from 'models' import DuelService from 'services/duel.service' import { fullGraphData, graphData } from 'tests/__mocks__/chartData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allDuelData, duelData, @@ -19,21 +19,17 @@ const mockGetPerformanceIndicators = jest.fn() const mockGetGraphData = jest.fn() jest.mock('./consumption.service', () => { - return jest.fn(() => { - return { - getPerformanceIndicators: mockGetPerformanceIndicators, - getGraphData: mockGetGraphData, - } - }) + return jest.fn(() => ({ + getPerformanceIndicators: mockGetPerformanceIndicators, + getGraphData: mockGetGraphData, + })) }) const mockAggregatePerformanceIndicators = jest.fn() jest.mock('./performanceIndicator.service', () => { - return jest.fn(() => { - return { - aggregatePerformanceIndicators: mockAggregatePerformanceIndicators, - } - }) + return jest.fn(() => ({ + aggregatePerformanceIndicators: mockAggregatePerformanceIndicators, + })) }) describe('Duel service', () => { diff --git a/src/services/ecogesture.service.spec.ts b/src/services/ecogesture.service.spec.ts index db5c4424d..df4796ddc 100644 --- a/src/services/ecogesture.service.spec.ts +++ b/src/services/ecogesture.service.spec.ts @@ -3,7 +3,7 @@ import ecogestureData from 'db/ecogestureData.json' import { EquipmentType, IndividualOrCollective, WarmingType } from 'enums' import { Ecogesture } from 'models' import { ProfileEcogesture } from 'models/profileEcogesture.model' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { BoilerEcogesture, BoilerEcogestureFalse, diff --git a/src/services/enedisMonthlyAnalysisData.service.spec.ts b/src/services/enedisMonthlyAnalysisData.service.spec.ts index ee545f25b..fd72985c3 100644 --- a/src/services/enedisMonthlyAnalysisData.service.spec.ts +++ b/src/services/enedisMonthlyAnalysisData.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { EnedisMonthlyAnalysisData } from 'models/enedisMonthlyAnalysis' import { MaxPowerEntity } from 'models/maxPower.model' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { maxPowerData, mockDataLoadEnedisAnalysis, diff --git a/src/services/exploration.service.spec.ts b/src/services/exploration.service.spec.ts index 966588ab3..9745d5f30 100644 --- a/src/services/exploration.service.spec.ts +++ b/src/services/exploration.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { UserExplorationState } from 'enums' import { ExplorationEntity, UserChallenge, UserExploration } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allExplorationEntities, explorationEntity, diff --git a/src/services/fluid.service.spec.ts b/src/services/fluid.service.spec.ts index 26c3114ba..fd3878c55 100644 --- a/src/services/fluid.service.spec.ts +++ b/src/services/fluid.service.spec.ts @@ -3,7 +3,7 @@ import { FluidSlugType, FluidState, FluidType } from 'enums' import { DateTime } from 'luxon' import { FluidStatus } from 'models' import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { konnectorsData } from 'tests/__mocks__/konnectorsData.mock' import { triggerStateData } from 'tests/__mocks__/triggerStateData.mock' import { triggersData } from 'tests/__mocks__/triggersData.mock' @@ -11,42 +11,34 @@ import FluidService from './fluid.service' const mockGetAccountByType = jest.fn() jest.mock('./account.service', () => { - return jest.fn(() => { - return { - getAccountByType: mockGetAccountByType, - } - }) + return jest.fn(() => ({ + getAccountByType: mockGetAccountByType, + })) }) const mockGetKonnector = jest.fn() jest.mock('./konnector.service', () => { - return jest.fn(() => { - return { - getKonnector: mockGetKonnector, - } - }) + return jest.fn(() => ({ + getKonnector: mockGetKonnector, + })) }) const mockGetTrigger = jest.fn() const mockFetchTriggerState = jest.fn() jest.mock('./triggers.service', () => { - return jest.fn(() => { - return { - getTrigger: mockGetTrigger, - fetchTriggerState: mockFetchTriggerState, - } - }) + return jest.fn(() => ({ + getTrigger: mockGetTrigger, + fetchTriggerState: mockFetchTriggerState, + })) }) const mockFetchAllFirstDateData = jest.fn() const mockFetchAllLastDateData = jest.fn() jest.mock('./consumption.service', () => { - return jest.fn(() => { - return { - fetchAllFirstDateData: mockFetchAllFirstDateData, - fetchAllLastDateData: mockFetchAllLastDateData, - } - }) + return jest.fn(() => ({ + fetchAllFirstDateData: mockFetchAllFirstDateData, + fetchAllLastDateData: mockFetchAllLastDateData, + })) }) const mockDataDates: (DateTime | null)[] = [ diff --git a/src/services/fluidsPrices.service.spec.ts b/src/services/fluidsPrices.service.spec.ts index f1455d8a2..c1620f889 100644 --- a/src/services/fluidsPrices.service.spec.ts +++ b/src/services/fluidsPrices.service.spec.ts @@ -2,7 +2,7 @@ import { QueryResult } from 'cozy-client' import { FluidType } from 'enums' import { DateTime } from 'luxon' import { FluidPrice } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allLastFluidPrices, fluidPrices, diff --git a/src/services/initialization.service.spec.ts b/src/services/initialization.service.spec.ts index fe608098c..073bc74f0 100644 --- a/src/services/initialization.service.spec.ts +++ b/src/services/initialization.service.spec.ts @@ -8,7 +8,7 @@ import { DateTime } from 'luxon' import { Profile, UserChallenge } from 'models' import { allChallengeEntityData } from 'tests/__mocks__/challengeEntity.mock' import { graphData } from 'tests/__mocks__/chartData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allDuelEntity } from 'tests/__mocks__/duelData.mock' import { allExplorationEntities } from 'tests/__mocks__/explorationData.mock' import { fluidPrices } from 'tests/__mocks__/fluidPrice.mock' @@ -26,31 +26,25 @@ import InitializationService from './initialization.service' const mockCreateIndexKonnector = jest.fn() jest.mock('./konnector.service', () => { - return jest.fn(() => { - return { - createIndexKonnector: mockCreateIndexKonnector, - } - }) + return jest.fn(() => ({ + createIndexKonnector: mockCreateIndexKonnector, + })) }) const mockCreateIndexAccount = jest.fn() jest.mock('./account.service', () => { - return jest.fn(() => { - return { - createIndexAccount: mockCreateIndexAccount, - } - }) + return jest.fn(() => ({ + createIndexAccount: mockCreateIndexAccount, + })) }) const mockGetProfile = jest.fn() const mockUpdateProfile = jest.fn() jest.mock('./profile.service', () => { - return jest.fn(() => { - return { - getProfile: mockGetProfile, - updateProfile: mockUpdateProfile, - } - }) + return jest.fn(() => ({ + getProfile: mockGetProfile, + updateProfile: mockUpdateProfile, + })) }) const mockGetAllChallengeEntities = jest.fn() @@ -60,78 +54,64 @@ const mockGetUserChallengeDataload = jest.fn() const mockUserChallengeUpdateFlag = jest.fn() const mockInitChallengeDuelProgress = jest.fn() jest.mock('./challenge.service', () => { - return jest.fn(() => { - return { - getAllChallengeEntities: mockGetAllChallengeEntities, - deleteAllChallengeEntities: mockDeleteAllChallengeEntities, - buildUserChallengeList: mockBuildUserChallengeList, - getUserChallengeDataload: mockGetUserChallengeDataload, - updateUserChallenge: mockUserChallengeUpdateFlag, - initChallengeDuelProgress: mockInitChallengeDuelProgress, - } - }) + return jest.fn(() => ({ + getAllChallengeEntities: mockGetAllChallengeEntities, + deleteAllChallengeEntities: mockDeleteAllChallengeEntities, + buildUserChallengeList: mockBuildUserChallengeList, + getUserChallengeDataload: mockGetUserChallengeDataload, + updateUserChallenge: mockUserChallengeUpdateFlag, + initChallengeDuelProgress: mockInitChallengeDuelProgress, + })) }) const mockGetAllPrices = jest.fn() const mockDeleteAllFluidsPrices = jest.fn() jest.mock('./fluidsPrices.service', () => { - return jest.fn(() => { - return { - getAllPrices: mockGetAllPrices, - deleteAllFluidsPrices: mockDeleteAllFluidsPrices, - } - }) + return jest.fn(() => ({ + getAllPrices: mockGetAllPrices, + deleteAllFluidsPrices: mockDeleteAllFluidsPrices, + })) }) const mockGetAllDuelEntities = jest.fn() const mockDeleteAllDuelEntities = jest.fn() jest.mock('./duel.service', () => { - return jest.fn(() => { - return { - getAllDuelEntities: mockGetAllDuelEntities, - deleteAllDuelEntities: mockDeleteAllDuelEntities, - } - }) + return jest.fn(() => ({ + getAllDuelEntities: mockGetAllDuelEntities, + deleteAllDuelEntities: mockDeleteAllDuelEntities, + })) }) const mockGetAllQuizEntities = jest.fn() const mockDeleteAllQuizEntities = jest.fn() jest.mock('./quiz.service', () => { - return jest.fn(() => { - return { - getAllQuizEntities: mockGetAllQuizEntities, - deleteAllQuizEntities: mockDeleteAllQuizEntities, - } - }) + return jest.fn(() => ({ + getAllQuizEntities: mockGetAllQuizEntities, + deleteAllQuizEntities: mockDeleteAllQuizEntities, + })) }) const mockGetAllExplorationEntities = jest.fn() const mockDeleteAllExplorationEntities = jest.fn() jest.mock('./exploration.service', () => { - return jest.fn(() => { - return { - getAllExplorationEntities: mockGetAllExplorationEntities, - deleteAllExplorationEntities: mockDeleteAllExplorationEntities, - } - }) + return jest.fn(() => ({ + getAllExplorationEntities: mockGetAllExplorationEntities, + deleteAllExplorationEntities: mockDeleteAllExplorationEntities, + })) }) const mockGetKonnectorAccountStatus = jest.fn() jest.mock('./konnectorStatus.service', () => { - return jest.fn(() => { - return { - getKonnectorAccountStatus: mockGetKonnectorAccountStatus, - } - }) + return jest.fn(() => ({ + getKonnectorAccountStatus: mockGetKonnectorAccountStatus, + })) }) const mockGetFluidStatus = jest.fn() jest.mock('./fluid.service', () => { - return jest.fn(() => { - return { - getFluidStatus: mockGetFluidStatus, - } - }) + return jest.fn(() => ({ + getFluidStatus: mockGetFluidStatus, + })) }) const mockIsConsentVersionUpToDate = jest.fn() @@ -139,14 +119,12 @@ const mockIsLastTermValidated = jest.fn() const mockGetTermsVersionType = jest.fn() const mockGetLastTerm = jest.fn() jest.mock('./terms.service', () => { - return jest.fn(() => { - return { - isConsentVersionUpToDate: mockIsConsentVersionUpToDate, - isLastTermValidated: mockIsLastTermValidated, - getTermsVersionType: mockGetTermsVersionType, - getLastTerm: mockGetLastTerm, - } - }) + return jest.fn(() => ({ + isConsentVersionUpToDate: mockIsConsentVersionUpToDate, + isLastTermValidated: mockIsLastTermValidated, + getTermsVersionType: mockGetTermsVersionType, + getLastTerm: mockGetLastTerm, + })) }) describe('Initialization service', () => { @@ -156,15 +134,10 @@ describe('Initialization service', () => { jest.fn() ) beforeEach(() => { - mockClient.query.mockClear() - mockClient.create.mockClear() + jest.clearAllMocks() }) describe('initProfile method', () => { - beforeEach(() => { - mockGetProfile.mockClear() - mockUpdateProfile.mockClear() - }) it('should return the profil when existing', async () => { mockGetProfile.mockResolvedValueOnce(mockProfileState) mockUpdateProfile.mockResolvedValueOnce(mockProfileState) @@ -211,10 +184,6 @@ describe('Initialization service', () => { }) describe('initFluidPrices method', () => { - beforeEach(() => { - mockGetAllPrices.mockClear() - mockDeleteAllFluidsPrices.mockClear() - }) it('should do nothing because prices are already created', async () => { mockGetAllPrices.mockResolvedValueOnce(fluidPrices) const isDone = await initializationService.initFluidPrices() @@ -227,10 +196,6 @@ describe('Initialization service', () => { }) }) describe('initChallengeEntity method', () => { - beforeEach(() => { - mockGetAllChallengeEntities.mockClear() - mockDeleteAllChallengeEntities.mockClear() - }) it('should return hash when challenges hash is already up to date', async () => { mockGetAllChallengeEntities.mockResolvedValueOnce(challengeEntityData) const hash = hashFile(challengeEntityData) @@ -329,10 +294,6 @@ describe('Initialization service', () => { }) describe('initDuelEntity method', () => { - beforeEach(() => { - mockGetAllDuelEntities.mockClear() - mockDeleteAllDuelEntities.mockClear() - }) it('should return hash when duel hash is already up to date', async () => { mockGetAllDuelEntities.mockResolvedValueOnce(duelEntityData) const hash = hashFile(duelEntityData) @@ -425,10 +386,6 @@ describe('Initialization service', () => { }) describe('initQuizEntity method', () => { - beforeEach(() => { - mockGetAllQuizEntities.mockClear() - mockDeleteAllQuizEntities.mockClear() - }) it('should return hash when quiz hash is already up to date', async () => { mockGetAllQuizEntities.mockResolvedValueOnce(quizEntityData) const hash = hashFile(quizEntityData) @@ -521,10 +478,6 @@ describe('Initialization service', () => { }) describe('initExplorationEntity method', () => { - beforeEach(() => { - mockGetAllExplorationEntities.mockClear() - mockDeleteAllExplorationEntities.mockClear() - }) it('should return hash when explorations hash is already up to date', async () => { mockGetAllExplorationEntities.mockResolvedValueOnce(explorationEntityData) const hash = hashFile(explorationEntityData) @@ -674,9 +627,6 @@ describe('Initialization service', () => { }) describe('initFluidType method', () => { - beforeEach(() => { - mockGetKonnectorAccountStatus.mockClear() - }) it('should return all fluid types', async () => { mockGetKonnectorAccountStatus.mockResolvedValueOnce([ FluidType.ELECTRICITY, @@ -704,9 +654,6 @@ describe('Initialization service', () => { }) describe('initFluidStatus method', () => { - beforeEach(() => { - mockGetFluidStatus.mockClear() - }) it('should return all fluids type', async () => { mockGetFluidStatus.mockResolvedValueOnce(fluidStatusData) await expect(initializationService.initFluidStatus()).resolves.toEqual( @@ -728,9 +675,6 @@ describe('Initialization service', () => { }) describe('initUserChallenges method', () => { - beforeEach(() => { - mockBuildUserChallengeList.mockClear() - }) it('should return all userChallenges', async () => { mockBuildUserChallengeList.mockResolvedValueOnce(userChallengeData) await expect( @@ -754,9 +698,6 @@ describe('Initialization service', () => { }) describe('initDuelProgress method', () => { - beforeEach(() => { - mockInitChallengeDuelProgress.mockClear() - }) it('should return updatedUserChallenge and dataload', async () => { const expectedUpdatedUserChallenge: UserChallenge = { ...userChallengeData[0], diff --git a/src/services/konnector.service.spec.ts b/src/services/konnector.service.spec.ts index d13fc9c5f..85791bc51 100644 --- a/src/services/konnector.service.spec.ts +++ b/src/services/konnector.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { Konnector } from 'models' import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { konnectorsData } from 'tests/__mocks__/konnectorsData.mock' import { triggerStateData } from 'tests/__mocks__/triggerStateData.mock' import { triggersData } from 'tests/__mocks__/triggersData.mock' @@ -10,12 +10,10 @@ import KonnectorService from './konnector.service' const mockGetTrigger = jest.fn() const mockFetchTriggerState = jest.fn() jest.mock('./triggers.service', () => { - return jest.fn(() => { - return { - getTrigger: mockGetTrigger, - fetchTriggerState: mockFetchTriggerState, - } - }) + return jest.fn(() => ({ + getTrigger: mockGetTrigger, + fetchTriggerState: mockFetchTriggerState, + })) }) describe('KonnectorService service', () => { diff --git a/src/services/konnectorStatus.service.spec.ts b/src/services/konnectorStatus.service.spec.ts index 8363fb7e4..204f5f149 100644 --- a/src/services/konnectorStatus.service.spec.ts +++ b/src/services/konnectorStatus.service.spec.ts @@ -1,14 +1,12 @@ import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import KonnectorStatusService from './konnectorStatus.service' const mockGetAccountByType = jest.fn() jest.mock('./account.service', () => { - return jest.fn(() => { - return { - getAccountByType: mockGetAccountByType, - } - }) + return jest.fn(() => ({ + getAccountByType: mockGetAccountByType, + })) }) describe('KonnectorService service', () => { diff --git a/src/services/mail.service.spec.ts b/src/services/mail.service.spec.ts index b18adf458..6d2094221 100644 --- a/src/services/mail.service.spec.ts +++ b/src/services/mail.service.spec.ts @@ -1,4 +1,4 @@ -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import MailService from './mail.service' describe('Mail service', () => { diff --git a/src/services/partnersInfo.service.spec.ts b/src/services/partnersInfo.service.spec.ts index e6d00896e..652109c9e 100644 --- a/src/services/partnersInfo.service.spec.ts +++ b/src/services/partnersInfo.service.spec.ts @@ -1,13 +1,11 @@ import { PartnersInfo } from 'models/partnersInfo.model' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import PartnersInfoService from './partnersInfo.service' jest.mock('services/environment.service', () => { - return jest.fn(() => { - return { - isProduction: () => true, - } - }) + return jest.fn(() => ({ + isProduction: () => true, + })) }) /* eslint-disable camelcase */ diff --git a/src/services/profile.service.spec.ts b/src/services/profile.service.spec.ts index e23cf9877..c30366ec2 100644 --- a/src/services/profile.service.spec.ts +++ b/src/services/profile.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { DateTime } from 'luxon' import { Profile } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { mockProfileState } from 'tests/__mocks__/store' import ProfileService from './profile.service' diff --git a/src/services/profileEcogesture.service.spec.ts b/src/services/profileEcogesture.service.spec.ts index a52714795..a68faa2b3 100644 --- a/src/services/profileEcogesture.service.spec.ts +++ b/src/services/profileEcogesture.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { EquipmentType } from 'enums' import { ProfileEcogesture } from 'models/profileEcogesture.model' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { mockProfileEcogestureUpdated } from 'tests/__mocks__/profileEcogesture.mock' import ProfileEcogestureService from './profileEcogesture.service' diff --git a/src/services/profileType.service.spec.ts b/src/services/profileType.service.spec.ts index fc9dc8e3b..73909c5b3 100644 --- a/src/services/profileType.service.spec.ts +++ b/src/services/profileType.service.spec.ts @@ -10,7 +10,7 @@ import { } from 'enums' import { DateTime } from 'luxon' import { ProfileType } from 'models/profileType.model' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { mockCorrectedConsumption, mockEstimatedConsumption, diff --git a/src/services/profileTypeEntity.service.spec.ts b/src/services/profileTypeEntity.service.spec.ts index a1b91cc8c..b47674c0a 100644 --- a/src/services/profileTypeEntity.service.spec.ts +++ b/src/services/profileTypeEntity.service.spec.ts @@ -1,6 +1,6 @@ import { QueryResult } from 'cozy-client' import { ProfileType } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { profileTypeData } from 'tests/__mocks__/profileType.mock' import ProfileTypeEntityService from './profileTypeEntity.service' diff --git a/src/services/queryRunner.service.spec.ts b/src/services/queryRunner.service.spec.ts index 9627d2adf..f273f8f47 100644 --- a/src/services/queryRunner.service.spec.ts +++ b/src/services/queryRunner.service.spec.ts @@ -2,7 +2,7 @@ import { QueryResult } from 'cozy-client' import { DataloadState, FluidType, TimeStep } from 'enums' import { DateTime } from 'luxon' import { Dataload, DataloadEntity } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { loadDayData } from 'tests/__mocks__/loadDayData.mock' import { loadMinuteData } from 'tests/__mocks__/loadMinuteData.mock' import { loadMonthData } from 'tests/__mocks__/loadMonthData.mock' diff --git a/src/services/quiz.service.spec.ts b/src/services/quiz.service.spec.ts index 9e5e91850..6db5b0f90 100644 --- a/src/services/quiz.service.spec.ts +++ b/src/services/quiz.service.spec.ts @@ -20,7 +20,7 @@ import { graphData, graphMonthData, } from 'tests/__mocks__/chartData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { UserQuizDone, UserQuizReseted, @@ -40,12 +40,10 @@ const randomSpy = jest.spyOn(Math, 'random') const mockGetGraphData = jest.fn() const mockGetMaxLoad = jest.fn() jest.mock('./consumption.service', () => { - return jest.fn(() => { - return { - getGraphData: mockGetGraphData, - getMaxLoad: mockGetMaxLoad, - } - }) + return jest.fn(() => ({ + getGraphData: mockGetGraphData, + getMaxLoad: mockGetMaxLoad, + })) }) describe('Quiz service', () => { diff --git a/src/services/terms.service.spec.ts b/src/services/terms.service.spec.ts index 08ba3d743..eb6c6769b 100644 --- a/src/services/terms.service.spec.ts +++ b/src/services/terms.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { DateTime } from 'luxon' import { Term } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import mockConfig from 'tests/__mocks__/mockConfig.mock' import { mockOutdatedTerm, diff --git a/src/services/triggers.service.spec.ts b/src/services/triggers.service.spec.ts index 58b444dc7..23aac8b37 100644 --- a/src/services/triggers.service.spec.ts +++ b/src/services/triggers.service.spec.ts @@ -1,7 +1,7 @@ import { QueryResult } from 'cozy-client' import { Trigger, TriggerState } from 'models' import { accountsData } from 'tests/__mocks__/accountsData.mock' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { konnectorsData } from 'tests/__mocks__/konnectorsData.mock' import { triggerStateData } from 'tests/__mocks__/triggerStateData.mock' import { triggersData } from 'tests/__mocks__/triggersData.mock' @@ -9,11 +9,9 @@ import TriggerService from './triggers.service' const mockCreateTrigger = jest.fn() jest.mock('cozy-harvest-lib/dist/connections/triggers', () => { - return jest.fn(() => { - return { - createTrigger: mockCreateTrigger, - } - }) + return jest.fn(() => ({ + createTrigger: mockCreateTrigger, + })) }) describe('TriggerService service', () => { diff --git a/src/services/usageEvent.service.spec.ts b/src/services/usageEvent.service.spec.ts index 64aa8e84f..3994abba1 100644 --- a/src/services/usageEvent.service.spec.ts +++ b/src/services/usageEvent.service.spec.ts @@ -2,7 +2,7 @@ import { QueryResult } from 'cozy-client' import { UsageEventType } from 'enums' import { DateTime } from 'luxon' import { AddEventParams, UsageEventEntity } from 'models' -import mockClient from 'tests/__mocks__/client' +import mockClient from 'tests/__mocks__/client.mock' import { allUsageEventsData, connectionAttemptEGLError, diff --git a/src/store/profileEcogesture/profileEcogesture.action.spec.ts b/src/store/profileEcogesture/profileEcogesture.action.spec.ts index 45337183a..3881312f8 100644 --- a/src/store/profileEcogesture/profileEcogesture.action.spec.ts +++ b/src/store/profileEcogesture/profileEcogesture.action.spec.ts @@ -8,12 +8,10 @@ import { const mockUpdateProfileEcogesture = jest.fn() const mockNewProfileEcogestureEntry = jest.fn() jest.mock('services/profileEcogesture.service', () => { - return jest.fn(() => { - return { - updateProfileEcogesture: mockUpdateProfileEcogesture, - newProfileEcogestureEntry: mockNewProfileEcogestureEntry, - } - }) + return jest.fn(() => ({ + updateProfileEcogesture: mockUpdateProfileEcogesture, + newProfileEcogestureEntry: mockNewProfileEcogestureEntry, + })) }) describe('profileEcogesture actions', () => { diff --git a/tests/__mocks__/client.ts b/tests/__mocks__/client.mock.ts similarity index 100% rename from tests/__mocks__/client.ts rename to tests/__mocks__/client.mock.ts diff --git a/tests/__mocks__/store/store.ts b/tests/__mocks__/store/store.ts index edcf8340d..13a90c7ef 100644 --- a/tests/__mocks__/store/store.ts +++ b/tests/__mocks__/store/store.ts @@ -1,7 +1,7 @@ import configureStore from 'redux-mock-store' import thunkMiddleware from 'redux-thunk' import { AppActionsTypes, EcolyoState, MockEcolyoState } from 'store/store' -import mockClient from '../client' +import mockClient from '../client.mock' import { mockProfileEcogesture } from '../profileEcogesture.mock' import { mockAnalysisState } from './analysis.state.mock' import { mockChallengeState } from './challenge.state.mock' diff --git a/tests/jestLib/setup.js b/tests/jestLib/setup.js deleted file mode 100644 index 46f8d0d25..000000000 --- a/tests/jestLib/setup.js +++ /dev/null @@ -1,37 +0,0 @@ -require('babel-polyfill') -require('jest-canvas-mock') - -import { configure } from 'enzyme' -import Adapter from 'enzyme-adapter-react-16' - -configure({ adapter: new Adapter() }) - -// polyfill for requestAnimationFrame -/* istanbul ignore next */ -global.requestAnimationFrame = cb => { - setTimeout(cb, 0) -} - -global.cozy = { - bar: { - BarLeft: ({ children }) => children, - BarRight: ({ children }) => children, - BarCenter: ({ children }) => children, - setTheme: () => null, - }, -} - -Object.defineProperty(window, 'getComputedStyle', { - value: () => ({ - getPropertyValue: prop => { - switch (prop) { - case '--blue': - return '#58ffff' - case '--greyDark': - return '#7b7b7b' - default: - return '#FFFFFF' - } - }, - }), -}) diff --git a/tests/jestLib/setupTests.ts b/tests/jestLib/setupTests.ts new file mode 100644 index 000000000..a71f0dfd2 --- /dev/null +++ b/tests/jestLib/setupTests.ts @@ -0,0 +1,24 @@ +require('babel-polyfill') +require('jest-canvas-mock') + +import { configure } from 'enzyme' +import Adapter from 'enzyme-adapter-react-16' +import mockClient from 'tests/__mocks__/client.mock' + +configure({ adapter: new Adapter() }) + +jest.mock('cozy-ui/transpiled/react/I18n', () => ({ + useI18n: jest.fn(() => ({ + t: (key: string) => key, + })), +})) + +jest.mock('cozy-client', () => ({ + ...jest.requireActual('cozy-client'), + useClient: () => mockClient, +})) + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useNavigate: () => jest.fn(), +})) diff --git a/yarn.lock b/yarn.lock index b0430e79d..1271b362e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2762,6 +2762,21 @@ "@types/d3-transition" "^2" "@types/d3-zoom" "^2" +"@types/enzyme-adapter-react-16@^1.0.6": + version "1.0.6" + resolved "https://registry.yarnpkg.com/@types/enzyme-adapter-react-16/-/enzyme-adapter-react-16-1.0.6.tgz#8aca7ae2fd6c7137d869b6616e696d21bb8b0cec" + integrity sha512-VonDkZ15jzqDWL8mPFIQnnLtjwebuL9YnDkqeCDYnB4IVgwUm0mwKkqhrxLL6mb05xm7qqa3IE95m8CZE9imCg== + dependencies: + "@types/enzyme" "*" + +"@types/enzyme@*": + version "3.10.13" + resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.13.tgz#332c0ed59b01f7b1c398c532a1c21a5feefabeb1" + integrity sha512-FCtoUhmFsud0Yx9fmZk179GkdZ4U9B0GFte64/Md+W/agx0L5SxsIIbhLBOxIb9y2UfBA4WQnaG1Od/UsUQs9Q== + dependencies: + "@types/cheerio" "*" + "@types/react" "^16" + "@types/enzyme@^3.10.8": version "3.10.12" resolved "https://registry.yarnpkg.com/@types/enzyme/-/enzyme-3.10.12.tgz#ac4494801b38188935580642f772ad18f72c132f" -- GitLab