From f38e9df70ea2081ab3daeab3061e86a1d03ecfaa Mon Sep 17 00:00:00 2001
From: Bastien Dumont <bdumont@grandlyon.com>
Date: Tue, 30 Apr 2024 11:24:35 +0200
Subject: [PATCH] avoid beforeEach

---
 .../SGEConnect/StepAddress.spec.tsx           | 16 ++++++++--
 .../EcogestureSelectionDetail.spec.tsx        | 32 ++++++++++++++-----
 .../WelcomeModal/WelcomeModal.spec.tsx        | 12 ++++---
 3 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/src/components/Connection/SGEConnect/StepAddress.spec.tsx b/src/components/Connection/SGEConnect/StepAddress.spec.tsx
index e7e1326c2..62a897e65 100644
--- a/src/components/Connection/SGEConnect/StepAddress.spec.tsx
+++ b/src/components/Connection/SGEConnect/StepAddress.spec.tsx
@@ -18,15 +18,13 @@ describe('StepAddress component', () => {
   })
 
   describe('should change inputs', () => {
-    beforeEach(() => {
+    it('should change address value', async () => {
       render(
         <StepAddress
           sgeState={mockGlobalState.sgeConnect}
           onChange={mockHandleChange}
         />
       )
-    })
-    it('should change address value', async () => {
       const input = screen.getByRole('textbox', {
         name: 'auth.enedissgegrandlyon.address',
       })
@@ -36,6 +34,12 @@ describe('StepAddress component', () => {
       expect(mockHandleChange).toHaveBeenCalledWith('address', 't')
     })
     it('should change zipCode value', async () => {
+      render(
+        <StepAddress
+          sgeState={mockGlobalState.sgeConnect}
+          onChange={mockHandleChange}
+        />
+      )
       const input = screen.getByRole('spinbutton', {
         name: 'auth.enedissgegrandlyon.zipCode',
       })
@@ -46,6 +50,12 @@ describe('StepAddress component', () => {
     })
 
     it('should change city value', async () => {
+      render(
+        <StepAddress
+          sgeState={mockGlobalState.sgeConnect}
+          onChange={mockHandleChange}
+        />
+      )
       const input = screen.getByRole('textbox', {
         name: 'auth.enedissgegrandlyon.city',
       })
diff --git a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx
index 5608a326d..f16ad9ebe 100644
--- a/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx
+++ b/src/components/EcogestureSelection/EcogestureSelectionDetail/EcogestureSelectionDetail.spec.tsx
@@ -20,25 +20,27 @@ describe('EcogestureSelectionDetail component', () => {
   })
 
   describe('should click on buttons', () => {
-    let container: HTMLElement
-    beforeEach(async () => {
-      container = render(
+    it('should toggle more details', async () => {
+      render(
         <EcogestureSelectionDetail
           ecogesture={mockedEcogesturesData[0]}
           validate={mockValidate}
           title={mockedEcogesturesData[0].shortName}
         />
-      ).container
-      await waitFor(() => null, { container })
-    })
-
-    it('should toggle more details', async () => {
+      )
       await act(async () => {
         await userEvent.click(screen.getByText('ecogesture_modal.show_more'))
       })
       expect(screen.getByText('ecogesture_modal.show_less')).toBeInTheDocument()
     })
     it('should call validate with objective to true', async () => {
+      render(
+        <EcogestureSelectionDetail
+          ecogesture={mockedEcogesturesData[0]}
+          validate={mockValidate}
+          title={mockedEcogesturesData[0].shortName}
+        />
+      )
       await act(async () => {
         await userEvent.click(
           screen.getByText('ecogesture_selection.button_objective')
@@ -48,6 +50,13 @@ describe('EcogestureSelectionDetail component', () => {
     })
 
     it('should call validate with doing to true', async () => {
+      render(
+        <EcogestureSelectionDetail
+          ecogesture={mockedEcogesturesData[0]}
+          validate={mockValidate}
+          title={mockedEcogesturesData[0].shortName}
+        />
+      )
       await act(async () => {
         await userEvent.click(
           screen.getByText('ecogesture_selection.button_doing')
@@ -57,6 +66,13 @@ describe('EcogestureSelectionDetail component', () => {
     })
 
     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 userEvent.click(
           screen.getByText('ecogesture_selection.button_skip')
diff --git a/src/components/WelcomeModal/WelcomeModal.spec.tsx b/src/components/WelcomeModal/WelcomeModal.spec.tsx
index 0db03efef..e6104c842 100644
--- a/src/components/WelcomeModal/WelcomeModal.spec.tsx
+++ b/src/components/WelcomeModal/WelcomeModal.spec.tsx
@@ -52,24 +52,21 @@ describe('WelcomeModal component', () => {
   })
 
   it('should not be rendered', () => {
-    const { container } = render(
+    render(
       <Provider store={store}>
         <WelcomeModal open={false} />
       </Provider>
     )
-    expect(container.firstChild).toBeNull()
     expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
   })
 
   describe('should test modal interactivity', () => {
-    beforeEach(() => {
+    it('should send mail and update profile when user click on the ok button', async () => {
       render(
         <Provider store={store}>
           <WelcomeModal open={true} />
         </Provider>
       )
-    })
-    it('should send mail and update profile when user click on the ok button', async () => {
       await act(async () => {
         await userEvent.click(
           screen.getByText('onboarding.welcomeModal.button_valid')
@@ -85,6 +82,11 @@ describe('WelcomeModal component', () => {
     })
 
     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 userEvent.click(
           screen.getAllByLabelText(
-- 
GitLab