Newer
Older
import { Button } from '@material-ui/core'
import React from 'react'
import UsageEventService from 'services/usageEvent.service'
import * as challengeActions from 'store/challenge/challenge.slice'
import { defaultEcogestureData } from 'tests/__mocks__/actionData.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
const mockUpdateUserChallenge = jest.fn()
return jest.fn(() => ({
updateUserChallenge: mockUpdateUserChallenge,
}))
jest.mock('services/usageEvent.service')
const mockAddEvent = jest.fn()
UsageEventService.addEvent = mockAddEvent
it('should render correctly', async () => {
const wrapper = mount(
<Provider store={store}>
<ActionModal
handleCloseClick={jest.fn()}
action={defaultEcogestureData[1]}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
await waitForComponentToPaint(wrapper)
expect(toJson(wrapper)).toMatchSnapshot()
})
it('should click on button and update action to ongoing', async () => {
const updateChallengeSpy = jest.spyOn(
challengeActions,
'updateUserChallengeList'
)
mockUpdateUserChallenge.mockResolvedValueOnce(userChallengeData[1])
const wrapper = mount(
<Provider store={store}>
<ActionModal
handleCloseClick={jest.fn()}
action={defaultEcogestureData[1]}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
wrapper.find(Button).first().simulate('click')
expect(updateChallengeSpy).toHaveBeenCalledTimes(1)