1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/app/pages/send/send-content/send-amount-row/amount-max-button/tests/amount-max-button-container.test.js
Erik Marks 76a2a9bb8b
@metamask/eslint config@5.0.0 (#10358)
* @metamask/eslint-config@5.0.0
* Update eslintrc and prettierrc
* yarn lint:fix
2021-02-04 10:15:23 -08:00

90 lines
2.7 KiB
JavaScript

import assert from 'assert';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
let mapStateToProps;
let mapDispatchToProps;
const actionSpies = {
setMaxModeTo: sinon.spy(),
updateSendAmount: sinon.spy(),
};
const duckActionSpies = {
updateSendErrors: sinon.spy(),
};
proxyquire('../amount-max-button.container.js', {
'react-redux': {
connect: (ms, md) => {
mapStateToProps = ms;
mapDispatchToProps = md;
return () => ({});
},
},
'../../../../../selectors': {
getGasTotal: (s) => `mockGasTotal:${s}`,
getSendToken: (s) => `mockSendToken:${s}`,
getSendFromBalance: (s) => `mockBalance:${s}`,
getTokenBalance: (s) => `mockTokenBalance:${s}`,
getSendMaxModeState: (s) => `mockMaxModeOn:${s}`,
getBasicGasEstimateLoadingStatus: (s) => `mockButtonDataLoading:${s}`,
},
'./amount-max-button.utils.js': {
calcMaxAmount: (mockObj) => mockObj.val + 1,
},
'../../../../../store/actions': actionSpies,
'../../../../../ducks/send/send.duck': duckActionSpies,
});
describe('amount-max-button container', function () {
describe('mapStateToProps()', function () {
it('should map the correct properties to props', function () {
assert.deepStrictEqual(mapStateToProps('mockState'), {
balance: 'mockBalance:mockState',
buttonDataLoading: 'mockButtonDataLoading:mockState',
gasTotal: 'mockGasTotal:mockState',
maxModeOn: 'mockMaxModeOn:mockState',
sendToken: 'mockSendToken:mockState',
tokenBalance: 'mockTokenBalance:mockState',
});
});
});
describe('mapDispatchToProps()', function () {
let dispatchSpy;
let mapDispatchToPropsObject;
beforeEach(function () {
dispatchSpy = sinon.spy();
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
});
describe('setAmountToMax()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.setAmountToMax({ val: 11, foo: 'bar' });
assert(dispatchSpy.calledTwice);
assert(duckActionSpies.updateSendErrors.calledOnce);
assert.deepStrictEqual(
duckActionSpies.updateSendErrors.getCall(0).args[0],
{
amount: null,
},
);
assert(actionSpies.updateSendAmount.calledOnce);
assert.strictEqual(actionSpies.updateSendAmount.getCall(0).args[0], 12);
});
});
describe('setMaxModeTo()', function () {
it('should dispatch an action', function () {
mapDispatchToPropsObject.setMaxModeTo('mockVal');
assert(dispatchSpy.calledOnce);
assert.strictEqual(
actionSpies.setMaxModeTo.getCall(0).args[0],
'mockVal',
);
});
});
});
});