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 EditGasFeePopover from './edit-gas-fee-popover';
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
2022-02-03 01:28:28 +01:00
|
|
|
createTransactionEventFragment: jest.fn(),
|
2021-11-18 18:54:58 +01:00
|
|
|
}));
|
|
|
|
|
2021-11-23 18:46:33 +01:00
|
|
|
jest.mock('../../../contexts/transaction-modal', () => ({
|
|
|
|
useTransactionModalContext: () => ({
|
|
|
|
closeModal: () => undefined,
|
|
|
|
currentModal: 'editGasFee',
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
2021-11-18 18:54:58 +01:00
|
|
|
const MOCK_FEE_ESTIMATE = {
|
|
|
|
low: {
|
|
|
|
minWaitTimeEstimate: 360000,
|
|
|
|
maxWaitTimeEstimate: 300000,
|
2022-01-06 03:47:26 +01:00
|
|
|
suggestedMaxPriorityFeePerGas: 3,
|
|
|
|
suggestedMaxFeePerGas: 53,
|
2021-11-18 18:54:58 +01:00
|
|
|
},
|
|
|
|
medium: {
|
|
|
|
minWaitTimeEstimate: 30000,
|
|
|
|
maxWaitTimeEstimate: 60000,
|
2022-01-06 03:47:26 +01:00
|
|
|
suggestedMaxPriorityFeePerGas: 7,
|
|
|
|
suggestedMaxFeePerGas: 70,
|
2021-11-18 18:54:58 +01:00
|
|
|
},
|
|
|
|
high: {
|
|
|
|
minWaitTimeEstimate: 15000,
|
|
|
|
maxWaitTimeEstimate: 15000,
|
2022-01-06 03:47:26 +01:00
|
|
|
suggestedMaxPriorityFeePerGas: 10,
|
|
|
|
suggestedMaxFeePerGas: 100,
|
2021-11-18 18:54:58 +01:00
|
|
|
},
|
2022-01-06 03:47:26 +01:00
|
|
|
latestPriorityFeeRange: [2, 6],
|
|
|
|
estimatedBaseFee: 50,
|
|
|
|
networkCongestion: 0.7,
|
2021-11-18 18:54:58 +01:00
|
|
|
};
|
|
|
|
|
2021-12-12 00:26:28 +01:00
|
|
|
const render = ({ txProps, contextProps } = {}) => {
|
2021-11-18 18:54:58 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
nativeCurrency: ETH,
|
|
|
|
provider: {},
|
|
|
|
cachedBalances: {},
|
|
|
|
accounts: {
|
|
|
|
'0xAddress': {
|
|
|
|
address: '0xAddress',
|
2021-11-23 19:18:44 +01:00
|
|
|
balance: '0x1F4',
|
2021-11-18 18:54:58 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
featureFlags: { advancedInlineGas: true },
|
|
|
|
gasFeeEstimates: MOCK_FEE_ESTIMATE,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(
|
2021-11-23 19:18:44 +01:00
|
|
|
<GasFeeContextProvider
|
|
|
|
transaction={{ txParams: { gas: '0x5208' }, ...txProps }}
|
2021-12-12 00:26:28 +01:00
|
|
|
{...contextProps}
|
2021-11-23 19:18:44 +01:00
|
|
|
>
|
2021-11-18 18:54:58 +01:00
|
|
|
<EditGasFeePopover />
|
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('EditGasFeePopover', () => {
|
|
|
|
it('should renders low / medium / high options', () => {
|
2022-01-18 18:37:52 +01:00
|
|
|
render({ txProps: { dappSuggestedGasFees: { maxFeePerGas: '0x5208' } } });
|
2021-11-18 18:54:58 +01:00
|
|
|
|
|
|
|
expect(screen.queryByText('🐢')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🦊')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🦍')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('🌐')).toBeInTheDocument();
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('⚙️')).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('Low')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Market')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Aggressive')).toBeInTheDocument();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryByText('Site')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Advanced')).toBeInTheDocument();
|
2021-11-18 18:54:58 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should show time estimates', () => {
|
2021-11-23 19:18:44 +01:00
|
|
|
render();
|
2021-11-18 20:08:29 +01:00
|
|
|
expect(screen.queryAllByText('5 min')).toHaveLength(2);
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByText('15 sec')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show gas fee estimates', () => {
|
2021-11-23 19:18:44 +01:00
|
|
|
render();
|
2021-11-18 18:54:58 +01:00
|
|
|
expect(screen.queryByTitle('0.001113 ETH')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.00147 ETH')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.0021 ETH')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-23 19:18:44 +01:00
|
|
|
|
|
|
|
it('should not show insufficient balance message if transaction value is less than balance', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
render({ txProps: { userFeeLevel: 'high', txParams: { value: '0x64' } } });
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(screen.queryByText('Insufficient funds.')).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show insufficient balance message if transaction value is more than balance', () => {
|
2021-12-12 00:26:28 +01:00
|
|
|
render({
|
|
|
|
txProps: { userFeeLevel: 'high', txParams: { value: '0x5208' } },
|
|
|
|
});
|
2021-11-23 19:18:44 +01:00
|
|
|
expect(screen.queryByText('Insufficient funds.')).toBeInTheDocument();
|
|
|
|
});
|
2021-12-12 00:26:28 +01:00
|
|
|
|
|
|
|
it('should not show low, aggressive and dapp-suggested options for swap', () => {
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SWAPS },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('🐢')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🦊')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🦍')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🌐')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('🔄')).toBeInTheDocument();
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('⚙️')).toBeInTheDocument();
|
2021-12-12 00:26:28 +01:00
|
|
|
expect(screen.queryByText('Low')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Market')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Aggressive')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Site')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Swap suggested')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Advanced')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show time estimates for swaps', () => {
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SWAPS },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Time')).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Max fee')).toBeInTheDocument();
|
|
|
|
});
|
2022-01-06 03:47:26 +01:00
|
|
|
|
|
|
|
it('should show correct header for edit gas mode', () => {
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SWAPS },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Edit gas fee')).toBeInTheDocument();
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.CANCEL },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Edit cancellation gas fee')).toBeInTheDocument();
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SPEED_UP },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Edit speed up gas fee')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show low option for cancel mode', () => {
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.CANCEL },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Low')).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not show low option for speedup mode', () => {
|
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SPEED_UP },
|
|
|
|
});
|
|
|
|
expect(screen.queryByText('Low')).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2022-01-06 23:40:31 +01:00
|
|
|
it('should show tenPercentIncreased option for cancel gas mode', () => {
|
2022-01-06 03:47:26 +01:00
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.CANCEL },
|
|
|
|
});
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('10% increase')).toBeInTheDocument();
|
2022-01-06 03:47:26 +01:00
|
|
|
});
|
|
|
|
|
2022-01-06 23:40:31 +01:00
|
|
|
it('should show tenPercentIncreased option for speedup gas mode', () => {
|
2022-01-06 03:47:26 +01:00
|
|
|
render({
|
|
|
|
contextProps: { editGasMode: EDIT_GAS_MODES.SPEED_UP },
|
|
|
|
});
|
2022-01-06 23:40:31 +01:00
|
|
|
expect(screen.queryByText('10% increase')).toBeInTheDocument();
|
2022-01-06 03:47:26 +01:00
|
|
|
});
|
2021-11-18 18:54:58 +01:00
|
|
|
});
|