2018-05-05 17:11:53 +02:00
|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
|
|
|
|
let mapStateToProps
|
|
|
|
let mapDispatchToProps
|
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
setMaxModeTo: sinon.spy(),
|
|
|
|
updateSendAmount: sinon.spy(),
|
|
|
|
}
|
|
|
|
const duckActionSpies = {
|
|
|
|
updateSendErrors: sinon.spy(),
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyquire('../amount-max-button.container.js', {
|
|
|
|
'react-redux': {
|
|
|
|
connect: (ms, md) => {
|
|
|
|
mapStateToProps = ms
|
|
|
|
mapDispatchToProps = md
|
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
2020-05-04 21:06:28 +02:00
|
|
|
'../../../../../selectors': {
|
2018-05-05 17:11:53 +02:00
|
|
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
2020-05-29 19:46:10 +02:00
|
|
|
getSendToken: (s) => `mockSendToken:${s}`,
|
2018-05-05 17:11:53 +02:00
|
|
|
getSendFromBalance: (s) => `mockBalance:${s}`,
|
|
|
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
2020-05-04 17:22:34 +02:00
|
|
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
2020-05-04 21:06:28 +02:00
|
|
|
getBasicGasEstimateLoadingStatus: (s) => `mockButtonDataLoading:${s}`,
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2020-11-03 00:41:28 +01:00
|
|
|
'./amount-max-button.utils.js': {
|
|
|
|
calcMaxAmount: (mockObj) => mockObj.val + 1,
|
|
|
|
},
|
2019-04-17 21:15:13 +02:00
|
|
|
'../../../../../store/actions': actionSpies,
|
|
|
|
'../../../../../ducks/send/send.duck': duckActionSpies,
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('amount-max-button container', function () {
|
|
|
|
describe('mapStateToProps()', function () {
|
|
|
|
it('should map the correct properties to props', function () {
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(mapStateToProps('mockState'), {
|
2018-05-05 17:11:53 +02:00
|
|
|
balance: 'mockBalance:mockState',
|
2019-05-20 18:38:08 +02:00
|
|
|
buttonDataLoading: 'mockButtonDataLoading:mockState',
|
2018-05-05 17:11:53 +02:00
|
|
|
gasTotal: 'mockGasTotal:mockState',
|
|
|
|
maxModeOn: 'mockMaxModeOn:mockState',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: 'mockSendToken:mockState',
|
2018-05-05 17:11:53 +02:00
|
|
|
tokenBalance: 'mockTokenBalance:mockState',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
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('setAmountToMax()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.setAmountToMax({ val: 11, foo: 'bar' })
|
|
|
|
assert(dispatchSpy.calledTwice)
|
|
|
|
assert(duckActionSpies.updateSendErrors.calledOnce)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
|
|
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
amount: null,
|
|
|
|
},
|
|
|
|
)
|
2018-05-05 17:11:53 +02:00
|
|
|
assert(actionSpies.updateSendAmount.calledOnce)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(actionSpies.updateSendAmount.getCall(0).args[0], 12)
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('setMaxModeTo()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2018-05-05 17:11:53 +02:00
|
|
|
mapDispatchToPropsObject.setMaxModeTo('mockVal')
|
|
|
|
assert(dispatchSpy.calledOnce)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
actionSpies.setMaxModeTo.getCall(0).args[0],
|
|
|
|
'mockVal',
|
|
|
|
)
|
2018-05-05 17:11:53 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|