Skip to content
Snippets Groups Projects
ChallengeView.spec.tsx 1.47 KiB
Newer Older
  • Learn to ignore specific revisions
  • Yoan VALLET's avatar
    Yoan VALLET committed
    import React from 'react'
    
    import { mount } from 'enzyme'
    import toJson from 'enzyme-to-json'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    import ChallengeView from 'components/Challenge/ChallengeView'
    import * as reactRedux from 'react-redux'
    import { challengeStateDataFull } from '../../../tests/__mocks__/challengeStateData.mock'
    
    import {
      createMockStore,
      mockInitialEcolyoState,
    } from '../../../tests/__mocks__/store'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    const mockUseSelector = jest.spyOn(reactRedux, 'useSelector')
    
    
    Hugo's avatar
    Hugo committed
    jest.mock('cozy-ui/transpiled/react/I18n', () => {
      return {
        useI18n: jest.fn(() => {
          return {
            t: (str: string) => str,
          }
        }),
      }
    })
    
    
    jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
    jest.mock('components/Header/Header', () => 'mock-header')
    jest.mock('components/Content/Content', () => 'mock-content')
    jest.mock('components/Challenge/ChallengeCard', () => 'mock-challengecard')
    
    const useSelectorSpy = jest.spyOn(reactRedux, 'useSelector')
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    describe('ChallengeView component', () => {
    
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      let store: any
      beforeEach(() => {
        store = createMockStore(mockInitialEcolyoState)
        useSelectorSpy.mockClear()
      })
    
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      it('should be rendered correctly', () => {
        mockUseSelector.mockReturnValue(challengeStateDataFull)
    
        const wrapper = mount(
          <reactRedux.Provider store={store}>
            <ChallengeView />
          </reactRedux.Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    })