1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/ui/pages/swaps/create-new-swap/create-new-swap.test.js
2023-02-02 20:37:53 +00:00

83 lines
2.1 KiB
JavaScript

import React from 'react';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import {
renderWithProvider,
createSwapsMockStore,
fireEvent,
setBackgroundConnection,
} from '../../../../test/jest';
import {
setSwapsFromToken,
navigateBackToBuildQuote,
} from '../../../ducks/swaps/swaps';
import CreateNewSwap from '.';
const middleware = [thunk];
const createProps = (customProps = {}) => {
return {
sensitiveProperties: {},
...customProps,
};
};
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(),
};
});
describe('CreateNewSwap', () => {
const props = createProps({ sensitiveTrackingProperties: {} });
beforeEach(() => {
jest.clearAllMocks();
});
it('renders the component with initial props', () => {
const store = configureMockStore()(createSwapsMockStore());
const { getByText } = renderWithProvider(
<CreateNewSwap {...props} />,
store,
);
expect(getByText('Create a new swap')).toBeInTheDocument();
});
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 { getByText } = renderWithProvider(
<CreateNewSwap {...props} />,
store,
);
await fireEvent.click(getByText('Create a new swap'));
expect(setSwapFromTokenMock).toHaveBeenCalledTimes(1);
expect(navigateBackToBuildQuoteMock).toHaveBeenCalledTimes(1);
});
});