2021-02-04 19:15:23 +01:00
|
|
|
import sinon from 'sinon';
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
import { setMaxModeTo, updateSendAmount } from '../../../../../store/actions';
|
|
|
|
|
|
|
|
import { updateSendErrors } from '../../../../../ducks/send/send.duck';
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let mapStateToProps;
|
|
|
|
let mapDispatchToProps;
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
jest.mock('react-redux', () => ({
|
|
|
|
connect: (ms, md) => {
|
|
|
|
mapStateToProps = ms;
|
|
|
|
mapDispatchToProps = md;
|
|
|
|
return () => ({});
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-04-15 20:01:46 +02:00
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../../../../app/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}`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('./amount-max-button.utils.js', () => ({
|
|
|
|
calcMaxAmount: (mockObj) => mockObj.val + 1,
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('../../../../../../app/store/actions', () => ({
|
|
|
|
setMaxModeTo: jest.fn(),
|
|
|
|
updateSendAmount: jest.fn(),
|
|
|
|
}));
|
|
|
|
jest.mock('../../../../../../app/ducks/send/send.duck', () => ({
|
|
|
|
updateSendErrors: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
require('./amount-max-button.container.js');
|
2018-05-05 17:11:53 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('amount-max-button container', () => {
|
|
|
|
describe('mapStateToProps()', () => {
|
|
|
|
it('should map the correct properties to props', () => {
|
|
|
|
expect(mapStateToProps('mockState')).toStrictEqual({
|
2018-05-05 17:11:53 +02:00
|
|
|
balance: 'mockBalance:mockState',
|
2019-05-20 18:38:08 +02:00
|
|
|
buttonDataLoading: 'mockButtonDataLoading:mockState',
|
2018-05-05 17:11:53 +02:00
|
|
|
gasTotal: 'mockGasTotal:mockState',
|
|
|
|
maxModeOn: 'mockMaxModeOn:mockState',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: 'mockSendToken:mockState',
|
2018-05-05 17:11:53 +02:00
|
|
|
tokenBalance: 'mockTokenBalance:mockState',
|
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('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-04-15 20:01:46 +02:00
|
|
|
describe('setAmountToMax()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.setAmountToMax({ val: 11, foo: 'bar' });
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
|
|
|
expect(updateSendErrors).toHaveBeenCalled();
|
|
|
|
expect(updateSendErrors).toHaveBeenCalledWith({ amount: null });
|
|
|
|
expect(updateSendAmount).toHaveBeenCalled();
|
|
|
|
expect(updateSendAmount).toHaveBeenCalledWith(12);
|
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('setMaxModeTo()', () => {
|
|
|
|
it('should dispatch an action', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
mapDispatchToPropsObject.setMaxModeTo('mockVal');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
|
|
|
expect(setMaxModeTo).toHaveBeenCalledWith('mockVal');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|