1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-12 12:47:14 +01:00
metamask-extension/ui/app/pages/send/send-content/send-gas-row/tests/send-gas-row-container.test.js

167 lines
5.0 KiB
JavaScript
Raw Normal View History

import assert from 'assert'
import proxyquire from 'proxyquire'
import sinon from 'sinon'
let mapDispatchToProps
let mergeProps
const actionSpies = {
showModal: sinon.spy(),
setGasPrice: sinon.spy(),
setGasTotal: sinon.spy(),
setGasLimit: sinon.spy(),
}
const sendDuckSpies = {
showGasButtonGroup: sinon.spy(),
}
const gasDuckSpies = {
resetCustomData: sinon.spy(),
setCustomGasPrice: sinon.spy(),
setCustomGasLimit: sinon.spy(),
}
proxyquire('../send-gas-row.container.js', {
'react-redux': {
connect: (_, md, mp) => {
mapDispatchToProps = md
mergeProps = mp
return () => ({})
},
},
'../../../../selectors': {
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
},
'../../send.utils.js': {
2020-11-03 00:41:28 +01:00
isBalanceSufficient: ({ amount, gasTotal, balance, conversionRate }) =>
`${amount}:${gasTotal}:${balance}:${conversionRate}`,
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
},
'../../../../store/actions': actionSpies,
'../../../../ducks/send/send.duck': sendDuckSpies,
'../../../../ducks/gas/gas.duck': gasDuckSpies,
})
describe('send-gas-row container', function () {
describe('mapDispatchToProps()', function () {
let dispatchSpy
let mapDispatchToPropsObject
beforeEach(function () {
dispatchSpy = sinon.spy()
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
actionSpies.setGasTotal.resetHistory()
})
describe('showCustomizeGasModal()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.showCustomizeGasModal()
assert(dispatchSpy.calledOnce)
2020-11-13 00:04:29 +01:00
assert.deepStrictEqual(actionSpies.showModal.getCall(0).args[0], {
2020-11-03 00:41:28 +01:00
name: 'CUSTOMIZE_GAS',
hideBasic: true,
})
})
})
describe('setGasPrice()', function () {
it('should dispatch an action', function () {
2020-11-13 00:04:29 +01:00
mapDispatchToPropsObject.setGasPrice({
gasPrice: 'mockNewPrice',
gasLimit: 'mockLimit',
})
assert(dispatchSpy.calledThrice)
assert(actionSpies.setGasPrice.calledOnce)
2020-11-13 00:04:29 +01:00
assert.strictEqual(
actionSpies.setGasPrice.getCall(0).args[0],
'mockNewPrice',
)
assert.strictEqual(
2020-11-03 00:41:28 +01:00
gasDuckSpies.setCustomGasPrice.getCall(0).args[0],
'mockNewPrice',
)
assert(actionSpies.setGasTotal.calledOnce)
2020-11-13 00:04:29 +01:00
assert.strictEqual(
2020-11-03 00:41:28 +01:00
actionSpies.setGasTotal.getCall(0).args[0],
'mockLimitmockNewPrice',
)
})
})
describe('setGasLimit()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.setGasLimit('mockNewLimit', 'mockPrice')
assert(dispatchSpy.calledThrice)
assert(actionSpies.setGasLimit.calledOnce)
2020-11-13 00:04:29 +01:00
assert.strictEqual(
actionSpies.setGasLimit.getCall(0).args[0],
'mockNewLimit',
)
assert.strictEqual(
2020-11-03 00:41:28 +01:00
gasDuckSpies.setCustomGasLimit.getCall(0).args[0],
'mockNewLimit',
)
assert(actionSpies.setGasTotal.calledOnce)
2020-11-13 00:04:29 +01:00
assert.strictEqual(
2020-11-03 00:41:28 +01:00
actionSpies.setGasTotal.getCall(0).args[0],
'mockNewLimitmockPrice',
)
})
})
describe('showGasButtonGroup()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.showGasButtonGroup()
assert(dispatchSpy.calledOnce)
assert(sendDuckSpies.showGasButtonGroup.calledOnce)
})
})
describe('resetCustomData()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.resetCustomData()
assert(dispatchSpy.calledOnce)
assert(gasDuckSpies.resetCustomData.calledOnce)
})
})
})
describe('mergeProps', function () {
it('should return the expected props when isConfirm is true', function () {
const stateProps = {
gasPriceButtonGroupProps: {
someGasPriceButtonGroupProp: 'foo',
anotherGasPriceButtonGroupProp: 'bar',
},
someOtherStateProp: 'baz',
}
const dispatchProps = {
setGasPrice: sinon.spy(),
someOtherDispatchProp: sinon.spy(),
}
const ownProps = { someOwnProp: 123 }
const result = mergeProps(stateProps, dispatchProps, ownProps)
2020-11-13 00:04:29 +01:00
assert.strictEqual(result.someOtherStateProp, 'baz')
assert.strictEqual(
2020-11-03 00:41:28 +01:00
result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp,
'foo',
)
2020-11-13 00:04:29 +01:00
assert.strictEqual(
2020-11-03 00:41:28 +01:00
result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp,
'bar',
)
2020-11-13 00:04:29 +01:00
assert.strictEqual(result.someOwnProp, 123)
2020-11-13 00:04:29 +01:00
assert.strictEqual(dispatchProps.setGasPrice.callCount, 0)
result.gasPriceButtonGroupProps.handleGasPriceSelection()
2020-11-13 00:04:29 +01:00
assert.strictEqual(dispatchProps.setGasPrice.callCount, 1)
2020-11-13 00:04:29 +01:00
assert.strictEqual(dispatchProps.someOtherDispatchProp.callCount, 0)
result.someOtherDispatchProp()
2020-11-13 00:04:29 +01:00
assert.strictEqual(dispatchProps.someOtherDispatchProp.callCount, 1)
})
})
})