Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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,
})
})
})