1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 12:56:01 +01:00
metamask-extension/ui/components/app/edit-gas-fee-popover/network-statistics/network-statistics.test.js
Elliot Winkler f8f4397339
Degrade gracefully when gas API is down (#13865)
When the gas API is down, the logic we use will no longer compute all of
the data that the gas API returns in order to reduce the burden on
Infura. Specifically, only estimated fees for different priority levels,
as well as the latest base fee, will be available; all other data
points, such as the latest and historical priority fee range and network
stability, will be missing. This commit updates the frontend logic to
account for this lack of data by merely hiding the relevant pieces of
the UI that would otherwise be shown.
2022-03-11 11:59:58 -07:00

119 lines
3.3 KiB
JavaScript

import React from 'react';
import { renderWithProvider, screen } from '../../../../../test/jest';
import configureStore from '../../../../store/store';
import { GasFeeContext } from '../../../../contexts/gasFee';
import NetworkStatistics from './network-statistics';
const renderComponent = ({ gasFeeContext = {}, state = {} } = {}) => {
const store = configureStore(state);
return renderWithProvider(
<GasFeeContext.Provider value={gasFeeContext}>
<NetworkStatistics />
</GasFeeContext.Provider>,
store,
);
};
describe('NetworkStatistics', () => {
it('should render the latest base fee rounded to no decimal places', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
estimatedBaseFee: '50.0112',
},
},
});
expect(screen.getByText('50 GWEI')).toBeInTheDocument();
});
it('should not render the latest base fee if it is not present', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
estimatedBaseFee: null,
},
},
});
expect(
screen.queryByTestId('formatted-latest-base-fee'),
).not.toBeInTheDocument();
});
it('should not render the latest base fee if no gas fee estimates are available', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: null,
},
});
expect(
screen.queryByTestId('formatted-latest-base-fee'),
).not.toBeInTheDocument();
});
it('should render the latest priority fee range, with the low end of the range rounded to 1 decimal place and the high end rounded to no decimal places', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
latestPriorityFeeRange: ['1.100001668', '2.5634234'],
},
},
});
expect(screen.getByText('1.1 - 3 GWEI')).toBeInTheDocument();
});
it('should not render the latest priority fee range if it is not present', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
latestPriorityFeeRange: null,
},
},
});
expect(
screen.queryByTestId('formatted-latest-priority-fee-range'),
).not.toBeInTheDocument();
});
it('should not render the latest priority fee range if no gas fee estimates are available', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: null,
},
});
expect(
screen.queryByTestId('formatted-latest-priority-fee-range'),
).not.toBeInTheDocument();
});
it('should render the network status slider', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
networkCongestion: 0.5,
},
},
});
expect(screen.getByText('Stable')).toBeInTheDocument();
});
it('should not render the network status slider if the network congestion is not available', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: {
networkCongestion: null,
},
},
});
expect(screen.queryByTestId('status-slider-label')).not.toBeInTheDocument();
});
it('should not render the network status slider if no gas fee estimates are available', () => {
renderComponent({
gasFeeContext: {
gasFeeEstimates: null,
},
});
expect(screen.queryByTestId('status-slider-label')).not.toBeInTheDocument();
});
});