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.
131 lines
3.4 KiB
131 lines
3.4 KiB
4 years ago
|
import sinon from 'sinon';
|
||
7 years ago
|
|
||
4 years ago
|
import {
|
||
|
updateSendTokenBalance,
|
||
|
updateGasData,
|
||
|
setGasTotal,
|
||
|
} from '../../store/actions';
|
||
|
|
||
|
import { updateSendErrors, resetSendState } from '../../ducks/send/send.duck';
|
||
|
|
||
4 years ago
|
let mapDispatchToProps;
|
||
7 years ago
|
|
||
4 years ago
|
jest.mock('react-redux', () => ({
|
||
|
connect: (_, md) => {
|
||
|
mapDispatchToProps = md;
|
||
|
return () => ({});
|
||
7 years ago
|
},
|
||
4 years ago
|
}));
|
||
|
|
||
|
jest.mock('react-router-dom', () => ({
|
||
|
withRouter: () => undefined,
|
||
|
}));
|
||
|
|
||
|
jest.mock('redux', () => ({
|
||
|
compose: (_, arg2) => () => arg2(),
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../store/actions', () => ({
|
||
4 years ago
|
updateSendTokenBalance: jest.fn(),
|
||
|
updateGasData: jest.fn(),
|
||
|
setGasTotal: jest.fn(),
|
||
|
}));
|
||
4 years ago
|
jest.mock('../../ducks/send/send.duck', () => ({
|
||
4 years ago
|
updateSendErrors: jest.fn(),
|
||
|
resetSendState: jest.fn(),
|
||
|
}));
|
||
|
|
||
|
jest.mock('./send.utils.js', () => ({
|
||
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
||
|
}));
|
||
|
|
||
|
require('./send.container.js');
|
||
7 years ago
|
|
||
4 years ago
|
describe('send 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('updateAndSetGasLimit()', () => {
|
||
7 years ago
|
const mockProps = {
|
||
7 years ago
|
blockGasLimit: 'mockBlockGasLimit',
|
||
7 years ago
|
editingTransactionId: '0x2',
|
||
|
gasLimit: '0x3',
|
||
|
gasPrice: '0x4',
|
||
|
selectedAddress: '0x4',
|
||
5 years ago
|
sendToken: { address: '0x1' },
|
||
7 years ago
|
to: 'mockTo',
|
||
|
value: 'mockValue',
|
||
6 years ago
|
data: undefined,
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
it('should dispatch a setGasTotal action when editingTransactionId is truthy', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps);
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(setGasTotal).toHaveBeenCalledWith('0x30x4');
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should dispatch an updateGasData action when editingTransactionId is falsy', () => {
|
||
4 years ago
|
const {
|
||
|
gasPrice,
|
||
|
selectedAddress,
|
||
|
sendToken,
|
||
|
blockGasLimit,
|
||
|
to,
|
||
|
value,
|
||
|
data,
|
||
4 years ago
|
} = mockProps;
|
||
4 years ago
|
mapDispatchToPropsObject.updateAndSetGasLimit({
|
||
|
...mockProps,
|
||
|
editingTransactionId: false,
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(updateGasData).toHaveBeenCalledWith({
|
||
4 years ago
|
gasPrice,
|
||
|
selectedAddress,
|
||
|
sendToken,
|
||
|
blockGasLimit,
|
||
|
to,
|
||
|
value,
|
||
|
data,
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('updateSendTokenBalance()', () => {
|
||
7 years ago
|
const mockProps = {
|
||
|
address: '0x10',
|
||
|
tokenContract: '0x00a',
|
||
5 years ago
|
sendToken: { address: '0x1' },
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateSendTokenBalance({ ...mockProps });
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(updateSendTokenBalance).toHaveBeenCalledWith(mockProps);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('updateSendErrors()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.updateSendErrors('mockError');
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(updateSendErrors).toHaveBeenCalledWith('mockError');
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('resetSendState()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.resetSendState();
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(resetSendState).toHaveBeenCalled();
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|