2021-11-18 18:54:58 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { screen } from '@testing-library/react';
|
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
import { EDIT_GAS_MODES } from '../../../../../shared/constants/gas';
|
2021-11-18 18:54:58 +01:00
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
|
|
|
import { ETH } from '../../../../helpers/constants/common';
|
|
|
|
import configureStore from '../../../../store/store';
|
|
|
|
import { GasFeeContextProvider } from '../../../../contexts/gasFee';
|
|
|
|
|
|
|
|
import EditGasItem from './edit-gas-item';
|
|
|
|
|
|
|
|
jest.mock('../../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
2021-11-18 20:08:29 +01:00
|
|
|
getGasFeeTimeEstimate: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve('unknown')),
|
2021-11-18 18:54:58 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
const MOCK_FEE_ESTIMATE = {
|
|
|
|
low: {
|
|
|
|
minWaitTimeEstimate: 360000,
|
|
|
|
maxWaitTimeEstimate: 300000,
|
|
|
|
suggestedMaxPriorityFeePerGas: '3',
|
|
|
|
suggestedMaxFeePerGas: '53',
|
|
|
|
},
|
|
|
|
medium: {
|
|
|
|
minWaitTimeEstimate: 30000,
|
|
|
|
maxWaitTimeEstimate: 60000,
|
|
|
|
suggestedMaxPriorityFeePerGas: '7',
|
|
|
|
suggestedMaxFeePerGas: '70',
|
|
|
|
},
|
|
|
|
high: {
|
|
|
|
minWaitTimeEstimate: 15000,
|
|
|
|
maxWaitTimeEstimate: 15000,
|
|
|
|
suggestedMaxPriorityFeePerGas: '10',
|
|
|
|
suggestedMaxFeePerGas: '100',
|
|
|
|
},
|
|
|
|
estimatedBaseFee: '50',
|
|
|
|
};
|
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
const ESTIMATE_MOCK = {
|
2021-11-18 20:08:29 +01:00
|
|
|
maxFeePerGas: '0x59682f10',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
};
|
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
const renderComponent = ({
|
|
|
|
componentProps,
|
|
|
|
transactionProps,
|
|
|
|
contextProps,
|
|
|
|
} = {}) => {
|
2021-11-18 18:54:58 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
nativeCurrency: ETH,
|
|
|
|
provider: {},
|
|
|
|
cachedBalances: {},
|
|
|
|
accounts: {
|
|
|
|
'0xAddress': {
|
|
|
|
address: '0xAddress',
|
|
|
|
balance: '0x176e5b6f173ebe66',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
featureFlags: { advancedInlineGas: true },
|
2022-01-06 03:47:26 +01:00
|
|
|
gasEstimateType: 'fee-market',
|
2021-11-18 18:54:58 +01:00
|
|
|
gasFeeEstimates: MOCK_FEE_ESTIMATE,
|
2021-11-18 20:08:29 +01:00
|
|
|
advancedGasFee: {
|
2022-01-10 20:34:54 +01:00
|
|
|
maxBaseFee: '100',
|
2021-11-18 20:08:29 +01:00
|
|
|
priorityFee: '2',
|
|
|
|
},
|
2021-11-18 18:54:58 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(
|
2021-11-18 20:08:29 +01:00
|
|
|
<GasFeeContextProvider
|
|
|
|
transaction={{ txParams: { gas: '0x5208' }, ...transactionProps }}
|
2021-12-12 00:26:28 +01:00
|
|
|
{...contextProps}
|
2021-11-18 20:08:29 +01:00
|
|
|
>
|
2021-11-29 18:40:48 +01:00
|
|
|
<EditGasItem priorityLevel="low" {...componentProps} />
|
2021-11-18 18:54:58 +01:00
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('EditGasItem', () => {
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should renders low gas estimate option for priorityLevel low', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({ componentProps: { priorityLevel: 'low' } });
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(screen.queryByRole('button', { name: 'low' })).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('🐢')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Low')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('5 min')).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByTitle('0.001113 ETH')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should renders market gas estimate option for priorityLevel medium', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({ componentProps: { priorityLevel: 'medium' } });
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(
|
|
|
|
screen.queryByRole('button', { name: 'medium' }),
|
|
|
|
).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('🦊')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Market')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('5 min')).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByTitle('0.00147 ETH')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should renders aggressive gas estimate option for priorityLevel high', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({ componentProps: { priorityLevel: 'high' } });
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(screen.queryByRole('button', { name: 'high' })).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('🦍')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('Aggressive')).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('15 sec')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.0021 ETH')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-18 20:08:29 +01:00
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
it('should render priorityLevel high as "Swap suggested" for swaps', () => {
|
|
|
|
renderComponent({
|
|
|
|
componentProps: { priorityLevel: 'high' },
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SWAPS },
|
|
|
|
});
|
|
|
|
expect(screen.queryByRole('button', { name: 'high' })).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🔄')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Swap suggested')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('15 sec')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.0021 ETH')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should highlight option is priorityLevel is currently selected', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({
|
|
|
|
componentProps: { priorityLevel: 'high' },
|
|
|
|
transactionProps: { userFeeLevel: 'high' },
|
|
|
|
});
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(
|
2021-12-03 16:59:48 +01:00
|
|
|
document.getElementsByClassName('edit-gas-item--selected'),
|
2021-11-18 20:08:29 +01:00
|
|
|
).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should renders site gas estimate option for priorityLevel dappSuggested', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({
|
|
|
|
componentProps: { priorityLevel: 'dappSuggested' },
|
2022-01-06 03:47:26 +01:00
|
|
|
transactionProps: { dappSuggestedGasFees: ESTIMATE_MOCK },
|
2021-12-12 00:26:28 +01:00
|
|
|
});
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(
|
|
|
|
screen.queryByRole('button', { name: 'dappSuggested' }),
|
|
|
|
).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('🌐')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Site')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.0000315 ETH')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should renders advance gas estimate option for priorityLevel custom', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
renderComponent({
|
|
|
|
componentProps: { priorityLevel: 'custom' },
|
|
|
|
transactionProps: { userFeeLevel: 'high' },
|
|
|
|
});
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(
|
|
|
|
screen.queryByRole('button', { name: 'custom' }),
|
|
|
|
).toBeInTheDocument();
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('⚙️')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('Advanced')).toBeInTheDocument();
|
|
|
|
// below value of custom gas fee estimate is default obtained from state.metamask.advancedGasFee
|
2022-01-10 20:34:54 +01:00
|
|
|
expect(screen.queryByTitle('0.0021 ETH')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
});
|
2022-01-06 03:47:26 +01:00
|
|
|
|
|
|
|
it('should renders +10% gas estimate option for priorityLevel minimum', () => {
|
|
|
|
renderComponent({
|
2022-01-06 23:40:31 +01:00
|
|
|
componentProps: { priorityLevel: 'tenPercentIncreased' },
|
2022-01-06 03:47:26 +01:00
|
|
|
transactionProps: {
|
2022-01-06 23:40:31 +01:00
|
|
|
userFeeLevel: 'tenPercentIncreased',
|
2022-01-06 03:47:26 +01:00
|
|
|
previousGas: ESTIMATE_MOCK,
|
|
|
|
},
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.CANCEL },
|
|
|
|
});
|
|
|
|
expect(
|
2022-01-06 23:40:31 +01:00
|
|
|
screen.queryByRole('button', { name: 'tenPercentIncreased' }),
|
2022-01-06 03:47:26 +01:00
|
|
|
).toBeInTheDocument();
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('10% increase')).toBeInTheDocument();
|
2022-01-06 03:47:26 +01:00
|
|
|
expect(screen.queryByTitle('0.00003465 ETH')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-18 18:54:58 +01:00
|
|
|
});
|