diff --git a/.vscode/settings.json b/.vscode/settings.json index 744ba2f959c9b84531a5fdfd830bb49e9083c9da..44149075fc752fbcc16c98a9ecdd76ee8460778b 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 cbbdcfe6bdc490310cf09c967750408436271a71..6358f0010306c4fbb8435f2f88795297250e0e5e 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 b7f05b0d24a5af398ee08898945e15a67182444c..8ba4fe8976e20f647cfe3bb4010a023be3f07973 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 2abec216346e68f453971e69183ad25689360883..2c05f3c115ef1df48b59bb4b52d1e942d8d88b7e 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 bc15c74764a44b76d7ae970ce1e889f84b8708c5..72c90f35e2cbce3c8ffb4a40d599b0ffc929dc63 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 6b41863f9af0dd2b4291866b4e2589cfacdef79d..fee4477b804e9af5d1fbc67c7d044293ecaa758e 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 ab20ba7b2e5199dc4f3704af0472f1753455ffb3..93f2bcdac3ccd81c76135f09db10b4a2ba320ef7 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 b48eee51020267bd8a9c1b127cfa0c9d34640ee7..0716cc3b749132ea1d63f5c3bb37eb61b6bc8fdf 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 a0237a2bc91874ffd60f4acaca18fb45aebfc9cc..e243a3a28008104d95de3620c8b498994cf12361 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 64b0d920969483a1cbef908f7ca100b9ee5d2269..9f54ea0a10ff088b54107d22b7f92b382aa26b64 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 3f2f8f492d68b0b091d728c3aa13a9dd2b13416f..de69a0814379f8b24950e6235fc664908603cf8c 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 e34726252580be8ce999890662cf936c5d0f000a..8f8936c0d3cf2af2b1ed9abf4ccbc39efda0fb70 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 1481e2c88be5683913d68da59c169d82dc26d707..6045ccf904a12b96be67fcb3c24e77c91ea44270 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 f0756b7ec8a6b237dd9abffafde7ea0f0926c6af..16f33ebcedfbd10f8eb694b5c4ff89052ee9770a 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 72b8d6d0ae351f664830e8ca4f2dd25a701a92b0..88c4aa8ec70d728fbe32848d9bc463299b0af6e5 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 7dba81723472e81684336ada81a404b31ee39de5..9524348096134b9c11095febedd2255ee79e62ab 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 c833c8c1436ddc64079cd1305e5e715a3ec3553b..85a452c6db5e384be71fdd6129a52102096fbf82 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 7b7e0363fa06afec1dca1b7e2989eed468a2137d..8dda881935a9c200430556bf76648e16b79fa0f0 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 243264d3ab2c82835ea4e780e627ab5dd1209a32..b6f18e5460fa79ce0379d5e9560cfb91fee9f7f3 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 f8b37f9576d90ecd9062022c086654154b25015d..6f8997cf4802ee46ee3accbf6fb15ef2a6b95f55 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 6c008806ce8a8a662be71a645850af9c4d97780a..bf62f78673d796a587fb730f9716389a48084137 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 064408f847341c177a3126e6e7fc58b9bd978066..c866cabdfc46bb9b18fb06bc7a13fe3ceb9305ca 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 21effece2964a740f0ee06ca9229979d33ed8bb4..4bcfcc3a643b781db65fc4cb74f4a0d43d3d1f1e 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 51fdf9afc8fb55da3bd36ef397e67caa433e9f52..9c4a0a2f27cd73a15d69acde9b1ad4786a9582ee 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 73bf140fac49d5bb373daedb3a8d4b52fe84dd23..22af2203e4cc13b5adafe0770bf075b5c54b83a4 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 4065b79a95263d9d80105608cc039d1d1a998470..5395d8e193876cc7176b2022e6717eac11544c5e 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 027b0268a8f52a745ded159605419471feb3cf0d..b711bf01d054b954d88b651e55d3f93c1d70d6fe 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 08dfd9aa58dc937e1aacc769da0c058d41a1d070..0cf83e9a1b06f17772d8146401b3366ac861c282 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 6fadd106ab70c6682efa1efc2d433a737f2af515..04014cf96f27ac15071b2dab80342001f909dbdf 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 e223c20f9a7fed67a626e148b6c312732b705fc8..310572994d34e6d7e4e3a479e080c996d8c603fc 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 a28970ae9f5f0c699366229fc959519f27262654..1d8f8cb1abce23621b028e2b7b91bbe4d4f0db25 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 da25e6dc0c2c8707dad491c65ae6fe9a62d83964..c10ede15c1f41fca123b0f9e5473e1845e292fad 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 1e3c9eb391471f3f22a2fb03406b635619656fb5..0ff617522637e524d35052ef38840788e4c87b1e 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 83f0718f5ebeb49f8e761b57954e80bc6e80d3e0..5c3056586516010172a1a063caf5fe63384ccc92 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 685b0f43c3611c73af46c5d36f7f5669fbedf4ce..f1482257208d279c2dd0eed0a81feeb4f02a1356 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 e8c666f6a39b70bc1c9e123bca3043ce0813fc60..f49c1b48e180abeb6e48f244166bf46494b3f9ba 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 8703cfe9d26aae3f4a0ac6312de2543d2d6fb02a..27cd6d1eed3ab8978b06f3d21398a5890c2fce85 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 c1fd7f53cb99ecbc22b2185f3a802532a43b3448..c5915516acfff3f7dca52840d7c9e2c01f5e1604 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 b03a29c2ac3ccdb4ec7d4cebaf7b8194d1e0270a..de738abe48d8e42a4f067e58b9190c7e04879028 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 93cea948d5cfa8cde4fe42c82e194fb9afb72f90..ea767693397e0a5b816c5b3b0929a703902c491b 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 0c577af1b4dfcea6ceb16e86946e4e9e08357960..30d79f957431c78317760898f2ea0b05bba533f6 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 3f1b2bc7d506b2a7e4b23660225209763785a4d4..840893b54596f048dfc9fd03f6720d0d824e3783 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 316d9e0f3dbcb45eb804fc9a6a0d45395f049235..eab06f6c662dab4514e4bfa2d2700f528cade3c2 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 500aa61c3d1f980e32a7d7b7f35880b0a6c38f1e..785ca968a3de16578d2baa84243cf8257fdbf9a8 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 f1e6c713688e9f909bfbedb066133b74f63ce445..c2ca84554bed9594ee4cbedefd83143ca964127e 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 9e92e02056782b3109b42a205c757d22355d5bb1..562541f5d959e1480967fe4c37ccec4fe39de638 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 16d66b146963068c23261f38b416e2e246b5e2ae..3579c54ab88ad34d8f1db15334f65455e1c9f4da 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 b711a57693d2b35f1c4c605cc96a703f70f8cbc1..6268e2f341d3e85908aa8a1e2b822d78581302a6 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 7c2a6f0cb73e53bdec614ffdd269b6565e6b2177..bb036742c1c30ebb6c91a7fb3761642d9cd8b7f3 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 04ed871e42595e0ea9de17f8f85851e15f8151fe..28699710e7d5fa9239d9b75d879c894a85d1104a 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 50cf24a07dfafd8dc9f13def060af367ae308451..4517997e1748978a089adc3a5dcf152e6c69f8ee 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 55db7ace88c67ceedcbd1dce897870f9c336842a..35226df5e9569c1ea89f17af3be08acdeb67e623 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 2b0e5ab969f196d15e92e0b64c1c90b580806b89..28f63e5570ce5e0d5eb6cd4f2381ca35bd74a17d 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 84ab4e32d036923f598054c2c56538f8a455b9e4..aef6fc33e7a13cfca6e51e8647c945e6ce906d91 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 fd38a9ca2c013560658cea971831c7cd262f5fda..144cbc4d6b1f190b943ee7654f0139a6f7a306aa 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 c2032052700da9cc5aac03ac28bdbdf5805a9eb3..7992098174f530db86f4248ec920195f69afc53f 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 250e959f535461ed203a62bf1d3f227ac389a46b..b7e0256198e84b91442a3e4a8a8a911d0c760cff 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 6f230b8b3517f80e1f92015982747f9c7ab54114..8dd1a1c779f26d63751c650bfa524caba7633bbb 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 44fa9239fca30913f95b803af1048f33afdbe9c0..3f79b27a926a75fb72caf145534616e1c18385fb 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 b16023eb1f40f12b959c0af893e4d5da755881b6..5c7a807be742818b637fdd9bbfdf7363de51112e 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 b9dedb9d253cd5310c4aeef0766858df1c0462c9..8cd2494ef27ec449db23f6afc6184dce346eb196 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 38538b7fcc09408328481152c597f49cf382b118..c8763df63e5fbb524b73033abcabce425d044f75 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 7345593c2b4661b86bf8bbce18e10815d131fbf7..2f9eb9c8db8afaa204d5f76f903226a6592ed7e4 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 6e68360600735a634d14c3d23966922c7450d88c..4a73f4cf35e6d2c5551678bb6a8639c2fdf4607c 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 4a87bdd34022db59a06192fe5656a87700618548..99029ebbc233b10ce774ad17a8ee9ab1e809b214 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 4ef56d04819513f36fe4b984e910b34bcc3c0cbf..822eff26b405e9e7c99bc755697de2a10d4f7583 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 f590ca9f362f8ed65754fafe386665d4bf1cb69a..80a35498f7563ae764171373d2f3653ec22c9fc3 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 f1f88b60870a349985be0ed6050fc74979b81878..ed1f8b01bfd824f6031c9d867e765570efac1432 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 074a0c972bbe69f41d6499ef077043e68843efc8..836668c817c2485778f5debce45af380ada292d5 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 5a91aa831bf60d66938f34bcf85be63cdb4a1680..56a97459a19a5216b13c877d45b8cea9786355a9 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 e6d11ab23243b0c647232ec8e1947682347ca3c4..d2cdc41219c4946089271ceae696567d599ad5a8 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 47c4af89762cdfdc55bb99e22c17c855f1898b9b..9f527a984e5c9e729de3761d3035f2399a8dac88 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 cc90f64a6afd4fbb5a5e57a6d5714bde7539f211..e51a18972c6a03163e26b0a59c5d9b973da3f9a9 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 f877e968e697fe21158d638e430d7a69e27a442b..8cfd17faf6db498327f1a08d2520afb395bdd7c4 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 9bb6ec44bdf89e6702facebbbb8334be3ff2e571..5f9148b0379bd6bb81982b521e23bd2b3e489304 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 17d8c832f022b3c824956153dbf2d46c8f57c457..f9eb724daac10611df25dc09f03a69a68ea564eb 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 35690f5f2acb565fc1d1bcc112a3a32b6db5efa5..0ac6b73e5884385bfddb078699cf61d6c1a1de39 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 09315002eed7e99c1a374ef13de84dabcdd96f8e..3dca815a0eeac991f12710e7b5b55da94a0b3663 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 73666bc8973e16c2083d7ba6ca91b7a711d77030..80927a48fe58dc2349b6a756cfbaeab302f51402 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 b586ef0805304710c0393bd553f89071845fa1b8..102b0d4b3b40bf4ec8a6146657b06d9b213ef254 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 502f657b4dfe5fbede39d01be563da923e731765..3d97bafc6e7d1818a5eb16eaa519467f1ae1e7b6 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 717d72343eb4b4e3cf295faecef64af16e6567e3..77256f6dc3a6203aa1fd52e46c032f4db2f70854 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 1f02899586d6f5f39292cdd282ec026577cd3cc9..1efe25a5ee1b77c66b2e72a4ea8a45bdbfa06bcc 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 cf1ebcde7f1e8378ae561a912957674629d14e5b..6d248173c0e505d11a7d2ed6f6b4e94de80229ac 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 bded38e56adb198ea87f56117e6db48cec16285f..8909ac3fb08ea93c2135fee9ae4789885bf69701 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 3b81ac7bdfa7b9e3bf990a93cda82d55ff2dbe05..0ccba339a75399d3b83515fb202f4d9b7741ded7 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 13d309ddfbb17765cde97b784c6f2f7bc7e221d6..a25ce5445ca3091dec4e2a374ef3a7237ac118d1 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 4af3daef4421820938602c6fec8ad31eb9f50951..b6359dd88ff4b2d0f1e63d9615ab7c7b94247a6f 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 7f83daeea5e7906a2d806ccd090991dd5b19f66f..b2f3141ca6eaacce91aa0cd11a60e755297fc0ea 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 ded77ef64de974756e232a04e9584829df33726e..08bc2048c80cd920cf7ec6c4291944c56f159bd5 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 11ca91568d6fd47e52c0100fe022edf9471ed94e..234ba798c846879c520b2fdc1091dcbb1e3ea964 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 389ed334e2ebd8b034a658c39fd57ad25398f400..4ea8699db42cada633e20108310d45a64d088909 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 e78072219b38ea6267704bc98a54f9ec09487b83..8daffa84a7912563618badc5a146c455b15fef0c 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 4267bb61c0d3a557923a03774e6a42e7b204bb37..fd468838a054e0940ab340371fa5e0856548697f 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 3b64f2ffebcc0a1f393cc148c3d51d8e9657a554..ee403e980aae1b5d781265dc8e19e539e68ac1f6 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 5ce641f8ba8ab1b93e7ae877e9120fb7dff20072..9d92f7ab09c2fa5be1a428d01eff76b1718c3b00 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 a5c62560756dbedead4deb6e31669b553183bd48..5b817591bf6040deab0540b88f806542e5078fb4 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 e0e0a6c02bc70636fe72f2fa4e868ab77449de95..2264ab47644e03aa5a944a1974c56eea05e30711 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 ea48ce7a064bd13ae64aa8f5e0e2b6b92c31898f..274a14b02a7b75dd088148174d95780760d286bd 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 074620e9adc3d654c45205babd4a955806af6afe..8bd279a70e7324ec27ffaaeaf7b40fcc5b073548 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 595f02a28dac731cc6d6cf5177a08f52e32e60ee..b156f88bdaa38b1f97e2ebba58900d9ccf3f8d21 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 2d4d38d1835f0f6aa15e0366a9cea9e360a57194..d837f1ecb75f5f12291ba4f8b884ea56b951c80a 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 8f232344ec545f768a97758cc0caefd0d2905909..9cae908979dd046567044598190bbda60fa0cb97 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 47a2973bbde48e323573de16947a7d5ace542c2e..505bc5610081f730a5c63d4d6869eedcd2285cdb 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 729e3c5d13d8721ad2e9fe24dbc4223c7940dad3..c54c118d73c5d35603892d5c7fd1eb25e25bbd49 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 7fbb634fed45bb60975334e14092029819b4a66d..91618983d037be9155a6d8a2d79f67b139c1741a 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 dad8e7e2186219fbf001e0bad3c5c2813a5d6961..b457828e3ad1b908fe88acef7ac8fafdaa7a9e69 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 34e6a2069ba1dbf0468890b4ec2ae7be1f13742d..3afe225cedebd2d113d6995bc6c510bd1b8c30c6 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 604f3b94e5eb09d477e2ee79c5981fdb293cdb6c..6cb90a0e016525de85d2dac06908ed39551c8344 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 fcfd0a73a341c0315e34122e5f7c4def8d17a492..c25414ec7dda48cecacb4e9bf17a59ba8695d948 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 8630ed7db81b74347810bea258e11a4625ca56fb..2857c5f1235e615589ca6622159e30f00f606245 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 f7480cd76e1780e54a5cd5e26834b39939143397..2bc41f57b908daa0b20931d8a48be0fef4720aa2 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 acbae4f38e8eebfa627ebb5520eef62175c42866..f3cb6b4f33f294ff4767901ceafbf2aa58280998 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 ea98b5c5bfe26e8e4f4db25366f0348c62902e85..93d8846db6808891dfce8569b1bb4924ef66289c 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 4316fa7b4566de16e46db741a3dd21dccea41554..55cbffee7411bb30bd48c38f9dce6e0d059c8cc7 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 e4cc40d630564e3ca1124c25d25d427b2f90bd57..190508b0a3b43e85ffa0c7ce0d07a6d65012fdc1 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 31f4ab7bbe2725bfc636f12e0125ddb71f77acba..ad9864f10b2466b2e313d4f6228a5033dd9d8294 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 6a40244d587d5ccf6834e38b97e741d3a7ab6c85..6bbdb5dc30564e920ce41dad76e9924daaf21e1c 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 0706893304330f61f6e863c92198ca28ef6147d0..7453ae5807b74ace9fb9c815221a1bf67e2555ba 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 f5534ba25fc6a219b5a3b7f29c164e0ec2e25a9f..55ada4892d7ed895434fbd064e9bec9021e7b524 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 ff2e62e9b54880aeadcaa475debee440be1d6073..4aaf2652da6311e72375e239a01f4a283aa3156b 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 afe8e36dc9fc7cae82640158f83f799abebba0f0..efaf28189242e8be1aaa2611bf7560d58c607686 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 1bf3e9ddb78dc9b07866b38059f6490e89fcbda2..4abad2652cce93fb255da34448fda9a142e631cc 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 9d5265440d875c94d6575b4aaaf0b982cb9063bb..f272691bbd6efd2744606f5d494b34c4a50c4b7f 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 891f30ff4593eaec9b1599a8f25efdd912d71114..c575f170dfc097af77f0f2df3bf6ade0f059bc4e 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 e0370e7171d2a7cb8288462b7c347f7352535739..5ee630d394f4889819d8870ea47a778ba2e02c28 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 04bfc3bd539c61100758c873a7f86f577cb46a87..a2192fa8995f0b01af52e76805d20169ff381f28 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 4dfc32037237de0c390d8ad2b3082f8a65cf29ee..8ad0f7374488588c3031ec8da08b872056d2044c 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 6b9038e26cd357f367b78e65d8be12b203870ac7..1329a7fd31bb63acf52a33fa598d40c021b4c2d8 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 d849881aceec402b8def9dc26ebcc8a00553b158..1421e6ce31b630dbe81e2859b64ccc84908c5ffa 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 26972046496b3703741bb194be32755f30942399..e30abb302c4f9edb801e003c5dcabcebc7335f42 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 9b42e7b327cc6fd22e150b50371d3d50ed436d2a..b05a3a8f6def8a18aa4d9406bef1677bc694215c 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 7ad781c8af5631392fef6ca525cbf8745f925b2a..40f0962f05fc29a234711ced6b822ae0f5f04d95 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 cffe3f6e0cbf9cbd88ff3577e541a6ead3619bfe..55bce081c191a794a3c82d34dafa55c0c344c466 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 98c55a3c22a09c7d2f8148895a331b33610b8322..2277171e630a2a725a43747ee81bd56cadb6384b 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 aa759feb5612166a3c39b9519f166cd7da136645..2f3837093ea572132a209200d5be30813769565e 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 3cbbcf8a52a862a0736e5f0a694b117ee4c9dfef..8e54916bc82c6fc57c15e19143b5445b98707f21 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 1e856af6ed8e092fc57a2182907d8931bf0cddad..e2653b92ad8d0b25428984fbb73461a13912c05b 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 ccc09d96320a3b1a3fe8ae53e3c3cf30d3152541..1c8144711c383bebe7ab3f60a0cea09f67986d5f 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 ac15474dde018dde96a75f64aa64d005446b20ff..01cc232537a5da4339ab3337eeb4541942cfac08 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 cc905cb48f1118962a2c8df342437c5492096bef..f615514e3d753f11560337e1c47e5bffe8d63fd6 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 3a80eab66113b3bcbd6bffe4a5e3761344ee829b..a427bd1cac2d56d05c8c9eaee6663c9c0fe5597d 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 8bce59cfcd691104647b15d7b5e045e87aa3c347..9d6706a61c940ef8303dc14fc44d19d71a7da353 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 4474c7db3eb7c3c586f3b4864939d67986d6f43b..af4ee1112100df5ab2d99daa6c575bb5b735cf74 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 c07a3181a75b55484bcb3d6898d2bf6bf1f839a3..f316279e7a84243e810a6172b9ab895b41b607ae 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 fea058abfdf7fd6103e6f6a6618090177f695b50..e43bb207ecead2a8e3b815d1961296c08897a983 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 df7b19a1fb983d6d4f6ba54746320da3d14c5027..ea0ca3a00376b4300f96a109dc36a506b73fe6e7 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 2b5c19152022e84c409189551cb03989a8d62222..a683a391bc374a7d06d970be2ffd5624617ed275 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 ae41efe92266ad48cdd6ddc46d403dcfc88ec184..445efa37ffd5330e4e4f23b02ca88105b548f1fb 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 f402858a3b6732e3308553b99c16c9241082144c..ba675a859c898aac29c919567cb254f70d7509d1 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 fbd69e543255dbc5ff9e977a6ecd5ec5b3ac7f35..6808d6cef52b8beae50f4e74fb8a7a9db869084f 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 86db4ddc4da30da4640c7484676454c84313ec4a..f50bf5e4a55f1cccae447c3bc05c7289a896200b 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 db5c4424d0d4fb2745fadad377e8b274703e77b8..df4796ddcc9a10110950de45d65b03e62d72ca36 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 ee545f25b65d955de84d44c0401c616706498b09..fd72985c39bc3781c9645494dfe27fb7d44840d8 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 966588ab3a73bb935c6567f902cb5497a5f7bd29..9745d5f306389ac3c1f338ec4c2a606217698638 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 26c3114ba4afaf6b84b6a3911408969362d87ff6..fd3878c55a1cc99c81652e2c3bead30182c10de4 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 f1455d8a27f36cb6a10135f317f6bcf42599459d..c1620f889e8317e7417de95806a0cdf6060da188 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 fe608098c1e6f7d4ddc9426357ac6991399bd4ec..073bc74f048fe627bbe3227fe7a8476773c842fe 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 d13fc9c5f119218c3e0527efcf68d527897c2589..85791bc51a8d69d579e48baa7d2c966f1017364b 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 8363fb7e41eed435cefd8b1150434a443ef95b2a..204f5f149fb5da63c5ed12b865f50e1946fc093f 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 b18adf458dad610fc87334ab389df431f0972c65..6d209422168492dff206183dc6f460861f6e0a3c 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 e6d00896edac3059ab1fd874c960978b1cc48d1d..652109c9ea3ffc5336c82241081da350a07eed3d 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 e23cf9877fb13d3404c8f4ce9ee8416183f5efec..c30366ec2bd7246006f3c4bb77adcfd64de34b3d 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 a5271479517b324b3d10fa8171cb1d4942c1207e..a68faa2b36da81aa02a99675d63f32bc42fa8992 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 fc9dc8e3be3fc03e20381cf6d5f58039e74ede58..73909c5b355fc60f7ae44c7503bf1aae16345228 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 a1b91cc8cec4fe419595209ce77b2f7a43c48dbf..b47674c0a5f6af43d71d2ed062632255d9c1b412 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 9627d2adfdaf906a5f5683b911373c538032b655..f273f8f47701ac839585b0914d45e5c835f0a88d 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 9e5e91850849aaf19bf72e13ab02723e18ab8d05..6db5b0f9046c00307bed171c4200ff6a60e71239 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 08ba3d743a772d705e57c22e0fc795ff53b864d9..eb6c6769b20fffcd96774a1e5448de474ad97da9 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 58b444dc71d7ad8f1b31f12f2db835f0eaf305c0..23aac8b3769adef41f454a05637b77322d1588c7 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 64aa8e84fa697a57666078143f72785e78e800a3..3994abba1328121a249063816982b316aaf5d2d5 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 45337183ac538c100c005897ca9c74964cce3d84..3881312f88b287297ab41a65ede1685b076235c8 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 edcf8340dbf730b315fc53f4494cfaed9d850e79..13a90c7ef181ffc8ebbd6b8d2065a3602452cff8 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 46f8d0d2523f3d6a709e375759f70074a9fd8d85..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..a71f0dfd2226a5d58074a29a9f37c71fc0e1e1d6 --- /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 b0430e79d6dbbbffe6f455426eb17d2a79f1c9f5..1271b362e76a5b6ab32994bf5af5be0ac5bed037 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"