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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
import assert from 'assert'
import SendReducer, {
openFromDropdown,
closeFromDropdown,
openToDropdown,
closeToDropdown,
updateSendErrors,
showGasButtonGroup,
hideGasButtonGroup,
} from '../send.duck.js'
describe('Send Duck', () => {
const mockState = {
send: {
mockProp: 123,
},
}
const initState = {
fromDropdownOpen: false,
toDropdownOpen: false,
errors: {},
gasButtonGroupShown: true,
}
const OPEN_FROM_DROPDOWN = 'metamask/send/OPEN_FROM_DROPDOWN'
const CLOSE_FROM_DROPDOWN = 'metamask/send/CLOSE_FROM_DROPDOWN'
const OPEN_TO_DROPDOWN = 'metamask/send/OPEN_TO_DROPDOWN'
const CLOSE_TO_DROPDOWN = 'metamask/send/CLOSE_TO_DROPDOWN'
const UPDATE_SEND_ERRORS = 'metamask/send/UPDATE_SEND_ERRORS'
const RESET_SEND_STATE = 'metamask/send/RESET_SEND_STATE'
const SHOW_GAS_BUTTON_GROUP = 'metamask/send/SHOW_GAS_BUTTON_GROUP'
const HIDE_GAS_BUTTON_GROUP = 'metamask/send/HIDE_GAS_BUTTON_GROUP'
describe('SendReducer()', () => {
it('should initialize state', () => {
assert.deepEqual(
SendReducer({}),
initState
)
})
it('should return state unchanged if it does not match a dispatched actions type', () => {
assert.deepEqual(
SendReducer(mockState, {
type: 'someOtherAction',
value: 'someValue',
}),
Object.assign({}, mockState.send)
)
})
it('should set fromDropdownOpen to true when receiving a OPEN_FROM_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: OPEN_FROM_DROPDOWN,
}),
Object.assign({fromDropdownOpen: true}, mockState.send)
)
})
it('should return a new object (and not just modify the existing state object)', () => {
assert.deepEqual(SendReducer(mockState), mockState.send)
assert.notEqual(SendReducer(mockState), mockState.send)
})
it('should set fromDropdownOpen to false when receiving a CLOSE_FROM_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: CLOSE_FROM_DROPDOWN,
}),
Object.assign({fromDropdownOpen: false}, mockState.send)
)
})
it('should set toDropdownOpen to true when receiving a OPEN_TO_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: OPEN_TO_DROPDOWN,
}),
Object.assign({toDropdownOpen: true}, mockState.send)
)
})
it('should set toDropdownOpen to false when receiving a CLOSE_TO_DROPDOWN action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: CLOSE_TO_DROPDOWN,
}),
Object.assign({toDropdownOpen: false}, mockState.send)
)
})
it('should set gasButtonGroupShown to true when receiving a SHOW_GAS_BUTTON_GROUP action', () => {
assert.deepEqual(
SendReducer(Object.assign({}, mockState, { gasButtonGroupShown: false }), {
type: SHOW_GAS_BUTTON_GROUP,
}),
Object.assign({gasButtonGroupShown: true}, mockState.send)
)
})
it('should set gasButtonGroupShown to false when receiving a HIDE_GAS_BUTTON_GROUP action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: HIDE_GAS_BUTTON_GROUP,
}),
Object.assign({gasButtonGroupShown: false}, mockState.send)
)
})
it('should extend send.errors with the value of a UPDATE_SEND_ERRORS action', () => {
const modifiedMockState = Object.assign({}, mockState, {
send: {
errors: {
someError: false,
},
},
})
assert.deepEqual(
SendReducer(modifiedMockState, {
type: UPDATE_SEND_ERRORS,
value: { someOtherError: true },
}),
Object.assign({}, modifiedMockState.send, {
errors: {
someError: false,
someOtherError: true,
},
})
)
})
it('should return the initial state in response to a RESET_SEND_STATE action', () => {
assert.deepEqual(
SendReducer(mockState, {
type: RESET_SEND_STATE,
}),
Object.assign({}, initState)
)
})
})
describe('openFromDropdown', () => {
assert.deepEqual(
openFromDropdown(),
{ type: OPEN_FROM_DROPDOWN }
)
})
describe('closeFromDropdown', () => {
assert.deepEqual(
closeFromDropdown(),
{ type: CLOSE_FROM_DROPDOWN }
)
})
describe('openToDropdown', () => {
assert.deepEqual(
openToDropdown(),
{ type: OPEN_TO_DROPDOWN }
)
})
describe('closeToDropdown', () => {
assert.deepEqual(
closeToDropdown(),
{ type: CLOSE_TO_DROPDOWN }
)
})
describe('showGasButtonGroup', () => {
assert.deepEqual(
showGasButtonGroup(),
{ type: SHOW_GAS_BUTTON_GROUP }
)
})
describe('hideGasButtonGroup', () => {
assert.deepEqual(
hideGasButtonGroup(),
{ type: HIDE_GAS_BUTTON_GROUP }
)
})
describe('updateSendErrors', () => {
assert.deepEqual(
updateSendErrors('mockErrorObject'),
{ type: UPDATE_SEND_ERRORS, value: 'mockErrorObject' }
)
})
})
|