2018-05-05 17:11:53 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
|
|
|
|
let mapDispatchToProps
|
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
updateSendTokenBalance: sinon.spy(),
|
2018-05-20 02:37:44 +02:00
|
|
|
updateGasData: sinon.spy(),
|
2018-05-05 17:11:53 +02:00
|
|
|
setGasTotal: sinon.spy(),
|
|
|
|
}
|
|
|
|
const duckActionSpies = {
|
|
|
|
updateSendErrors: sinon.spy(),
|
2018-06-29 19:19:40 +02:00
|
|
|
resetSendState: sinon.spy(),
|
2018-05-05 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proxyquire('../send.container.js', {
|
|
|
|
'react-redux': {
|
2019-12-08 04:10:47 +01:00
|
|
|
connect: (_, md) => {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToProps = md
|
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
2020-08-14 13:47:02 +02:00
|
|
|
'react-router-dom': { withRouter: () => undefined },
|
2020-02-24 23:58:26 +01:00
|
|
|
'redux': { compose: (_, arg2) => () => arg2() },
|
2019-04-17 21:15:13 +02:00
|
|
|
'../../store/actions': actionSpies,
|
|
|
|
'../../ducks/send/send.duck': duckActionSpies,
|
2018-05-05 17:11:53 +02:00
|
|
|
'./send.utils.js': {
|
|
|
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
|
|
|
},
|
2019-04-11 19:50:03 +02:00
|
|
|
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send 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)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateAndSetGasLimit()', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
const mockProps = {
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit: 'mockBlockGasLimit',
|
2018-05-05 17:11:53 +02:00
|
|
|
editingTransactionId: '0x2',
|
|
|
|
gasLimit: '0x3',
|
|
|
|
gasPrice: '0x4',
|
|
|
|
selectedAddress: '0x4',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: '0x1' },
|
2018-05-23 18:43:25 +02:00
|
|
|
to: 'mockTo',
|
|
|
|
value: 'mockValue',
|
2018-09-27 15:46:24 +02:00
|
|
|
data: undefined,
|
2018-05-05 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch a setGasTotal action when editingTransactionId is truthy', function () {
|
2018-09-13 10:47:05 +02:00
|
|
|
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps)
|
2018-05-05 17:11:53 +02:00
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.equal(
|
|
|
|
actionSpies.setGasTotal.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
'0x30x4',
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch an updateGasData action when editingTransactionId is falsy', function () {
|
2020-05-29 19:46:10 +02:00
|
|
|
const { gasPrice, selectedAddress, sendToken, blockGasLimit, to, value, data } = mockProps
|
2018-09-13 10:47:05 +02:00
|
|
|
mapDispatchToPropsObject.updateAndSetGasLimit(
|
2020-07-14 17:20:41 +02:00
|
|
|
Object.assign({}, mockProps, { editingTransactionId: false }),
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
2018-05-20 02:37:44 +02:00
|
|
|
actionSpies.updateGasData.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
{ gasPrice, selectedAddress, sendToken, blockGasLimit, to, value, data },
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateSendTokenBalance()', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
const mockProps = {
|
|
|
|
address: '0x10',
|
|
|
|
tokenContract: '0x00a',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: '0x1' },
|
2018-05-05 17:11:53 +02:00
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch an action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.updateSendTokenBalance(Object.assign({}, mockProps))
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.updateSendTokenBalance.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
mockProps,
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateSendErrors()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.updateSendErrors('mockError')
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.equal(
|
|
|
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
'mockError',
|
2018-05-05 17:11:53 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('resetSendState()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-06-29 19:19:40 +02:00
|
|
|
mapDispatchToPropsObject.resetSendState()
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.equal(
|
|
|
|
duckActionSpies.resetSendState.getCall(0).args.length,
|
2020-07-14 17:20:41 +02:00
|
|
|
0,
|
2018-06-29 19:19:40 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
})
|