Newer
Older
import { FluidType } from 'enums'
import { mount } from 'enzyme'
import { Provider } from 'react-redux'
import { graphData } from 'tests/__mocks__/chartData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import MaxConsumptionCard from './MaxConsumptionCard'
const mockGetGraphData = jest.fn(() => graphData)
jest.mock('services/consumption.service', () => {
return jest.fn(() => ({
getMaxLoad: mockGetMaxLoad,
getGraphData: mockGetGraphData,
}))
jest.mock('components/Charts/BarChart', () => 'mock-BarChart')
describe('MaxConsumptionCard component', () => {
it('should be rendered correctly', async () => {
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard
fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
/>
)
await waitForComponentToPaint(wrapper)
expect(wrapper.find('mock-BarChart').exists()).toBeTruthy()
it('should be rendered with one fluid and not display arrows', async () => {
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard fluidsWithData={[FluidType.ELECTRICITY]} />
await waitForComponentToPaint(wrapper)
expect(wrapper.find('.arrow').exists()).toBeFalsy()
})
it('should be rendered with several fluids and click navigate between fluid', async () => {
const wrapper = mount(
<Provider store={store}>
<MaxConsumptionCard
fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
/>
await waitForComponentToPaint(wrapper)
expect(wrapper.find('.arrow-next').exists()).toBeTruthy()
wrapper.find('.arrow-next').first().simulate('click')
await waitForComponentToPaint(wrapper)

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

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

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

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