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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
import React from 'react'
import assert from 'assert'
import shallow from '../../../../../lib/shallow-with-context'
import sinon from 'sinon'
import GasModalPageContainer from '../gas-modal-page-container.component.js'
import PageContainer from '../../../page-container'
import { Tab } from '../../../tabs'
const propsMethodSpies = {
cancelAndClose: sinon.spy(),
onSubmit: sinon.spy(),
}
const mockGasPriceButtonGroupProps = {
buttonDataLoading: false,
className: 'gas-price-button-group',
gasButtonInfo: [
{
feeInPrimaryCurrency: '$0.52',
feeInSecondaryCurrency: '0.0048 ETH',
timeEstimate: '~ 1 min 0 sec',
priceInHexWei: '0xa1b2c3f',
},
{
feeInPrimaryCurrency: '$0.39',
feeInSecondaryCurrency: '0.004 ETH',
timeEstimate: '~ 1 min 30 sec',
priceInHexWei: '0xa1b2c39',
},
{
feeInPrimaryCurrency: '$0.30',
feeInSecondaryCurrency: '0.00354 ETH',
timeEstimate: '~ 2 min 1 sec',
priceInHexWei: '0xa1b2c30',
},
],
handleGasPriceSelection: 'mockSelectionFunction',
noButtonActiveByDefault: true,
showCheck: true,
newTotalFiat: 'mockNewTotalFiat',
newTotalEth: 'mockNewTotalEth',
}
const mockInfoRowProps = {
originalTotalFiat: 'mockOriginalTotalFiat',
originalTotalEth: 'mockOriginalTotalEth',
newTotalFiat: 'mockNewTotalFiat',
newTotalEth: 'mockNewTotalEth',
sendAmount: 'mockSendAmount',
transactionFee: 'mockTransactionFee',
}
const GP = GasModalPageContainer.prototype
describe('GasModalPageContainer Component', function () {
let wrapper
beforeEach(() => {
wrapper = shallow(<GasModalPageContainer
cancelAndClose={propsMethodSpies.cancelAndClose}
onSubmit={propsMethodSpies.onSubmit}
updateCustomGasPrice={() => 'mockupdateCustomGasPrice'}
updateCustomGasLimit={() => 'mockupdateCustomGasLimit'}
customGasPrice={21}
customGasLimit={54321}
gasPriceButtonGroupProps={mockGasPriceButtonGroupProps}
infoRowProps={mockInfoRowProps}
customGasPriceInHex={'mockCustomGasPriceInHex'}
customGasLimitInHex={'mockCustomGasLimitInHex'}
/>, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
})
afterEach(() => {
propsMethodSpies.cancelAndClose.resetHistory()
})
describe('render', () => {
it('should render a PageContainer compenent', () => {
assert.equal(wrapper.find(PageContainer).length, 1)
})
it('should pass correct props to PageContainer', () => {
const {
title,
subtitle,
disabled,
} = wrapper.find(PageContainer).props()
assert.equal(title, 'customGas')
assert.equal(subtitle, 'customGasSubTitle')
assert.equal(disabled, false)
})
it('should pass the correct onCancel and onClose methods to PageContainer', () => {
const {
onCancel,
onClose,
} = wrapper.find(PageContainer).props()
assert.equal(propsMethodSpies.cancelAndClose.callCount, 0)
onCancel()
assert.equal(propsMethodSpies.cancelAndClose.callCount, 1)
onClose()
assert.equal(propsMethodSpies.cancelAndClose.callCount, 2)
})
it('should pass the correct renderTabs property to PageContainer', () => {
sinon.stub(GP, 'renderTabs').returns('mockTabs')
const renderTabsWrapperTester = shallow(<GasModalPageContainer />, { context: { t: (str1, str2) => str2 ? str1 + str2 : str1 } })
const { tabsComponent } = renderTabsWrapperTester.find(PageContainer).props()
assert.equal(tabsComponent, 'mockTabs')
GasModalPageContainer.prototype.renderTabs.restore()
})
})
describe('renderTabs', () => {
beforeEach(() => {
sinon.spy(GP, 'renderBasicTabContent')
sinon.spy(GP, 'renderAdvancedTabContent')
sinon.spy(GP, 'renderInfoRows')
})
afterEach(() => {
GP.renderBasicTabContent.restore()
GP.renderAdvancedTabContent.restore()
GP.renderInfoRows.restore()
})
it('should render a Tabs component with "Basic" and "Advanced" tabs', () => {
const renderTabsResult = wrapper.instance().renderTabs(mockInfoRowProps, {
gasPriceButtonGroupProps: mockGasPriceButtonGroupProps,
otherProps: 'mockAdvancedTabProps',
})
const renderedTabs = shallow(renderTabsResult)
assert.equal(renderedTabs.props().className, 'tabs')
const tabs = renderedTabs.find(Tab)
assert.equal(tabs.length, 2)
assert.equal(tabs.at(0).props().name, 'basic')
assert.equal(tabs.at(1).props().name, 'advanced')
assert.equal(tabs.at(0).childAt(0).props().className, 'gas-modal-content')
assert.equal(tabs.at(1).childAt(0).props().className, 'gas-modal-content')
})
it('should call renderBasicTabContent and renderAdvancedTabContent with the expected props', () => {
assert.equal(GP.renderBasicTabContent.callCount, 0)
assert.equal(GP.renderAdvancedTabContent.callCount, 0)
wrapper.instance().renderTabs(mockInfoRowProps, { gasPriceButtonGroupProps: mockGasPriceButtonGroupProps, otherProps: 'mockAdvancedTabProps' })
assert.equal(GP.renderBasicTabContent.callCount, 1)
assert.equal(GP.renderAdvancedTabContent.callCount, 1)
assert.deepEqual(GP.renderBasicTabContent.getCall(0).args[0], mockGasPriceButtonGroupProps)
assert.deepEqual(GP.renderAdvancedTabContent.getCall(0).args[0], { otherProps: 'mockAdvancedTabProps' })
})
it('should call renderInfoRows with the expected props', () => {
assert.equal(GP.renderInfoRows.callCount, 0)
wrapper.instance().renderTabs(mockInfoRowProps, { gasPriceButtonGroupProps: mockGasPriceButtonGroupProps, otherProps: 'mockAdvancedTabProps' })
assert.equal(GP.renderInfoRows.callCount, 2)
assert.deepEqual(GP.renderInfoRows.getCall(0).args, ['mockNewTotalFiat', 'mockNewTotalEth', 'mockSendAmount', 'mockTransactionFee'])
assert.deepEqual(GP.renderInfoRows.getCall(1).args, ['mockNewTotalFiat', 'mockNewTotalEth', 'mockSendAmount', 'mockTransactionFee'])
})
it('should not render the basic tab if hideBasic is true', () => {
const renderTabsResult = wrapper.instance().renderTabs(mockInfoRowProps, {
gasPriceButtonGroupProps: mockGasPriceButtonGroupProps,
otherProps: 'mockAdvancedTabProps',
hideBasic: true,
})
const renderedTabs = shallow(renderTabsResult)
const tabs = renderedTabs.find(Tab)
assert.equal(tabs.length, 1)
assert.equal(tabs.at(0).props().name, 'advanced')
})
})
describe('renderBasicTabContent', () => {
it('should render', () => {
const renderBasicTabContentResult = wrapper.instance().renderBasicTabContent(mockGasPriceButtonGroupProps)
assert.deepEqual(
renderBasicTabContentResult.props.gasPriceButtonGroupProps,
mockGasPriceButtonGroupProps
)
})
})
describe('renderAdvancedTabContent', () => {
it('should render with the correct props', () => {
const renderAdvancedTabContentResult = wrapper.instance().renderAdvancedTabContent({
convertThenUpdateCustomGasPrice: () => 'mockConvertThenUpdateCustomGasPrice',
convertThenUpdateCustomGasLimit: () => 'mockConvertThenUpdateCustomGasLimit',
customGasPrice: 123,
customGasLimit: 456,
newTotalFiat: '$0.30',
})
const advancedTabContentProps = renderAdvancedTabContentResult.props
assert.equal(advancedTabContentProps.updateCustomGasPrice(), 'mockConvertThenUpdateCustomGasPrice')
assert.equal(advancedTabContentProps.updateCustomGasLimit(), 'mockConvertThenUpdateCustomGasLimit')
assert.equal(advancedTabContentProps.customGasPrice, 123)
assert.equal(advancedTabContentProps.customGasLimit, 456)
assert.equal(advancedTabContentProps.timeRemaining, '1 min 31 sec')
assert.equal(advancedTabContentProps.totalFee, '$0.30')
})
})
describe('renderInfoRows', () => {
it('should render the info rows with the passed data', () => {
const baseClassName = 'gas-modal-content__info-row'
const renderedInfoRowsContainer = shallow(wrapper.instance().renderInfoRows(
'mockNewTotalFiat',
' mockNewTotalEth',
' mockSendAmount',
' mockTransactionFee'
))
assert(renderedInfoRowsContainer.childAt(0).hasClass(baseClassName))
const renderedInfoRows = renderedInfoRowsContainer.childAt(0).children()
assert.equal(renderedInfoRows.length, 4)
assert(renderedInfoRows.at(0).hasClass(`${baseClassName}__send-info`))
assert(renderedInfoRows.at(1).hasClass(`${baseClassName}__transaction-info`))
assert(renderedInfoRows.at(2).hasClass(`${baseClassName}__total-info`))
assert(renderedInfoRows.at(3).hasClass(`${baseClassName}__fiat-total-info`))
assert.equal(renderedInfoRows.at(0).text(), 'sendAmount mockSendAmount')
assert.equal(renderedInfoRows.at(1).text(), 'transactionFee mockTransactionFee')
assert.equal(renderedInfoRows.at(2).text(), 'newTotal mockNewTotalEth')
assert.equal(renderedInfoRows.at(3).text(), 'mockNewTotalFiat')
})
})
})
|