2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
|
|
|
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(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-20 06:16:43 +02:00
|
|
|
|
|
|
|
const sendDuckSpies = {
|
|
|
|
showGasButtonGroup: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
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) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToProps = md;
|
|
|
|
mergeProps = mp;
|
|
|
|
return () => ({});
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
},
|
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': {
|
2020-11-03 00:41:28 +01:00
|
|
|
isBalanceSufficient: ({ amount, gasTotal, balance, conversionRate }) =>
|
|
|
|
`${amount}:${gasTotal}:${balance}:${conversionRate}`,
|
2019-02-06 01:24:28 +01:00
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send-gas-row container', function () {
|
|
|
|
describe('mapDispatchToProps()', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let dispatchSpy;
|
|
|
|
let mapDispatchToPropsObject;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatchSpy = sinon.spy();
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
|
|
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
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,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
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 () {
|
2020-11-13 00:04:29 +01:00
|
|
|
mapDispatchToPropsObject.setGasPrice({
|
|
|
|
gasPrice: 'mockNewPrice',
|
|
|
|
gasLimit: 'mockLimit',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
assert(dispatchSpy.calledThrice);
|
|
|
|
assert(actionSpies.setGasPrice.calledOnce);
|
2020-11-13 00:04:29 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
actionSpies.setGasPrice.getCall(0).args[0],
|
|
|
|
'mockNewPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-13 00:04:29 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
gasDuckSpies.setCustomGasPrice.getCall(0).args[0],
|
|
|
|
'mockNewPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
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',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
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',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-13 00:04:29 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
gasDuckSpies.setCustomGasLimit.getCall(0).args[0],
|
|
|
|
'mockNewLimit',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
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',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
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 () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.showGasButtonGroup();
|
|
|
|
assert(dispatchSpy.calledOnce);
|
|
|
|
assert(sendDuckSpies.showGasButtonGroup.calledOnce);
|
|
|
|
});
|
|
|
|
});
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('resetCustomData()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +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',
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 17:51:13 +01:00
|
|
|
const dispatchProps = {
|
2018-09-20 06:16:43 +02:00
|
|
|
setGasPrice: sinon.spy(),
|
|
|
|
someOtherDispatchProp: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
const ownProps = { someOwnProp: 123 };
|
|
|
|
const result = mergeProps(stateProps, dispatchProps, ownProps);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(result.someOtherStateProp, 'baz');
|
2020-11-13 00:04:29 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp,
|
|
|
|
'foo',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-13 00:04:29 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp,
|
|
|
|
'bar',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
assert.strictEqual(result.someOwnProp, 123);
|
|
|
|
|
|
|
|
assert.strictEqual(dispatchProps.setGasPrice.callCount, 0);
|
|
|
|
result.gasPriceButtonGroupProps.handleGasPriceSelection();
|
|
|
|
assert.strictEqual(dispatchProps.setGasPrice.callCount, 1);
|
|
|
|
|
|
|
|
assert.strictEqual(dispatchProps.someOtherDispatchProp.callCount, 0);
|
|
|
|
result.someOtherDispatchProp();
|
|
|
|
assert.strictEqual(dispatchProps.someOtherDispatchProp.callCount, 1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|