Skip to content
Snippets Groups Projects
SgeConnectView.spec.tsx 2.74 KiB
Newer Older
  • Learn to ignore specific revisions
  • Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { render, screen } from '@testing-library/react'
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    import { SgeStore } from 'models'
    
    import React from 'react'
    
    import { Provider } from 'react-redux'
    
    import { BrowserRouter } from 'react-router-dom'
    
    import { SgeStatusWithAccount } from 'tests/__mocks__/fluidStatusData.mock'
    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')
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    const store = createMockEcolyoStore()
    
    const mockConnect = jest.fn()
    const mockUpdate = jest.fn()
    
    jest.mock('components/Hooks/useKonnectorAuth', () =>
      jest.fn(() => [mockConnect, mockUpdate])
    )
    
    
    // mock sge state with shouldLaunchAccount set to true
    jest.mock('components/Connection/useForm', () => ({
      useFormData: jest.fn().mockReturnValue({ formData: {} }),
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
      createInitialSgeState: jest.fn<SgeStore, []>().mockReturnValue({
    
        address: '',
        lastName: '',
        firstName: '',
        pdl: 0,
        zipCode: 0,
        city: '',
        currentStep: 0,
        dataConsent: false,
        shouldLaunchAccount: true,
        pdlConfirm: false,
      }),
    }))
    
    
    describe('SgeConnectView component', () => {
      beforeEach(() => {
    
        jest.clearAllMocks()
    
      })
      it('should be rendered correctly', () => {
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        const { container } = render(
    
          <Provider store={store}>
    
            <BrowserRouter>
              <SgeConnectView />
            </BrowserRouter>
    
          </Provider>
        )
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
        expect(container).toMatchSnapshot()
    
      it('should be on stepIdentity by default with button disabled', () => {
    
        render(
          <Provider store={store}>
            <BrowserRouter>
              <SgeConnectView />
            </BrowserRouter>
          </Provider>
        )
        expect(
          screen.getByText('auth.enedissgegrandlyon.identityTitle')
        ).toBeInTheDocument()
    
    
        const prevButton = screen.getByLabelText(
          'profile_type.accessibility.button_previous'
        )
        const nextButton = screen.getByLabelText(
          'profile_type.accessibility.button_next'
        )
    
        expect(prevButton).toBeDisabled()
        expect(nextButton).toBeDisabled()
    
    
      describe('should test methods from useKonnectorAuth hook', () => {
    
        it('should launch account and trigger creation process', () => {
    
          render(
            <Provider store={store}>
              <SgeConnectView />
            </Provider>
          )
          expect(mockConnect).toHaveBeenCalled()
        })
    
        it('should launch existing account update process', () => {
    
          const store = createMockEcolyoStore({
            global: {
              ...mockGlobalState,
              fluidStatus: [SgeStatusWithAccount],
            },
          })
          render(
            <Provider store={store}>
              <SgeConnectView />
            </Provider>
          )
          expect(mockUpdate).toHaveBeenCalled()
        })
      })