Skip to content
Snippets Groups Projects
SgeInit.spec.tsx 2.22 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { Button } from '@material-ui/core'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import { SgeStatusWithAccount } from 'tests/__mocks__/fluidStatusData.mock'
    
    import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
    import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
    
    import SgeInit from './SgeInit'
    
    const mockedNavigate = jest.fn()
    
    jest.mock('react-router-dom', () => ({
      ...jest.requireActual('react-router-dom'),
    
      useNavigate: () => mockedNavigate,
    
    }))
    
    const mockConnect = jest.fn()
    const mockUpdate = jest.fn()
    
    jest.mock('components/Hooks/useKonnectorAuth', () =>
      jest.fn(() => [mockConnect, mockUpdate])
    )
    
    describe('SgeInit component', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      const store = createMockEcolyoStore()
    
      it('should be rendered correctly', () => {
        const wrapper = mount(
          <Provider store={store}>
    
            <SgeInit />
    
          </Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should go to sge connect steps', () => {
        const wrapper = mount(
          <Provider store={store}>
    
            <SgeInit />
    
          </Provider>
        )
        wrapper.find(Button).first().simulate('click')
    
        expect(mockedNavigate).toHaveBeenCalled()
    
      })
      it('should launch account and trigger creation process', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
    
            ...mockGlobalState,
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              shouldLaunchAccount: true,
    
            },
          },
        })
    
        const wrapper = mount(
          <Provider store={store}>
    
            <SgeInit />
    
          </Provider>
        )
        await waitForComponentToPaint(wrapper)
        expect(mockConnect).toHaveBeenCalled()
      })
      it('should launch existing account update process', async () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
    
            ...mockGlobalState,
            fluidStatus: [SgeStatusWithAccount],
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              shouldLaunchAccount: true,
    
            },
          },
        })
        const wrapper = mount(
          <Provider store={store}>
    
            <SgeInit />
    
          </Provider>
        )
        await waitForComponentToPaint(wrapper)
        expect(mockUpdate).toHaveBeenCalled()
      })
    })