Skip to content
Snippets Groups Projects
ChallengeCardLast.spec.tsx 1.31 KiB
Newer Older
  • Learn to ignore specific revisions
  • import React from 'react'
    import { mount } from 'enzyme'
    import ChallengeCardLast from './ChallengeCardLast'
    import { Provider } from 'react-redux'
    import configureStore from 'redux-mock-store'
    import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock'
    
    
    // Value coming from jest.config
    declare let __SAU_IDEA_DIRECT_LINK__: string
    
    
    jest.mock('cozy-ui/transpiled/react/I18n', () => {
      return {
        useI18n: jest.fn(() => {
          return {
            t: (str: string) => str,
          }
        }),
      }
    })
    
    const mockStore = configureStore([])
    
    describe('ChallengeCardLast component', () => {
    
      const store = mockStore({
        ecolyo: {
          global: globalStateData,
        },
      })
    
    
      it('should be rendered correctly', () => {
        const wrapper = mount(
          <Provider store={store}>
            <ChallengeCardLast />
          </Provider>
        )
        expect(wrapper).toMatchSnapshot()
      })
    
    
      it('should open SAU new idea link', () => {
        global.open = jest.fn()
    
        const wrapper = mount(
          <Provider store={store}>
            <ChallengeCardLast />
          </Provider>
        )
        wrapper.find('.btn_lastCard').first().simulate('click')
        expect(window.open).toBeCalledTimes(1)
        expect(global.open).toHaveBeenCalledWith(
          `${__SAU_IDEA_DIRECT_LINK__}?version=0.0.0`
        )
      })