From f5c375989c9d3cec0a813253a19603eca04920a3 Mon Sep 17 00:00:00 2001 From: "guilhem.carron" <gcarron@grandlyon.com> Date: Thu, 8 Jul 2021 17:39:16 +0200 Subject: [PATCH] Add unsubsribe test --- src/components/Options/UnSubscribe.spec.tsx | 61 +++++++++++++++++++ .../__snapshots__/UnSubscribe.spec.tsx.snap | 18 ++++++ 2 files changed, 79 insertions(+) create mode 100644 src/components/Options/UnSubscribe.spec.tsx create mode 100644 src/components/Options/__snapshots__/UnSubscribe.spec.tsx.snap diff --git a/src/components/Options/UnSubscribe.spec.tsx b/src/components/Options/UnSubscribe.spec.tsx new file mode 100644 index 000000000..e77f60d6a --- /dev/null +++ b/src/components/Options/UnSubscribe.spec.tsx @@ -0,0 +1,61 @@ +import React from 'react' +import { mount } from 'enzyme' +import { Provider } from 'react-redux' +import { + createMockStore, + mockInitialEcolyoState, +} from '../../../tests/__mocks__/store' +import * as profileActions from 'store/profile/profile.actions' +import UnSubscribe from './UnSubscribe' +import { Button } from '@material-ui/core' + +jest.mock('cozy-ui/transpiled/react/I18n', () => { + return { + useI18n: jest.fn(() => { + return { + t: (str: string) => str, + } + }), + } +}) + +const mockUpdateProfile = jest.fn() +jest.mock('services/profile.service', () => { + return jest.fn(() => { + return { + updateProfile: mockUpdateProfile, + } + }) +}) +// const useDispatchSpy = jest.spyOn(reactRedux, 'useDispatch') +const updateProfileSpy = jest.spyOn(profileActions, 'updateProfile') + +describe('UnSubscribe component', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let store: any + beforeEach(() => { + store = createMockStore(mockInitialEcolyoState) + updateProfileSpy.mockClear() + }) + + it('should be rendered correctly', () => { + const wrapper = mount( + <Provider store={store}> + <UnSubscribe /> + </Provider> + ).getElement() + expect(wrapper).toMatchSnapshot() + }) + + it('should click on button and deactivate report', () => { + const wrapper = mount( + <Provider store={store}> + <UnSubscribe /> + </Provider> + ) + wrapper.find(Button).simulate('click') + expect(updateProfileSpy).toHaveBeenCalledWith({ + sendAnalysisNotification: false, + }) + }) +}) diff --git a/src/components/Options/__snapshots__/UnSubscribe.spec.tsx.snap b/src/components/Options/__snapshots__/UnSubscribe.spec.tsx.snap new file mode 100644 index 000000000..fc7a7ac67 --- /dev/null +++ b/src/components/Options/__snapshots__/UnSubscribe.spec.tsx.snap @@ -0,0 +1,18 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`UnSubscribe component should be rendered correctly 1`] = ` +<Provider + store={ + Object { + "clearActions": [Function], + "dispatch": [Function], + "getActions": [Function], + "getState": [Function], + "replaceReducer": [Function], + "subscribe": [Function], + } + } +> + <UnSubscribe /> +</Provider> +`; -- GitLab