Newer
Older
import toJson from 'enzyme-to-json'
import React from 'react'
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { globalStateData } from '../../../../tests/__mocks__/globalStateData.mock'
import StepAddress from './StepAddress'
jest.mock('cozy-ui/transpiled/react/I18n', () => {
return {
useI18n: jest.fn(() => {
return {
t: (str: string) => str,
}
}),
}
})
const mockStore = configureStore([])
describe('StepAddress component', () => {
it('should be rendered correctly', () => {
const mockHandleChange = jest.fn()
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
const wrapper = mount(
<Provider store={store}>
<StepAddress
sgeState={globalStateData.sgeConnect}
onChange={mockHandleChange}
/>
</Provider>
)
expect(toJson(wrapper)).toMatchSnapshot()
})
it('should change address value', () => {
const mockHandleChange = jest.fn()
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
const wrapper = mount(
<Provider store={store}>
<StepAddress
sgeState={globalStateData.sgeConnect}
onChange={mockHandleChange}
/>
</Provider>
)
wrapper.find('#address').first().simulate('change')
expect(mockHandleChange).toHaveBeenCalledWith('address', '')
})
it('should change zipCode value', () => {
const mockHandleChange = jest.fn()
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
const wrapper = mount(
<Provider store={store}>
<StepAddress
sgeState={globalStateData.sgeConnect}
onChange={mockHandleChange}
/>
</Provider>
)
wrapper.find('#zipCode').first().simulate('change')
expect(mockHandleChange).toHaveBeenCalledWith('zipCode', '', 5)
})
it('should have an existing zipCode value', () => {
const mockHandleChange = jest.fn()
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
const wrapper = mount(
<Provider store={store}>
<StepAddress
sgeState={{ ...globalStateData.sgeConnect, zipCode: 69200 }}
onChange={mockHandleChange}
/>
</Provider>
)
expect(wrapper.find('#zipCode').first().props().value).toBe(69200)
})
it('should change city value', () => {
const mockHandleChange = jest.fn()
const store = mockStore({
ecolyo: {
global: globalStateData,
},
})
const wrapper = mount(
<Provider store={store}>
<StepAddress
sgeState={globalStateData.sgeConnect}
onChange={mockHandleChange}
/>
</Provider>
)
wrapper.find('#city').first().simulate('change')
expect(mockHandleChange).toHaveBeenCalledWith('city', '')
})
})