Skip to content
Snippets Groups Projects
Commit 3ae046d1 authored by Rémi PAPIN's avatar Rémi PAPIN
Browse files

Feedback + Options

parent 50eb715c
Branches
Tags
1 merge request!139Features/unit tests
'use strict'
/* eslint-env jest */
import React from 'react' import React from 'react'
import { mount, shallow, ShallowWrapper } from 'enzyme' import { mount, shallow, ShallowWrapper } from 'enzyme'
import FeedbackModal from 'components/Feedback/FeedbackModal' import FeedbackModal from 'components/Feedback/FeedbackModal'
...@@ -9,7 +7,6 @@ import mockClient from '../../services/__mocks__/client' ...@@ -9,7 +7,6 @@ import mockClient from '../../services/__mocks__/client'
import { useClient } from 'cozy-client' import { useClient } from 'cozy-client'
import Modal from 'components/CommonKit/Modal/Modal' import Modal from 'components/CommonKit/Modal/Modal'
import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton' import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
import { fn } from 'moment'
const mockSendMail = jest.fn() const mockSendMail = jest.fn()
jest.mock('services/mail.service', () => { jest.mock('services/mail.service', () => {
...@@ -20,15 +17,6 @@ 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', () => { jest.mock('cozy-ui/transpiled/react/I18n', () => {
return { return {
useI18n: jest.fn(() => { useI18n: jest.fn(() => {
...@@ -41,9 +29,6 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => { ...@@ -41,9 +29,6 @@ jest.mock('cozy-ui/transpiled/react/I18n', () => {
const client = useClient() const client = useClient()
const handleFeedbackModalClose = jest.fn() const handleFeedbackModalClose = jest.fn()
//jest.mock('cozy-client')
// const { useClient } = (Client as unknown) as typeof MockClient
describe('FeedbackModal component', () => { describe('FeedbackModal component', () => {
it('should render the component', () => { it('should render the component', () => {
const component = shallow( const component = shallow(
...@@ -53,10 +38,10 @@ describe('FeedbackModal component', () => { ...@@ -53,10 +38,10 @@ describe('FeedbackModal component', () => {
}) })
}) })
describe('FeedbackModal functionnalities', () => { describe('FeedbackModal functionnalities', () => {
const wrapper = shallow(
<FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
)
it('should should send an email to the support', () => { it('should should send an email to the support', () => {
const wrapper = shallow(
<FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
)
const expectedMailData = { const expectedMailData = {
mode: 'from', mode: 'from',
to: [{ name: 'Support', email: 'ecolyo@grandlyon.com' }], to: [{ name: 'Support', email: 'ecolyo@grandlyon.com' }],
...@@ -105,15 +90,21 @@ describe('FeedbackModal functionnalities', () => { ...@@ -105,15 +90,21 @@ describe('FeedbackModal functionnalities', () => {
) )
}) })
it('should close the modal and reset the inputs', () => { it('should close the modal and reset the inputs', () => {
const wrapper = shallow(
<FeedbackModal open={true} handleCloseClick={handleFeedbackModalClose} />
)
const mockElement = { style: { overflowY: 'style' } } const mockElement = { style: { overflowY: 'style' } }
jest.spyOn(document, 'querySelector').mockReturnValue(mockElement) jest.spyOn(document, 'querySelector').mockReturnValue(mockElement)
const mockResetInputs = jest.spyOn(FeedbackModal, 'resetInputs') //const mockResetInputs = jest.spyOn(FeedbackModal, 'resetInputs')
//jest.spyOn(instance, 'resetInputs')
wrapper wrapper
.find(Modal) .find(Modal)
.dive() .dive()
.find(StyledIconButton) .find(StyledIconButton)
.simulate('click') .simulate('click')
expect(handleFeedbackModalClose).toHaveBeenCalledTimes(1) expect(handleFeedbackModalClose).toHaveBeenCalledTimes(1)
//expect(mockResetInputs).toHaveBeenCalledTimes(1)
// expect(resetInputs).toHaveBeenCalledTimes(1)
}) })
}) })
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,
})
})
})
...@@ -21,6 +21,7 @@ const ReportOptions: React.FC = () => { ...@@ -21,6 +21,7 @@ const ReportOptions: React.FC = () => {
haveSeenLastReport: userProfile.report.haveSeenLastReport, haveSeenLastReport: userProfile.report.haveSeenLastReport,
monthlyReportDate: userProfile.report.monthlyReportDate, monthlyReportDate: userProfile.report.monthlyReportDate,
} }
console.log(reportAttributes)
try { try {
await userProfileService await userProfileService
.updateUserProfile({ report: reportAttributes }) .updateUserProfile({ report: reportAttributes })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment