2021-11-05 18:23:15 +01:00
|
|
|
import React from 'react';
|
2021-11-18 20:08:29 +01:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2021-11-05 18:23:15 +01:00
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../../shared/constants/gas';
|
|
|
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
2021-11-12 04:22:54 +01:00
|
|
|
import { GasFeeContextProvider } from '../../../contexts/gasFee';
|
2021-11-05 18:23:15 +01:00
|
|
|
import { renderWithProvider } from '../../../../test/jest';
|
|
|
|
import configureStore from '../../../store/store';
|
|
|
|
|
|
|
|
import GasDetailsItem from './gas-details-item';
|
|
|
|
|
2021-11-12 04:22:54 +01:00
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation(() => Promise.resolve()),
|
|
|
|
addPollingTokenToAppState: jest.fn(),
|
2021-11-18 20:08:29 +01:00
|
|
|
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
|
2021-11-12 04:22:54 +01:00
|
|
|
}));
|
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
const render = ({ contextProps } = {}) => {
|
2021-11-05 18:23:15 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
2022-01-06 03:47:26 +01:00
|
|
|
...mockState.metamask,
|
2021-11-12 04:22:54 +01:00
|
|
|
accounts: {
|
2022-01-06 03:47:26 +01:00
|
|
|
[mockState.metamask.selectedAddress]: {
|
|
|
|
address: mockState.metamask.selectedAddress,
|
|
|
|
balance: '0x1F4',
|
2021-11-12 04:22:54 +01:00
|
|
|
},
|
|
|
|
},
|
2022-01-06 03:47:26 +01:00
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
gasFeeEstimates: mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET],
|
2021-11-05 18:23:15 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-11-12 04:22:54 +01:00
|
|
|
return renderWithProvider(
|
2022-01-06 03:47:26 +01:00
|
|
|
<GasFeeContextProvider
|
|
|
|
transaction={{
|
|
|
|
txParams: {
|
|
|
|
gas: '0x5208',
|
|
|
|
maxFeePerGas: '0x59682f10',
|
|
|
|
maxPriorityFeePerGas: '0x59682f00',
|
|
|
|
},
|
|
|
|
userFeeLevel: 'medium',
|
|
|
|
}}
|
|
|
|
{...contextProps}
|
|
|
|
>
|
|
|
|
<GasDetailsItem userAcknowledgedGasMissing={false} />
|
2021-11-12 04:22:54 +01:00
|
|
|
</GasFeeContextProvider>,
|
|
|
|
store,
|
|
|
|
);
|
2021-11-05 18:23:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('GasDetailsItem', () => {
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should render label', async () => {
|
2021-11-05 18:23:15 +01:00
|
|
|
render();
|
2021-11-18 20:08:29 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('(estimated)')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
2022-01-06 03:47:26 +01:00
|
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
2021-11-18 20:08:29 +01:00
|
|
|
});
|
2021-11-05 18:23:15 +01:00
|
|
|
});
|
2021-11-12 04:22:54 +01:00
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should show warning icon if estimates are high', async () => {
|
2021-11-29 17:08:24 +01:00
|
|
|
render({
|
|
|
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'high' } },
|
|
|
|
});
|
2021-11-18 20:08:29 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByText('⚠ Max fee:')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-12 04:22:54 +01:00
|
|
|
});
|
|
|
|
|
2021-11-18 20:08:29 +01:00
|
|
|
it('should not show warning icon if estimates are not high', async () => {
|
2021-11-29 17:08:24 +01:00
|
|
|
render({
|
|
|
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'low' } },
|
|
|
|
});
|
2021-11-18 20:08:29 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
|
|
|
});
|
2021-11-12 04:22:54 +01:00
|
|
|
});
|
2021-11-24 18:02:53 +01:00
|
|
|
|
|
|
|
it('should return null if there is simulationError and user has not acknowledged gasMissing warning', () => {
|
|
|
|
const { container } = render({
|
|
|
|
contextProps: {
|
2021-11-29 17:08:24 +01:00
|
|
|
transaction: {
|
|
|
|
txParams: {},
|
|
|
|
simulationFails: true,
|
|
|
|
userFeeLevel: 'low',
|
|
|
|
},
|
2021-11-24 18:02:53 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
expect(container.innerHTML).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not return null even if there is simulationError if user acknowledged gasMissing warning', async () => {
|
|
|
|
render();
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-06 03:47:26 +01:00
|
|
|
it('should render gas fee details', async () => {
|
|
|
|
render();
|
2021-11-24 18:02:53 +01:00
|
|
|
await waitFor(() => {
|
2022-01-06 03:47:26 +01:00
|
|
|
expect(screen.queryAllByTitle('0.0000315 ETH').length).toBeGreaterThan(0);
|
|
|
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
2021-11-24 18:02:53 +01:00
|
|
|
});
|
|
|
|
});
|
2021-11-05 18:23:15 +01:00
|
|
|
});
|