2021-11-29 18:40:48 +01:00
|
|
|
import React from 'react';
|
2021-12-08 23:56:10 +01:00
|
|
|
import { fireEvent, screen } from '@testing-library/react';
|
2021-11-29 18:40:48 +01:00
|
|
|
|
2021-12-01 01:31:21 +01:00
|
|
|
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-11-29 18:40:48 +01:00
|
|
|
|
2021-12-06 19:47:26 +01:00
|
|
|
import { AdvancedGasFeePopoverContextProvider } from '../../context';
|
2021-12-01 01:31:21 +01:00
|
|
|
import PriorityfeeInput from './priority-fee-input';
|
2021-11-29 18:40:48 +01:00
|
|
|
|
2021-12-01 01:31:21 +01:00
|
|
|
jest.mock('../../../../../store/actions', () => ({
|
2021-11-29 18:40:48 +01:00
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
2021-12-01 01:31:21 +01:00
|
|
|
removePollingTokenFromAppState: jest.fn(),
|
2021-11-29 18:40:48 +01:00
|
|
|
}));
|
|
|
|
|
|
|
|
const render = (txProps) => {
|
|
|
|
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',
|
|
|
|
...txProps,
|
|
|
|
}}
|
|
|
|
>
|
2021-12-06 19:47:26 +01:00
|
|
|
<AdvancedGasFeePopoverContextProvider>
|
2021-12-01 01:31:21 +01:00
|
|
|
<PriorityfeeInput />
|
2021-12-06 19:47:26 +01:00
|
|
|
</AdvancedGasFeePopoverContextProvider>
|
2021-11-29 18:40:48 +01:00
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('PriorityfeeInput', () => {
|
|
|
|
it('should renders advancedGasFee.priorityfee value if current estimate used is not custom', () => {
|
|
|
|
render({
|
|
|
|
userFeeLevel: 'high',
|
|
|
|
});
|
|
|
|
expect(document.getElementsByTagName('input')[0]).toHaveValue(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should renders priorityfee value from transaction if current estimate used is custom', () => {
|
|
|
|
render({
|
|
|
|
txParams: {
|
|
|
|
maxPriorityFeePerGas: '0x77359400',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(document.getElementsByTagName('input')[0]).toHaveValue(2);
|
|
|
|
});
|
2021-12-08 23:56:10 +01:00
|
|
|
|
|
|
|
it('should show error if value entered is 0', () => {
|
|
|
|
render({
|
|
|
|
txParams: {
|
|
|
|
maxPriorityFeePerGas: '0x174876E800',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText('Priority fee must be greater than 0.'),
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
fireEvent.change(document.getElementsByTagName('input')[0], {
|
|
|
|
target: { value: 0 },
|
|
|
|
});
|
|
|
|
expect(
|
|
|
|
screen.queryByText('Priority fee must be greater than 0.'),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
2021-11-29 18:40:48 +01:00
|
|
|
});
|