Skip to content
Snippets Groups Projects
ActionBegin.spec.tsx 3.87 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Button } from '@material-ui/core'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    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 { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    import ActionModal from '../ActionModal/ActionModal'
    
    import ActionBegin from './ActionBegin'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    const mockgetCustomActions = jest.fn()
    const mockgetDefaultActions = jest.fn()
    
    jest.mock('services/action.service', () => {
    
      return jest.fn(() => ({
        getCustomActions: mockgetCustomActions,
        getDefaultActions: mockgetDefaultActions,
      }))
    
    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
        })
    
    Guilhem CARRON's avatar
    Guilhem CARRON 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()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
      it('should render correctly with custom action', async () => {
        mockgetCustomActions.mockResolvedValue([
          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
        })
        const wrapper = mount(
          <Provider store={store}>
            <ActionBegin
    
              action={mockedEcogesturesData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
            />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
        expect(wrapper.find('.action-title').text()).toBe('Coup de vent')
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    
      it('should render chosen action', 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
        })
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
            <ActionBegin
              action={defaultEcogestureData[1]}
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
            />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        expect(wrapper.find(ActionBegin).exists()).toBeTruthy()
      })
    
      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
        })
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
            <ActionBegin
              action={defaultEcogestureData[1]}
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
            />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
        wrapper.find(Button).first().simulate('click')
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        expect(wrapper.find(ActionModal).exists()).toBeTruthy()
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(wrapper.find(ActionModal).prop('open')).toBeTruthy()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    
      it('should go to the list', 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
        })
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
            <ActionBegin
              action={defaultEcogestureData[1]}
              setShowList={jest.fn()}
              userChallenge={userChallengeData[1]}
            />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
        wrapper.find(Button).at(1).simulate('click')