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

Merge branch 'rtl-ec-form' into 'dev'

test(rtl): ecogesture form

See merge request !1045
parents 7a63e5ce b7fa73a0
No related branches found
No related tags found
2 merge requests!10622.7 Release,!1045test(rtl): ecogesture form
import { Button } from '@material-ui/core'
import { render, screen, waitFor } from '@testing-library/react' import { render, screen, waitFor } from '@testing-library/react'
import { EquipmentType } from 'enums' import { EquipmentType } from 'enums'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { mockProfileEcogesture } from 'tests/__mocks__/profileEcogesture.mock' import { mockProfileEcogesture } from 'tests/__mocks__/profileEcogesture.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store' import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormEquipment from './EcogestureFormEquipment' import EcogestureFormEquipment from './EcogestureFormEquipment'
const mockSetPreviousStep = jest.fn() const mockSetPreviousStep = jest.fn()
...@@ -50,7 +47,7 @@ describe('EcogestureFormEquipment component', () => { ...@@ -50,7 +47,7 @@ describe('EcogestureFormEquipment component', () => {
}) })
it('should click on disabled back button', async () => { it('should click on disabled back button', async () => {
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormEquipment <EcogestureFormEquipment
currentProfileEcogesture={mockProfileEcogesture} currentProfileEcogesture={mockProfileEcogesture}
...@@ -60,10 +57,14 @@ describe('EcogestureFormEquipment component', () => { ...@@ -60,10 +57,14 @@ describe('EcogestureFormEquipment component', () => {
/> />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper)
wrapper.find(Button).first().simulate('click')
await waitForComponentToPaint(wrapper)
expect(wrapper.find('.icons-container').exists()).toBeTruthy() expect(
container.getElementsByClassName('icons-container').length
).toBeTruthy()
expect(
screen.getByRole('button', {
name: 'profile_type.accessibility.button_next',
})
).toBeDisabled()
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import { import {
...@@ -8,7 +7,6 @@ import { ...@@ -8,7 +7,6 @@ import {
mockProfileEcogesture, mockProfileEcogesture,
} from 'tests/__mocks__/profileEcogesture.mock' } from 'tests/__mocks__/profileEcogesture.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store' import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormSingleChoice from './EcogestureFormSingleChoice' import EcogestureFormSingleChoice from './EcogestureFormSingleChoice'
jest.mock( jest.mock(
...@@ -36,8 +34,8 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -36,8 +34,8 @@ describe('EcogestureFormSingleChoice component', () => {
) )
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
it('should click on disabled button', async () => { it('should render disabled prev button', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormSingleChoice <EcogestureFormSingleChoice
step={0} step={0}
...@@ -49,13 +47,12 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -49,13 +47,12 @@ describe('EcogestureFormSingleChoice component', () => {
/> />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) const [prev] = screen.getAllByRole('button')
wrapper.find(Button).first().simulate('click') expect(prev).toBeDisabled()
expect(mockHandlePreviousStep).toHaveBeenCalledTimes(0)
}) })
it('should pick a choice and go next', async () => { it('should pick a choice and go next', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormSingleChoice <EcogestureFormSingleChoice
step={0} step={0}
...@@ -67,15 +64,13 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -67,15 +64,13 @@ describe('EcogestureFormSingleChoice component', () => {
/> />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) await userEvent.click(screen.getAllByRole('radio')[0])
wrapper.find('input').first().simulate('change') const [, next] = screen.getAllByRole('button')
await waitForComponentToPaint(wrapper) await userEvent.click(next)
wrapper.find(Button).at(1).simulate('click')
expect(mockHandleNextStep).toHaveBeenCalledTimes(1) expect(mockHandleNextStep).toHaveBeenCalledTimes(1)
}) })
it('should go back', async () => { it('should go back', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormSingleChoice <EcogestureFormSingleChoice
step={1} step={1}
...@@ -87,12 +82,12 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -87,12 +82,12 @@ describe('EcogestureFormSingleChoice component', () => {
/> />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) const [prev] = screen.getAllByRole('button')
wrapper.find(Button).first().simulate('click') await userEvent.click(prev)
expect(mockHandlePreviousStep).toHaveBeenCalledTimes(1) expect(mockHandlePreviousStep).toHaveBeenCalledTimes(1)
}) })
it('should keep previous answer', async () => { it('should keep previous answer', async () => {
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormSingleChoice <EcogestureFormSingleChoice
step={0} step={0}
...@@ -104,7 +99,8 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -104,7 +99,8 @@ describe('EcogestureFormSingleChoice component', () => {
/> />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper)
expect(wrapper.find('input').first().hasClass('checked-input')).toBe(true) const radio = screen.getByRole('radio', { checked: true })
expect(radio).toBeInTheDocument()
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { Provider } from 'react-redux' import { Provider } from 'react-redux'
import * as storeHooks from 'store/hooks' import * as storeHooks from 'store/hooks'
import { mockProfileEcogesture } from 'tests/__mocks__/profileEcogesture.mock' import { mockProfileEcogesture } from 'tests/__mocks__/profileEcogesture.mock'
import { createMockEcolyoStore } from 'tests/__mocks__/store' import { createMockEcolyoStore } from 'tests/__mocks__/store'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EcogestureFormView from './EcogestureFormView' import EcogestureFormView from './EcogestureFormView'
jest.mock('components/Header/CozyBar', () => 'mock-cozybar') jest.mock('components/Header/CozyBar', () => 'mock-cozybar')
jest.mock('components/Header/Header', () => 'mock-header') jest.mock('components/Header/Header', () => 'mock-header')
jest.mock('components/Content/Content', () => 'mock-content')
jest.mock( jest.mock(
'components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal', 'components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal',
() => 'mock-ecogesturelaunchmodal' () => 'mock-ecogesturelaunchmodal'
) )
const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch') const mockAppDispatch = jest.spyOn(storeHooks, 'useAppDispatch')
jest.mock('components/Content/Content', () => 'mock-content')
const mockedNavigate = jest.fn() const mockedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({ jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'), ...jest.requireActual('react-router-dom'),
...@@ -41,55 +40,56 @@ describe('EcogestureFormView component', () => { ...@@ -41,55 +40,56 @@ describe('EcogestureFormView component', () => {
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
it('should render singleChoice', async () => { it('should render singleChoice', async () => {
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) expect(
expect(wrapper.find('.ecogesture-form-single').exists()).toBeTruthy() container.getElementsByClassName('ecogesture-form-single').length
).toBeTruthy()
}) })
it('should render profiletype form step because profiletype is completed', async () => { it('should render profiletype form step because profiletype is completed', async () => {
const store = createMockEcolyoStore({ const store = createMockEcolyoStore({
profile: { isProfileTypeCompleted: true }, profile: { isProfileTypeCompleted: true },
profileEcogesture: mockProfileEcogesture, profileEcogesture: mockProfileEcogesture,
}) })
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) expect(
expect(wrapper.find('.profile-type-container').exists()).toBeTruthy() container.getElementsByClassName('profile-type-container').length
).toBeTruthy()
}) })
it('should go to next step', async () => { it('should go to next step', async () => {
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper) // await waitFor(() => null, { container })
wrapper.find('input').first().simulate('change') await userEvent.click(screen.getAllByRole('radio')[0])
await waitForComponentToPaint(wrapper) await userEvent.click(screen.getAllByRole('button')[1])
wrapper.find(Button).at(1).simulate('click') expect(
await waitForComponentToPaint(wrapper) container.getElementsByClassName('ecogesture-form-single').length
expect(wrapper.find('.ecogesture-form-single').exists()).toBeTruthy() ).toBeTruthy()
}) })
it('should go to previous step', async () => { it('should go to previous step', async () => {
const wrapper = mount( const { container } = render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
// go first to next step
await waitForComponentToPaint(wrapper) const [, next] = screen.getAllByRole('button')
wrapper.find('input').first().simulate('change') await userEvent.click(screen.getAllByRole('radio')[0])
await waitForComponentToPaint(wrapper) await userEvent.click(next)
wrapper.find(Button).at(1).simulate('click')
await waitForComponentToPaint(wrapper) expect(
// then go back container.getElementsByClassName('ecogesture-form-single').length
wrapper.find(Button).first().simulate('click') ).toBeTruthy()
expect(wrapper.find('.ecogesture-form-single').exists()).toBeTruthy()
}) })
it('should handle form end', async () => { it('should handle form end', async () => {
...@@ -98,12 +98,11 @@ describe('EcogestureFormView component', () => { ...@@ -98,12 +98,11 @@ describe('EcogestureFormView component', () => {
.spyOn(React, 'useState') .spyOn(React, 'useState')
.mockImplementationOnce(() => [0, () => null]) .mockImplementationOnce(() => [0, () => null])
.mockImplementationOnce(() => [4, () => null]) .mockImplementationOnce(() => [4, () => null])
const wrapper = mount( render(
<Provider store={store}> <Provider store={store}>
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
await waitForComponentToPaint(wrapper)
expect(mockAppDispatch).toHaveBeenCalledTimes(2) expect(mockAppDispatch).toHaveBeenCalledTimes(2)
}) })
}) })
import { Button } from '@material-ui/core' import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import EcogestureLaunchFormModal from './EcogestureLaunchFormModal' import EcogestureLaunchFormModal from './EcogestureLaunchFormModal'
...@@ -16,13 +15,13 @@ describe('EcogestureLaunchFormModal component', () => { ...@@ -16,13 +15,13 @@ describe('EcogestureLaunchFormModal component', () => {
expect(baseElement).toMatchSnapshot() expect(baseElement).toMatchSnapshot()
}) })
it('should close modal', async () => { it('should close modal', async () => {
const wrapper = mount( render(
<EcogestureLaunchFormModal <EcogestureLaunchFormModal
open={true} open={true}
handleCloseClick={mockHandleClose} handleCloseClick={mockHandleClose}
/> />
) )
wrapper.find(Button).first().simulate('click') await userEvent.click(screen.getAllByRole('button')[0])
expect(mockHandleClose).toHaveBeenCalledTimes(1) expect(mockHandleClose).toHaveBeenCalledTimes(1)
}) })
}) })
import { render, waitFor } from '@testing-library/react' import { render, waitFor } from '@testing-library/react'
import { EquipmentType } from 'enums' import { EquipmentType } from 'enums'
import { mount } from 'enzyme'
import React from 'react' import React from 'react'
import { waitForComponentToPaint } from 'tests/__mocks__/testUtils'
import EquipmentIcon from './EquipmentIcon' import EquipmentIcon from './EquipmentIcon'
describe('EcogestureFormSingleChoice component', () => { describe('EcogestureFormSingleChoice component', () => {
...@@ -14,10 +12,10 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -14,10 +12,10 @@ describe('EcogestureFormSingleChoice component', () => {
expect(container).toMatchSnapshot() expect(container).toMatchSnapshot()
}) })
it('should render checked icon', async () => { it('should render checked icon', async () => {
const wrapper = mount( const { container } = render(
<EquipmentIcon equipment={EquipmentType.BOILER} isChecked={true} /> <EquipmentIcon equipment={EquipmentType.BOILER} isChecked={true} />
) )
await waitForComponentToPaint(wrapper) await waitFor(() => null, { container })
expect(wrapper.find('.checked').first().exists()).toBeTruthy() expect(container.getElementsByClassName('checked').length).toBeTruthy()
}) })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment