Skip to content
Snippets Groups Projects
SgeConnectView.spec.tsx 3.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { SgeStep } from 'enums'
    
    import { mount } from 'enzyme'
    
    import toJson from 'enzyme-to-json'
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import * as storeHooks from 'store/hooks'
    
    import { createMockEcolyoStore, mockGlobalState } from 'tests/__mocks__/store'
    
    import SgeConnectView from './SgeConnectView'
    
    jest.mock('components/Content/Content', () => 'mock-content')
    
    jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
    
    const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
    
    
    describe('SgeConnectView component', () => {
      beforeEach(() => {
    
        jest.clearAllMocks()
    
      })
      it('should be rendered correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore()
    
        const wrapper = mount(
          <Provider store={store}>
            <SgeConnectView />
          </Provider>
        )
        expect(toJson(wrapper)).toMatchSnapshot()
      })
      it('should render address Step', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              currentStep: SgeStep.Address,
    
            },
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <SgeConnectView />
          </Provider>
        )
        expect(wrapper.find('.stepAddress')).toBeTruthy()
      })
      it('should render identity Step', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              currentStep: SgeStep.IdentityAndPDL,
    
            },
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <SgeConnectView />
          </Provider>
        )
        expect(wrapper.find('.stepIdentity')).toBeTruthy()
      })
      it('should render consent Step', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              currentStep: SgeStep.Consent,
    
            },
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <SgeConnectView />
          </Provider>
        )
        expect(wrapper.find('.stepConsent')).toBeTruthy()
      })
      it('should render default Step', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore({
          global: {
            sgeConnect: {
              ...mockGlobalState.sgeConnect,
              currentStep: 99,
    
            },
          },
        })
        const wrapper = mount(
          <Provider store={store}>
            <SgeConnectView />
          </Provider>
        )
        expect(wrapper.find('.stepIdentity')).toBeTruthy()
      })
      describe('SgeConnectView Navigation methods', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const store = createMockEcolyoStore()
    
        it('should call nextStep method', () => {
          const wrapper = mount(
            <Provider store={store}>
              <SgeConnectView />
            </Provider>
          )
          wrapper.find('.profile-navigation-button').last().simulate('click')
    
          expect(mockAppDispatch).toHaveBeenCalled()
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        it('should not call disabled nextStep method', () => {
    
          const wrapper = mount(
            <Provider store={store}>
              <SgeConnectView />
            </Provider>
          )
          wrapper.find('.profile-navigation-button').last().simulate('click')
    
          expect(mockAppDispatch).toHaveBeenCalled()