2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
import {
|
|
|
|
updateSendTokenBalance,
|
|
|
|
updateGasData,
|
|
|
|
setGasTotal,
|
2021-06-10 19:53:15 +02:00
|
|
|
updateSendErrors,
|
|
|
|
resetSendState,
|
|
|
|
} from '../../ducks/send/send.duck';
|
2021-04-15 20:01:46 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
jest.mock('react-redux', () => ({
|
|
|
|
connect: (_, md) => {
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
|
|
withRouter: () => undefined,
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('redux', () => ({
|
|
|
|
compose: (_, arg2) => () => arg2(),
|
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../ducks/send/send.duck', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
updateSendErrors: jest.fn(),
|
|
|
|
resetSendState: jest.fn(),
|
2021-06-10 19:53:15 +02:00
|
|
|
updateSendTokenBalance: jest.fn(),
|
|
|
|
updateGasData: jest.fn(),
|
|
|
|
setGasTotal: jest.fn(),
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('./send.utils.js', () => ({
|
|
|
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
|
|
|
}));
|
|
|
|
|
|
|
|
require('./send.container.js');
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('send 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-04-15 20:01:46 +02:00
|
|
|
describe('updateAndSetGasLimit()', () => {
|
2018-05-05 17:11:53 +02:00
|
|
|
const mockProps = {
|
2018-05-22 17:16:53 +02:00
|
|
|
blockGasLimit: 'mockBlockGasLimit',
|
2018-05-05 17:11:53 +02:00
|
|
|
editingTransactionId: '0x2',
|
|
|
|
gasLimit: '0x3',
|
|
|
|
gasPrice: '0x4',
|
|
|
|
selectedAddress: '0x4',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: '0x1' },
|
2018-05-23 18:43:25 +02:00
|
|
|
to: 'mockTo',
|
|
|
|
value: 'mockValue',
|
2018-09-27 15:46:24 +02:00
|
|
|
data: undefined,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch a setGasTotal action when editingTransactionId is truthy', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(setGasTotal).toHaveBeenCalledWith('0x30x4');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an updateGasData action when editingTransactionId is falsy', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const {
|
|
|
|
gasPrice,
|
|
|
|
selectedAddress,
|
|
|
|
sendToken,
|
|
|
|
blockGasLimit,
|
|
|
|
to,
|
|
|
|
value,
|
|
|
|
data,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = mockProps;
|
2020-11-03 00:41:28 +01:00
|
|
|
mapDispatchToPropsObject.updateAndSetGasLimit({
|
|
|
|
...mockProps,
|
|
|
|
editingTransactionId: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(updateGasData).toHaveBeenCalledWith({
|
2020-11-03 00:41:28 +01:00
|
|
|
gasPrice,
|
|
|
|
selectedAddress,
|
|
|
|
sendToken,
|
|
|
|
blockGasLimit,
|
|
|
|
to,
|
|
|
|
value,
|
|
|
|
data,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('updateSendTokenBalance()', () => {
|
2018-05-05 17:11:53 +02:00
|
|
|
const mockProps = {
|
|
|
|
address: '0x10',
|
|
|
|
tokenContract: '0x00a',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: '0x1' },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateSendTokenBalance({ ...mockProps });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(updateSendTokenBalance).toHaveBeenCalledWith(mockProps);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('updateSendErrors()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateSendErrors('mockError');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(updateSendErrors).toHaveBeenCalledWith('mockError');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('resetSendState()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.resetSendState();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(resetSendState).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|