2021-12-03 16:59:48 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent, screen } from '@testing-library/react';
|
|
|
|
|
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../../../shared/constants/gas';
|
|
|
|
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
|
|
|
|
import mockEstimates from '../../../../../test/data/mock-estimates.json';
|
|
|
|
import mockState from '../../../../../test/data/mock-state.json';
|
|
|
|
import { GasFeeContextProvider } from '../../../../contexts/gasFee';
|
|
|
|
import configureStore from '../../../../store/store';
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
import { AdvancedGasFeePopoverContextProvider } from '../context';
|
2021-12-03 16:59:48 +01:00
|
|
|
import AdvancedGasFeeGasLimit from './advanced-gas-fee-gas-limit';
|
|
|
|
|
|
|
|
jest.mock('../../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
|
|
|
removePollingTokenFromAppState: jest.fn(),
|
|
|
|
}));
|
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
const render = (contextProps) => {
|
2021-12-03 16:59:48 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
...mockState.metamask,
|
|
|
|
accounts: {
|
|
|
|
[mockState.metamask.selectedAddress]: {
|
|
|
|
address: mockState.metamask.selectedAddress,
|
|
|
|
balance: '0x1F4',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
advancedGasFee: { priorityFee: 100 },
|
|
|
|
featureFlags: { advancedInlineGas: true },
|
|
|
|
gasFeeEstimates:
|
|
|
|
mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET].gasFeeEstimates,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return renderWithProvider(
|
|
|
|
<GasFeeContextProvider
|
|
|
|
transaction={{
|
|
|
|
userFeeLevel: 'custom',
|
|
|
|
txParams: { gas: '0x5208' },
|
|
|
|
}}
|
2021-12-06 19:47:26 +01:00
|
|
|
{...contextProps}
|
2021-12-03 16:59:48 +01:00
|
|
|
>
|
2021-12-06 19:47:26 +01:00
|
|
|
<AdvancedGasFeePopoverContextProvider>
|
2021-12-03 16:59:48 +01:00
|
|
|
<AdvancedGasFeeGasLimit />
|
2021-12-06 19:47:26 +01:00
|
|
|
</AdvancedGasFeePopoverContextProvider>
|
2021-12-03 16:59:48 +01:00
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('AdvancedGasFeeGasLimit', () => {
|
|
|
|
it('should show GasLimit from transaction', () => {
|
|
|
|
render();
|
|
|
|
expect(screen.getByText('21000')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show input when edit link is clicked', () => {
|
|
|
|
render();
|
|
|
|
expect(document.getElementsByTagName('input')).toHaveLength(0);
|
|
|
|
fireEvent.click(screen.queryByText('Edit'));
|
|
|
|
expect(document.getElementsByTagName('input')[0]).toHaveValue(21000);
|
|
|
|
});
|
2021-12-06 19:47:26 +01:00
|
|
|
|
|
|
|
it('should show error if gas limit is not in range', () => {
|
|
|
|
render();
|
|
|
|
fireEvent.click(screen.queryByText('Edit'));
|
|
|
|
fireEvent.change(document.getElementsByTagName('input')[0], {
|
|
|
|
target: { value: 20000 },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText(
|
|
|
|
'Gas limit must be greater than 20999 and less than 7920027',
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
fireEvent.change(document.getElementsByTagName('input')[0], {
|
|
|
|
target: { value: 8000000 },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText(
|
|
|
|
'Gas limit must be greater than 20999 and less than 7920027',
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
fireEvent.change(document.getElementsByTagName('input')[0], {
|
|
|
|
target: { value: 7000000 },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText(
|
|
|
|
'Gas limit must be greater than 20999 and less than 7920027',
|
|
|
|
),
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should validate gas limit against minimumGasLimit it is passed to context', () => {
|
|
|
|
render({ minimumGasLimit: '0x7530' });
|
|
|
|
fireEvent.click(screen.queryByText('Edit'));
|
|
|
|
fireEvent.change(document.getElementsByTagName('input')[0], {
|
|
|
|
target: { value: 25000 },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText(
|
|
|
|
'Gas limit must be greater than 29999 and less than 7920027',
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
2021-12-03 16:59:48 +01:00
|
|
|
});
|