Newer
Older
import { scaleBand, ScaleBand, scaleLinear } from 'd3'
import { FluidType, TimeStep } from 'enums'
import { DateTime } from 'luxon'
import React from 'react'
import { Provider } from 'react-redux'
import * as chartActions from 'store/chart/chart.slice'
import { graphData } from 'tests/__mocks__/chartData.mock'
import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
import Bar from './Bar'
const mockXScale: ScaleBand<string> = scaleBand()
.domain(
graphData.actualData.map(d =>
d.date.toLocaleString(DateTime.DATETIME_SHORT)
)
)
.range([0, 10])
.padding(0.2)
const mockParam = {
index: 4,
dataload: graphData.actualData[0],
compareDataload: graphData.actualData[1],
fluidType: FluidType.MULTIFLUID,
timeStep: TimeStep.DAY,
xScale: mockXScale,
yScale: scaleLinear(),
height: 20,
isSwitching: false,
isDuel: false,
}
const setSelectedDateSpy = jest.spyOn(chartActions, 'setSelectedDate')
describe('Bar component test', () => {
const store = createMockEcolyoStore({
chart: {
selectedDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', {
zone: 'utc',
}),
},
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
86
87
88
89
90
91
92
93
94
})
it('should correctly render Multifluid Bar', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Electricity Bar', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} fluidType={FluidType.ELECTRICITY} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Water Bar', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} fluidType={FluidType.WATER} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Gas Bar', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} fluidType={FluidType.GAS} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Bar with showCompare', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} compare={true} />
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Bar with isSwitching', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} isSwitching={true} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should correctly render Bar with isDuel', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} isDuel={true} />
</svg>
</Provider>
)
expect(wrapper.getElement()).toMatchSnapshot()
})
it('should dispatch selected date when bar is clicked', () => {
const wrapper = mount(
<Provider store={store}>
<svg>
<Bar {...mockParam} />
</svg>
</Provider>
)
wrapper.find('rect').first().simulate('click')
expect(setSelectedDateSpy).toHaveBeenCalledTimes(1)
expect(setSelectedDateSpy).toHaveBeenCalledWith(
graphData.actualData[0].date
)
})
})