From 7b8a127fe855f93069f84d141b59d5fee5982fcc Mon Sep 17 00:00:00 2001 From: "guilhem.carron" <gcarron@grandlyon.com> Date: Fri, 9 Jul 2021 11:47:55 +0200 Subject: [PATCH] Fix + improve report and mail test --- src/components/Options/ReportOptions.spec.tsx | 32 +++++++++++++------ src/services/mail.service.spec.ts | 8 ++--- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/components/Options/ReportOptions.spec.tsx b/src/components/Options/ReportOptions.spec.tsx index 18ba68366..65778d611 100644 --- a/src/components/Options/ReportOptions.spec.tsx +++ b/src/components/Options/ReportOptions.spec.tsx @@ -7,7 +7,7 @@ import { mockInitialEcolyoState, } from '../../../tests/__mocks__/store' import * as profileActions from 'store/profile/profile.actions' -import StyledSwitch from 'components/CommonKit/Switch/StyledSwitch' +import { Button } from '@material-ui/core' jest.mock('cozy-ui/transpiled/react/I18n', () => { return { @@ -44,13 +44,7 @@ describe('ReportOptions component', () => { <ReportOptions /> </Provider> ) - expect(wrapper.find(StyledSwitch)).toHaveLength(1) - expect( - wrapper - .find(StyledSwitch) - .first() - .props().checked - ).toBeFalsy() + expect(wrapper.find(Button).text()).toBe('profile.report.activate') }) it('should update the profile with sendAnalysisNotification to true', () => { @@ -60,12 +54,30 @@ describe('ReportOptions component', () => { </Provider> ) wrapper - .find('input') + .find(Button) .first() - .simulate('change', { target: { checked: 'true' } }) + .simulate('click') expect(updateProfileSpy).toBeCalledTimes(1) expect(updateProfileSpy).toHaveBeenCalledWith({ sendAnalysisNotification: true, }) }) + it('should be rendered with sendAnalysisNotification true and toggle it to false', () => { + mockInitialEcolyoState.profile.sendAnalysisNotification = true + store = createMockStore(mockInitialEcolyoState) + + const wrapper = mount( + <Provider store={store}> + <ReportOptions /> + </Provider> + ) + wrapper + .find(Button) + .first() + .simulate('click') + expect(updateProfileSpy).toBeCalledTimes(1) + expect(updateProfileSpy).toHaveBeenCalledWith({ + sendAnalysisNotification: false, + }) + }) }) diff --git a/src/services/mail.service.spec.ts b/src/services/mail.service.spec.ts index 4107a4504..265def8d0 100644 --- a/src/services/mail.service.spec.ts +++ b/src/services/mail.service.spec.ts @@ -8,7 +8,7 @@ describe('Mail service', () => { it('should return void when mail is sent', async () => { const mockMailData = { mode: 'noreply', - subject: '[Ecolyo] - Bienvenu', + subject: '[Ecolyo] - Bienvenue', parts: [ { type: 'text/html', @@ -24,7 +24,7 @@ describe('Mail service', () => { let error const mockMailData = { mode: 'noreply', - subject: '[Ecolyo] - Bienvenu', + subject: '[Ecolyo] - Bienvenue', parts: [ { type: 'text/html', @@ -95,7 +95,7 @@ describe('Mail service', () => { ) expect(result).toEqual( expect.stringContaining( - '<a href="https://user-ecolyo.test.com/#/options" style="color: #ffffff">Unsubscribe</a>' + '<a href="https://user-ecolyo.test.com/#/unsubscribe" style="color: #ffffff">Unsubscribe</a>' ) ) }) @@ -113,7 +113,7 @@ describe('Mail service', () => { ) expect(result).toEqual( expect.stringContaining( - '<a href="https://user-ecolyo.test.com/#/options" style="color: #ffffff">Unsubscribe</a>' + '<a href="https://user-ecolyo.test.com/#/unsubscribe" style="color: #ffffff">Unsubscribe</a>' ) ) }) -- GitLab