2021-04-27 22:16:17 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
2021-09-15 15:13:18 +02:00
|
|
|
import { fireEvent } from '@testing-library/react';
|
2021-04-27 22:16:17 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
createSwapsMockStore,
|
|
|
|
setBackgroundConnection,
|
2021-04-28 21:53:59 +02:00
|
|
|
} from '../../../../test/jest';
|
2021-04-27 22:16:17 +02:00
|
|
|
import BuildQuote from '.';
|
|
|
|
|
|
|
|
const middleware = [thunk];
|
|
|
|
const createProps = (customProps = {}) => {
|
|
|
|
return {
|
|
|
|
inputValue: '5',
|
|
|
|
onInputChange: jest.fn(),
|
2021-09-15 15:13:18 +02:00
|
|
|
ethBalance: '0x8',
|
2021-04-27 22:16:17 +02:00
|
|
|
setMaxSlippage: jest.fn(),
|
|
|
|
maxSlippage: 15,
|
|
|
|
selectedAccountAddress: 'selectedAccountAddress',
|
|
|
|
isFeatureFlagLoaded: false,
|
2021-09-09 22:56:27 +02:00
|
|
|
shuffledTokensList: [],
|
2021-04-27 22:16:17 +02:00
|
|
|
...customProps,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
setBackgroundConnection({
|
|
|
|
resetPostFetchState: jest.fn(),
|
2021-09-15 15:13:18 +02:00
|
|
|
removeToken: jest.fn(),
|
|
|
|
setBackgroundSwapRouteState: jest.fn(),
|
|
|
|
clearSwapsQuotes: jest.fn(),
|
|
|
|
stopPollingForQuotes: jest.fn(),
|
2021-04-27 22:16:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('BuildQuote', () => {
|
|
|
|
it('renders the component with initial props', () => {
|
|
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByText } = renderWithProvider(<BuildQuote {...props} />, store);
|
|
|
|
expect(getByText('Swap from')).toBeInTheDocument();
|
|
|
|
expect(getByText('Swap to')).toBeInTheDocument();
|
|
|
|
expect(getByText('ETH')).toBeInTheDocument();
|
|
|
|
expect(getByText('Slippage Tolerance')).toBeInTheDocument();
|
|
|
|
expect(getByText('2%')).toBeInTheDocument();
|
|
|
|
expect(getByText('3%')).toBeInTheDocument();
|
|
|
|
expect(getByText('Review Swap')).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
document.querySelector('.slippage-buttons__button-group'),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
2021-09-15 15:13:18 +02:00
|
|
|
|
|
|
|
it('clicks on the max button', () => {
|
|
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByTestId } = renderWithProvider(
|
|
|
|
<BuildQuote {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
fireEvent.click(getByTestId('build-quote__max-button'));
|
|
|
|
expect(props.onInputChange).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('types a number inside the input field', () => {
|
|
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByDisplayValue } = renderWithProvider(
|
|
|
|
<BuildQuote {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
fireEvent.change(getByDisplayValue('5'), {
|
|
|
|
target: { value: '8' },
|
|
|
|
});
|
|
|
|
expect(props.onInputChange).toHaveBeenCalled();
|
|
|
|
});
|
2021-04-27 22:16:17 +02:00
|
|
|
});
|