Skip to content
Snippets Groups Projects
DataloadSectionValue.spec.tsx 3.77 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { DataloadSectionType, FluidType } from 'enums'
    
    import { mount } from 'enzyme'
    import toJson from 'enzyme-to-json'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { Dataload } from 'models'
    import React from 'react'
    
    import {
      baseDataLoad,
      baseMultiFluidDataLoad,
    
    } from 'tests/__mocks__/chartData.mock'
    
    import DataloadSectionValue from './DataloadSectionValue'
    
    const mockToggleEstimationModal = jest.fn()
    
    describe('DataloadSectionValue component', () => {
      const mockDataload: Dataload = baseDataLoad
      const mockMultiDataload: Dataload = baseMultiFluidDataLoad
      it('should render correctly', () => {
        const wrapper = mount(
          <DataloadSectionValue
            dataload={mockDataload}
            fluidType={FluidType.ELECTRICITY}
            dataloadSectionType={DataloadSectionType.NO_COMPARE}
            toggleEstimationModal={mockToggleEstimationModal}
          />
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
    
      describe('case Singlefluid', () => {
        it('should render with unit when value < 1000', () => {
          const wrapper = mount(
            <DataloadSectionValue
              dataload={mockDataload}
              fluidType={FluidType.ELECTRICITY}
              dataloadSectionType={DataloadSectionType.NO_COMPARE}
              toggleEstimationModal={mockToggleEstimationModal}
            />
          )
          expect(
    
            wrapper.find(DataloadSectionValue).first().contains('12,00')
    
          ).toBeTruthy()
          expect(wrapper.find('.text-18-normal').text()).toBe(
            'FLUID.ELECTRICITY.UNIT'
          )
        })
        it('should render with mega unit when value >= 1000', () => {
          const _mockDatalaod: Dataload = { ...mockDataload, value: 1000 }
          const wrapper = mount(
            <DataloadSectionValue
              dataload={_mockDatalaod}
              fluidType={FluidType.ELECTRICITY}
              dataloadSectionType={DataloadSectionType.NO_COMPARE}
              toggleEstimationModal={mockToggleEstimationModal}
            />
          )
          expect(
    
            wrapper.find(DataloadSectionValue).first().contains('1,00')
    
          ).toBeTruthy()
          expect(wrapper.find('.text-18-normal').text()).toBe(
            'FLUID.ELECTRICITY.MEGAUNIT'
          )
        })
      })
    
      describe('case Multifluid', () => {
        it('should render correctly when comparison', () => {
          const wrapper = mount(
            <DataloadSectionValue
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.RIGHT}
              toggleEstimationModal={mockToggleEstimationModal}
            />
          )
          expect(
    
            wrapper.find(DataloadSectionValue).first().contains('12,00')
    
          ).toBeTruthy()
          expect(wrapper.find('.euroUnit').exists()).toBeTruthy()
        })
        it('should render correctly with a estimated link when no comparison', () => {
          const wrapper = mount(
            <DataloadSectionValue
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.NO_COMPARE}
              toggleEstimationModal={mockToggleEstimationModal}
            />
          )
          expect(
    
            wrapper.find(DataloadSectionValue).first().contains('12,00')
    
          expect(wrapper.find('.euroUnit').exists()).toBeTruthy()
    
          expect(wrapper.find('.estimated').exists()).toBeTruthy()
          expect(wrapper.find('.estimated').text()).toBe(
            'consumption_visualizer.estimated'
          )
        })
        it('should call toggleEstimationModal when click on the estimated link', () => {
          const wrapper = mount(
            <DataloadSectionValue
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.NO_COMPARE}
              toggleEstimationModal={mockToggleEstimationModal}
            />
          )
          wrapper.find('.estimated').simulate('click')
    
          expect(mockToggleEstimationModal).toHaveBeenCalled()