Newer
Older

Guilhem CARRON
committed
import React from 'react'
import { mount } from 'enzyme'
import { Provider } from 'react-redux'
import configureStore from 'redux-mock-store'
import ChallengeCardUnlocked from './ChallengeCardUnlocked'
import { userChallengeData } from '../../../tests/__mocks__/userChallengeData.mock'
import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
import ChallengeNoFluidModal from './ChallengeNoFluidModal'

Guilhem CARRON
committed
jest.mock('cozy-ui/transpiled/react/I18n', () => {
return {
useI18n: jest.fn(() => {
return {
t: (str: string) => str,
}
}),
}
})
const mockStartUserChallenge = jest.fn()
jest.mock('services/challenge.service', () => {
startUserChallenge: mockStartUserChallenge,
}
})
})
const mockStore = configureStore([])

Guilhem CARRON
committed
describe('ChallengeCardUnlocked component', () => {

Guilhem CARRON
committed
it('should be rendered correctly', () => {
})
const wrapper = mount(
<Provider store={store}>
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
expect(wrapper.find('.challengeTitle').text()).toEqual(
userChallengeData[0].title
)
expect(wrapper.find('.btn-duel-active').exists()).toBeTruthy()
expect(wrapper.find(ChallengeNoFluidModal).exists()).toBeTruthy()
expect(wrapper.find(ChallengeNoFluidModal).prop('open')).toBeFalsy()
it('should display ChallengeNoFluidModal when launching challenge without configured fluid', () => {
})
const wrapper = mount(
<Provider store={store}>
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
.find('.btn-duel-active')
expect(wrapper.find(ChallengeNoFluidModal).exists()).toBeTruthy()
expect(wrapper.find(ChallengeNoFluidModal).prop('open')).toBeTruthy()

Guilhem CARRON
committed
})
it('should not display ChallengeNoFluidModal and update userChallenge when launching challenge with configured fluid', () => {
const updateGlobalStoreData = {
...globalStateData,
fluidTypes: [FluidType.ELECTRICITY],

Hugo NOUTS
committed
fluidStatus: [{ status: 200 }],
})
const wrapper = mount(
<Provider store={store}>
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />

Guilhem CARRON
committed
)
.find('.btn-duel-active')
expect(wrapper.find(ChallengeNoFluidModal).exists()).toBeTruthy()
expect(wrapper.find(ChallengeNoFluidModal).prop('open')).toBeFalsy()
expect(mockStartUserChallenge).toHaveBeenCalledWith(userChallengeData[0])