Skip to content
Snippets Groups Projects
Commit 1a468098 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

chore(tests): fix cozy-bar tests

parent ec4b266d
Branches
Tags
2 merge requests!9322.5,!922chore(tests): fix cozy-bar tests
...@@ -5,7 +5,6 @@ import React from 'react' ...@@ -5,7 +5,6 @@ import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store' import configureStore from 'redux-mock-store'
import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock' import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
import { modalStateData } from '../../../tests/__mocks__/modalStateData.mock'
import { profileData } from '../../../tests/__mocks__/profileData.mock' import { profileData } from '../../../tests/__mocks__/profileData.mock'
import { userChallengeData } from '../../../tests/__mocks__/userChallengeData.mock' import { userChallengeData } from '../../../tests/__mocks__/userChallengeData.mock'
import ActionChoose from './ActionChoose' import ActionChoose from './ActionChoose'
...@@ -46,7 +45,6 @@ describe('ActionView component', () => { ...@@ -46,7 +45,6 @@ describe('ActionView component', () => {
challenge: { currentChallenge: userChallenge }, challenge: { currentChallenge: userChallenge },
global: { ...globalStateData, fluidTypes: [0, 1, 2] }, global: { ...globalStateData, fluidTypes: [0, 1, 2] },
profile: profileData, profile: profileData,
modal: modalStateData,
}, },
}) })
const wrapper = mount( const wrapper = mount(
...@@ -70,7 +68,6 @@ describe('ActionView component', () => { ...@@ -70,7 +68,6 @@ describe('ActionView component', () => {
challenge: { currentChallenge: userChallenge }, challenge: { currentChallenge: userChallenge },
global: { ...globalStateData, fluidTypes: [0, 1, 2] }, global: { ...globalStateData, fluidTypes: [0, 1, 2] },
profile: profileData, profile: profileData,
modal: modalStateData,
}, },
}) })
const wrapper = mount( const wrapper = mount(
...@@ -92,7 +89,6 @@ describe('ActionView component', () => { ...@@ -92,7 +89,6 @@ describe('ActionView component', () => {
ecolyo: { ecolyo: {
challenge: { currentChallenge: userChallenge }, challenge: { currentChallenge: userChallenge },
global: { ...globalStateData, fluidTypes: [0, 1, 2] }, global: { ...globalStateData, fluidTypes: [0, 1, 2] },
modal: modalStateData,
profile: profileData, profile: profileData,
}, },
}) })
......
// jest.mock('cozy-ui/transpiled/react/I18n', () => { import CozyBar from 'components/Header/CozyBar'
// return { import { ScreenType } from 'enum/screen.enum'
// useI18n: jest.fn(() => { import { mount } from 'enzyme'
// return { import toJson from 'enzyme-to-json'
// t: (str: string) => str, import React from 'react'
// } import { Provider } from 'react-redux'
// }), import configureStore from 'redux-mock-store'
// } import * as ModalAction from 'store/modal/modal.slice'
// }) import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
// const mockedNavigate = jest.fn() interface BarProps {
// jest.mock('react-router-dom', () => ({ children: React.ReactNode
// ...jest.requireActual('react-router-dom'), }
// useNavigate: () => mockedNavigate,
// }))
// const mockStore = configureStore([]) jest.mock('utils/cozyBar', () => {
return {
BarLeft: ({ children }: BarProps) => children,
BarCenter: ({ children }: BarProps) => children,
BarRight: ({ children }: BarProps) => children,
}
})
jest.mock('cozy-ui/transpiled/react/I18n', () => {
return {
useI18n: jest.fn(() => {
return {
t: (str: string) => str,
}
}),
}
})
const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigate,
}))
const mockStore = configureStore([])
describe('CozyBar component', () => { describe('CozyBar component', () => {
// TODO: fix CozyBar tests const store = mockStore({
it('should be tested correctly later', () => { ecolyo: {
expect(true).toBe(true) global: globalStateData,
},
})
it('should be rendered correctly without without left arrow', () => {
const wrapper = mount(
<Provider store={store}>
<CozyBar />
</Provider>
)
expect(toJson(wrapper)).toMatchSnapshot()
}) })
// it('should be rendered correctly', () => {
// const store = mockStore({
// ecolyo: {
// global: globalStateData,
// },
// })
// const wrapper = mount(
// <Provider store={store}>
// <CozyBar />
// </Provider>
// )
// expect(wrapper.find('BarCenter')).toHaveLength(1)
// expect(wrapper.find('BarRight')).toHaveLength(1)
// })
// it('should call handleClickBack when back button is clicked', () => { describe('should test displayBackArrow', () => {
// const store = mockStore({ it('should call navigate(-1) when back button is clicked and no function is provided', () => {
// ecolyo: { const wrapper = mount(
// global: globalStateData, <Provider store={store}>
// }, <CozyBar displayBackArrow={true} />
// }) </Provider>
// const wrapper = mount( )
// <Provider store={store}> expect(toJson(wrapper)).toMatchSnapshot()
// <CozyBar displayBackArrow={true} /> expect(wrapper.find('BarLeft')).toHaveLength(1)
// </Provider> wrapper.find('BarLeft').find('.cv-button').first().simulate('click')
// ) expect(mockedNavigate).toHaveBeenCalled()
// expect(wrapper.find('BarLeft')).toHaveLength(1) })
// wrapper.find('BarLeft').find('.cv-button').first().simulate('click')
// expect(mockedNavigate).toHaveBeenCalled()
// })
// it('should call handleClickFeedbacks when feedback button is clicked', () => { it('should call backFunction() when back button is clicked and function is provided', () => {
// const store = mockStore({ const mockBackFunction = jest.fn()
// ecolyo: { const wrapper = mount(
// global: globalStateData, <Provider store={store}>
// modal: modalStateData, <CozyBar displayBackArrow={true} backFunction={mockBackFunction} />
// }, </Provider>
// }) )
// const wrapper = mount( expect(toJson(wrapper)).toMatchSnapshot()
// <Provider store={store}> expect(wrapper.find('BarLeft')).toHaveLength(1)
// <CozyBar /> wrapper.find('BarLeft').find('.cv-button').first().simulate('click')
// </Provider> expect(mockBackFunction).toHaveBeenCalled()
// ) })
// const updateModalSpy = jest.spyOn(ModalAction, 'openFeedbackModal') })
// wrapper.find('BarRight').find('.cv-button').first().simulate('click')
// expect(updateModalSpy).toHaveBeenCalledWith(true)
// })
// it('should not be rendered with screen type different from mobile', () => { it('should call handleClickFeedbacks when feedback button is clicked', () => {
// const store = mockStore({ const wrapper = mount(
// ecolyo: { <Provider store={store}>
// global: { ...globalStateData, screenType: ScreenType.DESKTOP }, <CozyBar />
// }, </Provider>
// }) )
// const wrapper = mount( const updateModalSpy = jest.spyOn(ModalAction, 'openFeedbackModal')
// <Provider store={store}> wrapper.find('BarRight').find('.cv-button').first().simulate('click')
// <CozyBar /> expect(updateModalSpy).toHaveBeenCalledWith(true)
// </Provider> })
// )
// expect(wrapper).toEqual({}) it('should not be rendered with screen type different from mobile', () => {
// }) const store = mockStore({
ecolyo: {
global: { ...globalStateData, screenType: ScreenType.DESKTOP },
},
})
const wrapper = mount(
<Provider store={store}>
<CozyBar />
</Provider>
)
// Snapshot should be empty
expect(toJson(wrapper)).toMatchSnapshot()
})
}) })
...@@ -40,41 +40,38 @@ const CozyBar = ({ ...@@ -40,41 +40,38 @@ const CozyBar = ({
dispatch(openFeedbackModal(true)) dispatch(openFeedbackModal(true))
} }
const cozyBarCustom = (screen?: ScreenType) => { if (screenType === ScreenType.MOBILE) {
if (screen === ScreenType.MOBILE) { return (
return ( <>
<> {displayBackArrow && (
{displayBackArrow && ( <BarLeft>
<BarLeft>
<StyledIconButton
aria-label={t('header.accessibility.button_back')}
className="cv-button"
icon={BackArrowIcon}
onClick={handleClickBack}
/>
</BarLeft>
)}
<BarCenter>
<div className="cozy-bar">
<span className="app-title">{t(titleKey)}</span>
</div>
</BarCenter>
<BarRight>
<StyledIconButton <StyledIconButton
aria-label={t('header.accessibility.button_open_feedbacks')} aria-label={t('header.accessibility.button_back')}
className="cv-button" className="cv-button"
icon={FeedbackIcon} icon={BackArrowIcon}
sized={22} onClick={handleClickBack}
onClick={handleClickFeedbacks}
/> />
</BarRight> </BarLeft>
</> )}
) <BarCenter>
} <div className="cozy-bar">
<span className="app-title">{t(titleKey)}</span>
</div>
</BarCenter>
<BarRight>
<StyledIconButton
aria-label={t('header.accessibility.button_open_feedbacks')}
className="cv-button"
icon={FeedbackIcon}
sized={22}
onClick={handleClickFeedbacks}
/>
</BarRight>
</>
)
} else {
return null return null
} }
return cozyBarCustom(screenType)
} }
export default CozyBar export default CozyBar
This diff is collapsed.
...@@ -8,6 +8,7 @@ declare module 'cozy-bar' { ...@@ -8,6 +8,7 @@ declare module 'cozy-bar' {
appSlug?: string appSlug?: string
lang: string lang: string
iconPath: string iconPath: string
isInvertedTheme: string
cozyClient: Client cozyClient: Client
cozyURL?: string cozyURL?: string
ssl?: boolean ssl?: boolean
......
import { ModalState } from 'models'
export const modalStateData: ModalState = {
isFeedbacksOpen: false,
partnersIssueModal: {
egl: false,
enedis: false,
grdf: false,
},
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment