Skip to content
Snippets Groups Projects
ActionModal.spec.tsx 1.76 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import userEvent from '@testing-library/user-event'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { Provider } from 'react-redux'
    
    import * as challengeActions from 'store/challenge/challenge.slice'
    
    import { defaultEcogestureData } from 'tests/__mocks__/actionData.mock'
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import ActionModal from './ActionModal'
    
    
    const mockUpdateUserChallenge = jest.fn()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    jest.mock('services/challenge.service', () => {
    
      return jest.fn(() => ({
        updateUserChallenge: mockUpdateUserChallenge,
      }))
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    })
    
    describe('ActionModal component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should render correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { baseElement } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionModal
    
    Yoan VALLET's avatar
    Yoan VALLET committed
              open={true}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
              handleCloseClick={jest.fn()}
              action={defaultEcogestureData[1]}
              userChallenge={userChallengeData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(baseElement).toMatchSnapshot()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
      it('should click on button and update action to ongoing', async () => {
        const updateChallengeSpy = jest.spyOn(
          challengeActions,
          'updateUserChallengeList'
        )
    
        mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1])
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionModal
    
    Yoan VALLET's avatar
    Yoan VALLET committed
              open={true}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
              handleCloseClick={jest.fn()}
              action={defaultEcogestureData[1]}
              userChallenge={userChallengeData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
        await userEvent.click(screen.getByText('action_modal.accept'))
    
        expect(updateChallengeSpy).toHaveBeenCalledTimes(1)
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })