From 3ae046d12269a01597d7edc3d46e6684ef2091e1 Mon Sep 17 00:00:00 2001
From: rpapin <rpapin@grandlyon.com>
Date: Wed, 25 Nov 2020 10:47:34 +0100
Subject: [PATCH] Feedback + Options

---
 .../Feedback/FeedbackModal.spec.tsx           | 31 ++++-------
 src/components/Options/OptionsView.spec.tsx   | 53 +++++++++++++++++++
 src/components/Options/ReportOptions.tsx      |  1 +
 3 files changed, 65 insertions(+), 20 deletions(-)
 create mode 100644 src/components/Options/OptionsView.spec.tsx

diff --git a/src/components/Feedback/FeedbackModal.spec.tsx b/src/components/Feedback/FeedbackModal.spec.tsx
index 38a7bb1bd..171e4fbdd 100644
--- a/src/components/Feedback/FeedbackModal.spec.tsx
+++ b/src/components/Feedback/FeedbackModal.spec.tsx
@@ -1,5 +1,3 @@
-'use strict'
-/* eslint-env jest */
 import React from 'react'
 import { mount, shallow, ShallowWrapper } from 'enzyme'
 import FeedbackModal from 'components/Feedback/FeedbackModal'
@@ -9,7 +7,6 @@ import mockClient from '../../services/__mocks__/client'
 import { useClient } from 'cozy-client'
 import Modal from 'components/CommonKit/Modal/Modal'
 import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
-import { fn } from 'moment'
 
 const mockSendMail = jest.fn()
 jest.mock('services/mail.service', () => {
@@ -20,15 +17,6 @@ jest.mock('services/mail.service', () => {
   })
 })
 
-// const mockResetInputs = jest.fn()
-// jest.mock('./FeedbackModal', () => {
-//   return jest.fn(() => {
-//     return {
-//       resetInputs: mockResetInputs,
-//     }
-//   })
-// })
-
 jest.mock('cozy-ui/transpiled/react/I18n', () => {
   return {
     useI18n: jest.fn(() => {
@@ -41,9 +29,6 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
 const client = useClient()
 const handleFeedbackModalClose = jest.fn()
 
-//jest.mock('cozy-client')
-// const { useClient } = (Client as unknown) as typeof MockClient
-
 describe('FeedbackModal component', () => {
   it('should render the component', () => {
     const component = shallow(
@@ -53,10 +38,10 @@ describe('FeedbackModal component', () => {
   })
 })
 describe('FeedbackModal functionnalities', () => {
-  const wrapper = shallow(
-    <FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
-  )
   it('should should send an email to the support', () => {
+    const wrapper = shallow(
+      <FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
+    )
     const expectedMailData = {
       mode: 'from',
       to: [{ name: 'Support', email: 'ecolyo@grandlyon.com' }],
@@ -105,15 +90,21 @@ describe('FeedbackModal functionnalities', () => {
     )
   })
   it('should close the modal and reset the inputs', () => {
+    const wrapper = shallow(
+      <FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
+    )
     const mockElement = { style: { overflowY: 'style' } }
     jest.spyOn(document, 'querySelector').mockReturnValue(mockElement)
-    const mockResetInputs = jest.spyOn(FeedbackModal, 'resetInputs')
+    //const mockResetInputs = jest.spyOn(FeedbackModal, 'resetInputs')
+
+    //jest.spyOn(instance, 'resetInputs')
     wrapper
       .find(Modal)
       .dive()
       .find(StyledIconButton)
       .simulate('click')
     expect(handleFeedbackModalClose).toHaveBeenCalledTimes(1)
-    //expect(mockResetInputs).toHaveBeenCalledTimes(1)
+
+    // expect(resetInputs).toHaveBeenCalledTimes(1)
   })
 })
diff --git a/src/components/Options/OptionsView.spec.tsx b/src/components/Options/OptionsView.spec.tsx
new file mode 100644
index 000000000..d4cd2bd55
--- /dev/null
+++ b/src/components/Options/OptionsView.spec.tsx
@@ -0,0 +1,53 @@
+import React from 'react'
+import { mount, shallow, ShallowWrapper } from 'enzyme'
+import OptionsView from 'components/Options/OptionsView'
+import ReportOptions from 'components/Options/ReportOptions'
+import mockClient from '../../services/__mocks__/client'
+import { useClient } from 'cozy-client'
+
+const mockUpdateUserProfile = jest.fn()
+jest.mock('services/userProfile.service', () => {
+  return jest.fn(() => {
+    return {
+      updateUserProfile: mockUpdateUserProfile,
+    }
+  })
+})
+
+jest.mock('cozy-ui/transpiled/react/I18n', () => {
+  return {
+    useI18n: jest.fn(() => {
+      return {
+        t: (str: string) => str,
+        translate: jest.fn(),
+      }
+    }),
+  }
+})
+const client = useClient()
+const handleFeedbackModalClose = jest.fn()
+
+//jest.mock('cozy-client')
+// const { useClient } = (Client as unknown) as typeof MockClient
+
+describe('OptionsView component', () => {
+  it('should render the component', () => {
+    const component = shallow(<OptionsView />).getElement()
+    expect(component).toMatchSnapshot()
+  })
+})
+describe('ReportOptions functionalities', () => {
+  it('should render the component', () => {
+    const component = shallow(<ReportOptions />).getElement()
+    expect(component).toMatchSnapshot()
+  })
+  it('should change the user notification option', () => {
+    const reportAttributes = {}
+    const wrapper = shallow(<ReportOptions />)
+    wrapper.find('#never').simulate('click')
+
+    expect(mockUpdateUserProfile).toHaveBeenCalledWith({
+      report: reportAttributes,
+    })
+  })
+})
diff --git a/src/components/Options/ReportOptions.tsx b/src/components/Options/ReportOptions.tsx
index e4851d2fb..0b650e326 100644
--- a/src/components/Options/ReportOptions.tsx
+++ b/src/components/Options/ReportOptions.tsx
@@ -21,6 +21,7 @@ const ReportOptions: React.FC = () => {
         haveSeenLastReport: userProfile.report.haveSeenLastReport,
         monthlyReportDate: userProfile.report.monthlyReportDate,
       }
+      console.log(reportAttributes)
       try {
         await userProfileService
           .updateUserProfile({ report: reportAttributes })
-- 
GitLab