diff --git a/src/components/Action/ActionBegin/ActionBegin.spec.tsx b/src/components/Action/ActionBegin/ActionBegin.spec.tsx index f4e0ba50d1ed2e4016e6142ab11685a0f3bf6ede..99bab9320fa6c3606ad87e4aa26ae48d12fb5808 100644 --- a/src/components/Action/ActionBegin/ActionBegin.spec.tsx +++ b/src/components/Action/ActionBegin/ActionBegin.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -62,8 +62,7 @@ describe('ActionBegin component', () => { </Provider> ) await waitFor(() => null, { container }) - const title = screen.getByRole('heading') - expect(title).toHaveTextContent('Coup de vent') + expect(screen.getByText('Coup de vent')).toBeInTheDocument() }) it('should open launch Modal', async () => { const store = createMockEcolyoStore({ @@ -71,7 +70,7 @@ describe('ActionBegin component', () => { profile: mockProfileState, }) - render( + const { container } = render( <Provider store={store}> <ActionBegin action={defaultEcogestureData[1]} @@ -80,7 +79,10 @@ describe('ActionBegin component', () => { /> </Provider> ) - await userEvent.click(await screen.findByText('action.apply')) + await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(screen.getByText('action.apply')) + }) expect(await screen.findByRole('dialog')).toBeInTheDocument() }) }) diff --git a/src/components/Action/ActionCard/ActionCard.spec.tsx b/src/components/Action/ActionCard/ActionCard.spec.tsx index 6da3d6ac9cbbf3d88c792275d9ff1d3878f25f85..44a22ec8a316dfd5f773800f83fed2f55f3d8fb8 100644 --- a/src/components/Action/ActionCard/ActionCard.spec.tsx +++ b/src/components/Action/ActionCard/ActionCard.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -27,7 +27,7 @@ describe('ActionCard component', () => { expect(container).toMatchSnapshot() }) it('should open Ecogesture modal', async () => { - render( + const { container } = render( <Provider store={store}> <ActionCard setShowList={jest.fn()} @@ -36,7 +36,10 @@ describe('ActionCard component', () => { /> </Provider> ) - await userEvent.click(await screen.findByRole('button')) + await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(await screen.findByRole('button')) + }) expect(await screen.findByRole('dialog')).toBeInTheDocument() }) }) diff --git a/src/components/Action/ActionChoose/ActionChoose.spec.tsx b/src/components/Action/ActionChoose/ActionChoose.spec.tsx index c7f251918247054dcc6f0eacbb711aa37269d06c..936d23c5f8b50519f15a656dd8338415d5fde881 100644 --- a/src/components/Action/ActionChoose/ActionChoose.spec.tsx +++ b/src/components/Action/ActionChoose/ActionChoose.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -12,6 +12,9 @@ import { import { userChallengeData } from 'tests/__mocks__/userChallengeData.mock' import ActionChoose from './ActionChoose' +// jest.mock('components/Action/ActionBegin/ActionBegin', () => 'mock-ActionBegin') +jest.mock('components/Action/ActionList/ActionList', () => 'mock-ActionList') + jest.mock('services/ecogesture.service', () => { return jest.fn(() => ({ getEcogesturesByIds: jest.fn(() => []), @@ -65,8 +68,13 @@ describe('ActionChoose component', () => { <ActionChoose userChallenge={userChallengeData[1]} /> </Provider> ) - await userEvent.click(await screen.findByText('action.other')) - const elements = container.getElementsByClassName('action-list-container') - expect(elements.item(0)).toBeInTheDocument() + await waitFor(() => null, { container }) + + await act(async () => { + await userEvent.click(await screen.findByText('action.other')) + }) + + const list = container.getElementsByTagName('mock-ActionList')[0] + expect(list).toBeInTheDocument() }) }) diff --git a/src/components/Action/ActionDone/ActionDone.spec.tsx b/src/components/Action/ActionDone/ActionDone.spec.tsx index 09c2d698ff27ff4764736c633b536282298775cc..038a6dd206fee247504430ae81e435a579e305b0 100644 --- a/src/components/Action/ActionDone/ActionDone.spec.tsx +++ b/src/components/Action/ActionDone/ActionDone.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -35,7 +35,9 @@ describe('ActionDone component', () => { <ActionDone currentChallenge={userChallengeData[1]} /> </Provider> ) - await userEvent.click(await screen.findByText('action.ok')) + await act(async () => { + await userEvent.click(screen.getByText('action.ok')) + }) expect(updateChallengeSpy).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Action/ActionModal/ActionModal.spec.tsx b/src/components/Action/ActionModal/ActionModal.spec.tsx index a3c59c54d2523c2f93e0c264740a6389efe9afd2..138d005c3e36aa4cecbea8a50376afe0ac90490b 100644 --- a/src/components/Action/ActionModal/ActionModal.spec.tsx +++ b/src/components/Action/ActionModal/ActionModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -47,7 +47,9 @@ describe('ActionModal component', () => { /> </Provider> ) - await userEvent.click(await screen.findByText('action_modal.accept')) + await act(async () => { + await userEvent.click(screen.getByText('action_modal.accept')) + }) expect(updateChallengeSpy).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx index 899e6e3cdeb3b9216ac26e2433901bf913bc08cb..ed1789703e930b669c776175fc812a17f48beef9 100644 --- a/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx +++ b/src/components/Action/ActionOnGoing/ActionOnGoing.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { UserActionState } from 'enums' import { DateTime } from 'luxon' @@ -39,13 +39,14 @@ describe('ActionOnGoing component', () => { state: UserActionState.ONGOING, } - const { container } = render( + render( <Provider store={store}> <ActionOnGoing userAction={userAction1} /> </Provider> ) - await waitFor(() => null, { container }) - await userEvent.click(await screen.findByText('action.details')) + await act(async () => { + await userEvent.click(screen.getByText('action.details')) + }) expect(screen.findByRole('dialog')).toBeTruthy() }) }) diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx index 079b98bd5a78e418233b508098bda144c53b7faf..4c977c1746a4286808cb9dd47a64990ed6ecbf2f 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { PerformanceIndicator } from 'models' import React from 'react' @@ -99,8 +99,11 @@ describe('ElecHalfHourMonthlyAnalysis component', () => { <ElecHalfHourMonthlyAnalysis perfIndicator={mockPerfIndicator} /> </Provider> ) - await waitFor(() => null, { container }) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click( + screen.getByLabelText('consumption.accessibility.button_previous_value') + ) + }) expect(container.getElementsByClassName('week').length).toBeTruthy() }) @@ -114,13 +117,15 @@ describe('ElecHalfHourMonthlyAnalysis component', () => { ) mockGetPrices.mockResolvedValue(allLastFluidPrices[0]) - const { container } = render( + render( <Provider store={store}> <ElecHalfHourMonthlyAnalysis perfIndicator={mockPerfIndicator} /> </Provider> ) - await waitFor(() => null, { container }) - await userEvent.click(await screen.findByText('special_elec.showModal')) + + await waitFor(async () => { + await userEvent.click(screen.getByText('special_elec.showModal')) + }) expect(await screen.findByRole('dialog')).toBeInTheDocument() }) }) diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx index 40b4223d85a3391a47f9191cf56fe5b16723467e..b4a64e77f115d83106570606b527b27e5effa0d4 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/ElecHalfHourMonthlyAnalysis.tsx @@ -192,7 +192,7 @@ const ElecHalfHourMonthlyAnalysis = ({ </div> </div> <IconButton - aria-label={t('consumption.accessibility.button_previous_value')} + aria-label={t('consumption.accessibility.button_next_value')} onClick={handleChangeWeek} className="arrow-next" > diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap index e4058feef99e3df1d3e78658d97e488bcf281631..381a846028beec7849346c46e4cf5484949a4aee 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap @@ -94,7 +94,7 @@ exports[`ElecHalfHourMonthlyAnalysis component should be rendered correctly when </div> </div> <button - aria-label="consumption.accessibility.button_previous_value" + aria-label="consumption.accessibility.button_next_value" class="MuiButtonBase-root MuiIconButton-root arrow-next" tabindex="0" type="button" diff --git a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx index 18977eb0ddad4f84dfd778067a7610ab5b7d9b52..098ee31407b05bd54d157602076284e341516dc8 100644 --- a/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx +++ b/src/components/Analysis/MaxConsumptionCard/MaxConsumptionCard.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { FluidType } from 'enums' import React from 'react' @@ -48,24 +48,33 @@ describe('MaxConsumptionCard component', () => { </Provider> ) await waitFor(() => null, { container }) - const [prevButton, nextButton] = screen.getAllByRole('button') + const prevButton = screen.getByLabelText( + 'consumption.accessibility.button_previous_value' + ) + const nextButton = screen.getByLabelText( + 'consumption.accessibility.button_next_value' + ) // navigate next - await userEvent.click(nextButton) - await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(nextButton) + }) expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument() - await userEvent.click(nextButton) - await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(nextButton) + }) expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument() // navigate prev - await userEvent.click(prevButton) - await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(prevButton) + }) expect(screen.getByText('FLUID.GAS.LABEL')).toBeInTheDocument() - await userEvent.click(prevButton) - await waitFor(() => null, { container }) + await act(async () => { + await userEvent.click(prevButton) + }) expect(screen.getByText('FLUID.ELECTRICITY.LABEL')).toBeInTheDocument() }) }) diff --git a/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx b/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx index b18f888595a552c694c5afab6c02ad1a82919eea..7cb6a06109365de9896a3718bc9331d70b7a8684 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparator.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -97,7 +97,9 @@ describe('AnalysisConsumption component', () => { expect(rows.length).toBe(4) expect(screen.getByTestId('iconGoToProfile')).toBeInTheDocument() expect(screen.queryByTestId('goToProfile')).not.toBeInTheDocument() - await userEvent.click(screen.getByTestId('iconGoToProfile')) + await act(async () => { + await userEvent.click(screen.getByTestId('iconGoToProfile')) + }) expect(mockedNavigate).toHaveBeenCalledWith('/profileType') }) }) diff --git a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx index 56ef37bff49697a3fc05c852f9ef7586b8b3c7eb..1b2f9d2eae765da5f7caf69cd1ebcbc74b67efa3 100644 --- a/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx +++ b/src/components/Challenge/ChallengeCardDone/ChallengeCardDone.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import ChallengeCardDone from 'components/Challenge/ChallengeCardDone/ChallengeCardDone' import React from 'react' @@ -44,10 +44,10 @@ describe('ChallengeCardDone component', () => { <ChallengeCardDone userChallenge={userChallengeData[0]} /> </Provider> ) - const resetButton = screen.getByRole('button', { - name: 'challenge.card_done.reset_defi', + const resetButton = screen.getByText('challenge.card_done.reset_defi') + await act(async () => { + await userEvent.click(resetButton) }) - await userEvent.click(resetButton) expect(mockDispatch).toHaveBeenCalledWith({ type: 'challenge/updateUserChallengeList', }) diff --git a/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx b/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx index 17fb028e94d666557241b6bbe591b932a966472f..f4825300a48bdda50d2ff32104a254aaca806a28 100644 --- a/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx +++ b/src/components/Challenge/ChallengeCardLast/ChallengeCardLast.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import ChallengeCardLast from './ChallengeCardLast' @@ -16,7 +16,9 @@ describe('ChallengeCardLast component', () => { global.open = jest.fn() render(<ChallengeCardLast />) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByText('challenge.card_last.button')) + }) expect(window.open).toHaveBeenCalledTimes(1) expect(global.open).toHaveBeenCalledWith( `${__SAU_IDEA_DIRECT_LINK__}?version=0.0.0` diff --git a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx index c68290664e91dde33d8190813d44914eaa5f6485..9dae95a5e0d3387e6deb963948d6dadb053c08d6 100644 --- a/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx +++ b/src/components/Challenge/ChallengeCardUnlocked/ChallengeCardUnlocked.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { FluidState, FluidType } from 'enums' import React from 'react' @@ -27,7 +27,9 @@ describe('ChallengeCardUnlocked component', () => { </Provider> ) expect(screen.getByText('Simone VEILLE')).toBeInTheDocument() - expect(screen.getByRole('button')).toBeInTheDocument() + expect( + screen.getByText('challenge.card_unlocked.button_launch') + ).toBeInTheDocument() expect(screen.queryAllByRole('dialog').length).toBeFalsy() }) @@ -37,7 +39,11 @@ describe('ChallengeCardUnlocked component', () => { <ChallengeCardUnlocked userChallenge={userChallengeData[0]} /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click( + screen.getByText('challenge.card_unlocked.button_launch') + ) + }) expect(screen.queryAllByRole('dialog').length).toBeTruthy() }) @@ -56,7 +62,11 @@ describe('ChallengeCardUnlocked component', () => { <ChallengeCardUnlocked userChallenge={userChallengeData[0]} /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click( + screen.getByText('challenge.card_unlocked.button_launch') + ) + }) expect(screen.queryAllByRole('dialog').length).toBeFalsy() expect(mockStartUserChallenge).toHaveBeenCalledWith(userChallengeData[0]) }) diff --git a/src/components/Charts/Bar.spec.tsx b/src/components/Charts/Bar.spec.tsx index adb15d3502c845b9494097d54d3d5d16d6a5e585..73cf573db8ade5ee375ebe7be2e2fac8db7d7549 100644 --- a/src/components/Charts/Bar.spec.tsx +++ b/src/components/Charts/Bar.spec.tsx @@ -1,4 +1,4 @@ -import { render } from '@testing-library/react' +import { act, render } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { scaleLinear } from 'd3' import { FluidType, TimeStep } from 'enums' @@ -122,7 +122,9 @@ describe('Bar component test', () => { </svg> </Provider> ) - await userEvent.click(container.querySelector('rect') as Element) + await act(async () => { + await userEvent.click(container.querySelector('rect') as Element) + }) expect(setSelectedDateSpy).toHaveBeenCalledTimes(1) expect(setSelectedDateSpy).toHaveBeenCalledWith( graphData.actualData[0].date diff --git a/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx b/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx index b9be78286030fbeb9deedf9ac78ed3b28526f7e6..0584ba26ad02520ecf428b1d02aaa8fd35d0e689 100644 --- a/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx +++ b/src/components/CommonKit/FormNavigation/FormNavigation.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import FormNavigation from './FormNavigation' @@ -16,9 +16,13 @@ describe('FormNavigation component', () => { /> ) const [prevButton, nextButton] = screen.getAllByRole('button') - await userEvent.click(prevButton) + await act(async () => { + await userEvent.click(prevButton) + }) expect(mockHandlePrevious).toHaveBeenCalled() - await userEvent.click(nextButton) + await act(async () => { + await userEvent.click(nextButton) + }) expect(mockHandleNext).toHaveBeenCalled() }) }) diff --git a/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx b/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx index cf6cc00505123e43982dd9e58a8caae962f7ca0e..58c1ab6dc9a835d6d0aab431d46c9b9f0f439d49 100644 --- a/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx +++ b/src/components/Connection/ExpiredConsentModal/ExpiredConsentModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { FluidType } from 'enums' import React from 'react' @@ -45,9 +45,11 @@ describe('ExpiredConsentModal component', () => { /> </Provider> ) - await userEvent.click( - screen.getByRole('button', { name: 'consent_outdated.go' }) - ) + await act(async () => { + await userEvent.click( + screen.getByRole('button', { name: 'consent_outdated.go' }) + ) + }) expect(mockAppDispatch).toHaveBeenCalledTimes(1) expect(mockedNavigate).toHaveBeenCalledTimes(1) }) @@ -65,9 +67,11 @@ describe('ExpiredConsentModal component', () => { /> </Provider> ) - await userEvent.click( - screen.getByRole('button', { name: 'consent_outdated.go' }) - ) + await act(async () => { + await userEvent.click( + screen.getByRole('button', { name: 'consent_outdated.go' }) + ) + }) expect(mockAppDispatch).toHaveBeenCalledTimes(1) expect(mockedNavigate).toHaveBeenCalledTimes(1) }) @@ -82,9 +86,11 @@ describe('ExpiredConsentModal component', () => { /> </Provider> ) - await userEvent.click( - screen.getByRole('button', { name: 'consent_outdated.later' }) - ) + await act(async () => { + await userEvent.click( + screen.getByRole('button', { name: 'consent_outdated.later' }) + ) + }) expect(mockHandleCloseClick).toHaveBeenCalled() }) }) diff --git a/src/components/Connection/SGEConnect/SgeInit.spec.tsx b/src/components/Connection/SGEConnect/SgeInit.spec.tsx index 0346c88764ac82db46ad789a0f7c90a17d311a5d..ce86c8ed7187de1611899e17e18822ea377f9f84 100644 --- a/src/components/Connection/SGEConnect/SgeInit.spec.tsx +++ b/src/components/Connection/SGEConnect/SgeInit.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -27,7 +27,9 @@ describe('SgeInit component', () => { <SgeInit /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalled() }) }) diff --git a/src/components/Connection/SGEConnect/StepAddress.spec.tsx b/src/components/Connection/SGEConnect/StepAddress.spec.tsx index d5aae6a3af4b54692c0c3549c89de48388bd5bf2..e7e1326c249c7c046f6afce0d3856bfba13ee33a 100644 --- a/src/components/Connection/SGEConnect/StepAddress.spec.tsx +++ b/src/components/Connection/SGEConnect/StepAddress.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { mockGlobalState } from 'tests/__mocks__/store' @@ -30,14 +30,18 @@ describe('StepAddress component', () => { const input = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.address', }) - await userEvent.type(input, 't') + await act(async () => { + await userEvent.type(input, 't') + }) expect(mockHandleChange).toHaveBeenCalledWith('address', 't') }) it('should change zipCode value', async () => { const input = screen.getByRole('spinbutton', { name: 'auth.enedissgegrandlyon.zipCode', }) - await userEvent.type(input, '0') + await act(async () => { + await userEvent.type(input, '0') + }) expect(mockHandleChange).toHaveBeenCalledWith('zipCode', '0', 5) }) @@ -45,7 +49,9 @@ describe('StepAddress component', () => { const input = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.city', }) - await userEvent.type(input, 'c') + await act(async () => { + await userEvent.type(input, 'c') + }) expect(mockHandleChange).toHaveBeenCalledWith('city', 'c') }) }) diff --git a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx index afb9b5b3902c398071ee639f1c97dcd327935d1b..833facf6236beabdd56ce1519e39d1b42a748d74 100644 --- a/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx +++ b/src/components/Connection/SGEConnect/StepIdentityAndPdl.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { mockGlobalState } from 'tests/__mocks__/store' @@ -27,19 +27,25 @@ describe('StepIdentityAndPdl component', () => { const firstNameInput = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.firstName', }) - await userEvent.type(firstNameInput, 'n') + await act(async () => { + await userEvent.type(firstNameInput, 'n') + }) expect(mockHandleChange).toHaveBeenCalledWith('firstName', 'n') const lastNameInput = screen.getByRole('textbox', { name: 'auth.enedissgegrandlyon.lastName', }) - await userEvent.type(lastNameInput, 'n') + await act(async () => { + await userEvent.type(lastNameInput, 'n') + }) expect(mockHandleChange).toHaveBeenCalledWith('lastName', 'n') const pdlInput = screen.getByRole('spinbutton', { name: 'auth.enedissgegrandlyon.pdlLabel', }) - await userEvent.type(pdlInput, '0') + await act(async () => { + await userEvent.type(pdlInput, '0') + }) expect(mockHandleChange).toHaveBeenCalledWith('pdl', '0', 14) }) @@ -53,7 +59,9 @@ describe('StepIdentityAndPdl component', () => { const pdlModalButton = screen.getByRole('button', { name: 'auth.enedissgegrandlyon.pdlModal.title', }) - await userEvent.click(pdlModalButton) + await act(async () => { + await userEvent.click(pdlModalButton) + }) expect(screen.getByRole('dialog')).toBeInTheDocument() }) diff --git a/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx b/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx index 4545f197f9362f8244edeadfec59a4beb8ad823a..6994c6de28036a47ae215b162bece51aedba4ae7 100644 --- a/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadNoValue.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { DataloadState, FluidType } from 'enums' import React from 'react' @@ -121,7 +121,9 @@ describe('DataloadNoValue component', () => { /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockDispatch).toHaveBeenCalledWith({ type: 'chart/setShowConnectionDetails', payload: true, diff --git a/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx b/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx index 4b9d037bbc525929eaa3ba0fa2b1cf77b3d9cdb0..d86e8db5d2c95ba24408df2ff5950d04f2cac1c8 100644 --- a/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSectionValue.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { DataloadSectionType, FluidType } from 'enums' import { Dataload } from 'models' @@ -88,7 +88,9 @@ describe('DataloadSectionValue component', () => { toggleEstimationModal={mockToggleEstimationModal} /> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockToggleEstimationModal).toHaveBeenCalled() }) }) diff --git a/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx b/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx index 5c2018b0bdf54affb32cc73edda5c72f6954ecb3..d4aa9992cfdf208adfe638cac8ac532142b25222 100644 --- a/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx +++ b/src/components/ConsumptionVisualizer/InfoDataConsumptionVisualizer.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { DataloadState, FluidType } from 'enums' import { DateTime } from 'luxon' @@ -199,7 +199,9 @@ describe('InfoDataConsumptionVisualizer component', () => { /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(screen.getByRole('dialog')).toBeInTheDocument() }) @@ -214,7 +216,9 @@ describe('InfoDataConsumptionVisualizer component', () => { /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockAppDispatch).toHaveBeenCalled() }) }) diff --git a/src/components/CustomPopup/CustomPopupModal.spec.tsx b/src/components/CustomPopup/CustomPopupModal.spec.tsx index 357565d456e0d360ec9ad0730cafe63ed2b17ed4..5f3786a07ae9a3ee5fa7a06262232da12879cc40 100644 --- a/src/components/CustomPopup/CustomPopupModal.spec.tsx +++ b/src/components/CustomPopup/CustomPopupModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { @@ -11,13 +11,14 @@ import CustomPopupModal from './CustomPopupModal' const mockHandleClose = jest.fn() describe('CustomPopupModal component', () => { - it('should render correctly', () => { - const { baseElement } = render( + it('should render correctly', async () => { + const { baseElement, container } = render( <CustomPopupModal customPopup={mockCustomPopup} handleCloseClick={mockHandleClose} /> ) + await waitFor(() => null, { container }) expect(baseElement).toMatchSnapshot() }) @@ -36,24 +37,26 @@ describe('CustomPopupModal component', () => { expect(screen.getByRole('img')).toBeInTheDocument() }) - it('should not be rendered, popup not enabled', () => { - render( + it('should not be rendered, popup not enabled', async () => { + const { container } = render( <CustomPopupModal customPopup={mockCustomPopupOff} handleCloseClick={mockHandleClose} /> ) + await waitFor(() => null, { container }) const modal = screen.queryByTestId('title') expect(modal).not.toBeInTheDocument() }) - it('should not be rendered, popup outdated', () => { - render( + it('should not be rendered, popup outdated', async () => { + const { container } = render( <CustomPopupModal customPopup={mockCustomPopupOutdated} handleCloseClick={mockHandleClose} /> ) + await waitFor(() => null, { container }) const modal = screen.queryByTestId('title') expect(modal).not.toBeInTheDocument() }) @@ -65,9 +68,11 @@ describe('CustomPopupModal component', () => { handleCloseClick={mockHandleClose} /> ) - await userEvent.click( - screen.getByText('consumption.partner_issue_modal.ok') - ) + await act(async () => { + await userEvent.click( + screen.getByText('consumption.partner_issue_modal.ok') + ) + }) expect(mockHandleClose).toHaveBeenCalled() }) }) diff --git a/src/components/CustomPopup/__snapshots__/CustomPopupModal.spec.tsx.snap b/src/components/CustomPopup/__snapshots__/CustomPopupModal.spec.tsx.snap index e145623144afc9a9613a33fdbb3d64e1874246a6..eaf9112489058b5343173335bd0e8254e9578380 100644 --- a/src/components/CustomPopup/__snapshots__/CustomPopupModal.spec.tsx.snap +++ b/src/components/CustomPopup/__snapshots__/CustomPopupModal.spec.tsx.snap @@ -71,7 +71,7 @@ exports[`CustomPopupModal component should render correctly 1`] = ` width="100" > <use - xlink:href="#" + xlink:href="#test-file-stub" /> </svg> <div diff --git a/src/components/DateNavigator/DateNavigator.spec.tsx b/src/components/DateNavigator/DateNavigator.spec.tsx index 1708d74e8b7efe019174f6b90eddb8126c5acab5..2ad781149818e2afb06e6a05a387736069f90143 100644 --- a/src/components/DateNavigator/DateNavigator.spec.tsx +++ b/src/components/DateNavigator/DateNavigator.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { TimeStep } from 'enums' import { DateTime } from 'luxon' @@ -45,10 +45,13 @@ describe('DateNavigator component', () => { /> ) const [prevIcon, nextIcon] = screen.getAllByRole('button') - await userEvent.click(prevIcon) + await act(async () => { + await userEvent.click(prevIcon) + }) expect(mockHandlePrevDate).toHaveBeenCalledTimes(1) - - await userEvent.click(nextIcon) + await act(async () => { + await userEvent.click(nextIcon) + }) expect(mockHandleNextDate).toHaveBeenCalledTimes(1) }) diff --git a/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx b/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx index 2020acbf2463e81a138d16451c5542e727c618d3..60e1521ee5c96dc6b2864c1579b9e3d74da7aa67 100644 --- a/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx +++ b/src/components/Duel/DuelUnlocked/DuelUnlocked.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { FluidType, UserChallengeUpdateFlag } from 'enums' import React from 'react' @@ -38,7 +38,7 @@ describe('DuelUnlocked component', () => { screen.getByText(userChallengeData[1].duel.title) ).toBeInTheDocument() expect(screen.getByText(description)).toBeInTheDocument() - expect(screen.getByRole('button')).toBeInTheDocument() + expect(screen.getByText('duel.button_start')).toBeInTheDocument() }) it('should update userChallenge when launching duel with configured fluid', async () => { @@ -53,7 +53,9 @@ describe('DuelUnlocked component', () => { <DuelUnlocked userChallenge={userChallengeData[0]} /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByText('duel.button_start')) + }) expect(mockUserChallengeUpdateFlag).toHaveBeenCalledWith( userChallengeData[0], UserChallengeUpdateFlag.DUEL_START diff --git a/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx b/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx index 700c11a8efa8c5877468079223efc666210373b4..1c4a13ebee50d6e91291503b856d451e4fe83912 100644 --- a/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx +++ b/src/components/Ecogesture/EcogestureEmptyList/EcogestureEmptyList.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureEmptyList from './EcogestureEmptyList' @@ -9,7 +9,6 @@ jest.mock('react-router-dom', () => ({ useNavigate: () => mockedNavigate, })) const mockChangeTab = jest.fn() -const mockHandleClick = jest.fn() describe('EcogestureEmptyList component', () => { it('should be rendered correctly', () => { @@ -18,7 +17,7 @@ describe('EcogestureEmptyList component', () => { setTab={mockChangeTab} isObjective={true} isSelectionDone={false} - handleReinitClick={mockHandleClick} + handleReinitClick={jest.fn()} /> ) expect(container).toMatchSnapshot() @@ -29,10 +28,12 @@ describe('EcogestureEmptyList component', () => { setTab={mockChangeTab} isObjective={false} isSelectionDone={true} - handleReinitClick={mockHandleClick} + handleReinitClick={jest.fn()} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockChangeTab).toHaveBeenCalledTimes(1) }) it('should launch ecogesture form', async () => { @@ -41,10 +42,12 @@ describe('EcogestureEmptyList component', () => { setTab={mockChangeTab} isObjective={false} isSelectionDone={false} - handleReinitClick={mockHandleClick} + handleReinitClick={jest.fn()} /> ) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-form') }) it('should render doing text with empty list on completed selection', () => { @@ -53,7 +56,7 @@ describe('EcogestureEmptyList component', () => { setTab={mockChangeTab} isObjective={false} isSelectionDone={true} - handleReinitClick={mockHandleClick} + handleReinitClick={jest.fn()} /> ) expect( @@ -66,7 +69,7 @@ describe('EcogestureEmptyList component', () => { setTab={mockChangeTab} isObjective={true} isSelectionDone={true} - handleReinitClick={mockHandleClick} + handleReinitClick={jest.fn()} /> ) expect( diff --git a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx index 6ff90feae74098a6d7384f0306bebab7d0baa4ae..a2abc6d04310407832ce386f17237b90c7169bcd 100644 --- a/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx +++ b/src/components/Ecogesture/EcogestureInitModal/EcogestureInitModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureInitModal from './EcogestureInitModal' @@ -24,7 +24,9 @@ describe('EcogestureInitModal component', () => { handleLaunchForm={mockHandleLaunchForm} /> ) - await userEvent.click(screen.getAllByRole('button')[2]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[2]) + }) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) it('should close modal and launch form', async () => { @@ -35,7 +37,9 @@ describe('EcogestureInitModal component', () => { handleLaunchForm={mockHandleLaunchForm} /> ) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockHandleLaunchForm).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx b/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx index b230d0fd10a2a02fddb498042d9b629af2034c81..6ffa5471989aed0d41a2a142cd0bb893aae0cff6 100644 --- a/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx +++ b/src/components/Ecogesture/EcogestureList/EcogestureList.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -48,7 +48,7 @@ describe('EcogesturesList component', () => { }) it('should open the filter menu and select all ecogesture', async () => { - const { container } = render( + render( <Provider store={store}> <BrowserRouter> <EcogestureList @@ -60,14 +60,17 @@ describe('EcogesturesList component', () => { </BrowserRouter> </Provider> ) - await waitFor(() => null, { container }) - await userEvent.click(screen.getAllByRole('button')[0]) - await userEvent.click(screen.getAllByRole('menuitem')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) + await act(async () => { + await userEvent.click(screen.getAllByRole('menuitem')[1]) + }) expect(updateEcogestureFilter).toHaveBeenCalledTimes(1) }) it('should go to "/ecogesture-selection"', async () => { - const { container } = render( + render( <Provider store={store}> <BrowserRouter> <EcogestureList @@ -79,8 +82,9 @@ describe('EcogesturesList component', () => { </BrowserRouter> </Provider> ) - await waitFor(() => null, { container }) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-selection') }) }) diff --git a/src/components/Ecogesture/EcogestureNotFound/EcogestureNotFound.spec.tsx b/src/components/Ecogesture/EcogestureNotFound/EcogestureNotFound.spec.tsx index 28d77f7ca042e4cd09c9c22769d48655913f13cc..8edf29c77b74d32afaa735c7c804b78b166ba00e 100644 --- a/src/components/Ecogesture/EcogestureNotFound/EcogestureNotFound.spec.tsx +++ b/src/components/Ecogesture/EcogestureNotFound/EcogestureNotFound.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureNotFound from './EcogestureNotFound' @@ -22,7 +22,9 @@ describe('EcogestureNotFound component', () => { }) it('should click on button and be redirected', async () => { render(<EcogestureNotFound text="test" returnPage="ecogestures" />) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures') }) }) diff --git a/src/components/Ecogesture/EcogestureTabsView.spec.tsx b/src/components/Ecogesture/EcogestureTabsView.spec.tsx index e5dcabc9b1dbb9243163d9c7226f46dc4cf34918..4dceb4a19d0335aa6281f0c100fbc673b2c847d5 100644 --- a/src/components/Ecogesture/EcogestureTabsView.spec.tsx +++ b/src/components/Ecogesture/EcogestureTabsView.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import EcogestureTabsView from 'components/Ecogesture/EcogestureTabsView' import { Ecogesture } from 'models' @@ -70,27 +70,18 @@ describe('EcogestureView component', () => { it('should render ecogesture init modal', async () => { const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') - - const { container } = render( + render( <Provider store={store}> <EcogestureTabsView /> </Provider> ) - await waitFor(() => null, { container }) expect(screen.getByRole('dialog')).toBeInTheDocument() - await userEvent.click(screen.getAllByRole('button')[0]) + + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(updateProfileSpy).toHaveBeenCalledWith({ haveSeenEcogestureModal: true, }) }) - - it('should render empty list', async () => { - const { container } = render( - <Provider store={store}> - <EcogestureTabsView /> - </Provider> - ) - await waitFor(() => null, { container }) - expect(container).toMatchSnapshot() - }) }) diff --git a/src/components/Ecogesture/SingleEcogestureView.spec.tsx b/src/components/Ecogesture/SingleEcogestureView.spec.tsx index 5f89c46a40f1459f52cfd96a25921a9cfa704b22..2d42b995b77be45ca1d7fccafc9cb8f099876ed9 100644 --- a/src/components/Ecogesture/SingleEcogestureView.spec.tsx +++ b/src/components/Ecogesture/SingleEcogestureView.spec.tsx @@ -24,6 +24,9 @@ jest.mock('services/ecogesture.service', () => { }) describe('SingleEcogesture component', () => { + beforeEach(() => { + jest.clearAllMocks() + }) const store = createMockEcolyoStore() it('should be rendered correctly', async () => { mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]]) @@ -41,14 +44,14 @@ describe('SingleEcogesture component', () => { const updatedEcogesture = { ...mockedEcogesturesData[0], objective: true } mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture) - const { container } = render( + render( <Provider store={store}> <SingleEcogestureView /> </Provider> ) - await waitFor(() => null, { container }) - const [, objective] = screen.getAllByRole('button') - await userEvent.click(objective) + await waitFor(async () => { + await userEvent.click(screen.getByText('ecogesture.objective')) + }) expect(mockUpdateEcogesture).toHaveBeenCalledWith(updatedEcogesture) }) @@ -57,28 +60,27 @@ describe('SingleEcogesture component', () => { const updatedEcogesture = { ...mockedEcogesturesData[0], doing: true } mockUpdateEcogesture.mockResolvedValueOnce(updatedEcogesture) - const { container } = render( + render( <Provider store={store}> <SingleEcogestureView /> </Provider> ) - await waitFor(() => null, { container }) - const [, , doing] = screen.getAllByRole('button') - await userEvent.click(doing) + await waitFor(async () => { + await userEvent.click(screen.getByText('ecogesture.doing')) + }) expect(mockUpdateEcogesture).toHaveBeenCalledWith(updatedEcogesture) }) it('should toggle more details', async () => { mockGetEcogesturesByIds.mockResolvedValue([mockedEcogesturesData[0]]) - - const { container } = render( + render( <Provider store={store}> <SingleEcogestureView /> </Provider> ) - await waitFor(() => null, { container }) - const [showMore] = screen.getAllByRole('button') - await userEvent.click(showMore) + await waitFor(async () => { + await userEvent.click(screen.getByText('ecogesture_modal.show_more')) + }) expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument() }) }) diff --git a/src/components/Ecogesture/__snapshots__/EcogestureTabsView.spec.tsx.snap b/src/components/Ecogesture/__snapshots__/EcogestureTabsView.spec.tsx.snap index e3dd070242df6df5363f2accb2d8049b3b2a91f5..7ccd151382e3967c0377207e3fe1b6bf5c066cc7 100644 --- a/src/components/Ecogesture/__snapshots__/EcogestureTabsView.spec.tsx.snap +++ b/src/components/Ecogesture/__snapshots__/EcogestureTabsView.spec.tsx.snap @@ -232,236 +232,3 @@ exports[`EcogestureView component should be rendered correctly with 3 clickable </mock-content> </div> `; - -exports[`EcogestureView component should render empty list 1`] = ` -<div - aria-hidden="true" -> - <mock-cozybar - titlekey="common.title_ecogestures" - /> - <mock-header - desktoptitlekey="common.title_ecogestures" - > - <div - class="MuiTabs-root ecogestures-tabs" - > - <div - class="MuiTabs-scroller MuiTabs-fixed" - style="overflow: hidden;" - > - <div - aria-label="ecogestures-tabs" - class="MuiTabs-flexContainer MuiTabs-centered" - role="tablist" - > - <button - aria-controls="simple-tabpanel-0" - aria-selected="true" - class="MuiButtonBase-root MuiTab-root MuiTab-textColorInherit single-tab active Mui-selected" - id="simple-tab-0" - role="tab" - tabindex="0" - type="button" - > - <span - class="MuiTab-wrapper" - > - ecogesture.title_tab_0 - <br /> - (0) - </span> - <span - class="MuiTouchRipple-root" - /> - </button> - <button - aria-controls="simple-tabpanel-1" - aria-selected="false" - class="MuiButtonBase-root MuiTab-root MuiTab-textColorInherit single-tab" - id="simple-tab-1" - role="tab" - tabindex="0" - type="button" - > - <span - class="MuiTab-wrapper" - > - ecogesture.title_tab_1 - <br /> - (2) - </span> - <span - class="MuiTouchRipple-root" - /> - </button> - <button - aria-controls="simple-tabpanel-2" - aria-selected="false" - class="MuiButtonBase-root MuiTab-root MuiTab-textColorInherit single-tab" - id="simple-tab-2" - role="tab" - tabindex="0" - type="button" - > - <span - class="MuiTab-wrapper" - > - ecogesture.title_tab_2 - <br /> - (3) - </span> - <span - class="MuiTouchRipple-root" - /> - </button> - </div> - <span - class="PrivateTabIndicator-root-9 PrivateTabIndicator-colorSecondary-11 indicator-tab" - style="left: 0px; width: 0px;" - /> - </div> - </div> - </mock-header> - <mock-content> - <div - aria-labelledby="simple-tab-0" - id="simple-tabpanel-0" - role="tabpanel" - > - <div - class="ec-empty-container" - > - <div - class="ec-empty-content" - > - <svg - aria-hidden="true" - class="icon-big styles__icon___23x3R" - height="150" - width="150" - > - <use - xlink:href="#test-file-stub" - /> - </svg> - <div - class="text-16-normal" - > - ecogesture.emptyList.obj1 - </div> - <div - class="text-16-normal" - > - ecogesture.emptyList.obj2 - </div> - <div - class="buttons" - > - <button - aria-label="ecogesture.emptyList.btn1" - class="MuiButtonBase-root MuiButton-root MuiButton-text btnSecondary" - tabindex="0" - type="button" - > - <span - class="MuiButton-label" - > - ecogesture.emptyList.btn1 - </span> - </button> - <button - aria-label="ecogesture.emptyList.btn2" - class="MuiButtonBase-root MuiButton-root MuiButton-text btnPrimary" - tabindex="0" - type="button" - > - <span - class="MuiButton-label" - > - ecogesture.emptyList.btn2 - </span> - </button> - </div> - </div> - </div> - </div> - <div - aria-labelledby="simple-tab-1" - hidden="" - id="simple-tabpanel-1" - role="tabpanel" - > - <div - class="ec-empty-container" - > - <div - class="ec-empty-content" - > - <svg - aria-hidden="true" - class="icon-big styles__icon___23x3R" - height="150" - width="150" - > - <use - xlink:href="#test-file-stub" - /> - </svg> - <div - class="text-16-normal" - > - ecogesture.emptyList.doing1 - </div> - <div - class="text-16-normal" - > - ecogesture.emptyList.doing2 - </div> - <div - class="buttons" - > - <button - aria-label="ecogesture.emptyList.btn1" - class="MuiButtonBase-root MuiButton-root MuiButton-text btnSecondary" - tabindex="0" - type="button" - > - <span - class="MuiButton-label" - > - ecogesture.emptyList.btn1 - </span> - </button> - <button - aria-label="ecogesture.emptyList.btn2" - class="MuiButtonBase-root MuiButton-root MuiButton-text btnPrimary" - tabindex="0" - type="button" - > - <span - class="MuiButton-label" - > - ecogesture.emptyList.btn2 - </span> - </button> - </div> - </div> - </div> - </div> - <div - aria-labelledby="simple-tab-2" - hidden="" - id="simple-tabpanel-2" - role="tabpanel" - > - <mock-ecogesturelist - displayselection="false" - list="[object Object],[object Object],[object Object]" - selectiontotal="0" - selectionviewed="0" - /> - </div> - </mock-content> -</div> -`; diff --git a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx index 59dfa2b6d36071b61298edabf1f48741dec0b365..2ad4b9d739e95b24815f3f3201351459419d3683 100644 --- a/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormEquipment/EcogestureFormEquipment.spec.tsx @@ -56,9 +56,7 @@ describe('EcogestureFormEquipment component', () => { container.getElementsByClassName('icons-container').length ).toBeTruthy() expect( - screen.getByRole('button', { - name: 'profile_type.accessibility.button_end', - }) + screen.getByLabelText('profile_type.accessibility.button_end') ).toBeDisabled() }) }) diff --git a/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx b/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx index b7e89d07dbfa9cbc95c18262d2831f73c54d511e..23585af984f327d0f5992dd5f05312c9337adb95 100644 --- a/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormSingleChoice/EcogestureFormSingleChoice.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -50,7 +50,9 @@ describe('EcogestureFormSingleChoice component', () => { ) await userEvent.click(screen.getAllByRole('radio')[0]) const [, next] = screen.getAllByRole('button') - await userEvent.click(next) + await act(async () => { + await userEvent.click(next) + }) expect(mockHandleNextStep).toHaveBeenCalledTimes(1) }) it('should go back', async () => { @@ -67,7 +69,9 @@ describe('EcogestureFormSingleChoice component', () => { </Provider> ) const [prev] = screen.getAllByRole('button') - await userEvent.click(prev) + await act(async () => { + await userEvent.click(prev) + }) expect(mockHandlePreviousStep).toHaveBeenCalledTimes(1) }) it('should keep previous answer', async () => { diff --git a/src/components/EcogestureForm/EcogestureFormView.spec.tsx b/src/components/EcogestureForm/EcogestureFormView.spec.tsx index 501a60176665575e4f897dc6c382aaefa39b5f99..32c980399a654fbc21f0f43c2c3940fe01219cdc 100644 --- a/src/components/EcogestureForm/EcogestureFormView.spec.tsx +++ b/src/components/EcogestureForm/EcogestureFormView.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -69,9 +69,10 @@ describe('EcogestureFormView component', () => { <EcogestureFormView /> </Provider> ) - // await waitFor(() => null, { container }) - await userEvent.click(screen.getAllByRole('radio')[0]) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('radio')[0]) + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect( container.getElementsByClassName('ecogesture-form-single').length ).toBeTruthy() @@ -84,8 +85,10 @@ describe('EcogestureFormView component', () => { ) const [, next] = screen.getAllByRole('button') - await userEvent.click(screen.getAllByRole('radio')[0]) - await userEvent.click(next) + await act(async () => { + await userEvent.click(screen.getAllByRole('radio')[0]) + await userEvent.click(next) + }) expect( container.getElementsByClassName('ecogesture-form-single').length diff --git a/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx b/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx index be8c6d25ed9da77a23d42ded998b09c51d0d2d03..91b74191f49685b5e60965438098ba52b86214b2 100644 --- a/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx +++ b/src/components/EcogestureForm/EcogestureLaunchFormModal/EcogestureLaunchFormModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureLaunchFormModal from './EcogestureLaunchFormModal' @@ -21,7 +21,9 @@ describe('EcogestureLaunchFormModal component', () => { handleCloseClick={mockHandleClose} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx index 4f5261c876fa60a9f14195280c7176826b2c7e7d..b46581bdbc35cd960868c03ae0d093f57e620480 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, 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' @@ -34,24 +34,32 @@ describe('EcogestureSelectionDetail component', () => { it('should toggle more details', async () => { const [showMore] = screen.getAllByRole('button') - await userEvent.click(showMore) + await act(async () => { + 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) + await act(async () => { + await userEvent.click(objective) + }) expect(mockValidate).toHaveBeenCalledWith(true, false) }) it('should call validate with doing to true', async () => { const [, , doing] = screen.getAllByRole('button') - await userEvent.click(doing) + await act(async () => { + await userEvent.click(doing) + }) expect(mockValidate).toHaveBeenCalledWith(false, true) }) it('should call validate with objective and doing to false', async () => { const [, , , skip] = screen.getAllByRole('button') - await userEvent.click(skip) + await act(async () => { + await userEvent.click(skip) + }) expect(mockValidate).toHaveBeenCalledWith(false, false) }) }) diff --git a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx index bcf32fb5e275cd73f0aa02e926b606770626728b..fa12c6b0fc983509acaee214ad3da7a4daf390bf 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionEnd/EcogestureSelectionEnd.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import EcogestureSelectionEnd from './EcogestureSelectionEnd' @@ -21,7 +21,9 @@ describe('EcogestureSelectionEnd component', () => { it('should close modal and update profile', async () => { render(<EcogestureSelectionEnd />) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + 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 11801f5c9df1a75ea26f7c6354b5bf5a05e43c49..816790dae934dbf4730e98dcd6ac8288937f7831 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionModal/EcogestureSelectionModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import EcogestureSelectionModal from './EcogestureSelectionModal' @@ -22,7 +22,9 @@ describe('EcogestureInitModal component', () => { handleCloseClick={mockHandleClose} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + 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 0a5e78b1680da49a01b246af2f290c60ba4c1fb1..6512e87b69ca56cb4bd2766dc4734ccc9f813eec 100644 --- a/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx +++ b/src/components/EcogestureSelection/EcogestureSelectionRestart/EcogestureSelectionRestart.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import EcogestureSelectionRestart from './EcogestureSelectionRestart' @@ -20,13 +20,17 @@ describe('EcogestureSelectionRestart component', () => { 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]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures?tab=0') }) 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]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockRestart).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Exploration/ExplorationFinished.spec.tsx b/src/components/Exploration/ExplorationFinished.spec.tsx index 132eae2437c7893488c4f6a1b81d4c0edda1322a..903d268524541f31782be197158de9410f6745f8 100644 --- a/src/components/Exploration/ExplorationFinished.spec.tsx +++ b/src/components/Exploration/ExplorationFinished.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -26,7 +26,9 @@ describe('ExplorationFinished', () => { expect( screen.getByText(userChallengeData[0].exploration.message_success) ).toBeInTheDocument() - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockNavigate).toHaveBeenCalledWith(-1) }) }) diff --git a/src/components/Feedback/FeedbackModal.spec.tsx b/src/components/Feedback/FeedbackModal.spec.tsx index 192d36b49f6062bfa32d028fd6c2424acb9cc998..d1ab681bc0c716709e79d611af1e92478585ebaf 100644 --- a/src/components/Feedback/FeedbackModal.spec.tsx +++ b/src/components/Feedback/FeedbackModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import FeedbackModal from 'components/Feedback/FeedbackModal' import React from 'react' @@ -38,7 +38,9 @@ describe('FeedbackModal component', () => { <FeedbackModal /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[2]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[2]) + }) expect(window.open).toHaveBeenCalledTimes(1) expect(global.open).toHaveBeenCalledWith(`${__SAU_LINK__}?version=0.0.0`) }) diff --git a/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx b/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx index 60ddf0fedc7ea42905fcea16dbdd6798484559ad..1492e2a2cc24a3d5b45611d598ab8e3ebf2997b5 100644 --- a/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx +++ b/src/components/FluidChart/TimeStepSelector/TimeStepSelector.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import TimeStepSelector from 'components/FluidChart/TimeStepSelector/TimeStepSelector' import { FluidType, TimeStep } from 'enums' @@ -66,7 +66,9 @@ describe('TimeStepSelector component', () => { <TimeStepSelector fluidType={FluidType.WATER} /> </Provider> ) - await userEvent.click(screen.getAllByRole('listitem')[2]) + await act(async () => { + await userEvent.click(screen.getAllByRole('listitem')[2]) + }) expect(setCurrentTimeStepSpy).toHaveBeenCalledTimes(1) expect(setCurrentTimeStepSpy).toHaveBeenCalledWith(TimeStep.DAY) expect(setCurrentIndexSpy).toHaveBeenCalledTimes(1) @@ -85,7 +87,9 @@ describe('TimeStepSelector component', () => { <TimeStepSelector fluidType={FluidType.WATER} /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(setCurrentTimeStepSpy).toHaveBeenCalledTimes(1) expect(setCurrentTimeStepSpy).toHaveBeenCalledWith(TimeStep.WEEK) expect(setCurrentIndexSpy).toHaveBeenCalledTimes(1) diff --git a/src/components/Header/CozyBar.spec.tsx b/src/components/Header/CozyBar.spec.tsx index 3f747796d146ce793df13cf8de468e548830188a..4686fce253c292042027cf974c975d192817acb4 100644 --- a/src/components/Header/CozyBar.spec.tsx +++ b/src/components/Header/CozyBar.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import CozyBar from 'components/Header/CozyBar' import { ScreenType } from 'enums' @@ -44,7 +44,9 @@ describe('CozyBar component', () => { </Provider> ) expect(container).toMatchSnapshot() - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalled() }) @@ -56,7 +58,9 @@ describe('CozyBar component', () => { </Provider> ) expect(container).toMatchSnapshot() - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockBackFunction).toHaveBeenCalled() }) }) @@ -68,7 +72,9 @@ describe('CozyBar component', () => { </Provider> ) const updateModalSpy = jest.spyOn(ModalAction, 'openFeedbackModal') - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(updateModalSpy).toHaveBeenCalledWith(true) }) diff --git a/src/components/Header/Header.spec.tsx b/src/components/Header/Header.spec.tsx index 89b692b1ecb1ad9c3d31fa3b99514bbabb4c0b4d..60d6586be036eaa60c1824483de524ffb4568083 100644 --- a/src/components/Header/Header.spec.tsx +++ b/src/components/Header/Header.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import Header from 'components/Header/Header' import React from 'react' @@ -56,7 +56,9 @@ describe('Header component', () => { <Header desktopTitleKey="KEY" displayBackArrow={true} /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalled() }) it('should call custom back fn when back button is clicked', async () => { @@ -70,7 +72,9 @@ describe('Header component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockBack).toHaveBeenCalled() }) }) @@ -82,7 +86,9 @@ describe('Header component', () => { </Provider> ) const updateModalSpy = jest.spyOn(ModalAction, 'openFeedbackModal') - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(updateModalSpy).toHaveBeenCalledWith(true) }) }) diff --git a/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx b/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx index 1d4cf06cba60acf8e3a9e649986e10dd30811097..14ae6c3e8857d1357ba005074ac29d7632f5a8f6 100644 --- a/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx +++ b/src/components/Konnector/ConnectionNotFound/ConnectionNotFound.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import ConnectionNotFound from './ConnectionNotFound' @@ -16,8 +16,9 @@ describe('ConnectionNotFound component test', () => { it('should open konnector url when button is clicked', async () => { global.open = jest.fn() render(<ConnectionNotFound konnectorSlug={konnectorSlug} />) - await userEvent.click(screen.getByRole('button')) - + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(global.open).toHaveBeenCalledWith( 'http://localhost/#/discover/enedissgegrandlyon', '_blank' diff --git a/src/components/Konnector/KonnectorModal.spec.tsx b/src/components/Konnector/KonnectorModal.spec.tsx index 306d498d7b7904584e763e75b54e40c7ae307205..f453c7ea54190d40e4f90e0aa72d9a856256baa4 100644 --- a/src/components/Konnector/KonnectorModal.spec.tsx +++ b/src/components/Konnector/KonnectorModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { FluidType, KonnectorError } from 'enums' import React from 'react' @@ -67,7 +67,9 @@ describe('KonnectorModal component', () => { /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockHandleCloseClick).toHaveBeenCalled() }) it('should render login error', async () => { diff --git a/src/components/Konnector/KonnectorModalFooter.spec.tsx b/src/components/Konnector/KonnectorModalFooter.spec.tsx index 60d45605aa18477f48d48b7f5171550cfcb8ea8d..4b926d09676c019e16631adfbbb2e8c531a7f2b0 100644 --- a/src/components/Konnector/KonnectorModalFooter.spec.tsx +++ b/src/components/Konnector/KonnectorModalFooter.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { ERROR_EVENT } from 'cozy-harvest-lib/dist/models/flowEvents' import { KonnectorError } from 'enums' @@ -105,7 +105,9 @@ describe('KonnectorModalFooter component', () => { /> </Provider> ) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockClose).toHaveBeenCalled() }) it('should go back to login', async () => { @@ -121,7 +123,9 @@ describe('KonnectorModalFooter component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockDelete).toHaveBeenCalled() expect(mockedNavigate).toHaveBeenCalledTimes(1) }) @@ -138,7 +142,9 @@ describe('KonnectorModalFooter component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockDelete).toHaveBeenCalled() expect(mockedNavigate).toHaveBeenCalledTimes(1) }) @@ -155,7 +161,9 @@ describe('KonnectorModalFooter component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockedNavigate).toHaveBeenCalledTimes(1) expect(mockDelete).toHaveBeenCalledTimes(0) }) diff --git a/src/components/Konnector/KonnectorViewerList.spec.tsx b/src/components/Konnector/KonnectorViewerList.spec.tsx index 810bd21bbc68243dd8c51fc1405db101f94b022b..19b4ed1c4f1a44560dd9f3d7721cba0af944f963 100644 --- a/src/components/Konnector/KonnectorViewerList.spec.tsx +++ b/src/components/Konnector/KonnectorViewerList.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -28,7 +28,9 @@ describe('KonnectorViewerList component', () => { <KonnectorViewerList /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalled() }) }) diff --git a/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx b/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx index dc0bd5588f24e50858bd0f75a19d400d8ba6a26d..c1641e0cff8e7b7257607c0bf28d426172defc21 100644 --- a/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportDoneModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import ExportDoneModal from './exportDoneModal' @@ -27,7 +27,9 @@ describe('exportDoneModal component', () => { handleCloseClick={mockHandleClose} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx b/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx index 06371f31aa2e375692f2e16e1b1e418b7116d42a..3adc903b9f6b676ace0e2abb5588592cd5080bdb 100644 --- a/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportLoadingModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { allFluids } from 'utils/utils' @@ -27,7 +27,9 @@ describe('ExportLoadingModal component', () => { selectedFluids={allFluids} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx b/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx index 36a16b1b1727c67cf391de45df4aeb0698dc74f1..05e7e8aa883f9561b098f9010d0aa960f3862bb1 100644 --- a/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx +++ b/src/components/Options/ExportData/Modals/exportStartModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import ExportStartModal from './exportStartModal' @@ -24,7 +24,9 @@ describe('exportStartModal component', () => { handleDownloadClick={jest.fn()} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHandleClose).toHaveBeenCalledTimes(1) }) }) diff --git a/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx b/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx index e5c67e980ecfea5869f0448492ae90c398bdb5f1..a7b953d8941ae0ea616893516c5b44aa7135bc89 100644 --- a/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx +++ b/src/components/Options/ProfileTypeOptions/ProfileTypeOptions.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import ProfileTypeOptions from 'components/Options/ProfileTypeOptions/ProfileTypeOptions' import { @@ -31,7 +31,9 @@ describe('ProfileTypeOptions component', () => { </Provider> ) expect(container.getElementsByClassName('profile-icon').length).toBeTruthy() - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockedNavigate).toHaveBeenCalled() }) it('should be rendered when user complete profile type form', () => { diff --git a/src/components/Options/ReportOptions/ReportOptions.spec.tsx b/src/components/Options/ReportOptions/ReportOptions.spec.tsx index 008e755404fc612cda3a1c5c722377e7d0185da5..14752d0b242c4ba2333d151dca4fb41c539eaeac 100644 --- a/src/components/Options/ReportOptions/ReportOptions.spec.tsx +++ b/src/components/Options/ReportOptions/ReportOptions.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import ReportOptions from 'components/Options/ReportOptions/ReportOptions' import React from 'react' @@ -41,7 +41,9 @@ describe('ReportOptions component', () => { <ReportOptions /> </Provider> ) - await userEvent.click(screen.getAllByRole('checkbox')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('checkbox')[0]) + }) expect(updateProfileSpy).toHaveBeenCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledWith({ sendAnalysisNotification: false, @@ -57,7 +59,9 @@ describe('ReportOptions component', () => { <ReportOptions /> </Provider> ) - await userEvent.click(screen.getAllByRole('checkbox')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('checkbox')[0]) + }) expect(updateProfileSpy).toHaveBeenCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledWith({ sendAnalysisNotification: true, @@ -76,7 +80,9 @@ describe('ReportOptions component', () => { </Provider> ) expect(screen.getAllByRole('checkbox')[1]).not.toBeChecked() - await userEvent.click(screen.getAllByRole('checkbox')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('checkbox')[1]) + }) expect(updateProfileSpy).toHaveBeenCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledWith({ sendConsumptionAlert: true, diff --git a/src/components/Options/Unsubscribe/Unsubscribe.spec.tsx b/src/components/Options/Unsubscribe/Unsubscribe.spec.tsx index a014ff8cb0b1b83f6483b2673a042a1391bf78be..6586523d7cfee6f99417417ab73e69e0331dd298 100644 --- a/src/components/Options/Unsubscribe/Unsubscribe.spec.tsx +++ b/src/components/Options/Unsubscribe/Unsubscribe.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' +import { act, render, screen, waitFor } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import Unsubscribe from './Unsubscribe' @@ -21,7 +21,9 @@ describe('Unsubscribe component', () => { const { container } = render(<Unsubscribe />) await waitFor(() => null, { container }) const [subscribeBtn] = screen.getAllByRole('button') - await userEvent.click(subscribeBtn) + await act(async () => { + await userEvent.click(subscribeBtn) + }) expect(mockUpdateProfile).toHaveBeenCalled() // then should only display one button diff --git a/src/components/PartnerIssue/PartnerIssueModal.spec.tsx b/src/components/PartnerIssue/PartnerIssueModal.spec.tsx index be3c840762990e6e96e63bab2833f5d69580dfd5..5a39674762a0a580ce5d3c2a1c45763344de19cc 100644 --- a/src/components/PartnerIssue/PartnerIssueModal.spec.tsx +++ b/src/components/PartnerIssue/PartnerIssueModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { FluidType } from 'enums' import React from 'react' @@ -49,7 +49,9 @@ describe('PartnerIssueModal component', () => { issuedFluid={FluidType.ELECTRICITY} /> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHandleClose).toHaveBeenCalled() }) diff --git a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx index 402a3a0bffeea34b3b24e2479491759dbadf4bb7..03c6f736ff395a62d58ca0f0b22fe011ab9367de 100644 --- a/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx +++ b/src/components/ProfileType/ProfileTypeFinished/ProfileTypeFinished.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -45,7 +45,9 @@ describe('ProfileTypeFinished component', () => { <ProfileTypeFinished profileType={mockProfileType} /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-selection') }) }) diff --git a/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx b/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx index aa5330b3cc9dc91ec28ac0ec48172a87e6f9e898..8b3ffacff4e0885a9e84d88f4700e89c1116f096 100644 --- a/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx +++ b/src/components/Quiz/QuizBegin/QuizBegin.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { UserChallengeUpdateFlag } from 'enums' import React from 'react' @@ -23,7 +23,9 @@ describe('QuizBegin component', () => { </Provider> ) expect(container.getElementsByClassName('quiz-icon')[0]).toBeInTheDocument() - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(mockUserChallengeUpdateFlag).toHaveBeenCalledWith( userChallengeData[0], UserChallengeUpdateFlag.QUIZ_START diff --git a/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx b/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx index 8b2dc272d6852c08babfdb55b386e176f935185d..75761dee69cfe5c01204824c20b2eee0cbd600fd 100644 --- a/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx +++ b/src/components/Quiz/QuizFinish/QuizFinish.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -28,7 +28,9 @@ describe('QuizFinish', () => { </Provider> ) expect(container.getElementsByClassName('quiz-icon')[0]).toBeInTheDocument() - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockUserChallengeUpdateFlag).toHaveBeenCalled() expect(mockedNavigate).toHaveBeenCalledWith('/challenges') }) diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx index aa80b5f09caa65e5868dab46deb0908ccfcfb541..707db20c957bf13a88e956b40872912e4343738a 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContent.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -51,7 +51,9 @@ describe('QuizQuestionContent component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockedNavigate).toHaveBeenCalledWith('/challenges') }) }) diff --git a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx index 12809ef896773c3bc99e5b90f74c05926316ed62..818bded68e14a7f471837513b91daef3aebc2703 100644 --- a/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx +++ b/src/components/Quiz/QuizQuestion/QuizQuestionContentCustom.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -42,7 +42,9 @@ describe('QuizCustomQuestionContent component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockHistoryPush).toHaveBeenCalledWith('/challenges') expect(screen.getByText(questionEntity.questionLabel)).toBeInTheDocument() expect(screen.getAllByRole('radio').length).toBe(3) @@ -73,8 +75,10 @@ describe('QuizCustomQuestionContent component', () => { /> </Provider> ) - await userEvent.click(screen.getAllByRole('radio')[0]) - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('radio')[0]) + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockUpdateUserQuiz).toHaveBeenCalledWith( userChallengeData[0].quiz, questionEntity.answers[0].isTrue diff --git a/src/components/Splash/SplashRoot.spec.tsx b/src/components/Splash/SplashRoot.spec.tsx index a948480c9363206ed0cf6e0b31d2d78cade0a02e..3f57b513afae955128380a203e95c612e23b5b07 100644 --- a/src/components/Splash/SplashRoot.spec.tsx +++ b/src/components/Splash/SplashRoot.spec.tsx @@ -1,5 +1,4 @@ -import { render, screen, waitFor } from '@testing-library/react' -import { userEvent } from '@testing-library/user-event' +import { render, waitFor } from '@testing-library/react' import React from 'react' import { Provider } from 'react-redux' import { createMockEcolyoStore } from 'tests/__mocks__/store' @@ -22,7 +21,7 @@ describe('SplashRoot component', () => { expect(container).toMatchSnapshot() }) - it('should render the error screen and click on the reload button', async () => { + it('should render the error screen', async () => { const { container } = render( <Provider store={store}> <SplashRoot>children</SplashRoot> @@ -30,6 +29,5 @@ describe('SplashRoot component', () => { ) await waitFor(() => null, { container }) expect(container).toMatchSnapshot() - await userEvent.click(screen.getByRole('button')) }) }) diff --git a/src/components/Splash/SplashScreenError.spec.tsx b/src/components/Splash/SplashScreenError.spec.tsx index fdc4e5fa594aaaf15732ef0aee420bf1b119dc23..2aefa0711d893cb9594977a0c7f9e51014649ae5 100644 --- a/src/components/Splash/SplashScreenError.spec.tsx +++ b/src/components/Splash/SplashScreenError.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import { userEvent } from '@testing-library/user-event' import { InitStepsErrors } from 'models/initialisationSteps.model' import React from 'react' @@ -24,7 +24,9 @@ describe('SplashScreenError component', () => { }) it('should reload the page', async () => { render(<SplashScreenError error={InitStepsErrors.CONSENT_ERROR} />) - await userEvent.click(screen.getByRole('button')) + await act(async () => { + await userEvent.click(screen.getByRole('button')) + }) expect(window.location.reload).toHaveBeenCalled() }) }) diff --git a/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap b/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap index 4addaf3b692b89fdff97bc23f1eeef967277c2c7..d2a67d7649ceb5166b33e8c0e859df7fe08e0ba4 100644 --- a/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap +++ b/src/components/Splash/__snapshots__/SplashRoot.spec.tsx.snap @@ -50,7 +50,7 @@ exports[`SplashRoot component should be rendered correctly 1`] = ` </div> `; -exports[`SplashRoot component should render the error screen and click on the reload button 1`] = ` +exports[`SplashRoot component should render the error screen 1`] = ` <div> <div class="splash-root" diff --git a/src/components/Terms/TermsView.spec.tsx b/src/components/Terms/TermsView.spec.tsx index 037b939248a0dcbebad6be1fe69e24e795bc45f9..8d4ae3d90c4ce4b2ec99932ab76e316c2cdfa551 100644 --- a/src/components/Terms/TermsView.spec.tsx +++ b/src/components/Terms/TermsView.spec.tsx @@ -54,11 +54,13 @@ describe('TermsView component', () => { expect(mockUpdateProfile).toHaveBeenCalledTimes(0) const [boxGCU, boxLegal] = screen.getAllByRole('checkbox') - await userEvent.click(boxGCU) - await userEvent.click(boxLegal) - await userEvent.click(acceptButton) + await act(async () => { + await userEvent.click(boxGCU) + await userEvent.click(boxLegal) + await userEvent.click(acceptButton) + }) - expect(mockAppDispatch).toHaveBeenCalledTimes(4) + expect(mockAppDispatch).toHaveBeenCalledTimes(3) }) it('should open CGU modal', async () => { diff --git a/src/components/WelcomeModal/WelcomeModal.spec.tsx b/src/components/WelcomeModal/WelcomeModal.spec.tsx index f94a2e6f05297e5a25babbea00a54a3422e67aae..0d7dade73dcdd8dd2dc0293f17c02c0b9acd2901 100644 --- a/src/components/WelcomeModal/WelcomeModal.spec.tsx +++ b/src/components/WelcomeModal/WelcomeModal.spec.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react' +import { act, render, screen } from '@testing-library/react' import userEvent from '@testing-library/user-event' import React from 'react' import { Provider } from 'react-redux' @@ -70,7 +70,9 @@ describe('WelcomeModal component', () => { ) }) it('should send mail and update profile when user click on the ok button', async () => { - await userEvent.click(screen.getAllByRole('button')[1]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[1]) + }) expect(mockSendMail).toHaveBeenCalled() expect(updateProfileSpy).toHaveBeenCalledWith({ isFirstConnection: false, @@ -81,7 +83,9 @@ describe('WelcomeModal component', () => { }) it('should send mail and update profile when modal is closed by user', async () => { - await userEvent.click(screen.getAllByRole('button')[0]) + await act(async () => { + await userEvent.click(screen.getAllByRole('button')[0]) + }) expect(mockSendMail).toHaveBeenCalled() expect(updateProfileSpy).toHaveBeenCalledWith({ isFirstConnection: false,