Newer
Older
import { render, screen } from '@testing-library/react'
import React from 'react'
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'
const mockUpdateUserChallenge = jest.fn()
return jest.fn(() => ({
updateUserChallenge: mockUpdateUserChallenge,
}))
})
describe('ActionModal component', () => {
it('should render correctly', () => {
handleCloseClick={jest.fn()}
action={defaultEcogestureData[1]}
userChallenge={userChallengeData[1]}
setFocus={jest.fn()}
})
it('should click on button and update action to ongoing', async () => {
const updateChallengeSpy = jest.spyOn(
challengeActions,
'updateUserChallengeList'
)
mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1])
handleCloseClick={jest.fn()}
action={defaultEcogestureData[1]}
userChallenge={userChallengeData[1]}
setFocus={jest.fn()}
await userEvent.click(screen.getByText('action_modal.accept'))
expect(updateChallengeSpy).toHaveBeenCalledTimes(1)