Skip to content

Commit

Permalink
fix advanced-gas-fee-gas-limit.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Feb 20, 2024
1 parent cd086c4 commit b91d6f9
Showing 1 changed file with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ import configureStore from '../../../../../store/store';

import { AdvancedGasFeePopoverContextProvider } from '../context';
import AdvancedGasFeeGasLimit from './advanced-gas-fee-gas-limit';
import { act } from 'react-dom/test-utils';

jest.mock('../../../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
gasFeeStartPollingByNetworkClientId: jest
.fn()
.mockImplementation(() => Promise.resolve()),
addPollingTokenToAppState: jest.fn(),
removePollingTokenFromAppState: jest.fn(),
.mockResolvedValue('pollingToken'),
gasFeeStopPollingByPollingToken: jest.fn(),
getNetworkConfigurationByNetworkClientId: jest
.fn()
.mockResolvedValue({ chainId: '0x5' }),
}));

const render = (contextProps) => {


const render = async (contextProps) => {
const store = configureStore({
metamask: {
...mockState.metamask,
Expand All @@ -31,14 +35,26 @@ const render = (contextProps) => {
balance: '0x1F4',
},
},
advancedGasFee: { priorityFee: 100 },
advancedGasFee: { '0x5': { priorityFee: 100 } },
featureFlags: { advancedInlineGas: true },
gasFeeEstimates:
mockEstimates[GasEstimateTypes.feeMarket].gasFeeEstimates,
gasFeeEstimatesByChainId: {
...mockState.metamask.gasFeeEstimatesByChainId,
'0x5': {
...mockState.metamask.gasFeeEstimatesByChainId['0x5'],
gasFeeEstimates:
mockEstimates[GasEstimateTypes.feeMarket].gasFeeEstimates,
},
},
},
});

return renderWithProvider(
let result;

await act(
async () =>
renderWithProvider(
<GasFeeContextProvider
transaction={{
userFeeLevel: 'custom',
Expand All @@ -51,24 +67,26 @@ const render = (contextProps) => {
</AdvancedGasFeePopoverContextProvider>
</GasFeeContextProvider>,
store,
);
))

return result;
};

describe('AdvancedGasFeeGasLimit', () => {
it('should show GasLimit from transaction', () => {
render();
it('should show GasLimit from transaction', async () => {
await render();
expect(screen.getByText('21000')).toBeInTheDocument();
});

it('should show input when edit link is clicked', () => {
render();
it('should show input when edit link is clicked', async () => {
await render();
expect(document.getElementsByTagName('input')).toHaveLength(0);
fireEvent.click(screen.queryByText('Edit'));
expect(document.getElementsByTagName('input')[0]).toHaveValue(21000);
});

it('should show error if gas limit is not in range', () => {
render();
it('should show error if gas limit is not in range', async () => {
await render();
fireEvent.click(screen.queryByText('Edit'));
fireEvent.change(document.getElementsByTagName('input')[0], {
target: { value: 20000 },
Expand Down Expand Up @@ -96,8 +114,8 @@ describe('AdvancedGasFeeGasLimit', () => {
).not.toBeInTheDocument();
});

it('should validate gas limit against minimumGasLimit it is passed to context', () => {
render({ minimumGasLimit: '0x7530' });
it('should validate gas limit against minimumGasLimit it is passed to context', async () => {
await render({ minimumGasLimit: '0x7530' });
fireEvent.click(screen.queryByText('Edit'));
fireEvent.change(document.getElementsByTagName('input')[0], {
target: { value: 25000 },
Expand Down

0 comments on commit b91d6f9

Please sign in to comment.