Skip to content
Snippets Groups Projects
ActionView.spec.tsx 2.88 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render } from '@testing-library/react'
    
    import ActionView from 'components/Action/ActionView'
    
    import { UserActionState } from 'enums'
    
    import { Provider } from 'react-redux'
    
    import {
      createMockEcolyoStore,
      mockChallengeState,
    } from 'tests/__mocks__/store'
    
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
    jest.mock('components/Header/Header', () => 'mock-header')
    jest.mock('components/Content/Content', () => 'mock-content')
    
      'components/Action/ActionChoose/ActionChoose.tsx',
      () => 'mock-action-choose'
    )
    jest.mock(
      'components/Action/ActionOnGoing/ActionOnGoing.tsx',
      () => 'mock-action-onGoing'
    )
    jest.mock(
      'components/Action/ActionDone/ActionDone.tsx',
      () => 'mock-action-done'
    
    
    describe('ActionView component', () => {
    
      it('should render match snapshot with "Unstarted" state', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          challenge: {
    
            ...mockChallengeState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            currentChallenge: {
              ...userChallengeData[1],
              action: {
                ...userChallengeData[1].action,
                state: UserActionState.UNSTARTED,
              },
            },
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          },
    
        const { container } = render(
    
          <Provider store={store}>
            <ActionView />
          </Provider>
        )
    
        expect(container).toMatchSnapshot()
    
      it('should render match snapshot with "onGoing" state', () => {
    
        const store = createMockEcolyoStore({
          challenge: {
    
            ...mockChallengeState,
    
            currentChallenge: {
              ...userChallengeData[1],
              action: {
                ...userChallengeData[1].action,
                state: UserActionState.ONGOING,
              },
            },
          },
        })
        const { container } = render(
          <Provider store={store}>
            <ActionView />
          </Provider>
        )
        expect(container).toMatchSnapshot()
      })
    
      it('should render match snapshot with "Notification" state', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          challenge: {
    
            ...mockChallengeState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            currentChallenge: {
              ...userChallengeData[1],
              action: {
                ...userChallengeData[1].action,
                state: UserActionState.NOTIFICATION,
              },
            },
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          },
    
        const { container } = render(
    
          <Provider store={store}>
            <ActionView />
          </Provider>
        )
    
        expect(container).toMatchSnapshot()
    
      it('should render match snapshot with default case', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          challenge: {
    
            ...mockChallengeState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            currentChallenge: {
              ...userChallengeData[1],
              action: {
                ...userChallengeData[1].action,
              },
            },
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          },
    
        const { container } = render(
    
          <Provider store={store}>
            <ActionView />
          </Provider>
        )
    
        expect(container).toMatchSnapshot()