Skip to content
Snippets Groups Projects
DataloadSectionDetail.spec.tsx 4.08 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { DataloadSectionType, DataloadState, FluidType } from 'enums'
    
    import { mount } from 'enzyme'
    import toJson from 'enzyme-to-json'
    import { Dataload } from 'models'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import React from 'react'
    
    import { baseDataLoad } from 'tests/__mocks__/chartData.mock'
    
    import DataloadSectionDetail from './DataloadSectionDetail'
    
    describe('DataloadSectionDetail component', () => {
      const mockDataload: Dataload = baseDataLoad
    
      it('should render correctly', () => {
        const wrapper = mount(
          <DataloadSectionDetail
            dataload={mockDataload}
            fluidType={FluidType.ELECTRICITY}
            dataloadSectionType={DataloadSectionType.NO_COMPARE}
          />
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should not display if multifluid and comparison', () => {
        const wrapper = mount(
          <DataloadSectionDetail
            dataload={mockDataload}
            fluidType={FluidType.MULTIFLUID}
            dataloadSectionType={DataloadSectionType.RIGHT}
          />
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should not display value details if multifluid, no valueDetail and comparison', () => {
        const mockMultiDataload: Dataload = {
          ...mockDataload,
          state: DataloadState.AGGREGATED_EMPTY,
          valueDetail: null,
        }
        const wrapper = mount(
          <DataloadSectionDetail
            dataload={mockMultiDataload}
            fluidType={FluidType.MULTIFLUID}
            dataloadSectionType={DataloadSectionType.RIGHT}
          />
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
    
      describe('should display value details if multifluid and no comparison', () => {
        it('case all valid data', () => {
          const mockMultiDataload: Dataload = {
            ...mockDataload,
            state: DataloadState.AGGREGATED_VALID,
            valueDetail: [
              { value: 1, state: DataloadState.VALID },
              { value: 2, state: DataloadState.VALID },
              { value: 3, state: DataloadState.VALID },
            ],
          }
          const wrapper = mount(
            <DataloadSectionDetail
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.RIGHT}
            />
          )
          expect(toJson(wrapper)).toMatchSnapshot()
        })
        it('case valid and coming data', () => {
          const mockMultiDataload: Dataload = {
            ...mockDataload,
            state: DataloadState.AGGREGATED_WITH_COMING,
            valueDetail: [
              { value: 1, state: DataloadState.VALID },
              { value: -1, state: DataloadState.COMING },
              { value: 3, state: DataloadState.VALID },
            ],
          }
          const wrapper = mount(
            <DataloadSectionDetail
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.RIGHT}
            />
          )
          expect(toJson(wrapper)).toMatchSnapshot()
        })
        it('case valid and missing data', () => {
          const mockMultiDataload: Dataload = {
            ...mockDataload,
            state: DataloadState.AGGREGATED_WITH_HOLE_OR_MISSING,
            valueDetail: [
              { value: 1, state: DataloadState.VALID },
              { value: -1, state: DataloadState.MISSING },
              { value: 3, state: DataloadState.VALID },
            ],
          }
          const wrapper = mount(
            <DataloadSectionDetail
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.RIGHT}
            />
          )
          expect(toJson(wrapper)).toMatchSnapshot()
        })
        it('case valid and hole data', () => {
          const mockMultiDataload: Dataload = {
            ...mockDataload,
            state: DataloadState.AGGREGATED_WITH_HOLE_OR_MISSING,
            valueDetail: [
              { value: 1, state: DataloadState.VALID },
              { value: -1, state: DataloadState.HOLE },
              { value: 3, state: DataloadState.VALID },
            ],
          }
          const wrapper = mount(
            <DataloadSectionDetail
              dataload={mockMultiDataload}
              fluidType={FluidType.MULTIFLUID}
              dataloadSectionType={DataloadSectionType.RIGHT}
            />
          )
          expect(toJson(wrapper)).toMatchSnapshot()
        })
      })
    })