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.
157 lines
4.7 KiB
157 lines
4.7 KiB
4 years ago
|
import sinon from 'sinon';
|
||
7 years ago
|
|
||
4 years ago
|
import {
|
||
|
showModal,
|
||
|
setGasPrice,
|
||
|
setGasTotal,
|
||
|
setGasLimit,
|
||
|
} from '../../../../store/actions';
|
||
|
|
||
|
import {
|
||
|
resetCustomData,
|
||
|
setCustomGasPrice,
|
||
|
setCustomGasLimit,
|
||
|
} from '../../../../ducks/gas/gas.duck';
|
||
|
|
||
|
import { showGasButtonGroup } from '../../../../ducks/send/send.duck';
|
||
|
|
||
4 years ago
|
let mapDispatchToProps;
|
||
|
let mergeProps;
|
||
7 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
|
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
|
||
|
}));
|
||
|
|
||
|
jest.mock('../../send.utils.js', () => ({
|
||
|
isBalanceSufficient: ({ amount, gasTotal, balance, conversionRate }) =>
|
||
|
`${amount}:${gasTotal}:${balance}:${conversionRate}`,
|
||
|
|
||
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../store/actions', () => ({
|
||
4 years ago
|
showModal: jest.fn(),
|
||
|
setGasPrice: jest.fn(),
|
||
|
setGasTotal: jest.fn(),
|
||
|
setGasLimit: jest.fn(),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../ducks/send/send.duck', () => ({
|
||
4 years ago
|
showGasButtonGroup: jest.fn(),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../ducks/gas/gas.duck', () => ({
|
||
4 years ago
|
resetCustomData: jest.fn(),
|
||
|
setCustomGasPrice: jest.fn(),
|
||
|
setCustomGasLimit: jest.fn(),
|
||
|
}));
|
||
|
|
||
|
require('./send-gas-row.container.js');
|
||
7 years ago
|
|
||
4 years ago
|
describe('send-gas-row container', () => {
|
||
|
describe('mapDispatchToProps()', () => {
|
||
4 years ago
|
let dispatchSpy;
|
||
|
let mapDispatchToPropsObject;
|
||
7 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
dispatchSpy = sinon.spy();
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('showCustomizeGasModal()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.showCustomizeGasModal();
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(showModal).toHaveBeenCalledWith({
|
||
4 years ago
|
name: 'CUSTOMIZE_GAS',
|
||
|
hideBasic: true,
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('setGasPrice()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.setGasPrice({
|
||
|
gasPrice: 'mockNewPrice',
|
||
|
gasLimit: 'mockLimit',
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(dispatchSpy.calledThrice).toStrictEqual(true);
|
||
|
expect(setGasPrice).toHaveBeenCalled();
|
||
|
expect(setCustomGasPrice).toHaveBeenCalledWith('mockNewPrice');
|
||
|
expect(setGasTotal).toHaveBeenCalled();
|
||
|
expect(setGasTotal).toHaveBeenCalledWith('mockLimitmockNewPrice');
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('setGasLimit()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.setGasLimit('mockNewLimit', 'mockPrice');
|
||
4 years ago
|
expect(dispatchSpy.calledThrice).toStrictEqual(true);
|
||
|
expect(setGasLimit).toHaveBeenCalled();
|
||
|
expect(setCustomGasLimit).toHaveBeenCalledWith('mockNewLimit');
|
||
|
expect(setGasTotal).toHaveBeenCalled();
|
||
|
expect(setGasTotal).toHaveBeenCalledWith('mockNewLimitmockPrice');
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('showGasButtonGroup()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.showGasButtonGroup();
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(showGasButtonGroup).toHaveBeenCalled();
|
||
4 years ago
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('resetCustomData()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.resetCustomData();
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(resetCustomData).toHaveBeenCalled();
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
describe('mergeProps', () => {
|
||
|
it('should return the expected props when isConfirm is true', () => {
|
||
5 years ago
|
const stateProps = {
|
||
6 years ago
|
gasPriceButtonGroupProps: {
|
||
|
someGasPriceButtonGroupProp: 'foo',
|
||
|
anotherGasPriceButtonGroupProp: 'bar',
|
||
|
},
|
||
|
someOtherStateProp: 'baz',
|
||
4 years ago
|
};
|
||
5 years ago
|
const dispatchProps = {
|
||
6 years ago
|
setGasPrice: sinon.spy(),
|
||
|
someOtherDispatchProp: sinon.spy(),
|
||
4 years ago
|
};
|
||
|
const ownProps = { someOwnProp: 123 };
|
||
|
const result = mergeProps(stateProps, dispatchProps, ownProps);
|
||
6 years ago
|
|
||
4 years ago
|
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);
|
||
4 years ago
|
|
||
4 years ago
|
expect(dispatchProps.setGasPrice.callCount).toStrictEqual(0);
|
||
4 years ago
|
result.gasPriceButtonGroupProps.handleGasPriceSelection();
|
||
4 years ago
|
expect(dispatchProps.setGasPrice.callCount).toStrictEqual(1);
|
||
4 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
|
});
|
||
|
});
|
||
|
});
|