Skip to content
Snippets Groups Projects
ActionOnGoing.spec.tsx 1.51 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'
    
    import { UserActionState } from 'enums'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import { DateTime } from 'luxon'
    
    import React from 'react'
    import { Provider } from 'react-redux'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import {
      defaultEcogestureData,
      ecogestureDefault,
    } from 'tests/__mocks__/actionData.mock'
    
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    
    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
        ecogesture: ecogestureDefault,
    
    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 () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionOnGoing userAction={userAction} />
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        await waitFor(() => null, { container })
        expect(container).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,
        }
    
        render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          </Provider>
        )
    
        await userEvent.click(screen.getByText('action.details'))
    
        expect(screen.getByRole('dialog')).toBeTruthy()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })