Newer
Older
import AnalysisView from 'components/Analysis/AnalysisView'
import React from 'react'
import * as globalActions from 'store/global/global.slice'
import * as profileActions from 'store/profile/profile.slice'
mockAnalysisState,
jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
jest.mock('components/Header/Header', () => 'mock-header')
jest.mock('components/Content/Content', () => 'mock-content')
jest.mock('components/DateNavigator/DateNavigator', () => 'mock-datenavigator')
jest.mock('components/Analysis/MonthlyAnalysis', () => 'mock-monthlyanalysis')
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => ({
pathname: 'ecolyo.cozy.localhost:8080/#/analysis',
}),
}))
const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
const toggleAnalysisNotificationSpy = jest.spyOn(
globalActions,
'toggleAnalysisNotification'
)
const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile')
describe('AnalysisView component', () => {
})
it('should be rendered correctly', () => {
const wrapper = mount(
<Provider store={store}>
<AnalysisView />
</Provider>
)
expect(wrapper.find('mock-cozybar').exists()).toBeTruthy()
expect(wrapper.find('mock-header').exists()).toBeTruthy()
expect(wrapper.find('mock-datenavigator').exists()).toBeTruthy()
expect(wrapper.find('mock-monthlyanalysis').exists()).toBeTruthy()
})
it('should update profile and toggle analysis notification to false if notification is true', () => {
analysis: mockAnalysisState,
chart: mockChartState,
global: { analysisNotification: true },
profile: { ...mockProfileState, haveSeenLastAnalysis: true },
mockAppDispatch.mockReturnValue(jest.fn())
const wrapper = mount(
<Provider store={store}>
<AnalysisView />
</Provider>
)
expect(wrapper.find('mock-cozybar').exists()).toBeTruthy()
expect(wrapper.find('mock-header').exists()).toBeTruthy()
expect(wrapper.find('mock-datenavigator').exists()).toBeTruthy()
expect(wrapper.find('mock-monthlyanalysis').exists()).toBeTruthy()
expect(updateProfileSpy).toHaveBeenCalledTimes(1)
expect(updateProfileSpy).toHaveBeenCalledWith({
haveSeenLastAnalysis: true,
})
expect(toggleAnalysisNotificationSpy).toHaveBeenCalledTimes(1)
expect(toggleAnalysisNotificationSpy).toHaveBeenCalledWith(false)
})
})