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.
84 lines
2.6 KiB
84 lines
2.6 KiB
4 years ago
|
import sinon from 'sinon';
|
||
7 years ago
|
|
||
4 years ago
|
import { setMaxModeTo, updateSendAmount } from '../../../../../store/actions';
|
||
|
|
||
|
import { updateSendErrors } from '../../../../../ducks/send/send.duck';
|
||
|
|
||
4 years ago
|
let mapStateToProps;
|
||
|
let mapDispatchToProps;
|
||
7 years ago
|
|
||
4 years ago
|
jest.mock('react-redux', () => ({
|
||
|
connect: (ms, md) => {
|
||
|
mapStateToProps = ms;
|
||
|
mapDispatchToProps = md;
|
||
|
return () => ({});
|
||
4 years ago
|
},
|
||
4 years ago
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../../selectors', () => ({
|
||
4 years ago
|
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,
|
||
|
}));
|
||
|
|
||
4 years ago
|
jest.mock('../../../../../store/actions', () => ({
|
||
4 years ago
|
setMaxModeTo: jest.fn(),
|
||
|
updateSendAmount: jest.fn(),
|
||
|
}));
|
||
4 years ago
|
jest.mock('../../../../../ducks/send/send.duck', () => ({
|
||
4 years ago
|
updateSendErrors: jest.fn(),
|
||
|
}));
|
||
|
|
||
|
require('./amount-max-button.container.js');
|
||
7 years ago
|
|
||
4 years ago
|
describe('amount-max-button container', () => {
|
||
|
describe('mapStateToProps()', () => {
|
||
|
it('should map the correct properties to props', () => {
|
||
|
expect(mapStateToProps('mockState')).toStrictEqual({
|
||
7 years ago
|
balance: 'mockBalance:mockState',
|
||
6 years ago
|
buttonDataLoading: 'mockButtonDataLoading:mockState',
|
||
7 years ago
|
gasTotal: 'mockGasTotal:mockState',
|
||
|
maxModeOn: 'mockMaxModeOn:mockState',
|
||
5 years ago
|
sendToken: 'mockSendToken:mockState',
|
||
7 years ago
|
tokenBalance: 'mockTokenBalance:mockState',
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('mapDispatchToProps()', () => {
|
||
4 years ago
|
let dispatchSpy;
|
||
|
let mapDispatchToPropsObject;
|
||
7 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
dispatchSpy = sinon.spy();
|
||
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('setAmountToMax()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.setAmountToMax({ val: 11, foo: 'bar' });
|
||
4 years ago
|
expect(dispatchSpy.calledTwice).toStrictEqual(true);
|
||
|
expect(updateSendErrors).toHaveBeenCalled();
|
||
|
expect(updateSendErrors).toHaveBeenCalledWith({ amount: null });
|
||
|
expect(updateSendAmount).toHaveBeenCalled();
|
||
|
expect(updateSendAmount).toHaveBeenCalledWith(12);
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('setMaxModeTo()', () => {
|
||
|
it('should dispatch an action', () => {
|
||
4 years ago
|
mapDispatchToPropsObject.setMaxModeTo('mockVal');
|
||
4 years ago
|
expect(dispatchSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(setMaxModeTo).toHaveBeenCalledWith('mockVal');
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|