Skip to content
Snippets Groups Projects
Commit 9eaaccc6 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

test(sge): improve test & speed

parent 85d764f2
No related branches found
No related tags found
1 merge request!11623.0 Release
import { render, screen } from '@testing-library/react' import { render, screen } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { BrowserRouter } from 'react-router-dom' import { BrowserRouter } from 'react-router-dom'
import * as storeHooks from 'store/hooks'
import { createMockEcolyoStore } from 'tests/__mocks__/store' import { createMockEcolyoStore } from 'tests/__mocks__/store'
import SgeConnectView from './SgeConnectView' import SgeConnectView from './SgeConnectView'
jest.mock('components/Content/Content', () => 'mock-content') jest.mock('components/Content/Content', () => 'mock-content')
jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
const store = createMockEcolyoStore() const store = createMockEcolyoStore()
describe('SgeConnectView component', () => { describe('SgeConnectView component', () => {
...@@ -28,17 +25,25 @@ describe('SgeConnectView component', () => { ...@@ -28,17 +25,25 @@ describe('SgeConnectView component', () => {
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
describe('SgeConnectView Navigation methods', () => { it('should be on stepIdentity by default with button disabled', async () => {
it('should call nextStep method', async () => { render(
render( <Provider store={store}>
<Provider store={store}> <BrowserRouter>
<BrowserRouter> <SgeConnectView />
<SgeConnectView /> </BrowserRouter>
</BrowserRouter> </Provider>
</Provider> )
) expect(
await userEvent.click(screen.getAllByRole('button')[1]) screen.getByText('auth.enedissgegrandlyon.identityTitle')
expect(mockAppDispatch).toHaveBeenCalled() ).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()
}) })
}) })
...@@ -17,55 +17,61 @@ describe('StepIdentityAndPdl component', () => { ...@@ -17,55 +17,61 @@ describe('StepIdentityAndPdl component', () => {
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
describe('should change fields', () => { it('should be able to change fields', async () => {
beforeEach(() => { render(
jest.clearAllMocks() <StepIdentityAndPdl
render( sgeState={mockGlobalState.sgeConnect}
<StepIdentityAndPdl onChange={mockHandleChange}
sgeState={mockGlobalState.sgeConnect} />
onChange={mockHandleChange} )
/> const firstNameInput = screen.getByRole('textbox', {
) name: 'auth.enedissgegrandlyon.firstName',
})
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 change pdl value', async () => { await userEvent.type(firstNameInput, 'n')
const pdlInput = screen.getByRole('spinbutton', { expect(mockHandleChange).toHaveBeenCalledWith('firstName', 'n')
name: 'auth.enedissgegrandlyon.pdlLabel',
}) const lastNameInput = screen.getByRole('textbox', {
await userEvent.type(pdlInput, '0') name: 'auth.enedissgegrandlyon.lastName',
expect(mockHandleChange).toHaveBeenCalledWith('pdl', '0', 14)
}) })
it('should open hint modal', async () => { await userEvent.type(lastNameInput, 'n')
const pdlModalButton = screen.getByRole('button', { expect(mockHandleChange).toHaveBeenCalledWith('lastName', 'n')
name: 'auth.enedissgegrandlyon.pdlModal.title',
}) const pdlInput = screen.getByRole('spinbutton', {
await userEvent.click(pdlModalButton) name: 'auth.enedissgegrandlyon.pdlLabel',
expect(screen.getByRole('dialog')).toBeInTheDocument()
}) })
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( render(
<StepIdentityAndPdl <StepIdentityAndPdl
sgeState={{ ...mockGlobalState.sgeConnect, pdl: 11111111111111 }} sgeState={mockGlobalState.sgeConnect}
onChange={mockHandleChange} onChange={mockHandleChange}
/> />
) )
const pdlInput = screen.getByRole('spinbutton', { const pdlModalButton = screen.getByRole('button', {
name: 'auth.enedissgegrandlyon.pdlLabel', 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()
}) })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment