2021-07-02 15:48:34 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
|
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
createSwapsMockStore,
|
|
|
|
setBackgroundConnection,
|
2021-07-30 13:35:30 +02:00
|
|
|
MOCKS,
|
2021-07-02 15:48:34 +02:00
|
|
|
} from '../../../../test/jest';
|
|
|
|
import ViewQuote from '.';
|
|
|
|
|
2021-07-16 17:00:03 +02:00
|
|
|
jest.mock('../../../components/ui/info-tooltip/info-tooltip-icon', () => () =>
|
|
|
|
'<InfoTooltipIcon />',
|
|
|
|
);
|
|
|
|
|
2021-07-30 13:35:30 +02:00
|
|
|
jest.mock('../../../hooks/useGasFeeInputs', () => {
|
|
|
|
return {
|
|
|
|
useGasFeeInputs: () => {
|
|
|
|
return {
|
|
|
|
maxFeePerGas: 16,
|
|
|
|
maxPriorityFeePerGas: 3,
|
|
|
|
gasFeeEstimates: MOCKS.createGasFeeEstimatesForFeeMarket(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2021-07-02 15:48:34 +02:00
|
|
|
const middleware = [thunk];
|
|
|
|
const createProps = (customProps = {}) => {
|
|
|
|
return {
|
|
|
|
inputValue: '5',
|
|
|
|
onInputChange: jest.fn(),
|
|
|
|
ethBalance: '6 ETH',
|
|
|
|
setMaxSlippage: jest.fn(),
|
|
|
|
maxSlippage: 15,
|
|
|
|
selectedAccountAddress: 'selectedAccountAddress',
|
|
|
|
isFeatureFlagLoaded: false,
|
|
|
|
...customProps,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
setBackgroundConnection({
|
|
|
|
resetPostFetchState: jest.fn(),
|
|
|
|
safeRefetchQuotes: jest.fn(),
|
|
|
|
setSwapsErrorKey: jest.fn(),
|
2021-07-30 13:35:30 +02:00
|
|
|
getGasFeeEstimatesAndStartPolling: jest.fn(),
|
|
|
|
updateTransaction: jest.fn(),
|
2021-07-30 19:40:41 +02:00
|
|
|
getGasFeeTimeEstimate: jest.fn(),
|
2021-07-02 15:48:34 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('ViewQuote', () => {
|
|
|
|
it('renders the component with initial props', () => {
|
|
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByText, getByTestId } = renderWithProvider(
|
|
|
|
<ViewQuote {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(getByText('New quotes in')).toBeInTheDocument();
|
|
|
|
expect(getByTestId('main-quote-summary__source-row')).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
getByTestId('main-quote-summary__exchange-rate-container'),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
getByTestId('fee-card__savings-and-quotes-header'),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(getByTestId('fee-card__row-header')).toMatchSnapshot();
|
|
|
|
expect(getByText('Back')).toBeInTheDocument();
|
|
|
|
expect(getByText('Swap')).toBeInTheDocument();
|
|
|
|
});
|
2021-07-30 13:35:30 +02:00
|
|
|
|
|
|
|
it('renders the component with EIP-1559 enabled', () => {
|
|
|
|
const state = createSwapsMockStore();
|
|
|
|
state.metamask.networkDetails = {
|
|
|
|
EIPS: {
|
|
|
|
1559: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const store = configureMockStore(middleware)(state);
|
|
|
|
const props = createProps();
|
|
|
|
const { getByText, getByTestId } = renderWithProvider(
|
|
|
|
<ViewQuote {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(getByText('New quotes in')).toBeInTheDocument();
|
|
|
|
expect(getByTestId('main-quote-summary__source-row')).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
getByTestId('main-quote-summary__exchange-rate-container'),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(
|
|
|
|
getByTestId('fee-card__savings-and-quotes-header'),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
expect(getByText('Estimated gas fee')).toBeInTheDocument();
|
|
|
|
expect(getByText('0.01044 ETH')).toBeInTheDocument();
|
|
|
|
expect(getByText('Max fee')).toBeInTheDocument();
|
|
|
|
expect(getByText('Back')).toBeInTheDocument();
|
|
|
|
expect(getByText('Swap')).toBeInTheDocument();
|
|
|
|
});
|
2021-07-02 15:48:34 +02:00
|
|
|
});
|