2021-07-26 17:35:51 +02:00
|
|
|
import React from 'react';
|
2022-09-27 17:03:26 +02:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { waitFor } from '@testing-library/react';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2021-07-26 17:35:51 +02:00
|
|
|
|
2021-07-29 20:13:14 +02:00
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../../shared/constants/gas';
|
2022-09-27 17:03:26 +02:00
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
2021-07-26 17:35:51 +02:00
|
|
|
|
|
|
|
import GasTiming from '.';
|
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
jest.mock('../../../store/actions.js', () => ({
|
|
|
|
getGasFeeTimeEstimate: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
|
|
}));
|
2021-08-06 01:59:58 +02:00
|
|
|
|
2021-07-26 17:35:51 +02:00
|
|
|
describe('Gas timing', () => {
|
|
|
|
it('renders nothing when gas is loading', () => {
|
2022-09-27 17:03:26 +02:00
|
|
|
// Fails the networkAndAccountSupports1559 check
|
|
|
|
const nullGasState = {
|
|
|
|
metamask: {
|
2021-08-06 01:59:58 +02:00
|
|
|
gasFeeEstimates: null,
|
|
|
|
gasEstimateType: GAS_ESTIMATE_TYPES.FEE_MARKET,
|
2022-09-27 17:03:26 +02:00
|
|
|
},
|
|
|
|
};
|
2021-07-26 17:35:51 +02:00
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
const mockStore = configureMockStore()(nullGasState);
|
|
|
|
|
|
|
|
const { container } = renderWithProvider(<GasTiming />, mockStore);
|
|
|
|
expect(container).toMatchSnapshot();
|
2021-07-26 17:35:51 +02:00
|
|
|
});
|
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
it('renders "very likely" when high estimate is chosen', async () => {
|
|
|
|
const mockStore = configureMockStore()(mockState);
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
maxPriorityFeePerGas: '10',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<GasTiming {...props} />,
|
|
|
|
mockStore,
|
2021-08-06 01:59:58 +02:00
|
|
|
);
|
2021-07-26 17:35:51 +02:00
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByText(/Very likely in/u)).toBeInTheDocument();
|
|
|
|
});
|
2021-07-26 17:35:51 +02:00
|
|
|
});
|
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
it('renders "likely" when medium estimate is chosen', async () => {
|
|
|
|
const mockStore = configureMockStore()(mockState);
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
maxPriorityFeePerGas: '8',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<GasTiming {...props} />,
|
|
|
|
mockStore,
|
2021-08-06 01:59:58 +02:00
|
|
|
);
|
2021-07-26 17:35:51 +02:00
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByText(/Likely in/u)).toBeInTheDocument();
|
|
|
|
});
|
2021-07-26 17:35:51 +02:00
|
|
|
});
|
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
it('renders "maybe" when low estimate is chosen', async () => {
|
|
|
|
const mockStore = configureMockStore()(mockState);
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
maxPriorityFeePerGas: '3',
|
|
|
|
};
|
|
|
|
|
|
|
|
const { queryByText } = renderWithProvider(
|
|
|
|
<GasTiming {...props} />,
|
|
|
|
mockStore,
|
2021-08-06 01:59:58 +02:00
|
|
|
);
|
2021-07-26 17:35:51 +02:00
|
|
|
|
2022-09-27 17:03:26 +02:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(queryByText(/Maybe in/u)).toBeInTheDocument();
|
|
|
|
});
|
2021-07-26 17:35:51 +02:00
|
|
|
});
|
|
|
|
});
|