1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 23:06:37 +01:00
metamask-extension/ui/components/app/advanced-gas-inputs/advanced-gas-inputs.test.js
Mark Stacey d1cea85f33
Rename provider to providerConfig (#18907)
* Rename `provider` to `providerConfig`

The network controller `provider` state has been renamed to
 `providerConfig`. This better reflects what this state is, and makes
this controller more closely aligned with the core network controller.

All references to the provider configuration have been updated to
prefer `providerConfig` over `provider`, to make the distinction clear
between a provider and provider config.

Closes #18902

* Add migration
2023-05-02 13:23:20 -02:30

120 lines
3.4 KiB
JavaScript

import React from 'react';
import sinon from 'sinon';
import { renderWithProvider, fireEvent } from '../../../../test/jest';
import configureStore from '../../../store/store';
import AdvancedGasInputs from '.';
describe('AdvancedGasInputs', () => {
let clock;
const props = {
updateCustomGasPrice: jest.fn(),
updateCustomGasLimit: jest.fn(),
showGasPriceInfoModal: jest.fn(),
showGasLimitInfoModal: jest.fn(),
customGasPrice: 0,
customGasLimit: 0,
insufficientBalance: false,
customPriceIsSafe: true,
isSpeedUp: false,
minimumGasLimit: 21000,
};
const store = configureStore({ metamask: { providerConfig: {} } });
beforeEach(() => {
clock = sinon.useFakeTimers();
});
afterEach(() => {
clock.restore();
});
it("won't update gasPrice in props before debounce", () => {
const { getByTestId } = renderWithProvider(
<AdvancedGasInputs {...props} />,
store,
);
fireEvent.change(getByTestId('gas-price'), { target: { value: '10' } });
clock.tick(499);
expect(props.updateCustomGasPrice).toHaveBeenCalledTimes(0);
});
it('simulates onChange on gas price after debounce', () => {
const { getByTestId } = renderWithProvider(
<AdvancedGasInputs {...props} />,
store,
);
fireEvent.change(getByTestId('gas-price'), { target: { value: '10' } });
clock.tick(500);
expect(props.updateCustomGasPrice).toHaveBeenCalledTimes(1);
expect(props.updateCustomGasPrice).toHaveBeenCalledWith('2540be400');
});
it('wont update gasLimit in props before debounce', () => {
const { getByTestId } = renderWithProvider(
<AdvancedGasInputs {...props} />,
store,
);
fireEvent.change(getByTestId('gas-limit'), { target: { value: '21000' } });
clock.tick(499);
expect(props.updateCustomGasLimit).toHaveBeenCalledTimes(0);
});
it('simulates onChange on gas limit after debounce', () => {
const { getByTestId } = renderWithProvider(
<AdvancedGasInputs {...props} />,
store,
);
fireEvent.change(getByTestId('gas-limit'), { target: { value: '21000' } });
clock.tick(500);
expect(props.updateCustomGasLimit).toHaveBeenCalledTimes(1);
expect(props.updateCustomGasLimit).toHaveBeenCalledWith('5208');
});
it('errors when insufficientBalance under gas price and gas limit', () => {
const { getAllByText } = renderWithProvider(
<AdvancedGasInputs {...props} insufficientBalance />,
store,
);
expect(getAllByText('Insufficient balance.')).toHaveLength(2);
});
it('errors zero gas price / speed up', () => {
const { queryByText } = renderWithProvider(
<AdvancedGasInputs {...props} isSpeedUp />,
store,
);
expect(queryByText('Zero gas price on speed up')).toBeInTheDocument();
expect(queryByText('Gas limit must be at least 21000')).toBeInTheDocument();
});
it('warns when custom gas price is too low', () => {
const { queryByText } = renderWithProvider(
<AdvancedGasInputs {...props} customPriceIsSafe={false} />,
store,
);
expect(queryByText('Gas price extremely low')).toBeInTheDocument();
});
it('errors when custom gas price is too excessive', () => {
const { queryByText } = renderWithProvider(
<AdvancedGasInputs {...props} customPriceIsExcessive />,
store,
);
expect(queryByText('Gas price is excessive')).toBeInTheDocument();
});
});