2021-02-04 19:15:23 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import AmountMaxButton from '../amount-max-button.component';
|
2018-05-14 11:25:03 +02:00
|
|
|
|
|
|
|
describe('AmountMaxButton Component', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper;
|
|
|
|
let instance;
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
const propsMethodSpies = {
|
|
|
|
setAmountToMax: sinon.spy(),
|
|
|
|
setMaxModeTo: sinon.spy(),
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const MOCK_EVENT = { preventDefault: () => undefined };
|
2020-02-11 21:33:32 +01:00
|
|
|
|
|
|
|
before(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount');
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
beforeEach(function () {
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = shallow(
|
2019-12-03 17:35:44 +01:00
|
|
|
<AmountMaxButton
|
|
|
|
balance="mockBalance"
|
|
|
|
gasTotal="mockGasTotal"
|
|
|
|
maxModeOn={false}
|
2020-11-03 00:41:28 +01:00
|
|
|
sendToken={{ address: 'mockTokenAddress' }}
|
2019-12-03 17:35:44 +01:00
|
|
|
setAmountToMax={propsMethodSpies.setAmountToMax}
|
|
|
|
setMaxModeTo={propsMethodSpies.setMaxModeTo}
|
|
|
|
tokenBalance="mockTokenBalance"
|
2020-11-03 00:41:28 +01:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
context: {
|
|
|
|
t: (str) => `${str}_t`,
|
|
|
|
metricsEvent: () => undefined,
|
|
|
|
},
|
2019-05-07 18:12:14 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
instance = wrapper.instance();
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
afterEach(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
propsMethodSpies.setAmountToMax.resetHistory();
|
|
|
|
propsMethodSpies.setMaxModeTo.resetHistory();
|
|
|
|
AmountMaxButton.prototype.setMaxAmount.resetHistory();
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 21:33:32 +01:00
|
|
|
after(function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
sinon.restore();
|
|
|
|
});
|
2020-02-11 21:33:32 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('setMaxAmount', function () {
|
|
|
|
it('should call setAmountToMax with the correct params', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(propsMethodSpies.setAmountToMax.callCount, 0);
|
|
|
|
instance.setMaxAmount();
|
|
|
|
assert.strictEqual(propsMethodSpies.setAmountToMax.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(propsMethodSpies.setAmountToMax.getCall(0).args, [
|
2020-11-03 00:41:28 +01:00
|
|
|
{
|
2018-05-14 11:25:03 +02:00
|
|
|
balance: 'mockBalance',
|
|
|
|
gasTotal: 'mockGasTotal',
|
2020-05-29 19:46:10 +02:00
|
|
|
sendToken: { address: 'mockTokenAddress' },
|
2018-05-14 11:25:03 +02:00
|
|
|
tokenBalance: 'mockTokenBalance',
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('render', function () {
|
|
|
|
it('should render an element with a send-v2__amount-max class', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
assert(wrapper.exists('.send-v2__amount-max'));
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should call setMaxModeTo and setMaxAmount when the checkbox is checked', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { onClick } = wrapper.find('.send-v2__amount-max').props();
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
assert.strictEqual(AmountMaxButton.prototype.setMaxAmount.callCount, 0);
|
|
|
|
assert.strictEqual(propsMethodSpies.setMaxModeTo.callCount, 0);
|
|
|
|
onClick(MOCK_EVENT);
|
|
|
|
assert.strictEqual(AmountMaxButton.prototype.setMaxAmount.callCount, 1);
|
|
|
|
assert.strictEqual(propsMethodSpies.setMaxModeTo.callCount, 1);
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.deepStrictEqual(propsMethodSpies.setMaxModeTo.getCall(0).args, [
|
|
|
|
true,
|
2021-02-04 19:15:23 +01:00
|
|
|
]);
|
|
|
|
});
|
2018-05-14 11:25:03 +02:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render the expected text when maxModeOn is false', function () {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ maxModeOn: false });
|
|
|
|
assert.strictEqual(wrapper.find('.send-v2__amount-max').text(), 'max_t');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|