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

test: replace getByRole methods

parent 89146544
Branches
Tags
2 merge requests!1163test: replace getByRole methods,!11623.0 Release
Showing
with 92 additions and 93 deletions
...@@ -35,9 +35,12 @@ describe('MaxConsumptionCard component', () => { ...@@ -35,9 +35,12 @@ describe('MaxConsumptionCard component', () => {
</Provider> </Provider>
) )
await waitFor(() => null, { container }) await waitFor(() => null, { container })
const [prevButton, nextButton] = screen.getAllByRole('button') expect(
expect(prevButton).toBeDisabled() screen.getByLabelText('consumption.accessibility.button_previous_value')
expect(nextButton).toBeDisabled() ).toBeDisabled()
expect(
screen.getByLabelText('consumption.accessibility.button_next_value')
).toBeDisabled()
}) })
it('should be rendered with several fluids and click navigate between fluid', async () => { it('should be rendered with several fluids and click navigate between fluid', async () => {
const { container } = render( const { container } = render(
......
...@@ -65,10 +65,8 @@ describe('ChallengeCardDone component', () => { ...@@ -65,10 +65,8 @@ describe('ChallengeCardDone component', () => {
<ChallengeCardDone userChallenge={userChallengeData[0]} /> <ChallengeCardDone userChallenge={userChallengeData[0]} />
</Provider> </Provider>
) )
const resetButton = screen.getByRole('button', { const resetBtn = screen.getByLabelText('challenge.card_done.reset_defi')
name: 'challenge.card_done.reset_defi', expect(resetBtn).toHaveProperty('disabled')
})
expect(resetButton).toHaveProperty('disabled')
expect(mockDispatch).toHaveBeenCalledTimes(0) expect(mockDispatch).toHaveBeenCalledTimes(0)
expect(mockUpdateUserChallenge).toHaveBeenCalledTimes(0) expect(mockUpdateUserChallenge).toHaveBeenCalledTimes(0)
}) })
...@@ -78,10 +76,8 @@ describe('ChallengeCardDone component', () => { ...@@ -78,10 +76,8 @@ describe('ChallengeCardDone component', () => {
<ChallengeCardDone userChallenge={userChallengeData[1]} /> <ChallengeCardDone userChallenge={userChallengeData[1]} />
</Provider> </Provider>
) )
const resetButton = screen.getByRole('button', { const resetBtn = screen.getByLabelText('challenge.card_done.reset_defi')
name: 'challenge.card_done.reset_defi', expect(resetBtn).toHaveClass('btnPrimaryNegative')
})
expect(resetButton).toHaveClass('btnPrimaryNegative')
}) })
it('should be secondary button is challenge is won', async () => { it('should be secondary button is challenge is won', async () => {
render( render(
...@@ -89,10 +85,8 @@ describe('ChallengeCardDone component', () => { ...@@ -89,10 +85,8 @@ describe('ChallengeCardDone component', () => {
<ChallengeCardDone userChallenge={userChallengeData[0]} /> <ChallengeCardDone userChallenge={userChallengeData[0]} />
</Provider> </Provider>
) )
const resetButton = screen.getByRole('button', { const resetBtn = screen.getByLabelText('challenge.card_done.reset_defi')
name: 'challenge.card_done.reset_defi', expect(resetBtn).toHaveClass('btnSecondary')
})
expect(resetButton).toHaveClass('btnSecondary')
}) })
}) })
}) })
...@@ -84,7 +84,9 @@ describe('ChallengeCardUnlocked component', () => { ...@@ -84,7 +84,9 @@ describe('ChallengeCardUnlocked component', () => {
<ChallengeCardUnlocked userChallenge={userChallengeData[0]} /> <ChallengeCardUnlocked userChallenge={userChallengeData[0]} />
</Provider> </Provider>
) )
const resetButton = screen.getByRole('button') const launchBtn = screen.getByLabelText(
expect(resetButton).toHaveAttribute('disabled') 'challenge.accessibility.button_launch'
)
expect(launchBtn).toHaveAttribute('disabled')
}) })
}) })
...@@ -15,13 +15,14 @@ describe('FormNavigation component', () => { ...@@ -15,13 +15,14 @@ describe('FormNavigation component', () => {
disablePrevButton={false} disablePrevButton={false}
/> />
) )
const [prevButton, nextButton] = screen.getAllByRole('button')
await act(async () => { await act(async () => {
await userEvent.click(prevButton) await userEvent.click(
screen.getByText('profile_type.form.button_previous')
)
}) })
expect(mockHandlePrevious).toHaveBeenCalled() expect(mockHandlePrevious).toHaveBeenCalled()
await act(async () => { await act(async () => {
await userEvent.click(nextButton) await userEvent.click(screen.getByText('profile_type.form.button_next'))
}) })
expect(mockHandleNext).toHaveBeenCalled() expect(mockHandleNext).toHaveBeenCalled()
}) })
......
...@@ -46,9 +46,7 @@ describe('ExpiredConsentModal component', () => { ...@@ -46,9 +46,7 @@ describe('ExpiredConsentModal component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(screen.getByText('consent_outdated.go'))
screen.getByRole('button', { name: 'consent_outdated.go' })
)
}) })
expect(mockAppDispatch).toHaveBeenCalledTimes(1) expect(mockAppDispatch).toHaveBeenCalledTimes(1)
expect(mockedNavigate).toHaveBeenCalledTimes(1) expect(mockedNavigate).toHaveBeenCalledTimes(1)
...@@ -68,9 +66,7 @@ describe('ExpiredConsentModal component', () => { ...@@ -68,9 +66,7 @@ describe('ExpiredConsentModal component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(screen.getByText('consent_outdated.yes'))
screen.getByRole('button', { name: 'consent_outdated.go' })
)
}) })
expect(mockAppDispatch).toHaveBeenCalledTimes(1) expect(mockAppDispatch).toHaveBeenCalledTimes(1)
expect(mockedNavigate).toHaveBeenCalledTimes(1) expect(mockedNavigate).toHaveBeenCalledTimes(1)
...@@ -87,9 +83,7 @@ describe('ExpiredConsentModal component', () => { ...@@ -87,9 +83,7 @@ describe('ExpiredConsentModal component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(screen.getByText('consent_outdated.no'))
screen.getByRole('button', { name: 'consent_outdated.later' })
)
}) })
expect(mockHandleCloseClick).toHaveBeenCalled() expect(mockHandleCloseClick).toHaveBeenCalled()
}) })
......
...@@ -45,12 +45,12 @@ describe('SgeConnectView component', () => { ...@@ -45,12 +45,12 @@ describe('SgeConnectView component', () => {
screen.getByText('auth.enedissgegrandlyon.identityTitle') screen.getByText('auth.enedissgegrandlyon.identityTitle')
).toBeInTheDocument() ).toBeInTheDocument()
const prevButton = screen.getByRole('button', { const prevButton = screen.getByLabelText(
name: 'profile_type.accessibility.button_previous', 'profile_type.accessibility.button_previous'
}) )
const nextButton = screen.getByRole('button', { const nextButton = screen.getByLabelText(
name: 'profile_type.accessibility.button_next', 'profile_type.accessibility.button_next'
}) )
expect(prevButton).toBeDisabled() expect(prevButton).toBeDisabled()
expect(nextButton).toBeDisabled() expect(nextButton).toBeDisabled()
}) })
......
...@@ -28,7 +28,7 @@ describe('SgeInit component', () => { ...@@ -28,7 +28,7 @@ describe('SgeInit component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[0]) await userEvent.click(screen.getByText('auth.enedissgegrandlyon.connect'))
}) })
expect(mockedNavigate).toHaveBeenCalled() expect(mockedNavigate).toHaveBeenCalled()
}) })
......
...@@ -24,15 +24,15 @@ describe('StepConsent component', () => { ...@@ -24,15 +24,15 @@ describe('StepConsent component', () => {
onChange={mockHandleChange} onChange={mockHandleChange}
/> />
) )
const consentCheckbox = screen.getByRole('checkbox', { const consentCheckbox = screen.getByLabelText(
name: 'auth.enedissgegrandlyon.consentCheck1', 'auth.enedissgegrandlyon.consentCheck1'
}) )
await userEvent.click(consentCheckbox) await userEvent.click(consentCheckbox)
expect(mockHandleChange).toHaveBeenCalledWith('dataConsent', true) expect(mockHandleChange).toHaveBeenCalledWith('dataConsent', true)
const pdlCheckbox = screen.getByRole('checkbox', { const pdlCheckbox = screen.getByLabelText(
name: 'auth.enedissgegrandlyon.consentCheck2', 'auth.enedissgegrandlyon.consentCheck2'
}) )
await userEvent.click(pdlCheckbox) await userEvent.click(pdlCheckbox)
expect(mockHandleChange).toHaveBeenCalledWith('pdlConfirm', true) expect(mockHandleChange).toHaveBeenCalledWith('pdlConfirm', true)
}) })
......
...@@ -56,11 +56,10 @@ describe('StepIdentityAndPdl component', () => { ...@@ -56,11 +56,10 @@ describe('StepIdentityAndPdl component', () => {
onChange={mockHandleChange} onChange={mockHandleChange}
/> />
) )
const pdlModalButton = screen.getByRole('button', {
name: 'auth.enedissgegrandlyon.pdlModal.title',
})
await act(async () => { await act(async () => {
await userEvent.click(pdlModalButton) await userEvent.click(
screen.getByText('auth.enedissgegrandlyon.pdlModal.title')
)
}) })
expect(screen.getByRole('dialog')).toBeInTheDocument() expect(screen.getByRole('dialog')).toBeInTheDocument()
}) })
......
...@@ -122,7 +122,9 @@ describe('DataloadNoValue component', () => { ...@@ -122,7 +122,9 @@ describe('DataloadNoValue component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getByRole('button')) await userEvent.click(
screen.getByText('consumption_visualizer.missing_data')
)
}) })
expect(mockDispatch).toHaveBeenCalledWith({ expect(mockDispatch).toHaveBeenCalledWith({
type: 'chart/setShowConnectionDetails', type: 'chart/setShowConnectionDetails',
......
...@@ -89,7 +89,9 @@ describe('DataloadSectionValue component', () => { ...@@ -89,7 +89,9 @@ describe('DataloadSectionValue component', () => {
/> />
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getByRole('button')) await userEvent.click(
screen.getByText('consumption_visualizer.estimated')
)
}) })
expect(mockToggleEstimationModal).toHaveBeenCalled() expect(mockToggleEstimationModal).toHaveBeenCalled()
}) })
......
...@@ -189,7 +189,7 @@ describe('InfoDataConsumptionVisualizer component', () => { ...@@ -189,7 +189,7 @@ describe('InfoDataConsumptionVisualizer component', () => {
}) })
it('should click on last valid data date and move to it', async () => { it('should click on last valid data date and move to it', async () => {
const mockDataLoad = { ...baseDataLoad, state: DataloadState.EMPTY } const mockDataLoad = { ...baseDataLoad, state: DataloadState.UPCOMING }
render( render(
<Provider store={store}> <Provider store={store}>
<InfoDataConsumptionVisualizer <InfoDataConsumptionVisualizer
...@@ -200,9 +200,11 @@ describe('InfoDataConsumptionVisualizer component', () => { ...@@ -200,9 +200,11 @@ describe('InfoDataConsumptionVisualizer component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getByRole('button')) await userEvent.click(
screen.getByText('consumption_visualizer.last_available_data')
)
}) })
expect(screen.getByRole('dialog')).toBeInTheDocument() expect(mockAppDispatch).toHaveBeenCalled()
}) })
it('should click to display NoDataModal', async () => { it('should click to display NoDataModal', async () => {
...@@ -217,8 +219,10 @@ describe('InfoDataConsumptionVisualizer component', () => { ...@@ -217,8 +219,10 @@ describe('InfoDataConsumptionVisualizer component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getByRole('button')) await userEvent.click(
screen.getByText('consumption_visualizer.why_no_data')
)
}) })
expect(mockAppDispatch).toHaveBeenCalled() expect(screen.getByRole('dialog')).toBeInTheDocument()
}) })
}) })
...@@ -44,13 +44,16 @@ describe('DateNavigator component', () => { ...@@ -44,13 +44,16 @@ describe('DateNavigator component', () => {
timeStep={TimeStep.MONTH} timeStep={TimeStep.MONTH}
/> />
) )
const [prevIcon, nextIcon] = screen.getAllByRole('button')
await act(async () => { await act(async () => {
await userEvent.click(prevIcon) await userEvent.click(
screen.getByLabelText('consumption.accessibility.button_previous_value')
)
}) })
expect(mockHandlePrevDate).toHaveBeenCalledTimes(1) expect(mockHandlePrevDate).toHaveBeenCalledTimes(1)
await act(async () => { await act(async () => {
await userEvent.click(nextIcon) await userEvent.click(
screen.getByLabelText('consumption.accessibility.button_next_value')
)
}) })
expect(mockHandleNextDate).toHaveBeenCalledTimes(1) expect(mockHandleNextDate).toHaveBeenCalledTimes(1)
}) })
...@@ -66,8 +69,13 @@ describe('DateNavigator component', () => { ...@@ -66,8 +69,13 @@ describe('DateNavigator component', () => {
timeStep={TimeStep.MONTH} timeStep={TimeStep.MONTH}
/> />
) )
const [prevIcon, nextButton] = screen.getAllByRole('button') const prev = screen.queryByLabelText(
expect(prevIcon).toBeDisabled() 'consumption.accessibility.button_previous_value'
expect(nextButton).toBeDisabled() )
const next = screen.queryByLabelText(
'consumption.accessibility.button_next_value'
)
expect(prev).toBeDisabled()
expect(next).toBeDisabled()
}) })
}) })
...@@ -32,7 +32,7 @@ describe('EcogestureEmptyList component', () => { ...@@ -32,7 +32,7 @@ describe('EcogestureEmptyList component', () => {
/> />
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[0]) await userEvent.click(screen.getByLabelText('ecogesture.emptyList.btn1'))
}) })
expect(mockChangeTab).toHaveBeenCalledTimes(1) expect(mockChangeTab).toHaveBeenCalledTimes(1)
}) })
...@@ -46,7 +46,7 @@ describe('EcogestureEmptyList component', () => { ...@@ -46,7 +46,7 @@ describe('EcogestureEmptyList component', () => {
/> />
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[1]) await userEvent.click(screen.getByLabelText('ecogesture.emptyList.btn2'))
}) })
expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-form') expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-form')
}) })
......
...@@ -25,7 +25,7 @@ describe('EcogestureInitModal component', () => { ...@@ -25,7 +25,7 @@ describe('EcogestureInitModal component', () => {
/> />
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[2]) await userEvent.click(screen.getByText('ecogesture.initModal.btn1'))
}) })
expect(mockHandleClose).toHaveBeenCalledTimes(1) expect(mockHandleClose).toHaveBeenCalledTimes(1)
}) })
...@@ -38,7 +38,7 @@ describe('EcogestureInitModal component', () => { ...@@ -38,7 +38,7 @@ describe('EcogestureInitModal component', () => {
/> />
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[1]) await userEvent.click(screen.getByText('ecogesture.initModal.btn2'))
}) })
expect(mockHandleLaunchForm).toHaveBeenCalledTimes(1) expect(mockHandleLaunchForm).toHaveBeenCalledTimes(1)
}) })
......
...@@ -61,7 +61,7 @@ describe('EcogesturesList component', () => { ...@@ -61,7 +61,7 @@ describe('EcogesturesList component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[0]) await userEvent.click(screen.getByText('ecogesture.MENU_TITLE'))
}) })
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('menuitem')[1]) await userEvent.click(screen.getAllByRole('menuitem')[1])
...@@ -83,7 +83,7 @@ describe('EcogesturesList component', () => { ...@@ -83,7 +83,7 @@ describe('EcogesturesList component', () => {
</Provider> </Provider>
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('button')[1]) await userEvent.click(screen.getByText('ecogesture.button_selection'))
}) })
expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-selection') expect(mockedNavigate).toHaveBeenCalledWith('/ecogesture-selection')
}) })
......
...@@ -23,7 +23,7 @@ describe('EcogestureNotFound component', () => { ...@@ -23,7 +23,7 @@ describe('EcogestureNotFound component', () => {
it('should click on button and be redirected', async () => { it('should click on button and be redirected', async () => {
render(<EcogestureNotFound text="test" returnPage="ecogestures" />) render(<EcogestureNotFound text="test" returnPage="ecogestures" />)
await act(async () => { await act(async () => {
await userEvent.click(screen.getByRole('button')) await userEvent.click(screen.getByText('error_page.back'))
}) })
expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures') expect(mockedNavigate).toHaveBeenCalledWith('/ecogestures')
}) })
......
import { act, render, screen, waitFor } from '@testing-library/react' import { render, screen, waitFor } from '@testing-library/react'
import { userEvent } from '@testing-library/user-event' import { userEvent } from '@testing-library/user-event'
import EcogestureTabsView from 'components/Ecogesture/EcogestureTabsView' import EcogestureTabsView from 'components/Ecogesture/EcogestureTabsView'
import { Ecogesture } from 'models' import { Ecogesture } from 'models'
...@@ -77,8 +77,10 @@ describe('EcogestureView component', () => { ...@@ -77,8 +77,10 @@ describe('EcogestureView component', () => {
) )
expect(screen.getByRole('dialog')).toBeInTheDocument() expect(screen.getByRole('dialog')).toBeInTheDocument()
await act(async () => { await waitFor(async () => {
await userEvent.click(screen.getAllByRole('button')[0]) await userEvent.click(
screen.getByLabelText('feedback.accessibility.button_close')
)
}) })
expect(updateProfileSpy).toHaveBeenCalledWith({ expect(updateProfileSpy).toHaveBeenCalledWith({
haveSeenEcogestureModal: true, haveSeenEcogestureModal: true,
......
...@@ -49,9 +49,10 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -49,9 +49,10 @@ describe('EcogestureFormSingleChoice component', () => {
</Provider> </Provider>
) )
await userEvent.click(screen.getAllByRole('radio')[0]) await userEvent.click(screen.getAllByRole('radio')[0])
const [, next] = screen.getAllByRole('button')
await act(async () => { await act(async () => {
await userEvent.click(next) await userEvent.click(
screen.getByLabelText('profile_type.accessibility.button_next')
)
}) })
expect(mockHandleNextStep).toHaveBeenCalledTimes(1) expect(mockHandleNextStep).toHaveBeenCalledTimes(1)
}) })
...@@ -68,9 +69,10 @@ describe('EcogestureFormSingleChoice component', () => { ...@@ -68,9 +69,10 @@ describe('EcogestureFormSingleChoice component', () => {
/> />
</Provider> </Provider>
) )
const [prev] = screen.getAllByRole('button')
await act(async () => { await act(async () => {
await userEvent.click(prev) await userEvent.click(
screen.getByLabelText('profile_type.accessibility.button_previous')
)
}) })
expect(mockHandlePreviousStep).toHaveBeenCalledTimes(1) expect(mockHandlePreviousStep).toHaveBeenCalledTimes(1)
}) })
......
...@@ -71,29 +71,14 @@ describe('EcogestureFormView component', () => { ...@@ -71,29 +71,14 @@ describe('EcogestureFormView component', () => {
) )
await act(async () => { await act(async () => {
await userEvent.click(screen.getAllByRole('radio')[0]) await userEvent.click(screen.getAllByRole('radio')[0])
await userEvent.click(screen.getAllByRole('button')[1]) await userEvent.click(
screen.getByLabelText('profile_type.accessibility.button_next')
)
}) })
expect( expect(
container.getElementsByClassName('ecogesture-form-single').length container.getElementsByClassName('ecogesture-form-single').length
).toBeTruthy() ).toBeTruthy()
}) })
it('should go to previous step', async () => {
const { container } = render(
<Provider store={store}>
<EcogestureFormView />
</Provider>
)
const [, next] = screen.getAllByRole('button')
await act(async () => {
await userEvent.click(screen.getAllByRole('radio')[0])
await userEvent.click(next)
})
expect(
container.getElementsByClassName('ecogesture-form-single').length
).toBeTruthy()
})
it('should handle form end', async () => { it('should handle form end', async () => {
mockAppDispatch.mockReturnValue(jest.fn()) mockAppDispatch.mockReturnValue(jest.fn())
...@@ -115,7 +100,8 @@ describe('EcogestureFormView component', () => { ...@@ -115,7 +100,8 @@ describe('EcogestureFormView component', () => {
<EcogestureFormView /> <EcogestureFormView />
</Provider> </Provider>
) )
const [prev] = screen.getAllByRole('button') expect(
expect(prev).toBeDisabled() screen.getByLabelText('profile_type.accessibility.button_previous')
).toBeDisabled()
}) })
}) })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment