Skip to content
Snippets Groups Projects
TotalConsumption.spec.tsx 3.19 KiB
Newer Older
  • Learn to ignore specific revisions
  • Yoan VALLET's avatar
    Yoan VALLET committed
    import React from 'react'
    import { mount } from 'enzyme'
    import { FluidType } from 'enum/fluid.enum'
    import TotalConsumption from './TotalConsumption'
    import { mockInitialChartState } from '../../../tests/__mocks__/store'
    import { graphData } from '../../../tests/__mocks__/datachartData.mock'
    
    import { Provider } from 'react-redux'
    import configureStore from 'redux-mock-store'
    import { TimeStep } from 'enum/timeStep.enum'
    import { Dataload } from 'models'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    jest.mock('cozy-ui/transpiled/react/I18n', () => {
      return {
        useI18n: jest.fn(() => {
          return {
            t: (str: string) => str,
          }
        }),
      }
    })
    
    
    const mockStore = configureStore([])
    
    const store = mockStore({
      ecolyo: {
        chart: {
          mockInitialChartState,
        },
      },
    })
    
    const mockHalfHourChartState = {
      ...mockInitialChartState,
      currentTimeStep: TimeStep.HALF_AN_HOUR,
    }
    mockHalfHourChartState.currentTimeStep = TimeStep.HALF_AN_HOUR
    
    const storeHalfHour = mockStore({
      ecolyo: {
        chart: {
          mockHalfHourChartState,
        },
      },
    })
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    describe('TotalConsumption component', () => {
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        const component = mount(
    
          <Provider store={store}>
            <TotalConsumption
              fluidType={FluidType.ELECTRICITY}
              actualData={mockInitialChartState.currentDatachart.actualData}
            />
          </Provider>
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        )
    
        await act(async () => {
          await new Promise(resolve => setTimeout(resolve))
          component.update()
        })
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(component).toMatchSnapshot()
      })
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        const component = mount(
    
          <Provider store={store}>
            <TotalConsumption
              fluidType={FluidType.ELECTRICITY}
              actualData={graphData.actualData}
            />
          </Provider>
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        )
    
        await act(async () => {
          await new Promise(resolve => setTimeout(resolve))
          component.update()
        })
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(
          component
            .find('.euro-value')
            .first()
            .text()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        const component = mount(
    
          <Provider store={store}>
            <TotalConsumption
              fluidType={FluidType.MULTIFLUID}
              actualData={graphData.actualData}
            />
          </Provider>
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        )
    
        await act(async () => {
          await new Promise(resolve => setTimeout(resolve))
          component.update()
        })
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(
          component
            .find('.euro-value')
            .first()
            .text()
        ).toEqual('130,84')
      })
    
      it('should display ----- when half an hour electricity data is not activated', async () => {
        const emptyData: Dataload[] = []
        const component = mount(
          <Provider store={storeHalfHour}>
            <TotalConsumption
              fluidType={FluidType.ELECTRICITY}
              actualData={emptyData}
            />
          </Provider>
        )
        await act(async () => {
          await new Promise(resolve => setTimeout(resolve))
          component.update()
        })
    
        expect(
          component
            .find('.euro-value')
            .first()
            .text()
        ).toEqual('-----')
      })
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    })