Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React from 'react'
import { mount } from 'enzyme'
import { DateTime } from 'luxon'
import * as reactRedux from 'react-redux'
import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import MaxConsumptionCard from './MaxConsumptionCard'
import { FluidType } from 'enum/fluid.enum'
jest.mock('cozy-ui/transpiled/react/I18n', () => {
return {
useI18n: jest.fn(() => {
return {
t: (str: string) => str,
}
}),
}
})
const mockStore = configureStore([])
const mockUseSelector = jest.spyOn(reactRedux, 'useSelector')
describe('MaxConsumptionCard component', () => {
it('should be rendered correctly', () => {
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
mockUseSelector.mockReturnValue({
fluidTypes: [FluidType.ELECTRICITY, FluidType.GAS],
})
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard
analysisDate={DateTime.fromISO('2021-07-01T00:00:00.000Z', {
zone: 'utc',
})}
/>
</Provider>
).getElement()
expect(wrapper).toMatchSnapshot()
})
it('should be rendered with one fluid and not display arrows', () => {
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
mockUseSelector.mockReturnValue({ fluidTypes: [FluidType.ELECTRICITY] })
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard
analysisDate={DateTime.fromISO('2021-07-01T00:00:00.000Z', {
zone: 'utc',
})}
/>
</Provider>
)
expect(wrapper.find('.arrow').exists()).toBeFalsy()
})
it('should be rendered with several fluids and click navigate between fluid', async () => {
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
mockUseSelector.mockReturnValue({
fluidTypes: [FluidType.ELECTRICITY, FluidType.GAS],
})
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard
analysisDate={DateTime.fromISO('2021-07-01T00:00:00.000Z', {
zone: 'utc',
})}
/>
</Provider>
)
expect(wrapper.find('.arrow-next').exists()).toBeTruthy()
//navigate next
wrapper
.find('.arrow-next')
.first()
.simulate('click')

Guilhem CARRON
committed
expect(wrapper.find('.fluid').text()).toBe('FLUID.GAS.LABEL')
wrapper
.find('.arrow-next')
.first()
.simulate('click')

Guilhem CARRON
committed
expect(wrapper.find('.fluid').text()).toBe('FLUID.ELECTRICITY.LABEL')
//navigate prev
wrapper
.find('.arrow-prev')
.first()
.simulate('click')

Guilhem CARRON
committed
expect(wrapper.find('.fluid').text()).toBe('FLUID.GAS.LABEL')
wrapper
.find('.arrow-prev')
.first()
.simulate('click')

Guilhem CARRON
committed
expect(wrapper.find('.fluid').text()).toBe('FLUID.ELECTRICITY.LABEL')