Skip to content
Snippets Groups Projects
ActionOnGoing.spec.tsx 1.73 KiB
Newer Older
  • Learn to ignore specific revisions
  • Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { Button } from '@material-ui/core'
    
    import EcogestureModal from 'components/Ecogesture/EcogestureModal/EcogestureModal'
    
    import { UserActionState } from 'enums'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { DateTime } from 'luxon'
    
    import React from 'react'
    import { Provider } from 'react-redux'
    
    import { defaultEcogestureData } from 'tests/__mocks__/actionData.mock'
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    
    import ActionOnGoing from './ActionOnGoing'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    
    describe('ActionOnGoing component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        // TODO if ecogesture is null snapshot test is useless
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        startDate: DateTime.local(2020, 1, 1)
    
          .setZone('utc', {
            keepLocalTime: true,
          })
          .startOf('day'),
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        state: UserActionState.ONGOING,
      }
    
      it('should render correctly', async () => {
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
            <ActionOnGoing userAction={userAction} />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
        expect(toJson(wrapper)).toMatchSnapshot()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    
      it('should click on button open ecogesture Modal', async () => {
        const userAction1: UserAction = {
          ecogesture: defaultEcogestureData[1],
          startDate: null,
          state: UserActionState.ONGOING,
        }
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
    
        wrapper.find(Button).first().simulate('click')
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        expect(wrapper.find(EcogestureModal).exists()).toBeTruthy()
      })
    })