Skip to content
Snippets Groups Projects
ActionChoose.spec.tsx 2.3 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'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { AllEcogestureData } from 'tests/__mocks__/actionData.mock'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import {
      createMockEcolyoStore,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      mockChallengeState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      mockGlobalState,
      mockProfileState,
    
    } from 'tests/__mocks__/store'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    import ActionChoose from './ActionChoose'
    
    jest.mock('components/Action/ActionList/ActionList', () => 'mock-ActionList')
    
    
    jest.mock('services/ecogesture.service', () => {
    
      return jest.fn(() => ({
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        getEcogesturesByIds: jest.fn(() => []),
      }))
    })
    
    const mockGetDefaultActions = jest.fn()
    
    jest.mock('services/action.service', () => {
      return jest.fn(() => ({
        getCustomActions: jest.fn(),
        getDefaultActions: mockGetDefaultActions,
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    describe('ActionChoose component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore({
        global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
        profile: mockProfileState,
      })
    
      it('should render correctly', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        mockGetDefaultActions.mockResolvedValue([
          AllEcogestureData[0],
          AllEcogestureData[5],
          AllEcogestureData[2],
        ])
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
    
            <ActionChoose
              userChallenge={userChallengeData[1]}
              setFocus={jest.fn()}
            />
    
    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
      })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
      it('should go to the Action list', async () => {
        const store = createMockEcolyoStore({
          challenge: mockChallengeState,
          global: { ...mockGlobalState, fluidTypes: [0, 1, 2] },
          profile: mockProfileState,
        })
    
        mockGetDefaultActions.mockResolvedValue([
          AllEcogestureData[0],
          AllEcogestureData[5],
          AllEcogestureData[2],
        ])
    
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
    
            <ActionChoose
              userChallenge={userChallengeData[1]}
              setFocus={jest.fn()}
            />
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          </Provider>
        )
    
        await waitFor(() => null, { container })
    
        await userEvent.click(await screen.findByText('action.other'))
    
        const list = container.getElementsByTagName('mock-ActionList')[0]
        expect(list).toBeInTheDocument()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })