Skip to content
Snippets Groups Projects
TotalAnalysisChart.spec.tsx 3.16 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { DataloadState, FluidType } from 'enums'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    import { DateTime } from 'luxon'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { Datachart } from 'models'
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import { graphMonthData } from 'tests/__mocks__/chartData.mock'
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import TotalAnalysisChart from './TotalAnalysisChart'
    
    const mockGetGraphData = jest.fn()
    
    jest.mock('services/consumption.service', () => {
    
      return jest.fn(() => ({
        getGraphData: mockGetGraphData,
      }))
    
    jest.mock(
      'components/Analysis/TotalAnalysisChart/PieChart',
      () => 'mock-piechart'
    )
    jest.mock(
      'components/ConsumptionVisualizer/EstimatedConsumptionModal',
      () => 'mock-estimatedmodal'
    )
    
    
    describe('TotalAnalysisChart component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', async () => {
    
        const wrapper = mount(
          <Provider store={store}>
    
            <TotalAnalysisChart fluidsWithData={[FluidType.ELECTRICITY]} />
    
        await waitForComponentToPaint(wrapper)
    
        expect(toJson(wrapper)).toMatchSnapshot()
    
      })
      it('should render several fluids and display month data', async () => {
    
        mockGetGraphData.mockResolvedValue(graphMonthData)
    
        const wrapper = mount(
          <Provider store={store}>
            <TotalAnalysisChart
    
              fluidsWithData={[
                FluidType.ELECTRICITY,
                FluidType.WATER,
                FluidType.GAS,
              ]}
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.fluidconso').exists()).toBeTruthy()
      })
      it('should render empty price', async () => {
    
        const emptyData: Datachart = {
    
          actualData: [
            {
              date: DateTime.fromISO('2020-09-01T00:00:00.000Z', {
                zone: 'utc',
              }),
              value: 69.18029999999999,
    
              state: DataloadState.VALID,
              valueDetail: [{ value: -1, state: DataloadState.EMPTY }],
    
          comparisonData: null,
    
        mockGetGraphData.mockResolvedValue(emptyData)
    
        const wrapper = mount(
          <Provider store={store}>
            <TotalAnalysisChart
    
              fluidsWithData={[FluidType.ELECTRICITY, FluidType.WATER]}
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.fluidconso').text()).toBe('--- €')
      })
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
      it('should render empty price for one fluid', async () => {
    
        const emptyData: Datachart = {
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          actualData: [
            {
              date: DateTime.fromISO('2020-09-01T00:00:00.000Z', {
                zone: 'utc',
              }),
              value: 69.18029999999999,
    
              state: DataloadState.VALID,
              valueDetail: [{ value: -1, state: DataloadState.EMPTY }],
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
            },
          ],
    
          comparisonData: null,
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        }
    
        mockGetGraphData.mockResolvedValue(emptyData)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        const wrapper = mount(
          <Provider store={store}>
    
            <TotalAnalysisChart fluidsWithData={[FluidType.ELECTRICITY]} />
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
    Hugo SUBTIL's avatar
    Hugo SUBTIL committed
        expect(wrapper.find('.fluidconso').exists()).toBe(false)
      })