From a97f7b0551888e841e7e644bf6d6040a5fa58a4e Mon Sep 17 00:00:00 2001 From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com> Date: Mon, 7 Dec 2020 20:07:24 +0100 Subject: [PATCH] feat: update test for Headers components --- src/components/Header/CozyBar.spec.tsx | 11 ++++++++--- src/components/Header/CozyBar.tsx | 3 ++- src/components/Header/Header.spec.tsx | 11 ++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/components/Header/CozyBar.spec.tsx b/src/components/Header/CozyBar.spec.tsx index 185168195..d1959dc46 100644 --- a/src/components/Header/CozyBar.spec.tsx +++ b/src/components/Header/CozyBar.spec.tsx @@ -3,7 +3,6 @@ import { mount } from 'enzyme' import { Provider } from 'react-redux' import configureStore from 'redux-mock-store' import CozyBar from 'components/Header/CozyBar' -import { history } from 'components/App' import * as ModalAction from 'store/modal/modal.actions' import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' import { modalStateData } from '../../../test/__mocks__/modalStateData.mock' @@ -19,6 +18,13 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) +const mockGoBack = jest.fn() +jest.mock('react-router-dom', () => ({ + useHistory: () => ({ + goBack: mockGoBack, + }), +})) + const mockStore = configureStore([]) describe('CozyBar component', () => { @@ -44,14 +50,13 @@ describe('CozyBar component', () => { <CozyBar displayBackArrow={true} /> </Provider> ) - const goBackSpy = jest.spyOn(history, 'goBack') expect(wrapper.find('BarLeft')).toHaveLength(1) wrapper .find('BarLeft') .find('.cv-button') .first() .simulate('click') - expect(goBackSpy).toHaveBeenCalled() + expect(mockGoBack).toHaveBeenCalled() }) it('should call handleClickFeedbacks when feedback button is clicked', () => { diff --git a/src/components/Header/CozyBar.tsx b/src/components/Header/CozyBar.tsx index 4e907f4a0..089a4318b 100644 --- a/src/components/Header/CozyBar.tsx +++ b/src/components/Header/CozyBar.tsx @@ -3,7 +3,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { useSelector, useDispatch } from 'react-redux' import { EcolyoState } from 'store' import { updateModalIsFeedbacksOpen } from 'store/modal/modal.actions' -import { history } from 'components/App' +import { useHistory } from 'react-router-dom' import { ScreenType } from 'enum/screen.enum' @@ -21,6 +21,7 @@ const CozyBar = ({ displayBackArrow = false, }: CozyBarProps) => { const { t } = useI18n() + const history = useHistory() const dispatch = useDispatch() const { BarLeft, BarCenter, BarRight } = cozy.bar const { screenType } = useSelector((state: EcolyoState) => state.global) diff --git a/src/components/Header/Header.spec.tsx b/src/components/Header/Header.spec.tsx index 40a0a7060..1b6f35c58 100644 --- a/src/components/Header/Header.spec.tsx +++ b/src/components/Header/Header.spec.tsx @@ -2,7 +2,6 @@ import React from 'react' import { mount } from 'enzyme' import { Provider } from 'react-redux' import configureStore from 'redux-mock-store' -import { history } from 'components/App' import * as ModalAction from 'store/modal/modal.actions' import Header from 'components/Header/Header' import { globalStateData } from '../../../test/__mocks__/globalStateData.mock' @@ -19,6 +18,13 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { } }) +const mockGoBack = jest.fn() +jest.mock('react-router-dom', () => ({ + useHistory: () => ({ + goBack: mockGoBack, + }), +})) + const mocksetHeaderHeight = jest.fn() const mockStore = configureStore([]) @@ -92,13 +98,12 @@ describe('Header component', () => { /> </Provider> ) - const goBackSpy = jest.spyOn(history, 'goBack') wrapper .find('StyledIconButton') .find('.header-back-button') .first() .simulate('click') - expect(goBackSpy).toHaveBeenCalled() + expect(mockGoBack).toHaveBeenCalled() }) it('should call handleClickFeedbacks when feedback button is clicked', () => { -- GitLab