2018-05-05 17:11:53 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
|
|
|
|
let mapDispatchToProps
|
2018-09-20 06:16:43 +02:00
|
|
|
let mergeProps
|
2018-05-05 17:11:53 +02:00
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
showModal: sinon.spy(),
|
2018-09-20 06:16:43 +02:00
|
|
|
setGasPrice: sinon.spy(),
|
2019-02-06 01:24:28 +01:00
|
|
|
setGasTotal: sinon.spy(),
|
|
|
|
setGasLimit: sinon.spy(),
|
2018-09-20 06:16:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const sendDuckSpies = {
|
|
|
|
showGasButtonGroup: sinon.spy(),
|
2018-05-05 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
2018-11-05 18:01:46 +01:00
|
|
|
const gasDuckSpies = {
|
|
|
|
resetCustomData: sinon.spy(),
|
2019-02-06 18:13:45 +01:00
|
|
|
setCustomGasPrice: sinon.spy(),
|
|
|
|
setCustomGasLimit: sinon.spy(),
|
2018-11-05 18:01:46 +01:00
|
|
|
}
|
|
|
|
|
2018-05-05 17:11:53 +02:00
|
|
|
proxyquire('../send-gas-row.container.js', {
|
|
|
|
'react-redux': {
|
2019-12-08 04:10:47 +01:00
|
|
|
connect: (_, md, mp) => {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToProps = md
|
2018-09-20 06:16:43 +02:00
|
|
|
mergeProps = mp
|
2018-05-05 17:11:53 +02:00
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
2020-05-04 21:06:28 +02:00
|
|
|
'../../../../selectors': {
|
2020-05-04 17:22:34 +02:00
|
|
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
2019-02-06 01:24:28 +01:00
|
|
|
},
|
|
|
|
'../../send.utils.js': {
|
|
|
|
isBalanceSufficient: ({
|
|
|
|
amount,
|
|
|
|
gasTotal,
|
|
|
|
balance,
|
|
|
|
conversionRate,
|
|
|
|
}) => `${amount}:${gasTotal}:${balance}:${conversionRate}`,
|
|
|
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2019-04-17 21:15:13 +02:00
|
|
|
'../../../../store/actions': actionSpies,
|
|
|
|
'../../../../ducks/send/send.duck': sendDuckSpies,
|
|
|
|
'../../../../ducks/gas/gas.duck': gasDuckSpies,
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send-gas-row container', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('mapDispatchToProps()', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
let dispatchSpy
|
|
|
|
let mapDispatchToPropsObject
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
dispatchSpy = sinon.spy()
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
|
2019-02-06 01:24:28 +01:00
|
|
|
actionSpies.setGasTotal.resetHistory()
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('showCustomizeGasModal()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.showCustomizeGasModal()
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.showModal.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
{ name: 'CUSTOMIZE_GAS', hideBasic: true },
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('setGasPrice()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2019-02-06 01:24:28 +01:00
|
|
|
mapDispatchToPropsObject.setGasPrice('mockNewPrice', 'mockLimit')
|
2019-02-06 18:13:45 +01:00
|
|
|
assert(dispatchSpy.calledThrice)
|
2018-09-20 06:16:43 +02:00
|
|
|
assert(actionSpies.setGasPrice.calledOnce)
|
2019-02-08 14:50:25 +01:00
|
|
|
assert.equal(actionSpies.setGasPrice.getCall(0).args[0], 'mockNewPrice')
|
|
|
|
assert.equal(gasDuckSpies.setCustomGasPrice.getCall(0).args[0], 'mockNewPrice')
|
2019-02-06 01:24:28 +01:00
|
|
|
assert(actionSpies.setGasTotal.calledOnce)
|
2019-02-08 14:50:25 +01:00
|
|
|
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockLimitmockNewPrice')
|
2019-02-06 01:24:28 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('setGasLimit()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2019-02-06 01:24:28 +01:00
|
|
|
mapDispatchToPropsObject.setGasLimit('mockNewLimit', 'mockPrice')
|
2019-02-06 18:13:45 +01:00
|
|
|
assert(dispatchSpy.calledThrice)
|
2019-02-06 01:24:28 +01:00
|
|
|
assert(actionSpies.setGasLimit.calledOnce)
|
2019-02-08 14:50:25 +01:00
|
|
|
assert.equal(actionSpies.setGasLimit.getCall(0).args[0], 'mockNewLimit')
|
|
|
|
assert.equal(gasDuckSpies.setCustomGasLimit.getCall(0).args[0], 'mockNewLimit')
|
2019-02-06 01:24:28 +01:00
|
|
|
assert(actionSpies.setGasTotal.calledOnce)
|
2019-02-08 14:50:25 +01:00
|
|
|
assert.equal(actionSpies.setGasTotal.getCall(0).args[0], 'mockNewLimitmockPrice')
|
2018-09-20 06:16:43 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('showGasButtonGroup()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-09-20 06:16:43 +02:00
|
|
|
mapDispatchToPropsObject.showGasButtonGroup()
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert(sendDuckSpies.showGasButtonGroup.calledOnce)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('resetCustomData()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-11-05 18:01:46 +01:00
|
|
|
mapDispatchToPropsObject.resetCustomData()
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert(gasDuckSpies.resetCustomData.calledOnce)
|
|
|
|
})
|
|
|
|
})
|
2018-09-20 06:16:43 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('mergeProps', function () {
|
|
|
|
it('should return the expected props when isConfirm is true', function () {
|
|
|
|
const stateProps = {
|
2018-09-20 06:16:43 +02:00
|
|
|
gasPriceButtonGroupProps: {
|
|
|
|
someGasPriceButtonGroupProp: 'foo',
|
|
|
|
anotherGasPriceButtonGroupProp: 'bar',
|
|
|
|
},
|
|
|
|
someOtherStateProp: 'baz',
|
|
|
|
}
|
2020-02-11 17:51:13 +01:00
|
|
|
const dispatchProps = {
|
2018-09-20 06:16:43 +02:00
|
|
|
setGasPrice: sinon.spy(),
|
|
|
|
someOtherDispatchProp: sinon.spy(),
|
|
|
|
}
|
2020-02-11 17:51:13 +01:00
|
|
|
const ownProps = { someOwnProp: 123 }
|
2018-09-20 06:16:43 +02:00
|
|
|
const result = mergeProps(stateProps, dispatchProps, ownProps)
|
|
|
|
|
|
|
|
assert.equal(result.someOtherStateProp, 'baz')
|
|
|
|
assert.equal(result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp, 'foo')
|
|
|
|
assert.equal(result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp, 'bar')
|
|
|
|
assert.equal(result.someOwnProp, 123)
|
|
|
|
|
|
|
|
assert.equal(dispatchProps.setGasPrice.callCount, 0)
|
|
|
|
result.gasPriceButtonGroupProps.handleGasPriceSelection()
|
|
|
|
assert.equal(dispatchProps.setGasPrice.callCount, 1)
|
|
|
|
|
|
|
|
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 0)
|
|
|
|
result.someOtherDispatchProp()
|
|
|
|
assert.equal(dispatchProps.someOtherDispatchProp.callCount, 1)
|
|
|
|
})
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
})
|