2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import proxyquire from 'proxyquire';
|
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapDispatchToProps;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
updateSendTokenBalance: sinon.spy(),
|
2018-05-20 02:37:44 +02:00
|
|
|
updateGasData: sinon.spy(),
|
2018-05-05 17:11:53 +02:00
|
|
|
setGasTotal: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
const duckActionSpies = {
|
|
|
|
updateSendErrors: sinon.spy(),
|
2018-06-29 19:19:40 +02:00
|
|
|
resetSendState: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-05 17:11:53 +02:00
|
|
|
|
|
|
|
proxyquire('../send.container.js', {
|
|
|
|
'react-redux': {
|
2019-12-08 04:10:47 +01:00
|
|
|
connect: (_, md) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2018-05-05 17:11:53 +02:00
|
|
|
},
|
|
|
|
},
|
2020-08-14 13:47:02 +02:00
|
|
|
'react-router-dom': { withRouter: () => undefined },
|
2020-11-03 00:41:28 +01:00
|
|
|
redux: { compose: (_, arg2) => () => arg2() },
|
2019-04-17 21:15:13 +02:00
|
|
|
'../../store/actions': actionSpies,
|
|
|
|
'../../ducks/send/send.duck': duckActionSpies,
|
2018-05-05 17:11:53 +02:00
|
|
|
'./send.utils.js': {
|
|
|
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('send container', function () {
|
|
|
|
describe('mapDispatchToProps()', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let dispatchSpy;
|
|
|
|
let mapDispatchToPropsObject;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatchSpy = sinon.spy();
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateAndSetGasLimit()', function () {
|
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
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch a setGasTotal action when editingTransactionId is truthy', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps);
|
|
|
|
assert(dispatchSpy.calledOnce);
|
|
|
|
assert.strictEqual(
|
|
|
|
actionSpies.setGasTotal.getCall(0).args[0],
|
|
|
|
'0x30x4',
|
|
|
|
);
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch an updateGasData action when editingTransactionId is falsy', function () {
|
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
|
|
|
});
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(actionSpies.updateGasData.getCall(0).args[0], {
|
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
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateSendTokenBalance()', function () {
|
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
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateSendTokenBalance({ ...mockProps });
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(
|
2018-05-05 17:11:53 +02:00
|
|
|
actionSpies.updateSendTokenBalance.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
mockProps,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('updateSendErrors()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.updateSendErrors('mockError');
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2018-05-05 17:11:53 +02:00
|
|
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
2020-07-14 17:20:41 +02:00
|
|
|
'mockError',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('resetSendState()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.resetSendState();
|
|
|
|
assert(dispatchSpy.calledOnce);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
|
|
|
duckActionSpies.resetSendState.getCall(0).args.length,
|
|
|
|
0,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|