diff --git a/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx b/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx index d7c9af6ba030bc7974378d9cdb429050d76f1e0f..78c50f9b7869c29d52f36a96039a08bc7c381a1e 100644 --- a/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx +++ b/src/components/Connection/SGEConnect/SgeConnectView.spec.tsx @@ -1,16 +1,13 @@ import { render, screen } from '@testing-library/react' -import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' import { BrowserRouter } from 'react-router-dom' -import * as storeHooks from 'store/hooks' import { createMockEcolyoStore } 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') const store = createMockEcolyoStore() describe('SgeConnectView component', () => { @@ -28,17 +25,25 @@ describe('SgeConnectView component', () => { expect(container).toMatchSnapshot() }) - describe('SgeConnectView Navigation methods', () => { - it('should call nextStep method', async () => { - render( - <Provider store={store}> - <BrowserRouter> - <SgeConnectView /> - </BrowserRouter> - </Provider> - ) - await userEvent.click(screen.getAllByRole('button')[1]) - expect(mockAppDispatch).toHaveBeenCalled() + it('should be on stepIdentity by default with button disabled', async () => { + render( + <Provider store={store}> + <BrowserRouter> + <SgeConnectView /> + </BrowserRouter> + </Provider> + ) + expect( + screen.getByText('auth.enedissgegrandlyon.identityTitle') + ).toBeInTheDocument() + + const prevButton = screen.getByRole('button', { + name: 'profile_type.accessibility.button_previous', + }) + const nextButton = screen.getByRole('button', { + name: 'profile_type.accessibility.button_next', }) + expect(prevButton).toBeDisabled() + expect(nextButton).toBeDisabled() }) }) diff --git a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx index ef172bd9d6f3fb0345cd28e4816dc7d881da0b61..afb9b5b3902c398071ee639f1c97dcd327935d1b 100644 --- a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx +++ b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx @@ -17,55 +17,61 @@ describe('StepIdentityAndPdl component', () => { expect(container).toMatchSnapshot() }) - describe('should change fields', () => { - beforeEach(() => { - jest.clearAllMocks() - render( - <StepIdentityAndPdl - sgeState={mockGlobalState.sgeConnect} - onChange={mockHandleChange} - /> - ) - }) - it('should change firstName value', async () => { - const firstNameInput = screen.getByRole('textbox', { - name: 'auth.enedissgegrandlyon.firstName', - }) - await userEvent.type(firstNameInput, 'n') - expect(mockHandleChange).toHaveBeenCalledWith('firstName', 'n') - }) - it('should change lastName value', async () => { - const lastNameInput = screen.getByRole('textbox', { - name: 'auth.enedissgegrandlyon.lastName', - }) - await userEvent.type(lastNameInput, 'n') - expect(mockHandleChange).toHaveBeenCalledWith('lastName', 'n') + it('should be able to change fields', async () => { + render( + <StepIdentityAndPdl + sgeState={mockGlobalState.sgeConnect} + onChange={mockHandleChange} + /> + ) + const firstNameInput = screen.getByRole('textbox', { + name: 'auth.enedissgegrandlyon.firstName', }) - it('should change pdl value', async () => { - const pdlInput = screen.getByRole('spinbutton', { - name: 'auth.enedissgegrandlyon.pdlLabel', - }) - await userEvent.type(pdlInput, '0') - expect(mockHandleChange).toHaveBeenCalledWith('pdl', '0', 14) + await userEvent.type(firstNameInput, 'n') + expect(mockHandleChange).toHaveBeenCalledWith('firstName', 'n') + + const lastNameInput = screen.getByRole('textbox', { + name: 'auth.enedissgegrandlyon.lastName', }) - it('should open hint modal', async () => { - const pdlModalButton = screen.getByRole('button', { - name: 'auth.enedissgegrandlyon.pdlModal.title', - }) - await userEvent.click(pdlModalButton) - expect(screen.getByRole('dialog')).toBeInTheDocument() + await userEvent.type(lastNameInput, 'n') + expect(mockHandleChange).toHaveBeenCalledWith('lastName', 'n') + + const pdlInput = screen.getByRole('spinbutton', { + name: 'auth.enedissgegrandlyon.pdlLabel', }) + await userEvent.type(pdlInput, '0') + expect(mockHandleChange).toHaveBeenCalledWith('pdl', '0', 14) }) - it('should have an existing pdl value', () => { + + it('should open hint modal', async () => { render( <StepIdentityAndPdl - sgeState={{ ...mockGlobalState.sgeConnect, pdl: 11111111111111 }} + sgeState={mockGlobalState.sgeConnect} onChange={mockHandleChange} /> ) - const pdlInput = screen.getByRole('spinbutton', { - name: 'auth.enedissgegrandlyon.pdlLabel', + const pdlModalButton = screen.getByRole('button', { + name: 'auth.enedissgegrandlyon.pdlModal.title', }) - expect(pdlInput).toHaveValue(11111111111111) + await userEvent.click(pdlModalButton) + expect(screen.getByRole('dialog')).toBeInTheDocument() + }) + + it('should be rendered with values in fields', () => { + render( + <StepIdentityAndPdl + sgeState={{ + ...mockGlobalState.sgeConnect, + pdl: 11111111111111, + firstName: 'Zack', + lastName: 'Ichan', + zipCode: 69003, + }} + onChange={mockHandleChange} + /> + ) + expect(screen.getByDisplayValue(11111111111111)).toBeInTheDocument() + expect(screen.getByDisplayValue('Zack')).toBeInTheDocument() + expect(screen.getByDisplayValue('Ichan')).toBeInTheDocument() }) })