Newer
Older

Rémi PAILHAREY
committed
import { TimeStep } from 'enum/timeStep.enum'
import { mount } from 'enzyme'
import React from 'react'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import { graphData } from '../../../tests/__mocks__/chartData.mock'
import { mockInitialChartState } from '../../../tests/__mocks__/store'
import { waitForComponentToPaint } from '../../../tests/__mocks__/testUtils'

Rémi PAILHAREY
committed
jest.mock('cozy-ui/transpiled/react/I18n', () => {
return {
useI18n: jest.fn(() => {
return {
t: (str: string) => str,
}
}),
}
})

Rémi PAILHAREY
committed
const mockStore = configureStore([])
const mockChartStore = mockStore({

Rémi PAILHAREY
committed
ecolyo: {
chart: {
...mockInitialChartState,
currentDatachart: graphData,

Rémi PAILHAREY
committed
},
},
})

Rémi PAILHAREY
committed
it('should be rendered correctly', async () => {
<Provider store={mockChartStore}>
<TotalConsumption fluidType={FluidType.ELECTRICITY} />

Rémi PAILHAREY
committed
</Provider>

Rémi PAILHAREY
committed
it('should render euro value', async () => {
<Provider store={mockChartStore}>
<TotalConsumption fluidType={FluidType.ELECTRICITY} />

Rémi PAILHAREY
committed
</Provider>

Rémi PAILHAREY
committed
expect(component.find('.euro-value').first().text()).toEqual('22,77')

Rémi PAILHAREY
committed
it('should format multifluid value', async () => {
const component = mount(
<Provider store={mockChartStore}>
<TotalConsumption fluidType={FluidType.MULTIFLUID} />
</Provider>
)
expect(component.find('.euro-value').first().text()).toEqual('130,84')
})
it('should format multifluid value AND compared value', async () => {
const store = mockStore({
ecolyo: {
chart: {
...mockInitialChartState,
currentDatachart: graphData,
showCompare: true,
currentTimeStep: TimeStep.DAY,
},
},
})

Rémi PAILHAREY
committed
<Provider store={store}>
<TotalConsumption fluidType={FluidType.MULTIFLUID} />

Rémi PAILHAREY
committed
</Provider>

Rémi PAILHAREY
committed
expect(component.find('.euro-value').first().text()).toEqual('130,84')
expect(component.find('.euro-value').at(1).text()).toEqual('110,66')

Rémi PAILHAREY
committed
it('should display ----- when half an hour electricity data is not activated', async () => {
const store = mockStore({
ecolyo: {
chart: mockInitialChartState,
currentDatachart: graphData,
},
})

Rémi PAILHAREY
committed
const component = mount(
<Provider store={store}>
<TotalConsumption fluidType={FluidType.ELECTRICITY} />

Rémi PAILHAREY
committed
</Provider>
)

Rémi PAILHAREY
committed
expect(component.find('.euro-value').first().text()).toEqual('-----')

Rémi PAILHAREY
committed
})