diff --git a/packages/catalog-search/src/tests/FacetListBase.test.jsx b/packages/catalog-search/src/tests/FacetListBase.test.jsx
index 64ee7bbf2..4d02d6d7a 100644
--- a/packages/catalog-search/src/tests/FacetListBase.test.jsx
+++ b/packages/catalog-search/src/tests/FacetListBase.test.jsx
@@ -13,6 +13,7 @@ import SearchData from '../SearchContext';
const mockedNavigator = jest.fn();
jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
useLocation: jest.fn(),
useNavigate: () => mockedNavigator,
}));
diff --git a/packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx b/packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx
index 98d24ab56..7534c5fb8 100644
--- a/packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx
+++ b/packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx
@@ -2,16 +2,12 @@ import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import React from 'react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
+import { Link } from 'react-router-dom';
import SearchSuggestionItem from '../SearchSuggestionItem';
-const mockedNavigator = jest.fn();
-
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
- useNavigate: () => mockedNavigator,
- useLocation: () => ({
- pathname: '/',
- }),
+ Link: jest.fn(({ to, children }) => {children}),
}));
describe('', () => {
@@ -87,14 +83,19 @@ describe('', () => {
},
};
- const { container, history } = renderWithRouter();
+ const { container } = renderWithRouter(
+ ,
+ );
userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
- expect(history.location.pathname).toBe(mockData.program.url);
+
+ expect(Link).toHaveBeenCalled();
+ const [[props]] = Link.mock.calls;
+ expect(props.to).toBe(mockData.program.url);
});
test('fires callback on click if disableSuggestionRedirect is true', () => {
diff --git a/packages/catalog-search/src/tests/SearchSuggestions.test.jsx b/packages/catalog-search/src/tests/SearchSuggestions.test.jsx
index 878cb36fd..2d2af7ed8 100644
--- a/packages/catalog-search/src/tests/SearchSuggestions.test.jsx
+++ b/packages/catalog-search/src/tests/SearchSuggestions.test.jsx
@@ -2,9 +2,15 @@ import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import React from 'react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
+import { Link } from 'react-router-dom';
import SearchSuggestions from '../SearchSuggestions';
import { COURSE_TYPE_EXECUTIVE_EDUCATION } from '../data/constants';
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ Link: jest.fn(({ to, children }) => {children}),
+}));
+
const fakeSuggestionsData = {
nbHits: 2,
hits: [
@@ -58,6 +64,10 @@ const fakeSuggestionsDataEmptyAuthoringOrgs = {
const handleSubmit = jest.fn();
describe('', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
test('renders all data', () => {
renderWithRouter(', () => {
expect(handleSubmit.mock.calls.length).toBe(1);
});
- test.only('redirects to correct page on course click', () => {
+ test('redirects to correct page on course click', () => {
const { container } = renderWithRouter(
', () => {
handleSubmit={handleSubmit}
/>,
);
+
userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
- expect(true).toBe(true);
- // expect(window.location.pathname).toBe('/test-enterprise/course/edX+courseX');
+
+ expect(Link).toHaveBeenCalled();
+ const [props] = Link.mock.calls[0];
+ expect(props.to).toBe('/test-enterprise/course/edX+courseX');
});
test('redirects to correct page on program click', () => {
@@ -119,7 +132,10 @@ describe('', () => {
handleSubmit={handleSubmit}
/>);
userEvent.click(container.getElementsByClassName('suggestion-item')[1]);
- expect(window.location.pathname).toBe('/test-enterprise/program/456');
+
+ expect(Link).toHaveBeenCalled();
+ const [props] = Link.mock.calls[1];
+ expect(props.to).toBe('/test-enterprise/program/456');
});
test('properly handles exec ed content', () => {
const { container } = renderWithRouter(