2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
|
|
|
import { mount } from 'enzyme';
|
2021-03-16 22:00:08 +01:00
|
|
|
import AdvancedTabContent from './advanced-gas-inputs.container';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Advanced Gas Inputs', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let wrapper, clock;
|
2020-01-30 20:34:45 +01:00
|
|
|
|
|
|
|
const props = {
|
|
|
|
updateCustomGasPrice: sinon.spy(),
|
|
|
|
updateCustomGasLimit: sinon.spy(),
|
|
|
|
showGasPriceInfoModal: sinon.spy(),
|
|
|
|
showGasLimitInfoModal: sinon.spy(),
|
|
|
|
customGasPrice: 0,
|
|
|
|
customGasLimit: 0,
|
|
|
|
insufficientBalance: false,
|
|
|
|
customPriceIsSafe: true,
|
|
|
|
isSpeedUp: false,
|
2020-10-19 15:11:23 +02:00
|
|
|
minimumGasLimit: 21000,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
beforeEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
clock = sinon.useFakeTimers();
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper = mount(<AdvancedTabContent.WrappedComponent {...props} />, {
|
|
|
|
context: {
|
|
|
|
t: (str) => str,
|
2020-08-19 18:27:05 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
afterEach(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
clock.restore();
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('wont update gasPrice in props before debounce', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const event = { target: { value: 1 } };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.find('input').at(0).simulate('change', event);
|
|
|
|
clock.tick(499);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.updateCustomGasPrice.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('simulates onChange on gas price after debounce', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const event = { target: { value: 1 } };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.find('input').at(0).simulate('change', event);
|
|
|
|
clock.tick(500);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.updateCustomGasPrice.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.updateCustomGasPrice.calledWith(1)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('wont update gasLimit in props before debounce', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const event = { target: { value: 21000 } };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.find('input').at(1).simulate('change', event);
|
|
|
|
clock.tick(499);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.updateCustomGasLimit.callCount).toStrictEqual(0);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('simulates onChange on gas limit after debounce', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const event = { target: { value: 21000 } };
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.find('input').at(1).simulate('change', event);
|
|
|
|
clock.tick(500);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(props.updateCustomGasLimit.calledOnce).toStrictEqual(true);
|
|
|
|
expect(props.updateCustomGasLimit.calledWith(21000)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when insufficientBalance under gas price and gas limit', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ insufficientBalance: true });
|
2020-11-03 00:41:28 +01:00
|
|
|
const renderError = wrapper.find(
|
|
|
|
'.advanced-gas-inputs__gas-edit-row__error-text',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderError).toHaveLength(2);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderError.at(0).text()).toStrictEqual('insufficientBalance');
|
|
|
|
expect(renderError.at(1).text()).toStrictEqual('insufficientBalance');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors zero gas price / speed up', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ isSpeedUp: true });
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const renderError = wrapper.find(
|
|
|
|
'.advanced-gas-inputs__gas-edit-row__error-text',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderError).toHaveLength(2);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderError.at(0).text()).toStrictEqual(
|
|
|
|
'zeroGasPriceOnSpeedUpError',
|
|
|
|
);
|
|
|
|
expect(renderError.at(1).text()).toStrictEqual(
|
2021-02-04 19:15:23 +01:00
|
|
|
'gasLimitTooLowWithDynamicFee',
|
|
|
|
);
|
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('warns when custom gas price is too low', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
wrapper.setProps({ customPriceIsSafe: false });
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const renderWarning = wrapper.find(
|
|
|
|
'.advanced-gas-inputs__gas-edit-row__warning-text',
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderWarning).toHaveLength(1);
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderWarning.text()).toStrictEqual('gasPriceExtremelyLow');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-03-05 18:32:09 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('errors when custom gas price is too excessive', () => {
|
2021-03-05 18:32:09 +01:00
|
|
|
wrapper.setProps({ customPriceIsExcessive: true });
|
|
|
|
|
|
|
|
const renderError = wrapper.find(
|
|
|
|
'.advanced-gas-inputs__gas-edit-row__error-text',
|
|
|
|
);
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(renderError).toHaveLength(2);
|
|
|
|
expect(renderError.at(0).text()).toStrictEqual('gasPriceExcessiveInput');
|
2021-03-05 18:32:09 +01:00
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|