Newer
Older
import { render, screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import React from 'react'
import * as challengeActions from 'store/challenge/challenge.slice'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
const mockUpdateUserChallenge = jest.fn()
return jest.fn(() => ({
updateUserChallenge: mockUpdateUserChallenge,
}))
it('should be rendered correctly', () => {
<Provider store={store}>
<ActionDone currentChallenge={userChallengeData[1]} />
</Provider>
)
})
it('should click on button and update action to done', async () => {
const updateChallengeSpy = jest.spyOn(
challengeActions,
'updateUserChallengeList'
)
mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1])
<Provider store={store}>
<ActionDone currentChallenge={userChallengeData[1]} />
</Provider>
)
await userEvent.click(screen.getByText('action.ok'))
expect(updateChallengeSpy).toHaveBeenCalledTimes(1)