Skip to content
Snippets Groups Projects
ActionCard.spec.tsx 1.81 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Button } from '@material-ui/core'
    
    import defaultIcon from 'assets/icons/visu/duel/default.svg'
    
    import EcogestureModal from 'components/Ecogesture/EcogestureModal/EcogestureModal'
    
    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 { defaultEcogestureData } from 'tests/__mocks__/actionData.mock'
    import { createMockEcolyoStore } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock'
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    import ActionCard from './ActionCard'
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    jest.mock('cozy-ui/transpiled/react/I18n', () => ({
      useI18n: jest.fn(() => ({
        t: (str: string) => str,
      })),
    }))
    
    
    const mockImportIconById = jest.fn(() => defaultIcon)
    
        importIconById: jest.fn(() => {
          return mockImportIconById
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
    describe('ActionCard component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore({
        challenge: {
          currentChallenge: userChallengeData[1],
        },
      })
    
      it('should be rendered correctly', async () => {
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        const wrapper = mount(
          <Provider store={store}>
            <ActionCard
              setShowList={jest.fn()}
              setSelectedAction={jest.fn()}
              action={defaultEcogestureData[1]}
            />
          </Provider>
        )
    
        await waitForComponentToPaint(wrapper)
        expect(toJson(wrapper)).toMatchSnapshot()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
      it('should open modal', () => {
        const wrapper = mount(
          <Provider store={store}>
            <ActionCard
              setShowList={jest.fn()}
              setSelectedAction={jest.fn()}
              action={defaultEcogestureData[1]}
            />
          </Provider>
        )
    
        wrapper.find(Button).first().simulate('click')
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
        expect(wrapper.find(EcogestureModal).exists()).toBeTruthy()
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
      })
    })