2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
import { hideModal, setGasLimit, setGasPrice } from '../../../../store/actions';
|
|
|
|
|
|
|
|
import {
|
|
|
|
setCustomGasPrice,
|
|
|
|
setCustomGasLimit,
|
|
|
|
resetCustomData,
|
|
|
|
} from '../../../../ducks/gas/gas.duck';
|
|
|
|
|
|
|
|
import { hideGasButtonGroup } from '../../../../ducks/send/send.duck';
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
|
|
|
let mergeProps;
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
jest.mock('react-redux', () => ({
|
|
|
|
connect: (_, md, mp) => {
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
mergeProps = mp;
|
|
|
|
return () => ({});
|
2018-08-09 18:14:03 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../selectors', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
getBasicGasEstimateLoadingStatus: (s) =>
|
|
|
|
`mockBasicGasEstimateLoadingStatus:${Object.keys(s).length}`,
|
|
|
|
getRenderableBasicEstimateData: (s) =>
|
|
|
|
`mockRenderableBasicEstimateData:${Object.keys(s).length}`,
|
|
|
|
getDefaultActiveButtonIndex: (a, b) => a + b,
|
|
|
|
getCurrentEthBalance: (state) => state.metamask.balance || '0x0',
|
|
|
|
getSendToken: () => null,
|
|
|
|
getTokenBalance: (state) => state.metamask.send.tokenBalance || '0x0',
|
|
|
|
getCustomGasPrice: (state) => state.gas.customData.price || '0x0',
|
|
|
|
getCustomGasLimit: (state) => state.gas.customData.limit || '0x0',
|
|
|
|
getCurrentCurrency: jest.fn().mockReturnValue('usd'),
|
|
|
|
conversionRateSelector: jest.fn().mockReturnValue(50),
|
|
|
|
getSendMaxModeState: jest.fn().mockReturnValue(false),
|
|
|
|
getPreferences: jest.fn(() => ({
|
|
|
|
showFiatInTestnets: false,
|
|
|
|
})),
|
|
|
|
getIsMainnet: jest.fn().mockReturnValue(false),
|
|
|
|
isCustomPriceSafe: jest.fn().mockReturnValue(true),
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../store/actions', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
hideModal: jest.fn(),
|
|
|
|
setGasLimit: jest.fn(),
|
|
|
|
setGasPrice: jest.fn(),
|
|
|
|
updateTransaction: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../ducks/gas/gas.duck', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
setCustomGasPrice: jest.fn(),
|
|
|
|
setCustomGasLimit: jest.fn(),
|
|
|
|
resetCustomData: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../../ducks/send/send.duck', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
hideGasButtonGroup: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
require('./gas-modal-page-container.container');
|
|
|
|
|
|
|
|
describe('gas-modal-page-container container', () => {
|
|
|
|
describe('mapDispatchToProps()', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let dispatchSpy;
|
|
|
|
let mapDispatchToPropsObject;
|
2018-07-31 04:28:05 +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-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
|
|
|
dispatchSpy.resetHistory();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('hideGasButtonGroup()', () => {
|
|
|
|
it('should dispatch a hideGasButtonGroup action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.hideGasButtonGroup();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(hideGasButtonGroup).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('cancelAndClose()', () => {
|
|
|
|
it('should dispatch a hideModal action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.cancelAndClose();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
|
|
|
expect(hideModal).toHaveBeenCalled();
|
|
|
|
expect(resetCustomData).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('updateCustomGasPrice()', () => {
|
|
|
|
it('should dispatch a setCustomGasPrice action with the arg passed to updateCustomGasPrice hex prefixed', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateCustomGasPrice('ffff');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xffff');
|
|
|
|
// expect(
|
|
|
|
// setCustomGasPrice.getCall(0).args[0],
|
|
|
|
// '0xffff',
|
|
|
|
// );
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch a setCustomGasPrice action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateCustomGasPrice('0xffff');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xffff');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('updateCustomGasLimit()', () => {
|
|
|
|
it('should dispatch a setCustomGasLimit action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateCustomGasLimit('0x10');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(setCustomGasLimit).toHaveBeenCalled();
|
|
|
|
expect(setCustomGasLimit).toHaveBeenCalledWith('0x10');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-09-13 10:47:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('setGasData()', () => {
|
|
|
|
it('should dispatch a setGasPrice and setGasLimit action with the correct props', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.setGasData('ffff', 'aaaa');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
|
|
|
expect(setGasPrice).toHaveBeenCalled();
|
|
|
|
expect(setGasLimit).toHaveBeenCalled();
|
|
|
|
expect(setGasLimit).toHaveBeenCalledWith('ffff');
|
|
|
|
expect(setGasPrice).toHaveBeenCalledWith('aaaa');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-08-09 18:14:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('updateConfirmTxGasAndCalculate()', () => {
|
|
|
|
it('should dispatch a updateGasAndCalculate action with the correct props', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateConfirmTxGasAndCalculate('ffff', 'aaaa');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.callCount).toStrictEqual(3);
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
|
|
|
expect(setCustomGasLimit).toHaveBeenCalled();
|
|
|
|
expect(setCustomGasLimit).toHaveBeenCalledWith('0xffff');
|
|
|
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xaaaa');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-07-31 04:28:05 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('mergeProps', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let stateProps;
|
|
|
|
let dispatchProps;
|
|
|
|
let ownProps;
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2019-07-31 22:17:11 +02:00
|
|
|
stateProps = {
|
|
|
|
gasPriceButtonGroupProps: {
|
|
|
|
someGasPriceButtonGroupProp: 'foo',
|
|
|
|
anotherGasPriceButtonGroupProp: 'bar',
|
|
|
|
},
|
|
|
|
isConfirm: true,
|
|
|
|
someOtherStateProp: 'baz',
|
|
|
|
transaction: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 22:17:11 +02:00
|
|
|
dispatchProps = {
|
|
|
|
updateCustomGasPrice: sinon.spy(),
|
|
|
|
hideGasButtonGroup: sinon.spy(),
|
|
|
|
setGasData: sinon.spy(),
|
|
|
|
updateConfirmTxGasAndCalculate: sinon.spy(),
|
|
|
|
someOtherDispatchProp: sinon.spy(),
|
|
|
|
createSpeedUpTransaction: sinon.spy(),
|
|
|
|
hideSidebar: sinon.spy(),
|
|
|
|
hideModal: sinon.spy(),
|
|
|
|
cancelAndClose: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
ownProps = { someOwnProp: 123 };
|
|
|
|
});
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the expected props when isConfirm is true', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = mergeProps(stateProps, dispatchProps, ownProps);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.isConfirm).toStrictEqual(true);
|
|
|
|
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);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-13 01:37:16 +01:00
|
|
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideModal.callCount).toStrictEqual(0);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
result.onSubmit();
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-13 01:37:16 +01:00
|
|
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(1);
|
|
|
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideModal.callCount).toStrictEqual(1);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(0);
|
2020-11-13 01:37:16 +01:00
|
|
|
result.gasPriceButtonGroupProps.handleGasPriceSelection({
|
|
|
|
gasPrice: '0x0',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(1);
|
2018-09-20 06:16:43 +02: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
|
|
|
});
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return the expected props when isConfirm is false', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const result = mergeProps(
|
|
|
|
{ ...stateProps, isConfirm: false },
|
|
|
|
dispatchProps,
|
|
|
|
ownProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.isConfirm).toStrictEqual(false);
|
|
|
|
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);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-13 01:37:16 +01:00
|
|
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(0);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
result.onSubmit('mockNewLimit', 'mockNewPrice');
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-13 01:37:16 +01:00
|
|
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(1);
|
|
|
|
expect(dispatchProps.setGasData.getCall(0).args).toStrictEqual([
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockNewLimit',
|
|
|
|
'mockNewPrice',
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(1);
|
|
|
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(1);
|
2018-09-20 06:16:43 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(0);
|
2020-11-13 01:37:16 +01:00
|
|
|
result.gasPriceButtonGroupProps.handleGasPriceSelection({
|
|
|
|
gasPrice: '0x0',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(1);
|
2018-09-20 06:16:43 +02: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
|
|
|
});
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch the expected actions from obSubmit when isConfirm is false and isSpeedUp is true', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const result = mergeProps(
|
|
|
|
{ ...stateProps, isSpeedUp: true, isConfirm: false },
|
|
|
|
dispatchProps,
|
|
|
|
ownProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
result.onSubmit();
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(
|
2020-11-13 01:37:16 +01:00
|
|
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
|
|
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchProps.createSpeedUpTransaction.callCount).toStrictEqual(1);
|
|
|
|
expect(dispatchProps.hideSidebar.callCount).toStrictEqual(1);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|