Newer
Older
import { act, render, screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
} from 'tests/__mocks__/store'
import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
import ChallengeCardUnlocked from './ChallengeCardUnlocked'

Guilhem CARRON
committed
const mockStartUserChallenge = jest.fn()
jest.mock('services/challenge.service', () => {
return jest.fn(() => ({
startUserChallenge: mockStartUserChallenge,
}))

Hugo SUBTIL
committed
})
describe('ChallengeCardUnlocked component', () => {

Guilhem CARRON
committed
it('should be rendered correctly', () => {
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
expect(screen.getByText('Simone VEILLE')).toBeInTheDocument()
expect(
screen.getByText('challenge.card_unlocked.button_launch')
).toBeInTheDocument()
expect(screen.queryAllByRole('dialog').length).toBeFalsy()
it('should display ChallengeNoFluidModal when launching challenge without configured fluid', async () => {
render(
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
await act(async () => {
await userEvent.click(
screen.getByText('challenge.card_unlocked.button_launch')
)
})
expect(screen.queryAllByRole('dialog').length).toBeTruthy()

Guilhem CARRON
committed
})
it('should not display ChallengeNoFluidModal and update userChallenge when launching challenge with configured fluid', async () => {
mockStartUserChallenge.mockResolvedValue(userChallengeData[0])
fluidStatus: [
{ ...mockGlobalState.fluidStatus[0], status: FluidState.DONE },
],
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />

Guilhem CARRON
committed
)
await act(async () => {
await userEvent.click(
screen.getByText('challenge.card_unlocked.button_launch')
)
})
expect(screen.queryAllByRole('dialog').length).toBeFalsy()
expect(mockStartUserChallenge).toHaveBeenCalledWith(userChallengeData[0])

Guilhem CARRON
committed
})
it('should not be able to launch challenge if another one is active', () => {
mockStartUserChallenge.mockResolvedValue(userChallengeData[0])
const store = createMockEcolyoStore({
global: mockGlobalState,
challenge: {
...mockChallengeState,
currentChallenge: userChallengeData[1],
},
})
<Provider store={store}>
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
</Provider>
)
const launchBtn = screen.getByLabelText(
'challenge.accessibility.button_launch'
)
expect(launchBtn).toHaveAttribute('disabled')