2021-04-27 22:16:17 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import nock from 'nock';
|
|
|
|
import { waitFor } from '@testing-library/react';
|
|
|
|
|
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
createSwapsMockStore,
|
|
|
|
setBackgroundConnection,
|
|
|
|
MOCKS,
|
|
|
|
CONSTANTS,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../test/jest';
|
2021-04-27 22:16:17 +02:00
|
|
|
import Swap from '.';
|
|
|
|
|
|
|
|
const middleware = [thunk];
|
|
|
|
|
|
|
|
setBackgroundConnection({
|
|
|
|
resetPostFetchState: jest.fn(),
|
|
|
|
resetSwapsState: jest.fn(),
|
|
|
|
setSwapsLiveness: jest.fn(() => true),
|
|
|
|
setSwapsTokens: jest.fn(),
|
|
|
|
setSwapsTxGasPrice: jest.fn(),
|
2021-07-30 13:35:30 +02:00
|
|
|
disconnectGasFeeEstimatePoller: jest.fn(),
|
|
|
|
getGasFeeEstimatesAndStartPolling: jest.fn(),
|
2021-04-27 22:16:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Swap', () => {
|
2021-07-09 17:24:00 +02:00
|
|
|
let featureFlagsNock;
|
2021-04-27 22:16:17 +02:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
nock(CONSTANTS.METASWAP_BASE_URL)
|
2021-11-30 19:56:28 +01:00
|
|
|
.get('/networks/1/topAssets')
|
2021-04-27 22:16:17 +02:00
|
|
|
.reply(200, MOCKS.TOP_ASSETS_GET_RESPONSE);
|
|
|
|
|
|
|
|
nock(CONSTANTS.METASWAP_BASE_URL)
|
|
|
|
.get('/refreshTime')
|
|
|
|
.reply(200, MOCKS.REFRESH_TIME_GET_RESPONSE);
|
|
|
|
|
|
|
|
nock(CONSTANTS.METASWAP_BASE_URL)
|
2021-11-30 19:56:28 +01:00
|
|
|
.get('/networks/1/aggregatorMetadata')
|
2021-04-27 22:16:17 +02:00
|
|
|
.reply(200, MOCKS.AGGREGATOR_METADATA_GET_RESPONSE);
|
|
|
|
|
2021-11-30 19:56:28 +01:00
|
|
|
nock(CONSTANTS.GAS_API_URL)
|
|
|
|
.get('/networks/1/gasPrices')
|
2021-04-27 22:16:17 +02:00
|
|
|
.reply(200, MOCKS.GAS_PRICES_GET_RESPONSE);
|
|
|
|
|
2021-07-09 17:24:00 +02:00
|
|
|
nock(CONSTANTS.METASWAP_BASE_URL)
|
2021-11-30 19:56:28 +01:00
|
|
|
.get('/networks/1/tokens')
|
2021-04-27 22:16:17 +02:00
|
|
|
.reply(200, MOCKS.TOKENS_GET_RESPONSE);
|
2021-07-09 17:24:00 +02:00
|
|
|
|
2021-11-30 19:56:28 +01:00
|
|
|
featureFlagsNock = nock(CONSTANTS.METASWAP_BASE_URL)
|
2021-07-09 17:24:00 +02:00
|
|
|
.get('/featureFlags')
|
|
|
|
.reply(200, MOCKS.createFeatureFlagsResponse());
|
2021-04-27 22:16:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
nock.cleanAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders the component with initial props', async () => {
|
2023-06-15 20:17:21 +02:00
|
|
|
const swapsMockStore = createSwapsMockStore();
|
|
|
|
swapsMockStore.metamask.swapsState.swapsFeatureFlags.swapRedesign.extensionActive = false;
|
|
|
|
const store = configureMockStore(middleware)(swapsMockStore);
|
2021-04-27 22:16:17 +02:00
|
|
|
const { container, getByText } = renderWithProvider(<Swap />, store);
|
2021-07-09 17:24:00 +02:00
|
|
|
await waitFor(() => expect(featureFlagsNock.isDone()).toBe(true));
|
2021-04-27 22:16:17 +02:00
|
|
|
expect(getByText('Swap')).toBeInTheDocument();
|
|
|
|
expect(getByText('Cancel')).toBeInTheDocument();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|