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.
132 lines
3.6 KiB
132 lines
3.6 KiB
4 years ago
|
import assert from 'assert';
|
||
|
import proxyquire from 'proxyquire';
|
||
|
import sinon from 'sinon';
|
||
7 years ago
|
|
||
4 years ago
|
let mapDispatchToProps;
|
||
7 years ago
|
|
||
|
const actionSpies = {
|
||
|
updateSendTokenBalance: sinon.spy(),
|
||
7 years ago
|
updateGasData: sinon.spy(),
|
||
7 years ago
|
setGasTotal: sinon.spy(),
|
||
4 years ago
|
};
|
||
7 years ago
|
const duckActionSpies = {
|
||
|
updateSendErrors: sinon.spy(),
|
||
7 years ago
|
resetSendState: sinon.spy(),
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
proxyquire('./send.container.js', {
|
||
7 years ago
|
'react-redux': {
|
||
5 years ago
|
connect: (_, md) => {
|
||
4 years ago
|
mapDispatchToProps = md;
|
||
|
return () => ({});
|
||
7 years ago
|
},
|
||
|
},
|
||
4 years ago
|
'react-router-dom': { withRouter: () => undefined },
|
||
4 years ago
|
redux: { compose: (_, arg2) => () => arg2() },
|
||
6 years ago
|
'../../store/actions': actionSpies,
|
||
|
'../../ducks/send/send.duck': duckActionSpies,
|
||
7 years ago
|
'./send.utils.js': {
|
||
|
calcGasTotal: (gasLimit, gasPrice) => gasLimit + gasPrice,
|
||
|
},
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('send container', function () {
|
||
|
describe('mapDispatchToProps()', function () {
|
||
4 years ago
|
let dispatchSpy;
|
||
|
let mapDispatchToPropsObject;
|
||
7 years ago
|
|
||
5 years ago
|
beforeEach(function () {
|
||
4 years ago
|
dispatchSpy = sinon.spy();
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('updateAndSetGasLimit()', function () {
|
||
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
|
|
||
5 years ago
|
it('should dispatch a setGasTotal action when editingTransactionId is truthy', function () {
|
||
4 years ago
|
mapDispatchToPropsObject.updateAndSetGasLimit(mockProps);
|
||
|
assert(dispatchSpy.calledOnce);
|
||
|
assert.strictEqual(
|
||
|
actionSpies.setGasTotal.getCall(0).args[0],
|
||
|
'0x30x4',
|
||
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should dispatch an updateGasData action when editingTransactionId is falsy', function () {
|
||
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
|
});
|
||
|
assert(dispatchSpy.calledOnce);
|
||
4 years ago
|
assert.deepStrictEqual(actionSpies.updateGasData.getCall(0).args[0], {
|
||
4 years ago
|
gasPrice,
|
||
|
selectedAddress,
|
||
|
sendToken,
|
||
|
blockGasLimit,
|
||
|
to,
|
||
|
value,
|
||
|
data,
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('updateSendTokenBalance()', function () {
|
||
7 years ago
|
const mockProps = {
|
||
|
address: '0x10',
|
||
|
tokenContract: '0x00a',
|
||
5 years ago
|
sendToken: { address: '0x1' },
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
it('should dispatch an action', function () {
|
||
4 years ago
|
mapDispatchToPropsObject.updateSendTokenBalance({ ...mockProps });
|
||
|
assert(dispatchSpy.calledOnce);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
7 years ago
|
actionSpies.updateSendTokenBalance.getCall(0).args[0],
|
||
4 years ago
|
mockProps,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('updateSendErrors()', function () {
|
||
|
it('should dispatch an action', function () {
|
||
4 years ago
|
mapDispatchToPropsObject.updateSendErrors('mockError');
|
||
|
assert(dispatchSpy.calledOnce);
|
||
4 years ago
|
assert.strictEqual(
|
||
7 years ago
|
duckActionSpies.updateSendErrors.getCall(0).args[0],
|
||
4 years ago
|
'mockError',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('resetSendState()', function () {
|
||
|
it('should dispatch an action', function () {
|
||
4 years ago
|
mapDispatchToPropsObject.resetSendState();
|
||
|
assert(dispatchSpy.calledOnce);
|
||
4 years ago
|
assert.strictEqual(
|
||
|
duckActionSpies.resetSendState.getCall(0).args.length,
|
||
|
0,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|