Newer
Older
import { Button } from '@material-ui/core'
import React from 'react'
import { Provider } from 'react-redux'
import {
AllEcogestureData,
defaultEcogestureData,
} from 'tests/__mocks__/actionData.mock'
import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock'
import {
createMockEcolyoStore,
mockGlobalState,
mockProfileState,
} from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
import ActionModal from '../ActionModal/ActionModal'
import ActionBegin from './ActionBegin'
const mockgetCustomActions = jest.fn()
const mockgetDefaultActions = jest.fn()
jest.mock('services/action.service', () => {
return jest.fn(() => ({
getCustomActions: mockgetCustomActions,
getDefaultActions: mockgetDefaultActions,
}))

Hugo SUBTIL
committed
})
describe('ActionBegin component', () => {
it('should render correctly', async () => {
const store = createMockEcolyoStore({
global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
profile: mockProfileState,

Hugo SUBTIL
committed
const wrapper = mount(
<Provider store={store}>
<ActionBegin
action={defaultEcogestureData[1]}
setShowList={jest.fn()}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
await waitForComponentToPaint(wrapper)
expect(toJson(wrapper)).toMatchSnapshot()
})
it('should render correctly with custom action', async () => {
mockgetCustomActions.mockResolvedValue([
AllEcogestureData[0],
AllEcogestureData[5],
AllEcogestureData[2],
])
const store = createMockEcolyoStore({
global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
profile: { ...mockProfileState, isProfileTypeCompleted: true },
})
const wrapper = mount(
<Provider store={store}>
<ActionBegin
action={mockedEcogesturesData[1]}
setShowList={jest.fn()}
userChallenge={userChallengeData[1]}
/>
</Provider>
)

Hugo SUBTIL
committed
expect(wrapper.find('.action-title').text()).toBe('Coup de vent')
it('should render chosen action', async () => {
const store = createMockEcolyoStore({
global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
profile: mockProfileState,

Hugo SUBTIL
committed
const wrapper = mount(
<Provider store={store}>
<ActionBegin
action={defaultEcogestureData[1]}
setShowList={jest.fn()}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
expect(wrapper.find(ActionBegin).exists()).toBeTruthy()
})
it('should open launch Modal', async () => {
const store = createMockEcolyoStore({
global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
profile: mockProfileState,

Hugo SUBTIL
committed
const wrapper = mount(
<Provider store={store}>
<ActionBegin
action={defaultEcogestureData[1]}
setShowList={jest.fn()}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
wrapper.find(Button).first().simulate('click')
expect(wrapper.find(ActionModal).exists()).toBeTruthy()
expect(wrapper.find(ActionModal).prop('open')).toBeTruthy()
it('should go to the list', async () => {
const store = createMockEcolyoStore({
global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
profile: mockProfileState,

Hugo SUBTIL
committed
const wrapper = mount(
<Provider store={store}>
<ActionBegin
action={defaultEcogestureData[1]}
setShowList={jest.fn()}
userChallenge={userChallengeData[1]}
/>
</Provider>
)
wrapper.find(Button).at(1).simulate('click')