Skip to content
Snippets Groups Projects
ActionDone.spec.tsx 1.39 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'
    
    import { Provider } from 'react-redux'
    
    import * as challengeActions from 'store/challenge/challenge.slice'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    import ActionDone from './ActionDone'
    
    
    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
    })
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    
    describe('ActionDone component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
            <ActionDone currentChallenge={userChallengeData[1]} />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(container).toMatchSnapshot()
    
      })
      it('should click on button and update action to done', async () => {
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const updateChallengeSpy = jest.spyOn(
          challengeActions,
          'updateUserChallengeList'
        )
    
        mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1])
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        render(
    
          <Provider store={store}>
            <ActionDone currentChallenge={userChallengeData[1]} />
          </Provider>
        )
    
        await userEvent.click(screen.getByText('action.ok'))
    
        expect(updateChallengeSpy).toHaveBeenCalledTimes(1)