diff --git a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx index 70789a031d85eb81341d60a28172a2a4f3fab624..103be84900537085d3343dec0b456b4ab8f7b8ea 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx @@ -51,8 +51,8 @@ describe('EcogestureFormEquipment component', () => { <Provider store={store}> <EcogestureFormEquipment currentProfileEcogesture={mockProfileEcogesture} - setPreviousStep={mockSetPreviousStep} - setNextStepEcogestureForm={mockSetNextStep} + setPreviousStep={jest.fn()} + setNextStepEcogestureForm={jest.fn()} step={0} /> </Provider> diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx index 5b2b12e46d94f301c01a33087a0e0826b4fcbe0a..4f5261c876fa60a9f14195280c7176826b2c7e7d 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx @@ -1,8 +1,7 @@ -import { render, waitFor } from '@testing-library/react' -import { mount } from 'enzyme' +import { render, screen, waitFor } from '@testing-library/react' +import { userEvent } from '@testing-library/user-event' import React from 'react' import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' -import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureSelectionDetail from './EcogestureSelectionDetail' const mockValidate = jest.fn() @@ -20,59 +19,40 @@ describe('EcogestureSelectionDetail component', () => { expect(container).toMatchSnapshot() }) - it('should toggle more details', async () => { - const wrapper = mount( - <EcogestureSelectionDetail - ecogesture={mockedEcogesturesData[0]} - validate={mockValidate} - title={mockedEcogesturesData[0].shortName} - /> - ) - await waitForComponentToPaint(wrapper) + describe('should click on buttons', () => { + let container: HTMLElement + beforeEach(async () => { + container = render( + <EcogestureSelectionDetail + ecogesture={mockedEcogesturesData[0]} + validate={mockValidate} + title={mockedEcogesturesData[0].shortName} + /> + ).container + await waitFor(() => null, { container }) + }) - wrapper.find('.showMore').first().simulate('click') - await waitForComponentToPaint(wrapper) + it('should toggle more details', async () => { + const [showMore] = screen.getAllByRole('button') + await userEvent.click(showMore) + expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument() + }) + it('should call validate with objective to true', async () => { + const [, objective] = screen.getAllByRole('button') + await userEvent.click(objective) + expect(mockValidate).toHaveBeenCalledWith(true, false) + }) - expect(wrapper.find('.showMore').first().text()).toBe( - 'ecogesture_modal.show_less' - ) - }) - it('should call validate with objective to true', async () => { - const wrapper = mount( - <EcogestureSelectionDetail - ecogesture={mockedEcogesturesData[0]} - validate={mockValidate} - title={mockedEcogesturesData[0].shortName} - /> - ) - wrapper.find('.btnObjective').first().simulate('click') - await waitForComponentToPaint(wrapper) - expect(mockValidate).toHaveBeenCalledWith(true, false) - }) + it('should call validate with doing to true', async () => { + const [, , doing] = screen.getAllByRole('button') + await userEvent.click(doing) + expect(mockValidate).toHaveBeenCalledWith(false, true) + }) - it('should call validate with doing to true', async () => { - const wrapper = mount( - <EcogestureSelectionDetail - ecogesture={mockedEcogesturesData[0]} - validate={mockValidate} - title={mockedEcogesturesData[0].shortName} - /> - ) - wrapper.find('.btnDoing').first().simulate('click') - await waitForComponentToPaint(wrapper) - expect(mockValidate).toHaveBeenCalledWith(false, true) - }) - - it('should call validate with objective and doing to false', async () => { - const wrapper = mount( - <EcogestureSelectionDetail - ecogesture={mockedEcogesturesData[0]} - validate={mockValidate} - title={mockedEcogesturesData[0].shortName} - /> - ) - wrapper.find('.btnSkip').first().simulate('click') - await waitForComponentToPaint(wrapper) - expect(mockValidate).toHaveBeenCalledWith(false, false) + it('should call validate with objective and doing to false', async () => { + const [, , , skip] = screen.getAllByRole('button') + await userEvent.click(skip) + expect(mockValidate).toHaveBeenCalledWith(false, false) + }) }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.tsx index b264060f6e2be8545e2291ace04f6664d303972c..6d53bb111c2198f3055ae2e954179ac2bae1ab6e 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.tsx @@ -69,7 +69,7 @@ const EcogestureSelectionDetail = ({ <Button aria-label={t('ecogesture_selection.button_objective')} classes={{ - root: 'btnSecondary btnObjective', + root: 'btnSecondary', label: 'text-14-bold', }} onClick={() => validate(true, false)} @@ -80,7 +80,7 @@ const EcogestureSelectionDetail = ({ <Button aria-label={t('ecogesture_selection.button_doing')} classes={{ - root: 'btnSecondary btnDoing', + root: 'btnSecondary', label: 'text-14-bold', }} onClick={() => validate(false, true)} @@ -91,7 +91,7 @@ const EcogestureSelectionDetail = ({ <Button aria-label={t('ecogesture_selection.button_skip')} classes={{ - root: 'btnSecondary btnSkip', + root: 'btnSecondary', label: 'text-14-bold', }} onClick={() => validate(false, false)} diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap b/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap index 7e62bb3a0b57a0b4d8cfc62db57e2ad186b16971..bbd6adbd92d72288c227dec29d4990211f4e943e 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/__snapshots__/EcogestureSelectionDetail.spec.tsx.snap @@ -70,7 +70,7 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] = > <button aria-label="ecogesture_selection.button_objective" - class="MuiButtonBase-root MuiButton-root btnSecondary btnObjective MuiButton-text" + class="MuiButtonBase-root MuiButton-root btnSecondary MuiButton-text" tabindex="0" type="button" > @@ -95,7 +95,7 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] = </button> <button aria-label="ecogesture_selection.button_doing" - class="MuiButtonBase-root MuiButton-root btnSecondary btnDoing MuiButton-text" + class="MuiButtonBase-root MuiButton-root btnSecondary MuiButton-text" tabindex="0" type="button" > @@ -120,7 +120,7 @@ exports[`EcogestureSelectionDetail component should be rendered correctly 1`] = </button> <button aria-label="ecogesture_selection.button_skip" - class="MuiButtonBase-root MuiButton-root btnSecondary btnSkip MuiButton-text" + class="MuiButtonBase-root MuiButton-root btnSecondary MuiButton-text" tabindex="0" type="button" > diff --git a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx index 31f5647c2e6f50b682861331b4d8842fee19a98a..bcf32fb5e275cd73f0aa02e926b606770626728b 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx @@ -1,6 +1,5 @@ -import { Button } from '@material-ui/core' -import { render } from '@testing-library/react' -import { mount } from 'enzyme' +import { render, screen } from '@testing-library/react' +import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureSelectionEnd from './EcogestureSelectionEnd' @@ -20,9 +19,9 @@ describe('EcogestureSelectionEnd component', () => { expect(container).toMatchSnapshot() }) - it('should close modal and update profile', () => { - const wrapper = mount(<EcogestureSelectionEnd />) - wrapper.find(Button).simulate('click') + it('should close modal and update profile', async () => { + render(<EcogestureSelectionEnd />) + await userEvent.click(screen.getByRole('button')) expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures?tab=0') }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx index a8d883f8a75c6a25807eaf97bf702432d57073c2..11801f5c9df1a75ea26f7c6354b5bf5a05e43c49 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx @@ -1,6 +1,5 @@ -import { Button } from '@material-ui/core' -import { render } from '@testing-library/react' -import { mount } from 'enzyme' +import { render, screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import React from 'react' import EcogestureSelectionModal from './EcogestureSelectionModal' @@ -17,13 +16,13 @@ describe('EcogestureInitModal component', () => { }) it('should close modal and update profile', async () => { - const wrapper = mount( + render( <EcogestureSelectionModal open={true} handleCloseClick={mockHandleClose} /> ) - wrapper.find(Button).simulate('click') + await userEvent.click(screen.getAllByRole('button')[0]) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx index 45ff77212fc8838f0c2589e9c11e6360115e1033..0a5e78b1680da49a01b246af2f290c60ba4c1fb1 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx @@ -1,6 +1,5 @@ -import { Button } from '@material-ui/core' -import { render } from '@testing-library/react' -import { mount } from 'enzyme' +import { render, screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import React from 'react' import EcogestureSelectionRestart from './EcogestureSelectionRestart' @@ -19,19 +18,15 @@ describe('EcogestureSelectionRestart component', () => { expect(container).toMatchSnapshot() }) - it('should call go to the ecogesture view when user click on the button', () => { - const wrapper = mount( - <EcogestureSelectionRestart listLength={10} restart={mockRestart} /> - ) - wrapper.find(Button).at(0).simulate('click') + it('should call go to the ecogesture view when user click on the button', async () => { + render(<EcogestureSelectionRestart listLength={10} restart={mockRestart} />) + await userEvent.click(screen.getAllByRole('button')[0]) expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures?tab=0') }) - it('should call the restart when user click on the button', () => { - const wrapper = mount( - <EcogestureSelectionRestart listLength={10} restart={mockRestart} /> - ) - wrapper.find(Button).at(1).simulate('click') + it('should call the restart when user click on the button', async () => { + render(<EcogestureSelectionRestart listLength={10} restart={mockRestart} />) + await userEvent.click(screen.getAllByRole('button')[1]) expect(mockRestart).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx index 7c2706b21977e7827241f122b20d859d03af0449..b33791127a3110daff86b6232928dc750dc10066 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionView.spec.tsx @@ -1,10 +1,8 @@ import { render, waitFor } from '@testing-library/react' -import { mount } from 'enzyme' import React from 'react' import { Provider } from 'react-redux' import { mockedEcogesturesData } from 'tests/__mocks__/ecogesturesData.mock' import { createMockEcolyoStore } from 'tests/__mocks__/store' -import { waitForComponentToPaint } from 'tests/__mocks__/testUtils' import EcogestureSelectionView from './EcogestureSelectionView' const mockGetEcogestureListByProfile = jest.fn() @@ -49,35 +47,24 @@ describe('EcogestureSelection component', () => { ) await waitFor(() => null, { container }) expect(container).toMatchSnapshot() + expect( + container.getElementsByTagName('mock-ecogestureSelectionModal')[0] + ).toBeInTheDocument() + expect( + container.getElementsByTagName('mock-ecogestureSelectionDetail')[0] + ).toBeInTheDocument() }) - it('should render with the EcogestureSelectionModal', async () => { - mockGetEcogestureListByProfile.mockResolvedValue([mockedEcogesturesData[0]]) - const wrapper = mount( - <Provider store={store}> - <EcogestureSelectionView /> - </Provider> - ) - await waitForComponentToPaint(wrapper) - expect(wrapper.find('mock-ecogestureSelectionModal').exists()).toBeTruthy() - }) - it('should render with the EcogestureSelectionDetail', async () => { - mockGetEcogestureListByProfile.mockResolvedValue([mockedEcogesturesData[0]]) - const wrapper = mount( - <Provider store={store}> - <EcogestureSelectionView /> - </Provider> - ) - await waitForComponentToPaint(wrapper) - expect(wrapper.find('mock-ecogestureSelectionDetail').exists()).toBeTruthy() - }) + it('should render with the EcogestureSelectionEnd', async () => { mockGetEcogestureListByProfile.mockResolvedValue([]) - const wrapper = mount( + const { container } = render( <Provider store={store}> <EcogestureSelectionView /> </Provider> ) - await waitForComponentToPaint(wrapper) - expect(wrapper.find('mock-ecogestureSelectionEnd').exists()).toBeTruthy() + await waitFor(() => null, { container }) + expect( + container.getElementsByTagName('mock-ecogestureSelectionEnd')[0] + ).toBeInTheDocument() }) })