2022-07-11 17:53:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2022-10-04 18:55:05 +02:00
|
|
|
import thunk from 'redux-thunk';
|
2022-07-11 17:53:07 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
renderWithProvider,
|
|
|
|
createSwapsMockStore,
|
2022-10-04 18:55:05 +02:00
|
|
|
fireEvent,
|
|
|
|
setBackgroundConnection,
|
2022-07-11 17:53:07 +02:00
|
|
|
} from '../../../../test/jest';
|
2022-10-04 18:55:05 +02:00
|
|
|
import {
|
|
|
|
setSwapsFromToken,
|
|
|
|
navigateBackToBuildQuote,
|
|
|
|
} from '../../../ducks/swaps/swaps';
|
2022-07-11 17:53:07 +02:00
|
|
|
import CreateNewSwap from '.';
|
|
|
|
|
2022-10-04 18:55:05 +02:00
|
|
|
const middleware = [thunk];
|
2022-07-11 17:53:07 +02:00
|
|
|
const createProps = (customProps = {}) => {
|
|
|
|
return {
|
|
|
|
sensitiveProperties: {},
|
|
|
|
...customProps,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-04 18:55:05 +02:00
|
|
|
const backgroundConnection = {
|
|
|
|
navigateBackToBuildQuote: jest.fn(),
|
|
|
|
setBackgroundSwapRouteState: jest.fn(),
|
|
|
|
navigatedBackToBuildQuote: jest.fn(),
|
|
|
|
};
|
|
|
|
|
|
|
|
setBackgroundConnection(backgroundConnection);
|
|
|
|
|
|
|
|
jest.mock('../../../ducks/swaps/swaps', () => {
|
|
|
|
const actual = jest.requireActual('../../../ducks/swaps/swaps');
|
|
|
|
return {
|
|
|
|
...actual,
|
|
|
|
setSwapsFromToken: jest.fn(),
|
|
|
|
navigateBackToBuildQuote: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-07-11 17:53:07 +02:00
|
|
|
describe('CreateNewSwap', () => {
|
2022-10-04 18:55:05 +02:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-07-11 17:53:07 +02:00
|
|
|
it('renders the component with initial props', () => {
|
|
|
|
const store = configureMockStore()(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<CreateNewSwap {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
expect(getByText('Create a new swap')).toBeInTheDocument();
|
|
|
|
});
|
2022-10-04 18:55:05 +02:00
|
|
|
|
|
|
|
it('clicks on the Make another swap link', async () => {
|
|
|
|
const setSwapFromTokenMock = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
type: 'MOCK_ACTION',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
setSwapsFromToken.mockImplementation(setSwapFromTokenMock);
|
|
|
|
const navigateBackToBuildQuoteMock = jest.fn(() => {
|
|
|
|
return {
|
|
|
|
type: 'MOCK_ACTION',
|
|
|
|
};
|
|
|
|
});
|
|
|
|
navigateBackToBuildQuote.mockImplementation(navigateBackToBuildQuoteMock);
|
|
|
|
const store = configureMockStore(middleware)(createSwapsMockStore());
|
|
|
|
const props = createProps();
|
|
|
|
const { getByText } = renderWithProvider(
|
|
|
|
<CreateNewSwap {...props} />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
await fireEvent.click(getByText('Create a new swap'));
|
|
|
|
expect(setSwapFromTokenMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(navigateBackToBuildQuoteMock).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2022-07-11 17:53:07 +02:00
|
|
|
});
|