Skip to content
Snippets Groups Projects
DuelView.spec.tsx 5.23 KiB
Newer Older
  • Learn to ignore specific revisions
  • Yoan VALLET's avatar
    Yoan VALLET committed
    import DuelView from 'components/Duel/DuelView'
    
    import { UserChallengeState, UserDuelState } from 'enums'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { mount } from 'enzyme'
    
    import React from 'react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { Provider } from 'react-redux'
    
    import { challengeStateData } from 'tests/__mocks__/challengeStateData.mock'
    import { createMockEcolyoStore, mockChartState } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    import DuelError from './DuelError/DuelError'
    import DuelOngoing from './DuelOngoing/DuelOngoing'
    import DuelUnlocked from './DuelUnlocked/DuelUnlocked'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    
    jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
    jest.mock('components/Header/Header', () => 'mock-header')
    jest.mock('components/Content/Content', () => 'mock-content')
    
    
    jest.mock('react-router-dom', () => ({
      useLocation: () => ({
        search: '?id=CHALLENGE0002',
      }),
    
      useNavigate: () => jest.fn(),
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    }))
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    describe('DuelView component', () => {
      it('should be rendered with DuelError component when no current challenge', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({ challenge: challengeStateData })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(DuelError).exists()).toBeTruthy()
      })
    
    
      it('should be rendered with DuelOngoing component when current challenge with state = duel and duel state = done', () => {
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        const updatedUserChallenge = {
          ...userChallengeData[1],
          state: UserChallengeState.DUEL,
          duel: { ...userChallengeData[1].duel, state: UserDuelState.DONE },
        }
        const updatedChallengeState = {
          ...challengeStateData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          currentChallenge: updatedUserChallenge,
        }
    
        updatedChallengeState.userChallengeList[1] = updatedUserChallenge
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          challenge: updatedChallengeState,
          chart: mockChartState,
        })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
        expect(wrapper.find(DuelOngoing).exists()).toBeTruthy()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
      })
    
      it('should be rendered with DuelError component when current challenge with state = duel and duel state = locked', () => {
        const updatedUserChallenge = {
          ...userChallengeData[1],
          state: UserChallengeState.DUEL,
          duel: { ...userChallengeData[1].duel, state: UserDuelState.LOCKED },
        }
        const updatedChallengeState = {
          ...challengeStateData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          currentChallenge: updatedUserChallenge,
        }
    
        updatedChallengeState.userChallengeList[1] = updatedUserChallenge
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({ challenge: updatedChallengeState })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(DuelError).exists()).toBeTruthy()
      })
    
    
      it('should be rendered with DuelError component when current challenge with state != duel', () => {
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        const updatedUserChallenge = {
          ...userChallengeData[1],
          state: UserChallengeState.ONGOING,
        }
        const updatedChallengeState = {
          ...challengeStateData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          currentChallenge: updatedUserChallenge,
        }
    
        updatedChallengeState.userChallengeList[1] = updatedUserChallenge
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({ challenge: updatedChallengeState })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(DuelError).exists()).toBeTruthy()
      })
    
      it('should be rendered with DuelUnlocked component when current challenge with state = duel  and duel state = unlocked', () => {
        const updatedUserChallenge = {
          ...userChallengeData[1],
          state: UserChallengeState.DUEL,
          duel: { ...userChallengeData[1].duel, state: UserDuelState.UNLOCKED },
        }
        const updatedChallengeState = {
          ...challengeStateData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          currentChallenge: updatedUserChallenge,
        }
    
        updatedChallengeState.userChallengeList[1] = updatedUserChallenge
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({ challenge: updatedChallengeState })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(DuelUnlocked).exists()).toBeTruthy()
      })
    
      it('should be rendered with DuelOngoing component when current challenge with state = duel  and duel state = ongoing', () => {
        const updatedUserChallenge = {
          ...userChallengeData[1],
          state: UserChallengeState.DUEL,
          duel: { ...userChallengeData[1].duel, state: UserDuelState.ONGOING },
        }
        const updatedChallengeState = {
          ...challengeStateData,
    
    Yoan VALLET's avatar
    Yoan VALLET committed
          currentChallenge: updatedUserChallenge,
        }
    
        updatedChallengeState.userChallengeList[1] = updatedUserChallenge
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          challenge: updatedChallengeState,
          chart: mockChartState,
        })
        const wrapper = mount(
          <Provider store={store}>
            <DuelView />
          </Provider>
        )
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(DuelOngoing).exists()).toBeTruthy()
      })
    })