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
|
|
|
|
|
|
|
import { ETH } from '../../../helpers/constants/common';
|
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
|
|
|
}));
|
|
|
|
|
2021-11-24 18:02:53 +01:00
|
|
|
const render = ({ componentProps, contextProps } = {}) => {
|
2021-11-05 18:23:15 +01:00
|
|
|
const store = configureStore({
|
|
|
|
metamask: {
|
|
|
|
nativeCurrency: ETH,
|
|
|
|
preferences: {
|
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
|
|
|
},
|
|
|
|
provider: {},
|
2021-11-12 04:22:54 +01:00
|
|
|
cachedBalances: {},
|
|
|
|
accounts: {
|
|
|
|
'0xAddress': {
|
|
|
|
address: '0xAddress',
|
|
|
|
balance: '0x176e5b6f173ebe66',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selectedAddress: '0xAddress',
|
2021-11-05 18:23:15 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-11-12 04:22:54 +01:00
|
|
|
return renderWithProvider(
|
2021-11-29 17:08:24 +01:00
|
|
|
<GasFeeContextProvider transaction={{ txParams: {} }} {...contextProps}>
|
|
|
|
<GasDetailsItem userAcknowledgedGasMissing={false} {...componentProps} />
|
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();
|
|
|
|
expect(screen.queryByText('ETH')).toBeInTheDocument();
|
|
|
|
});
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should should render gas fee details', async () => {
|
|
|
|
render({
|
|
|
|
componentProps: {
|
|
|
|
hexMinimumTransactionFee: '0x1ca62a4f7800',
|
|
|
|
hexMaximumTransactionFee: '0x290ee75e3d900',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(screen.queryByTitle('0.0000315 ETH')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('ETH')).toBeInTheDocument();
|
|
|
|
expect(screen.queryByTitle('0.0007223')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
2021-11-05 18:23:15 +01:00
|
|
|
});
|