2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-06-10 19:53:15 +02:00
|
|
|
import { showModal } from '../../../../store/actions';
|
2021-04-15 20:01:46 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
resetCustomData,
|
|
|
|
setCustomGasPrice,
|
|
|
|
setCustomGasLimit,
|
|
|
|
} from '../../../../ducks/gas/gas.duck';
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
import { updateGasPrice, updateGasLimit } from '../../../../ducks/send';
|
2021-04-15 20:01:46 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
|
|
|
let mergeProps;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
jest.mock('react-redux', () => ({
|
|
|
|
connect: (_, md, mp) => {
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
mergeProps = mp;
|
|
|
|
return () => ({});
|
2019-02-06 01:24:28 +01:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
jest.mock('../../../../ducks/send', () => {
|
|
|
|
const original = jest.requireActual('../../../../ducks/send');
|
|
|
|
return {
|
|
|
|
...original,
|
|
|
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
|
|
|
updateGasPrice: jest.fn(),
|
|
|
|
updateGasLimit: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
|
|
|
|
jest.mock('../../send.utils.js', () => ({
|
|
|
|
isBalanceSufficient: ({ amount, gasTotal, balance, conversionRate }) =>
|
|
|
|
`${amount}:${gasTotal}:${balance}:${conversionRate}`,
|
|
|
|
|
|
|
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../store/actions', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
showModal: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../ducks/gas/gas.duck', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
resetCustomData: jest.fn(),
|
|
|
|
setCustomGasPrice: jest.fn(),
|
|
|
|
setCustomGasLimit: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
require('./send-gas-row.container.js');
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send-gas-row container', () => {
|
|
|
|
describe('mapDispatchToProps()', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let dispatchSpy;
|
|
|
|
let mapDispatchToPropsObject;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatchSpy = sinon.spy();
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-07-31 03:29:21 +02:00
|
|
|
describe('showLegacyCustomizeGasModal()', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-07-31 03:29:21 +02:00
|
|
|
mapDispatchToPropsObject.showLegacyCustomizeGasModal();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(showModal).toHaveBeenCalledWith({
|
2021-07-31 03:29:21 +02:00
|
|
|
name: 'LEGACY_CUSTOMIZE_GAS',
|
2020-11-03 00:41:28 +01:00
|
|
|
hideBasic: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
describe('updateGasPrice()', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
mapDispatchToPropsObject.updateGasPrice('mockNewPrice');
|
|
|
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
|
|
|
expect(updateGasPrice).toHaveBeenCalled();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setCustomGasPrice).toHaveBeenCalledWith('mockNewPrice');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2019-02-06 01:24:28 +01:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
describe('updateGasLimit()', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
mapDispatchToPropsObject.updateGasLimit('mockNewLimit');
|
|
|
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
|
|
|
expect(updateGasLimit).toHaveBeenCalled();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(setCustomGasLimit).toHaveBeenCalledWith('mockNewLimit');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('resetCustomData()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.resetCustomData();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(resetCustomData).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('mergeProps', () => {
|
|
|
|
it('should return the expected props when isConfirm is true', () => {
|
2020-02-11 17:51:13 +01:00
|
|
|
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 = {
|
2021-06-23 23:35:25 +02:00
|
|
|
updateGasPrice: sinon.spy(),
|
2018-09-20 06:16:43 +02:00
|
|
|
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-04-15 20:01:46 +02:00
|
|
|
expect(result.someOtherStateProp).toStrictEqual('baz');
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('foo');
|
|
|
|
expect(
|
2020-11-03 00:41:28 +01:00
|
|
|
result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual('bar');
|
|
|
|
expect(result.someOwnProp).toStrictEqual(123);
|
2021-02-04 19:15:23 +01:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(dispatchProps.updateGasPrice.callCount).toStrictEqual(0);
|
|
|
|
result.gasPriceButtonGroupProps.handleGasPriceSelection({
|
|
|
|
gasPrice: undefined,
|
|
|
|
});
|
|
|
|
expect(dispatchProps.updateGasPrice.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
result.someOtherDispatchProp();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|