1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-30 08:09:15 +01:00
metamask-extension/ui/components/app/edit-gas-fee-button/edit-gas-fee-button.test.js

154 lines
5.2 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { screen } from '@testing-library/react';
import {
2021-12-12 00:26:28 +01:00
EDIT_GAS_MODES,
GAS_ESTIMATE_TYPES,
PRIORITY_LEVELS,
} from '../../../../shared/constants/gas';
import { TransactionEnvelopeType } from '../../../../shared/constants/transaction';
import { GasFeeContextProvider } from '../../../contexts/gasFee';
import { renderWithProvider } from '../../../../test/jest';
import mockEstimates from '../../../../test/data/mock-estimates.json';
import mockState from '../../../../test/data/mock-state.json';
import configureStore from '../../../store/store';
import EditGasFeeButton from './edit-gas-fee-button';
jest.mock('../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
.fn()
.mockImplementation(() => Promise.resolve()),
addPollingTokenToAppState: jest.fn(),
createTransactionEventFragment: jest.fn(),
}));
const render = ({ componentProps, contextProps } = {}) => {
const store = configureStore({
metamask: {
...mockState.metamask,
accounts: {
[mockState.metamask.selectedAddress]: {
address: mockState.metamask.selectedAddress,
balance: '0x1F4',
},
},
gasFeeEstimates: mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET],
},
});
return renderWithProvider(
<GasFeeContextProvider {...contextProps}>
<EditGasFeeButton {...componentProps} />
</GasFeeContextProvider>,
store,
);
};
describe('EditGasFeeButton', () => {
it('should render edit link with text low if low gas estimates are selected', () => {
render({ contextProps: { transaction: { userFeeLevel: 'low' } } });
expect(screen.queryByText('🐢')).toBeInTheDocument();
expect(screen.queryByText('Low')).toBeInTheDocument();
});
it('should render edit link with text market if medium gas estimates are selected', () => {
render({ contextProps: { transaction: { userFeeLevel: 'medium' } } });
expect(screen.queryByText('🦊')).toBeInTheDocument();
expect(screen.queryByText('Market')).toBeInTheDocument();
});
2022-01-28 16:09:07 +01:00
it('should render edit link with text aggressive if high gas estimates are selected', () => {
render({ contextProps: { transaction: { userFeeLevel: 'high' } } });
expect(screen.queryByText('🦍')).toBeInTheDocument();
expect(screen.queryByText('Aggressive')).toBeInTheDocument();
});
2022-01-06 23:40:31 +01:00
it('should render edit link with text 10% increase if tenPercentIncreased gas estimates are selected', () => {
render({
contextProps: { transaction: { userFeeLevel: 'tenPercentIncreased' } },
});
expect(screen.queryByText('10% increase')).toBeInTheDocument();
});
it('should render edit link with text Site suggested if site suggested estimated are used', () => {
render({
contextProps: {
transaction: {
userFeeLevel: PRIORITY_LEVELS.DAPP_SUGGESTED,
dappSuggestedGasFees: { maxFeePerGas: 1, maxPriorityFeePerGas: 1 },
txParams: { maxFeePerGas: 1, maxPriorityFeePerGas: 1 },
},
},
});
expect(screen.queryByText('🌐')).toBeInTheDocument();
expect(screen.queryByText('Site suggested')).toBeInTheDocument();
expect(document.getElementsByClassName('info-tooltip')).toHaveLength(1);
});
2021-12-12 00:26:28 +01:00
it('should render edit link with text swap suggested if high gas estimates are selected for swaps', () => {
render({
contextProps: {
transaction: { userFeeLevel: 'high' },
editGasMode: EDIT_GAS_MODES.SWAPS,
},
});
expect(screen.queryByText('🔄')).toBeInTheDocument();
expect(screen.queryByText('Swap suggested')).toBeInTheDocument();
});
it('should render edit link with text advance if custom gas estimates are used', () => {
render({
contextProps: {
defaultEstimateToUse: 'custom',
transaction: {},
},
});
2022-01-06 23:40:31 +01:00
expect(screen.queryByText('⚙️')).toBeInTheDocument();
expect(screen.queryByText('Advanced')).toBeInTheDocument();
expect(screen.queryByText('Edit')).toBeInTheDocument();
});
it('should not render edit link if transaction has simulation error and prop userAcknowledgedGasMissing is false', () => {
render({
contextProps: {
transaction: {
simulationFails: true,
userFeeLevel: 'low',
},
},
componentProps: { userAcknowledgedGasMissing: false },
});
expect(screen.queryByRole('button')).not.toBeInTheDocument();
expect(screen.queryByText('Low')).not.toBeInTheDocument();
});
it('should render edit link if userAcknowledgedGasMissing is true even if transaction has simulation error', () => {
render({
contextProps: {
transaction: {
simulationFails: true,
userFeeLevel: 'low',
},
},
componentProps: { userAcknowledgedGasMissing: true },
});
expect(screen.queryByRole('button')).toBeInTheDocument();
expect(screen.queryByText('Low')).toBeInTheDocument();
});
it('should render null for legacy transactions', () => {
const { container } = render({
contextProps: {
transaction: {
userFeeLevel: 'low',
txParams: { type: TransactionEnvelopeType.legacy },
},
},
});
expect(container.firstChild).toBeNull();
});
});