From fe4288e268df4b6d07744b25bec297965b1386d6 Mon Sep 17 00:00:00 2001
From: "guilhem.carron" <gcarron@grandlyon.com>
Date: Thu, 29 Apr 2021 18:18:28 +0200
Subject: [PATCH] Fix tests

---
 src/components/Action/ActionDone.spec.tsx                 | 6 ++++++
 src/components/Action/ActionModal.spec.tsx                | 4 ++++
 src/components/Charts/Bar.tsx                             | 4 ++--
 .../__snapshots__/LegalNoticeLink.spec.tsx.snap           | 1 +
 src/components/TimeStepSelector/TimeStepSelector.spec.tsx | 4 ++++
 src/components/TimeStepSelector/TimeStepSelector.tsx      | 8 ++++----
 6 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/components/Action/ActionDone.spec.tsx b/src/components/Action/ActionDone.spec.tsx
index 5b8426140..522984b9c 100644
--- a/src/components/Action/ActionDone.spec.tsx
+++ b/src/components/Action/ActionDone.spec.tsx
@@ -10,6 +10,7 @@ import { Button } from '@material-ui/core'
 import * as reactRedux from 'react-redux'
 import * as challengeActions from 'store/challenge/challenge.actions'
 import { act } from '@testing-library/react'
+import UsageEventService from 'services/usageEvent.service'
 
 const mockStore = configureStore([])
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
@@ -21,6 +22,10 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
     }),
   }
 })
+jest.mock('services/usageEvent.service')
+const mockAddEvent = jest.fn()
+UsageEventService.addEvent = mockAddEvent
+
 const mockHistoryGoBack = jest.fn()
 jest.mock('react-router-dom', () => ({
   ...jest.requireActual('react-router-dom'),
@@ -36,6 +41,7 @@ jest.mock('services/challenge.service', () => {
     }
   })
 })
+
 describe('ActionDone component', () => {
   it('should be rendered correctly', () => {
     const store = mockStore({
diff --git a/src/components/Action/ActionModal.spec.tsx b/src/components/Action/ActionModal.spec.tsx
index b39dddcd7..3b7406011 100644
--- a/src/components/Action/ActionModal.spec.tsx
+++ b/src/components/Action/ActionModal.spec.tsx
@@ -11,6 +11,7 @@ import { Button } from '@material-ui/core'
 import * as reactRedux from 'react-redux'
 import * as challengeActions from 'store/challenge/challenge.actions'
 import { act } from '@testing-library/react'
+import UsageEventService from 'services/usageEvent.service'
 
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
   return {
@@ -29,6 +30,9 @@ jest.mock('services/challenge.service', () => {
     }
   })
 })
+jest.mock('services/usageEvent.service')
+const mockAddEvent = jest.fn()
+UsageEventService.addEvent = mockAddEvent
 const mockStore = configureStore([])
 
 describe('ActionModal component', () => {
diff --git a/src/components/Charts/Bar.tsx b/src/components/Charts/Bar.tsx
index 828ac75aa..1f66edfcb 100644
--- a/src/components/Charts/Bar.tsx
+++ b/src/components/Charts/Bar.tsx
@@ -56,8 +56,8 @@ const Bar = ({
   const fluidStyle =
     fluidType === FluidType.MULTIFLUID ? 'MULTIFLUID' : FluidType[fluidType]
 
-  const handleClick = async () => {
-    await UsageEventService.addEvent(client, {
+  const handleClick = () => {
+    UsageEventService.addEvent(client, {
       type: UsageEventType.CONSUMPTION_INTERACT_EVENT,
       context: FluidType[fluidType] + ' / ' + TimeStep[timeStep],
     })
diff --git a/src/components/LegalNotice/__snapshots__/LegalNoticeLink.spec.tsx.snap b/src/components/LegalNotice/__snapshots__/LegalNoticeLink.spec.tsx.snap
index 8d9f2c491..ac8a61cbe 100644
--- a/src/components/LegalNotice/__snapshots__/LegalNoticeLink.spec.tsx.snap
+++ b/src/components/LegalNotice/__snapshots__/LegalNoticeLink.spec.tsx.snap
@@ -32,6 +32,7 @@ exports[`LegalNoticeView component should be rendered correctly 1`] = `
     >
       <div
         className="card"
+        onClick={[Function]}
       >
         <div
           className="legal-notice-card"
diff --git a/src/components/TimeStepSelector/TimeStepSelector.spec.tsx b/src/components/TimeStepSelector/TimeStepSelector.spec.tsx
index 66b8364a4..7ddc8bb8d 100644
--- a/src/components/TimeStepSelector/TimeStepSelector.spec.tsx
+++ b/src/components/TimeStepSelector/TimeStepSelector.spec.tsx
@@ -11,6 +11,7 @@ import * as chartActions from 'store/chart/chart.actions'
 import { FluidType } from 'enum/fluid.enum'
 import { TimeStep } from 'enum/timeStep.enum'
 import { DateTime } from 'luxon'
+import UsageEventService from 'services/usageEvent.service'
 
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
   return {
@@ -21,6 +22,9 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
     }),
   }
 })
+jest.mock('services/usageEvent.service')
+const mockAddEvent = jest.fn()
+UsageEventService.addEvent = mockAddEvent
 
 const useSelectorSpy = jest.spyOn(reactRedux, 'useSelector')
 const useDispatchSpy = jest.spyOn(reactRedux, 'useDispatch')
diff --git a/src/components/TimeStepSelector/TimeStepSelector.tsx b/src/components/TimeStepSelector/TimeStepSelector.tsx
index 6576cec1d..3b9d04a70 100644
--- a/src/components/TimeStepSelector/TimeStepSelector.tsx
+++ b/src/components/TimeStepSelector/TimeStepSelector.tsx
@@ -50,7 +50,7 @@ const TimeStepSelector: React.FC<TimeStepSelectorProps> = ({
       ? [...timeStepElecArray]
       : [...timeStepMultiArray]
 
-  const handleZoomInClick = async () => {
+  const handleZoomInClick = () => {
     const previousTimeStep: TimeStep = dateChartService.definePreviousTimeStep(
       currentTimeStep
     )
@@ -58,7 +58,7 @@ const TimeStepSelector: React.FC<TimeStepSelectorProps> = ({
       previousTimeStep,
       selectedDate
     )
-    await UsageEventService.addEvent(client, {
+    UsageEventService.addEvent(client, {
       type: UsageEventType.CONSUMPTION_CHANGE_TIMESTEP_EVENT,
       target: TimeStep[previousTimeStep],
       context: FluidType[fluidType],
@@ -66,7 +66,7 @@ const TimeStepSelector: React.FC<TimeStepSelectorProps> = ({
     dispatch(setCurrentTimeStep(previousTimeStep))
     dispatch(setCurrentIndex(index))
   }
-  const handleZoomOutClick = async () => {
+  const handleZoomOutClick = () => {
     const nextTimeStep: TimeStep = dateChartService.defineNextTimeStep(
       currentTimeStep
     )
@@ -74,7 +74,7 @@ const TimeStepSelector: React.FC<TimeStepSelectorProps> = ({
       nextTimeStep,
       selectedDate
     )
-    await UsageEventService.addEvent(client, {
+    UsageEventService.addEvent(client, {
       type: UsageEventType.CONSUMPTION_CHANGE_TIMESTEP_EVENT,
       target: TimeStep[nextTimeStep],
       context: FluidType[fluidType],
-- 
GitLab