2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-09-17 06:37:50 +02:00
|
|
|
import { addToAddressBook, cancelTx } from '../../../store/actions';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { resetSendState, signTransaction } from '../../../ducks/send';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02: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 () => ({});
|
2019-04-05 06:02:47 +02:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../store/actions.js', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
addToAddressBook: jest.fn(),
|
2021-09-17 06:37:50 +02:00
|
|
|
cancelTx: jest.fn(),
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
jest.mock('../../../ducks/metamask/metamask', () => ({
|
|
|
|
getSendToAccounts: (s) => [`mockToAccounts:${s}`],
|
2021-06-10 19:53:15 +02:00
|
|
|
}));
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
jest.mock('../../../ducks/send', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
getGasPrice: (s) => `mockGasPrice:${s}`,
|
|
|
|
getSendTo: (s) => `mockTo:${s}`,
|
|
|
|
getSendErrors: (s) => `mockSendErrors:${s}`,
|
2021-09-17 06:37:50 +02:00
|
|
|
getSendStage: (s) => `mockStage:${s}`,
|
|
|
|
getDraftTransaction: (s) => ({ id: `draftTransaction:${s}` }),
|
2021-06-23 23:35:25 +02:00
|
|
|
resetSendState: jest.fn(),
|
|
|
|
signTransaction: jest.fn(),
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-28 21:53:59 +02:00
|
|
|
jest.mock('../../../selectors/custom-gas.js', () => ({
|
2021-04-15 20:01:46 +02:00
|
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => [
|
|
|
|
{ gasEstimateType: `mockGasEstimateType:${s}` },
|
|
|
|
],
|
|
|
|
}));
|
|
|
|
require('./send-footer.container.js');
|
|
|
|
|
|
|
|
describe('send-footer 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-06-23 23:35:25 +02:00
|
|
|
describe('resetSendState()', () => {
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should dispatch an action', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
mapDispatchToPropsObject.resetSendState();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(resetSendState).toHaveBeenCalled();
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-09-17 06:37:50 +02:00
|
|
|
describe('cancelTx()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
|
|
|
const draftTansaction = { id: 'ID' };
|
|
|
|
mapDispatchToPropsObject.cancelTx(draftTansaction);
|
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(cancelTx).toHaveBeenCalledTimes(1);
|
|
|
|
expect(cancelTx).toHaveBeenCalledWith(draftTansaction);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('sign()', () => {
|
2021-06-23 23:35:25 +02:00
|
|
|
it('should dispatch a signTransaction action', () => {
|
|
|
|
mapDispatchToPropsObject.sign();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
2021-06-23 23:35:25 +02:00
|
|
|
expect(signTransaction).toHaveBeenCalledTimes(1);
|
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('addToAddressBookIfNew()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
mapDispatchToPropsObject.addToAddressBookIfNew(
|
|
|
|
'mockNewAddress',
|
2021-06-23 23:35:25 +02:00
|
|
|
[{ address: 'mockToAccounts' }],
|
2020-11-03 00:41:28 +01:00
|
|
|
'mockNickname',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(addToAddressBook).toHaveBeenCalledWith(
|
2020-11-03 00:41:28 +01:00
|
|
|
'0xmockNewAddress',
|
|
|
|
'mockNickname',
|
2021-04-15 20:01:46 +02:00
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|