Skip to content
Snippets Groups Projects
TotalConsumption.spec.tsx 2.24 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen, waitFor } from '@testing-library/react'
    
    import { FluidType, TimeStep } from 'enums'
    
    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, mockChartState } from 'tests/__mocks__/store'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import TotalConsumption from './TotalConsumption'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const mockChartStore = createMockEcolyoStore({
      chart: {
        ...mockChartState,
        currentDatachart: graphData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    describe('TotalConsumption component', () => {
    
      it('should be rendered correctly and render euro value', async () => {
        const { container } = render(
    
          <Provider store={mockChartStore}>
            <TotalConsumption fluidType={FluidType.ELECTRICITY} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        )
    
        await waitFor(() => null, { container })
        expect(container).toMatchSnapshot()
    
    Pierre Ecarlat's avatar
    Pierre Ecarlat committed
        expect(screen.getByText('32,92')).toBeInTheDocument()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
        const { container } = render(
    
          <Provider store={mockChartStore}>
            <TotalConsumption fluidType={FluidType.MULTIFLUID} />
          </Provider>
        )
    
        await waitFor(() => null, { container })
        expect(screen.getByText('130,84')).toBeInTheDocument()
    
      })
      it('should format multifluid value AND compared value', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          chart: {
            ...mockChartState,
            currentDatachart: graphData,
            showCompare: true,
            currentTimeStep: TimeStep.DAY,
    
        const { container } = render(
    
            <TotalConsumption fluidType={FluidType.MULTIFLUID} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        )
    
        await waitFor(() => null, { container })
        expect(screen.getByText('130,84')).toBeInTheDocument()
        expect(screen.getByText('110,66')).toBeInTheDocument()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
      it('should display ----- when half an hour electricity data is not activated', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore()
    
        const { container } = render(
    
          <Provider store={store}>
            <TotalConsumption fluidType={FluidType.ELECTRICITY} />
    
        await waitFor(() => null, { container })
        expect(screen.getByText('-----')).toBeInTheDocument()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    })