Skip to content
Snippets Groups Projects
ActivateHalfHourLoad.spec.tsx 1.66 KiB
Newer Older
  • Learn to ignore specific revisions
  • Yoan VALLET's avatar
    Yoan VALLET committed
    import React from 'react'
    import { mount } from 'enzyme'
    import ActivateHalfHourLoad from './ActivateHalfHourLoad'
    import { Provider } from 'react-redux'
    import configureStore from 'redux-mock-store'
    import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
    import * as reactRedux from 'react-redux'
    import { userChallengeExplo1OnGoing } from '../../../tests/__mocks__/userChallengeData.mock'
    
    import Button from '@material-ui/core/Button'
    
    Yoan VALLET's avatar
    Yoan VALLET committed
    
    jest.mock('cozy-ui/transpiled/react/I18n', () => {
      return {
        useI18n: jest.fn(() => {
          return {
            t: (str: string) => str,
          }
        }),
      }
    })
    
    const mockUseSelector = jest.spyOn(reactRedux, 'useSelector')
    
    const mockConfigureStore = configureStore([])
    const mockStore = mockConfigureStore({
      ecolyo: {
        gloabl: globalStateData,
      },
    })
    
    describe('ActivateHalfHourLoad component test', () => {
      it('should open konnector website when button is clicked', () => {
        mockUseSelector.mockReturnValue(userChallengeExplo1OnGoing)
    
        const wrapper = mount(
          <Provider store={mockStore}>
            <ActivateHalfHourLoad />
          </Provider>
        )
    
        global.open = jest.fn()
    
    
        wrapper.find(Button).simulate('click')
    
    Yoan VALLET's avatar
    Yoan VALLET committed
        expect(global.open).toHaveBeenCalledWith(
          'https://mon-compte-particulier.enedis.fr/donnees/',
          '_blank'
        )
      })
    
      it('should render correctly ActivatehalfHourLoad', () => {
        mockUseSelector.mockReturnValue(userChallengeExplo1OnGoing)
    
        const wrapper = mount(
          <Provider store={mockStore}>
            <ActivateHalfHourLoad />
          </Provider>
        )
    
        expect(wrapper.getElement()).toMatchSnapshot()
      })
    })