Skip to content
Snippets Groups Projects
ActionCard.spec.tsx 1.52 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 { defaultEcogestureData } from 'tests/__mocks__/actionData.mock'
    
    import {
      createMockEcolyoStore,
      mockChallengeState,
    } from 'tests/__mocks__/store'
    
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import ActionCard from './ActionCard'
    
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    describe('ActionCard component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore({
        challenge: {
    
          ...mockChallengeState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
          currentChallenge: userChallengeData[1],
        },
      })
    
      it('should be rendered correctly', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionCard
              setShowList={jest.fn()}
              setSelectedAction={jest.fn()}
              action={defaultEcogestureData[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
      })
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      it('should open Ecogesture modal', async () => {
    
        const { container } = render(
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          <Provider store={store}>
            <ActionCard
              setShowList={jest.fn()}
              setSelectedAction={jest.fn()}
              action={defaultEcogestureData[1]}
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
            />
          </Provider>
        )
    
        await waitFor(() => null, { container })
    
        await userEvent.click(await screen.findByRole('button'))
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(await screen.findByRole('dialog')).toBeInTheDocument()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })