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-05 18:23:15 +01:00
|
|
|
const render = (props) => {
|
|
|
|
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(
|
|
|
|
<GasFeeContextProvider {...props}>
|
2021-11-18 20:08:29 +01:00
|
|
|
<GasDetailsItem txData={{ txParams: {} }} {...props} />
|
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-12 04:22:54 +01:00
|
|
|
render({ defaultEstimateToUse: '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-12 04:22:54 +01:00
|
|
|
render({ defaultEstimateToUse: '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-05 18:23:15 +01:00
|
|
|
});
|