Skip to content
Snippets Groups Projects
ActionDone.spec.tsx 1.72 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Button } from '@material-ui/core'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    import { Provider } from 'react-redux'
    
    import UsageEventService from 'services/usageEvent.service'
    
    import * as challengeActions from 'store/challenge/challenge.slice'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    import ActionDone from './ActionDone'
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    jest.mock('services/usageEvent.service')
    const mockAddEvent = jest.fn()
    UsageEventService.addEvent = mockAddEvent
    
    
    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', async () => {
    
        const wrapper = mount(
          <Provider store={store}>
            <ActionDone currentChallenge={userChallengeData[1]} />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
        expect(toJson(wrapper)).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])
    
        const wrapper = mount(
          <Provider store={store}>
            <ActionDone currentChallenge={userChallengeData[1]} />
          </Provider>
        )
    
        wrapper.find(Button).first().simulate('click')
    
        await waitForComponentToPaint(wrapper)
    
        expect(updateChallengeSpy).toHaveBeenCalledTimes(1)