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.
94 lines
2.8 KiB
94 lines
2.8 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import AmountMaxButton from './amount-max-button.component';
|
||
7 years ago
|
|
||
4 years ago
|
describe('AmountMaxButton Component', () => {
|
||
4 years ago
|
let wrapper;
|
||
|
let instance;
|
||
7 years ago
|
|
||
5 years ago
|
const propsMethodSpies = {
|
||
|
setAmountToMax: sinon.spy(),
|
||
|
setMaxModeTo: sinon.spy(),
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
4 years ago
|
const MOCK_EVENT = { preventDefault: () => undefined };
|
||
5 years ago
|
|
||
4 years ago
|
beforeAll(() => {
|
||
4 years ago
|
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount');
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
beforeEach(() => {
|
||
4 years ago
|
wrapper = shallow(
|
||
5 years ago
|
<AmountMaxButton
|
||
|
balance="mockBalance"
|
||
|
gasTotal="mockGasTotal"
|
||
|
maxModeOn={false}
|
||
4 years ago
|
sendToken={{ address: 'mockTokenAddress' }}
|
||
5 years ago
|
setAmountToMax={propsMethodSpies.setAmountToMax}
|
||
|
setMaxModeTo={propsMethodSpies.setMaxModeTo}
|
||
|
tokenBalance="mockTokenBalance"
|
||
4 years ago
|
/>,
|
||
|
{
|
||
|
context: {
|
||
|
t: (str) => `${str}_t`,
|
||
|
metricsEvent: () => undefined,
|
||
|
},
|
||
6 years ago
|
},
|
||
4 years ago
|
);
|
||
|
instance = wrapper.instance();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterEach(() => {
|
||
4 years ago
|
propsMethodSpies.setAmountToMax.resetHistory();
|
||
|
propsMethodSpies.setMaxModeTo.resetHistory();
|
||
|
AmountMaxButton.prototype.setMaxAmount.resetHistory();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
afterAll(() => {
|
||
4 years ago
|
sinon.restore();
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
describe('setMaxAmount', () => {
|
||
|
it('should call setAmountToMax with the correct params', () => {
|
||
|
expect(propsMethodSpies.setAmountToMax.callCount).toStrictEqual(0);
|
||
4 years ago
|
instance.setMaxAmount();
|
||
4 years ago
|
expect(propsMethodSpies.setAmountToMax.callCount).toStrictEqual(1);
|
||
|
expect(propsMethodSpies.setAmountToMax.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
{
|
||
7 years ago
|
balance: 'mockBalance',
|
||
|
gasTotal: 'mockGasTotal',
|
||
5 years ago
|
sendToken: { address: 'mockTokenAddress' },
|
||
7 years ago
|
tokenBalance: 'mockTokenBalance',
|
||
4 years ago
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('render', () => {
|
||
|
it('should render an element with a send-v2__amount-max class', () => {
|
||
|
expect(wrapper.find('.send-v2__amount-max')).toHaveLength(1);
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call setMaxModeTo and setMaxAmount when the checkbox is checked', () => {
|
||
4 years ago
|
const { onClick } = wrapper.find('.send-v2__amount-max').props();
|
||
7 years ago
|
|
||
4 years ago
|
expect(AmountMaxButton.prototype.setMaxAmount.callCount).toStrictEqual(0);
|
||
|
expect(propsMethodSpies.setMaxModeTo.callCount).toStrictEqual(0);
|
||
4 years ago
|
onClick(MOCK_EVENT);
|
||
4 years ago
|
expect(AmountMaxButton.prototype.setMaxAmount.callCount).toStrictEqual(1);
|
||
|
expect(propsMethodSpies.setMaxModeTo.callCount).toStrictEqual(1);
|
||
|
expect(propsMethodSpies.setMaxModeTo.getCall(0).args).toStrictEqual([
|
||
4 years ago
|
true,
|
||
4 years ago
|
]);
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should render the expected text when maxModeOn is false', () => {
|
||
4 years ago
|
wrapper.setProps({ maxModeOn: false });
|
||
4 years ago
|
expect(wrapper.find('.send-v2__amount-max').text()).toStrictEqual(
|
||
|
'max_t',
|
||
|
);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
});
|