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

avoid beforeEach

parent 0483a05d
Branches
Tags
1 merge request!1135Draft: test(lint): add testing library lint plugin
...@@ -18,15 +18,13 @@ describe('StepAddress component', () => { ...@@ -18,15 +18,13 @@ describe('StepAddress component', () => {
}) })
describe('should change inputs', () => { describe('should change inputs', () => {
beforeEach(() => { it('should change address value', async () => {
render( render(
<StepAddress <StepAddress
sgeState={mockGlobalState.sgeConnect} sgeState={mockGlobalState.sgeConnect}
onChange={mockHandleChange} onChange={mockHandleChange}
/> />
) )
})
it('should change address value', async () => {
const input = screen.getByRole('textbox', { const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.address', name: 'auth.enedissgegrandlyon.address',
}) })
...@@ -36,6 +34,12 @@ describe('StepAddress component', () => { ...@@ -36,6 +34,12 @@ describe('StepAddress component', () => {
expect(mockHandleChange).toHaveBeenCalledWith('address', 't') expect(mockHandleChange).toHaveBeenCalledWith('address', 't')
}) })
it('should change zipCode value', async () => { it('should change zipCode value', async () => {
render(
<StepAddress
sgeState={mockGlobalState.sgeConnect}
onChange={mockHandleChange}
/>
)
const input = screen.getByRole('spinbutton', { const input = screen.getByRole('spinbutton', {
name: 'auth.enedissgegrandlyon.zipCode', name: 'auth.enedissgegrandlyon.zipCode',
}) })
...@@ -46,6 +50,12 @@ describe('StepAddress component', () => { ...@@ -46,6 +50,12 @@ describe('StepAddress component', () => {
}) })
it('should change city value', async () => { it('should change city value', async () => {
render(
<StepAddress
sgeState={mockGlobalState.sgeConnect}
onChange={mockHandleChange}
/>
)
const input = screen.getByRole('textbox', { const input = screen.getByRole('textbox', {
name: 'auth.enedissgegrandlyon.city', name: 'auth.enedissgegrandlyon.city',
}) })
......
...@@ -20,25 +20,27 @@ describe('EcogestureSelectionDetail component', () => { ...@@ -20,25 +20,27 @@ describe('EcogestureSelectionDetail component', () => {
}) })
describe('should click on buttons', () => { describe('should click on buttons', () => {
let container: HTMLElement it('should toggle more details', async () => {
beforeEach(async () => { render(
container = render(
<EcogestureSelectionDetail <EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]} ecogesture={mockedEcogesturesData[0]}
validate={mockValidate} validate={mockValidate}
title={mockedEcogesturesData[0].shortName} title={mockedEcogesturesData[0].shortName}
/> />
).container )
await waitFor(() => null, { container })
})
it('should toggle more details', async () => {
await act(async () => { await act(async () => {
await userEvent.click(screen.getByText('ecogesture_modal.show_more')) await userEvent.click(screen.getByText('ecogesture_modal.show_more'))
}) })
expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument() expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument()
}) })
it('should call validate with objective to true', async () => { it('should call validate with objective to true', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(
screen.getByText('ecogesture_selection.button_objective') screen.getByText('ecogesture_selection.button_objective')
...@@ -48,6 +50,13 @@ describe('EcogestureSelectionDetail component', () => { ...@@ -48,6 +50,13 @@ describe('EcogestureSelectionDetail component', () => {
}) })
it('should call validate with doing to true', async () => { it('should call validate with doing to true', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(
screen.getByText('ecogesture_selection.button_doing') screen.getByText('ecogesture_selection.button_doing')
...@@ -57,6 +66,13 @@ describe('EcogestureSelectionDetail component', () => { ...@@ -57,6 +66,13 @@ describe('EcogestureSelectionDetail component', () => {
}) })
it('should call validate with objective and doing to false', async () => { it('should call validate with objective and doing to false', async () => {
render(
<EcogestureSelectionDetail
ecogesture={mockedEcogesturesData[0]}
validate={mockValidate}
title={mockedEcogesturesData[0].shortName}
/>
)
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(
screen.getByText('ecogesture_selection.button_skip') screen.getByText('ecogesture_selection.button_skip')
......
...@@ -52,24 +52,21 @@ describe('WelcomeModal component', () => { ...@@ -52,24 +52,21 @@ describe('WelcomeModal component', () => {
}) })
it('should not be rendered', () => { it('should not be rendered', () => {
const { container } = render( render(
<Provider store={store}> <Provider store={store}>
<WelcomeModal open={false} /> <WelcomeModal open={false} />
</Provider> </Provider>
) )
expect(container.firstChild).toBeNull()
expect(screen.queryByRole('dialog')).not.toBeInTheDocument() expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
}) })
describe('should test modal interactivity', () => { describe('should test modal interactivity', () => {
beforeEach(() => { it('should send mail and update profile when user click on the ok button', async () => {
render( render(
<Provider store={store}> <Provider store={store}>
<WelcomeModal open={true} /> <WelcomeModal open={true} />
</Provider> </Provider>
) )
})
it('should send mail and update profile when user click on the ok button', async () => {
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(
screen.getByText('onboarding.welcomeModal.button_valid') screen.getByText('onboarding.welcomeModal.button_valid')
...@@ -85,6 +82,11 @@ describe('WelcomeModal component', () => { ...@@ -85,6 +82,11 @@ describe('WelcomeModal component', () => {
}) })
it('should send mail and update profile when modal is closed by user', async () => { it('should send mail and update profile when modal is closed by user', async () => {
render(
<Provider store={store}>
<WelcomeModal open={true} />
</Provider>
)
await act(async () => { await act(async () => {
await userEvent.click( await userEvent.click(
screen.getAllByLabelText( screen.getAllByLabelText(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment