1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-27 04:46:10 +01:00
metamask-extension/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-popover.test.js
Jyoti Puri eb39290dcd
Fixes in EIP-1559 V2 implementation (#13574)
* Fixes in EIP-1559 V2 implementation

* Adding check for transaction.id in useTransactionEventFragment hook

* Update ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-gas-limit/advanced-gas-fee-gas-limit.js

Co-authored-by: Alex Donesky <adonesky@gmail.com>

* fix

* fix

* fix

* fix

* fix

* fix build

Co-authored-by: Dan J Miller <danjm.com@gmail.com>
Co-authored-by: Alex Donesky <adonesky@gmail.com>
2022-02-11 10:59:17 -03:30

99 lines
3.2 KiB
JavaScript

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 { MAX_GAS_LIMIT_DEC } from '../../../pages/send/send.constants';
import { GasFeeContextProvider } from '../../../contexts/gasFee';
import configureStore from '../../../store/store';
import AdvancedGasFeePopover from './advanced-gas-fee-popover';
jest.mock('../../../store/actions', () => ({
disconnectGasFeeEstimatePoller: jest.fn(),
getGasFeeEstimatesAndStartPolling: jest
.fn()
.mockImplementation(() => Promise.resolve()),
addPollingTokenToAppState: jest.fn(),
removePollingTokenFromAppState: jest.fn(),
createTransactionEventFragment: jest.fn(),
}));
jest.mock('../../../contexts/transaction-modal', () => ({
useTransactionModalContext: () => ({
closeModal: () => undefined,
currentModal: 'advancedGasFee',
}),
}));
const render = () => {
const store = configureStore({
metamask: {
...mockState.metamask,
accounts: {
[mockState.metamask.selectedAddress]: {
address: mockState.metamask.selectedAddress,
balance: '0x1F4',
},
},
featureFlags: { advancedInlineGas: true },
gasFeeEstimates:
mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET].gasFeeEstimates,
},
});
return renderWithProvider(
<GasFeeContextProvider
transaction={{
userFeeLevel: 'high',
txParams: { gas: '0x5208' },
}}
>
<AdvancedGasFeePopover />
</GasFeeContextProvider>,
store,
);
};
describe('AdvancedGasFeePopover', () => {
it('should renders save button enabled by default', () => {
render();
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeDisabled();
});
it('should disable save button if priority fee 0 is entered', () => {
render();
fireEvent.change(document.getElementsByTagName('input')[1], {
target: { value: 0 },
});
expect(screen.queryByRole('button', { name: 'Save' })).toBeDisabled();
});
it('should disable save button if priority fee entered is greater than base fee', () => {
render();
fireEvent.change(document.getElementsByTagName('input')[1], {
target: { value: 100000 },
});
expect(screen.queryByRole('button', { name: 'Save' })).toBeDisabled();
});
it('should disable save button if gas limit beyond range is entered', () => {
render();
fireEvent.click(screen.queryByText('Edit'));
fireEvent.change(document.getElementsByTagName('input')[3], {
target: { value: 0 },
});
expect(screen.queryByRole('button', { name: 'Save' })).toBeDisabled();
fireEvent.change(document.getElementsByTagName('input')[3], {
target: { value: 30000 },
});
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeDisabled();
fireEvent.change(document.getElementsByTagName('input')[3], {
target: { value: MAX_GAS_LIMIT_DEC + 1 },
});
expect(screen.queryByRole('button', { name: 'Save' })).toBeDisabled();
});
});