Skip to content
Snippets Groups Projects
ActionBegin.spec.tsx 2.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { render, screen, waitFor } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { userEvent } from '@testing-library/user-event'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { Provider } from 'react-redux'
    import {
      AllEcogestureData,
      defaultEcogestureData,
    
    } from 'tests/__mocks__/actionData.mock'
    import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import {
      createMockEcolyoStore,
      mockGlobalState,
      mockProfileState,
    
    } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    import ActionBegin from './ActionBegin'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const mockGetCustomActions = jest.fn()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    jest.mock('services/action.service', () => {
    
      return jest.fn(() => ({
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        getCustomActions: mockGetCustomActions,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    describe('ActionBegin component', () => {
      it('should render correctly', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
          profile: mockProfileState,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionBegin
              action={defaultEcogestureData[1]}
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
        expect(container).toMatchSnapshot()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
      it('should render correctly with custom action', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        mockGetCustomActions.mockResolvedValue([
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          AllEcogestureData[0],
          AllEcogestureData[5],
          AllEcogestureData[2],
        ])
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
          profile: { ...mockProfileState, isProfileTypeCompleted: true },
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionBegin
    
              action={mockedEcogesturesData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
    
        expect(screen.getByText('Coup de vent')).toBeInTheDocument()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    
      it('should open launch Modal', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
          profile: mockProfileState,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        })
    
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionBegin
              action={defaultEcogestureData[1]}
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
        await waitFor(() => null, { container })
    
        await userEvent.click(screen.getByText('action.apply'))
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(await screen.findByRole('dialog')).toBeInTheDocument()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })