You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
285 lines
10 KiB
285 lines
10 KiB
4 years ago
|
import sinon from 'sinon';
|
||
6 years ago
|
|
||
4 years ago
|
import { hideModal, setGasLimit, setGasPrice } from '../../../../store/actions';
|
||
|
|
||
|
import {
|
||
|
setCustomGasPrice,
|
||
|
setCustomGasLimit,
|
||
|
resetCustomData,
|
||
|
} from '../../../../ducks/gas/gas.duck';
|
||
|
|
||
|
import { hideGasButtonGroup } from '../../../../ducks/send/send.duck';
|
||
|
|
||
4 years ago
|
let mapDispatchToProps;
|
||
|
let mergeProps;
|
||
6 years ago
|
|
||
4 years ago
|
jest.mock('react-redux', () => ({
|
||
|
connect: (_, md, mp) => {
|
||
|
mapDispatchToProps = md;
|
||
|
mergeProps = mp;
|
||
|
return () => ({});
|
||
6 years ago
|
},
|
||
4 years ago
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../selectors', () => ({
|
||
4 years ago
|
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),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../store/actions', () => ({
|
||
4 years ago
|
hideModal: jest.fn(),
|
||
|
setGasLimit: jest.fn(),
|
||
|
setGasPrice: jest.fn(),
|
||
|
updateTransaction: jest.fn(),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../ducks/gas/gas.duck', () => ({
|
||
4 years ago
|
setCustomGasPrice: jest.fn(),
|
||
|
setCustomGasLimit: jest.fn(),
|
||
|
resetCustomData: jest.fn(),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../ducks/send/send.duck', () => ({
|
||
4 years ago
|
hideGasButtonGroup: jest.fn(),
|
||
|
}));
|
||
|
|
||
|
require('./gas-modal-page-container.container');
|
||
|
|
||
|
describe('gas-modal-page-container container', () => {
|
||
|
describe('mapDispatchToProps()', () => {
|
||
4 years ago
|
let dispatchSpy;
|
||
|
let mapDispatchToPropsObject;
|
||
6 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
dispatchSpy = sinon.spy();
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
|
dispatchSpy.resetHistory();
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('hideGasButtonGroup()', () => {
|
||
|
it('should dispatch a hideGasButtonGroup action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.hideGasButtonGroup();
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(hideGasButtonGroup).toHaveBeenCalled();
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('cancelAndClose()', () => {
|
||
|
it('should dispatch a hideModal action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.cancelAndClose();
|
||
4 years ago
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
||
|
expect(hideModal).toHaveBeenCalled();
|
||
|
expect(resetCustomData).toHaveBeenCalled();
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('updateCustomGasPrice()', () => {
|
||
|
it('should dispatch a setCustomGasPrice action with the arg passed to updateCustomGasPrice hex prefixed', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateCustomGasPrice('ffff');
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
||
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xffff');
|
||
|
// expect(
|
||
|
// setCustomGasPrice.getCall(0).args[0],
|
||
|
// '0xffff',
|
||
|
// );
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should dispatch a setCustomGasPrice action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateCustomGasPrice('0xffff');
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
||
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xffff');
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('updateCustomGasLimit()', () => {
|
||
|
it('should dispatch a setCustomGasLimit action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateCustomGasLimit('0x10');
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(setCustomGasLimit).toHaveBeenCalled();
|
||
|
expect(setCustomGasLimit).toHaveBeenCalledWith('0x10');
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('setGasData()', () => {
|
||
|
it('should dispatch a setGasPrice and setGasLimit action with the correct props', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.setGasData('ffff', 'aaaa');
|
||
4 years ago
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
||
|
expect(setGasPrice).toHaveBeenCalled();
|
||
|
expect(setGasLimit).toHaveBeenCalled();
|
||
|
expect(setGasLimit).toHaveBeenCalledWith('ffff');
|
||
|
expect(setGasPrice).toHaveBeenCalledWith('aaaa');
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('updateConfirmTxGasAndCalculate()', () => {
|
||
|
it('should dispatch a updateGasAndCalculate action with the correct props', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateConfirmTxGasAndCalculate('ffff', 'aaaa');
|
||
4 years ago
|
expect(dispatchSpy.callCount).toStrictEqual(3);
|
||
|
expect(setCustomGasPrice).toHaveBeenCalled();
|
||
|
expect(setCustomGasLimit).toHaveBeenCalled();
|
||
|
expect(setCustomGasLimit).toHaveBeenCalledWith('0xffff');
|
||
|
expect(setCustomGasPrice).toHaveBeenCalledWith('0xaaaa');
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('mergeProps', () => {
|
||
4 years ago
|
let stateProps;
|
||
|
let dispatchProps;
|
||
|
let ownProps;
|
||
6 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
5 years ago
|
stateProps = {
|
||
|
gasPriceButtonGroupProps: {
|
||
|
someGasPriceButtonGroupProp: 'foo',
|
||
|
anotherGasPriceButtonGroupProp: 'bar',
|
||
|
},
|
||
|
isConfirm: true,
|
||
|
someOtherStateProp: 'baz',
|
||
|
transaction: {},
|
||
4 years ago
|
};
|
||
5 years ago
|
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(),
|
||
4 years ago
|
};
|
||
|
ownProps = { someOwnProp: 123 };
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should return the expected props when isConfirm is true', () => {
|
||
4 years ago
|
const result = mergeProps(stateProps, dispatchProps, ownProps);
|
||
6 years ago
|
|
||
4 years ago
|
expect(result.isConfirm).toStrictEqual(true);
|
||
|
expect(result.someOtherStateProp).toStrictEqual('baz');
|
||
|
expect(
|
||
4 years ago
|
result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp,
|
||
4 years ago
|
).toStrictEqual('foo');
|
||
|
expect(
|
||
4 years ago
|
result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp,
|
||
4 years ago
|
).toStrictEqual('bar');
|
||
|
expect(result.someOwnProp).toStrictEqual(123);
|
||
6 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
||
4 years ago
|
).toStrictEqual(0);
|
||
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideModal.callCount).toStrictEqual(0);
|
||
6 years ago
|
|
||
4 years ago
|
result.onSubmit();
|
||
6 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
||
4 years ago
|
).toStrictEqual(1);
|
||
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideModal.callCount).toStrictEqual(1);
|
||
6 years ago
|
|
||
4 years ago
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(0);
|
||
4 years ago
|
result.gasPriceButtonGroupProps.handleGasPriceSelection({
|
||
|
gasPrice: '0x0',
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(1);
|
||
6 years ago
|
|
||
4 years ago
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(0);
|
||
4 years ago
|
result.someOtherDispatchProp();
|
||
4 years ago
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should return the expected props when isConfirm is false', () => {
|
||
4 years ago
|
const result = mergeProps(
|
||
|
{ ...stateProps, isConfirm: false },
|
||
|
dispatchProps,
|
||
|
ownProps,
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(result.isConfirm).toStrictEqual(false);
|
||
|
expect(result.someOtherStateProp).toStrictEqual('baz');
|
||
|
expect(
|
||
4 years ago
|
result.gasPriceButtonGroupProps.someGasPriceButtonGroupProp,
|
||
4 years ago
|
).toStrictEqual('foo');
|
||
|
expect(
|
||
4 years ago
|
result.gasPriceButtonGroupProps.anotherGasPriceButtonGroupProp,
|
||
4 years ago
|
).toStrictEqual('bar');
|
||
|
expect(result.someOwnProp).toStrictEqual(123);
|
||
6 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
||
4 years ago
|
).toStrictEqual(0);
|
||
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(0);
|
||
6 years ago
|
|
||
4 years ago
|
result.onSubmit('mockNewLimit', 'mockNewPrice');
|
||
6 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
||
4 years ago
|
).toStrictEqual(0);
|
||
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(1);
|
||
|
expect(dispatchProps.setGasData.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
'mockNewLimit',
|
||
|
'mockNewPrice',
|
||
4 years ago
|
]);
|
||
4 years ago
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(1);
|
||
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(1);
|
||
6 years ago
|
|
||
4 years ago
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(0);
|
||
4 years ago
|
result.gasPriceButtonGroupProps.handleGasPriceSelection({
|
||
|
gasPrice: '0x0',
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(dispatchProps.updateCustomGasPrice.callCount).toStrictEqual(1);
|
||
6 years ago
|
|
||
4 years ago
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(0);
|
||
4 years ago
|
result.someOtherDispatchProp();
|
||
4 years ago
|
expect(dispatchProps.someOtherDispatchProp.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should dispatch the expected actions from obSubmit when isConfirm is false and isSpeedUp is true', () => {
|
||
4 years ago
|
const result = mergeProps(
|
||
|
{ ...stateProps, isSpeedUp: true, isConfirm: false },
|
||
|
dispatchProps,
|
||
|
ownProps,
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
result.onSubmit();
|
||
6 years ago
|
|
||
4 years ago
|
expect(
|
||
4 years ago
|
dispatchProps.updateConfirmTxGasAndCalculate.callCount,
|
||
4 years ago
|
).toStrictEqual(0);
|
||
|
expect(dispatchProps.setGasData.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.hideGasButtonGroup.callCount).toStrictEqual(0);
|
||
|
expect(dispatchProps.cancelAndClose.callCount).toStrictEqual(1);
|
||
4 years ago
|
|
||
4 years ago
|
expect(dispatchProps.createSpeedUpTransaction.callCount).toStrictEqual(1);
|
||
|
expect(dispatchProps.hideSidebar.callCount).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|