Skip to content
Snippets Groups Projects
MaxConsumptionCard.spec.tsx 2.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { FluidType } from 'enums'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import React from 'react'
    
    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 mockGetMaxLoad = jest.fn(() => 0)
    
    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', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', async () => {
    
        const wrapper = mount(
          <Provider store={store}>
    
            <MaxConsumptionCard
              fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
            />
    
        )
        await waitForComponentToPaint(wrapper)
    
        expect(toJson(wrapper)).toMatchSnapshot()
    
        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)
    
        expect(wrapper.find('.fluid').text()).toBe('FLUID.GAS.LABEL')
    
        wrapper.find('.arrow-next').first().simulate('click')
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.fluid').text()).toBe('FLUID.ELECTRICITY.LABEL')
    
        wrapper.find('.arrow-prev').first().simulate('click')
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.fluid').text()).toBe('FLUID.GAS.LABEL')
    
        wrapper.find('.arrow-prev').first().simulate('click')
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.fluid').text()).toBe('FLUID.ELECTRICITY.LABEL')