You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.4 KiB
114 lines
3.4 KiB
3 years ago
|
import React from 'react';
|
||
3 years ago
|
import { screen, waitFor } from '@testing-library/react';
|
||
3 years ago
|
|
||
3 years ago
|
import { GAS_ESTIMATE_TYPES } from '../../../../shared/constants/gas';
|
||
|
import mockEstimates from '../../../../test/data/mock-estimates.json';
|
||
|
import mockState from '../../../../test/data/mock-state.json';
|
||
3 years ago
|
import { GasFeeContextProvider } from '../../../contexts/gasFee';
|
||
3 years ago
|
import { renderWithProvider } from '../../../../test/jest';
|
||
|
import configureStore from '../../../store/store';
|
||
|
|
||
|
import GasDetailsItem from './gas-details-item';
|
||
|
|
||
3 years ago
|
jest.mock('../../../store/actions', () => ({
|
||
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
||
|
getGasFeeEstimatesAndStartPolling: jest
|
||
|
.fn()
|
||
|
.mockImplementation(() => Promise.resolve()),
|
||
|
addPollingTokenToAppState: jest.fn(),
|
||
3 years ago
|
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
|
||
3 years ago
|
}));
|
||
|
|
||
3 years ago
|
const render = ({ contextProps } = {}) => {
|
||
3 years ago
|
const store = configureStore({
|
||
|
metamask: {
|
||
3 years ago
|
...mockState.metamask,
|
||
3 years ago
|
accounts: {
|
||
3 years ago
|
[mockState.metamask.selectedAddress]: {
|
||
|
address: mockState.metamask.selectedAddress,
|
||
|
balance: '0x1F4',
|
||
3 years ago
|
},
|
||
|
},
|
||
3 years ago
|
preferences: {
|
||
|
useNativeCurrencyAsPrimaryCurrency: true,
|
||
|
},
|
||
|
gasFeeEstimates: mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET],
|
||
3 years ago
|
},
|
||
|
});
|
||
|
|
||
3 years ago
|
return renderWithProvider(
|
||
3 years ago
|
<GasFeeContextProvider
|
||
|
transaction={{
|
||
|
txParams: {
|
||
|
gas: '0x5208',
|
||
|
maxFeePerGas: '0x59682f10',
|
||
|
maxPriorityFeePerGas: '0x59682f00',
|
||
|
},
|
||
|
userFeeLevel: 'medium',
|
||
|
}}
|
||
|
{...contextProps}
|
||
|
>
|
||
|
<GasDetailsItem userAcknowledgedGasMissing={false} />
|
||
3 years ago
|
</GasFeeContextProvider>,
|
||
|
store,
|
||
|
);
|
||
3 years ago
|
};
|
||
|
|
||
|
describe('GasDetailsItem', () => {
|
||
3 years ago
|
it('should render label', async () => {
|
||
3 years ago
|
render();
|
||
3 years ago
|
await waitFor(() => {
|
||
|
expect(screen.queryByText('Gas')).toBeInTheDocument();
|
||
|
expect(screen.queryByText('(estimated)')).toBeInTheDocument();
|
||
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
||
3 years ago
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
||
3 years ago
|
});
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
it('should show warning icon if estimates are high', async () => {
|
||
3 years ago
|
render({
|
||
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'high' } },
|
||
|
});
|
||
3 years ago
|
await waitFor(() => {
|
||
|
expect(screen.queryByText('⚠ Max fee:')).toBeInTheDocument();
|
||
|
});
|
||
3 years ago
|
});
|
||
|
|
||
3 years ago
|
it('should not show warning icon if estimates are not high', async () => {
|
||
3 years ago
|
render({
|
||
|
contextProps: { transaction: { txParams: {}, userFeeLevel: 'low' } },
|
||
|
});
|
||
3 years ago
|
await waitFor(() => {
|
||
|
expect(screen.queryByText('Max fee:')).toBeInTheDocument();
|
||
|
});
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
|
it('should return null if there is simulationError and user has not acknowledged gasMissing warning', () => {
|
||
|
const { container } = render({
|
||
|
contextProps: {
|
||
3 years ago
|
transaction: {
|
||
|
txParams: {},
|
||
|
simulationFails: true,
|
||
|
userFeeLevel: 'low',
|
||
|
},
|
||
3 years ago
|
},
|
||
|
});
|
||
|
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();
|
||
|
});
|
||
|
});
|
||
|
|
||
3 years ago
|
it('should render gas fee details', async () => {
|
||
|
render();
|
||
3 years ago
|
await waitFor(() => {
|
||
3 years ago
|
expect(screen.queryAllByTitle('0.0000315 ETH').length).toBeGreaterThan(0);
|
||
|
expect(screen.queryAllByText('ETH').length).toBeGreaterThan(0);
|
||
3 years ago
|
});
|
||
|
});
|
||
3 years ago
|
});
|