Skip to content
Snippets Groups Projects
MonthlyAnalysis.spec.tsx 1.91 KiB
Newer Older
  • Learn to ignore specific revisions
  • Yoan VALLET's avatar
    Yoan VALLET committed
    import MonthlyAnalysis from 'components/Analysis/MonthlyAnalysis'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    import { PerformanceIndicator } from 'models'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import React from 'react'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { Provider } from 'react-redux'
    
    import { BrowserRouter } from 'react-router-dom'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    
    const mockPI: PerformanceIndicator[] = [
      { value: 5, compareValue: 10, percentageVariation: 50 },
      { value: 5, compareValue: 10, percentageVariation: 50 },
    ]
    
    jest.mock('services/consumption.service', () => {
      return jest.fn(() => {
        return {
          getFluidsWithDataForTimePeriod: jest.fn(() => [0, 1, 2]),
    
          getFluidsWithIncompleteData: jest.fn(() => [0]),
    
          getPerformanceIndicators: jest.fn(() => mockPI),
        }
      })
    })
    
    jest.mock('components/Analysis/Comparison/Comparison', () => 'mock-comparison')
    jest.mock(
      'components/Analysis/TotalAnalysisChart/TotalAnalysisChart',
      () => 'mock-total-analysis'
    )
    jest.mock(
      'components/Analysis/MaxConsumptionCard/MaxConsumptionCard',
      () => 'mock-max-consumption'
    )
    jest.mock(
      'components/Analysis/ProfileComparator/ProfileComparator',
      () => 'mock-analysis'
    )
    jest.mock(
      'components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis',
      () => 'mock-half-hour-analysis'
    )
    
    window.scrollTo = jest.fn()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    describe('MonthlyAnalysis component', () => {
    
      it('should be rendered correctly', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
    
          <BrowserRouter>
            <Provider store={store}>
              <MonthlyAnalysis
                saveLastScrollPosition={jest.fn()}
                scrollPosition={0}
              />
            </Provider>
          </BrowserRouter>
    
        )
        await waitForComponentToPaint(wrapper)
        expect(toJson(wrapper)).toMatchSnapshot()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    })