Skip to content
Snippets Groups Projects
MaxConsumptionCard.spec.tsx 2.51 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen, waitFor } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { userEvent } from '@testing-library/user-event'
    
    import { FluidType } 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 } from 'tests/__mocks__/store'
    
    import MaxConsumptionCard from './MaxConsumptionCard'
    
    
    const mockGetGraphData = jest.fn(() => graphData)
    
    jest.mock('services/consumption.service', () => {
    
      return jest.fn(() => ({
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        getMaxLoad: jest.fn(() => 0),
    
        getGraphData: mockGetGraphData,
      }))
    
    describe('MaxConsumptionCard component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
    
            <MaxConsumptionCard
              fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
            />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
        expect(container).toMatchSnapshot()
    
      it('should be rendered with one fluid and not display arrows', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
    
            <MaxConsumptionCard fluidsWithData={[FluidType.ELECTRICITY]} />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
    
        expect(
          screen.getByLabelText('consumption.accessibility.button_previous_value')
        ).toBeDisabled()
        expect(
          screen.getByLabelText('consumption.accessibility.button_next_value')
        ).toBeDisabled()
    
      })
      it('should be rendered with several fluids and click navigate between fluid', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
    
            <MaxConsumptionCard
              fluidsWithData={[FluidType.ELECTRICITY, FluidType.GAS]}
            />
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
    
        const prevButton = screen.getByLabelText(
          'consumption.accessibility.button_previous_value'
        )
        const nextButton = screen.getByLabelText(
          'consumption.accessibility.button_next_value'
        )
    
        await userEvent.click(nextButton)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument()
    
    
        await userEvent.click(nextButton)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument()
    
    
        await userEvent.click(prevButton)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument()
    
    
        await userEvent.click(prevButton)
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument()