diff --git a/src/components/executive-education-2u/ExecutiveEducation2UPage.jsx b/src/components/executive-education-2u/ExecutiveEducation2UPage.jsx
index 09c67d34c4..62d55d09dd 100644
--- a/src/components/executive-education-2u/ExecutiveEducation2UPage.jsx
+++ b/src/components/executive-education-2u/ExecutiveEducation2UPage.jsx
@@ -7,7 +7,7 @@ import {
} from '@edx/paragon';
import { AppContext } from '@edx/frontend-platform/react';
import { logError } from '@edx/frontend-platform/logging';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import NotFoundPage from '../NotFoundPage';
import UserEnrollmentForm from './UserEnrollmentForm';
@@ -24,7 +24,7 @@ import { getCourseOrganizationDetails, getExecutiveEducationCoursePrice } from '
const ExecutiveEducation2UPage = () => {
const { enterpriseConfig } = useContext(AppContext);
const activeQueryParams = useActiveQueryParams();
- const history = useHistory();
+ const navigate = useNavigate();
const isExecEd2UFulfillmentEnabled = useMemo(() => {
const hasRequiredQueryParams = (activeQueryParams.has('course_uuid') && activeQueryParams.has('sku'));
@@ -87,12 +87,14 @@ const ExecutiveEducation2UPage = () => {
}, [contentMetadata]);
const handleCheckoutSuccess = () => {
- history.push({
- pathname: `/${enterpriseConfig.slug}/executive-education-2u/enrollment-completed`,
- state: {
- data: courseMetadata,
+ navigate(
+ `/${enterpriseConfig.slug}/executive-education-2u/enrollment-completed`,
+ {
+ state: {
+ data: courseMetadata,
+ },
},
- });
+ );
};
if (!isExecEd2UFulfillmentEnabled) {
diff --git a/src/components/executive-education-2u/ExecutiveEducation2UPage.test.jsx b/src/components/executive-education-2u/ExecutiveEducation2UPage.test.jsx
index 35ba332b69..4ea162889f 100644
--- a/src/components/executive-education-2u/ExecutiveEducation2UPage.test.jsx
+++ b/src/components/executive-education-2u/ExecutiveEducation2UPage.test.jsx
@@ -77,12 +77,10 @@ jest.mock('@edx/frontend-platform/logging', () => ({
logError: jest.fn(),
}));
-const mockedPush = jest.fn();
+const mockedNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockedPush,
- }),
+ useNavigate: () => mockedNavigate,
useLocation: jest.fn(),
}));
@@ -322,9 +320,7 @@ describe('ExecutiveEducation2UPage', () => {
renderWithRouter(
);
userEvent.click(screen.getByText('Mock submit enrollment form'));
- expect(mockedPush).toHaveBeenCalledTimes(1);
- expect(mockedPush).toHaveBeenCalledWith(
- { pathname: `/${enterpriseSlug}/executive-education-2u/enrollment-completed`, state: { data: {} } },
- );
+ expect(mockedNavigate).toHaveBeenCalledTimes(1);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${enterpriseSlug}/executive-education-2u/enrollment-completed`, { state: { data: {} } });
});
});
diff --git a/src/components/license-activation/LicenseActivation.jsx b/src/components/license-activation/LicenseActivation.jsx
index 127b3de0bd..4c50a265db 100644
--- a/src/components/license-activation/LicenseActivation.jsx
+++ b/src/components/license-activation/LicenseActivation.jsx
@@ -1,5 +1,5 @@
import React, { useContext, useEffect, useState } from 'react';
-import { Redirect, useLocation } from 'react-router-dom';
+import { Navigate, useLocation } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { AppContext } from '@edx/frontend-platform/react';
import { Alert, Container } from '@edx/paragon';
@@ -38,11 +38,10 @@ const LicenseActivation = () => {
const redirectToPath = location.state?.from ?? `/${enterpriseConfig.slug}`;
return (
-
);
}
diff --git a/src/components/license-activation/LicenseActivationPage.jsx b/src/components/license-activation/LicenseActivationPage.jsx
index 80b5391598..753a241263 100644
--- a/src/components/license-activation/LicenseActivationPage.jsx
+++ b/src/components/license-activation/LicenseActivationPage.jsx
@@ -1,5 +1,5 @@
import React, { useContext } from 'react';
-import { Redirect, useParams } from 'react-router-dom';
+import { Navigate, useParams } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { logInfo } from '@edx/frontend-platform/logging';
import { Alert } from '@edx/paragon';
@@ -32,10 +32,9 @@ const LicenseActivationPage = () => {
}
return (
-
);
}
diff --git a/src/components/license-activation/tests/LicenseActivation.test.jsx b/src/components/license-activation/tests/LicenseActivation.test.jsx
index fbc28a3071..1fc6c07940 100644
--- a/src/components/license-activation/tests/LicenseActivation.test.jsx
+++ b/src/components/license-activation/tests/LicenseActivation.test.jsx
@@ -1,19 +1,32 @@
import React from 'react';
-import { screen, waitFor } from '@testing-library/react';
+import { render, screen, waitFor } from '@testing-library/react';
import { AppContext } from '@edx/frontend-platform/react';
import '@testing-library/jest-dom/extend-expect';
import * as reactRouterDom from 'react-router-dom';
-import { Route } from 'react-router-dom';
+import {
+ Route, Routes, MemoryRouter, mockNavigate,
+} from 'react-router-dom';
import LicenseActivation, { LOADING_MESSAGE } from '../LicenseActivation';
-import { renderWithRouter } from '../../../utils/tests';
import { UserSubsidyContext } from '../../enterprise-user-subsidy/UserSubsidy';
-jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useLocation: jest.fn(() => ({})),
-}));
+jest.mock('react-router-dom', () => {
+ const mockNavigation = jest.fn();
+
+ // eslint-disable-next-line react/prop-types
+ const Navigate = ({ to }) => {
+ mockNavigation(to);
+ return
;
+ };
+
+ return {
+ ...jest.requireActual('react-router-dom'),
+ Navigate,
+ mockNavigate: mockNavigation,
+ useLocation: jest.fn(() => ({})),
+ };
+});
const TEST_ENTERPRISE_UUID = 'test-enterprise-uuid';
const TEST_ENTERPRISE_SLUG = 'test-enterprise-slug';
@@ -35,9 +48,11 @@ const LicenseActivationWithAppContext = ({
}}
>
-
-
-
+
+
+ } />
+
+
);
@@ -49,16 +64,11 @@ describe('LicenseActivation', () => {
// For the initial state, there is no activation success or error
const mockActivateUserLicense = jest.fn();
- const { history } = renderWithRouter(
-
,
- {
- route: TEST_ROUTE,
- },
- );
+ render(
);
await waitFor(() => {
expect(mockActivateUserLicense).toHaveBeenCalledWith(false);
@@ -67,7 +77,7 @@ describe('LicenseActivation', () => {
expect(screen.queryAllByText(LOADING_MESSAGE)).toHaveLength(1);
// assert we did NOT get redirected
- expect(history.location.pathname).toEqual(TEST_ROUTE);
+ expect(mockNavigate).not.toHaveBeenCalled();
});
});
@@ -76,15 +86,12 @@ describe('LicenseActivation', () => {
new Error("Couldn't activate license"),
);
- const { history } = renderWithRouter(
+ render(
,
- {
- route: TEST_ROUTE,
- },
);
expect(mockActivateUserLicense).toHaveBeenCalledWith(false);
@@ -94,7 +101,7 @@ describe('LicenseActivation', () => {
expect(screen.getByRole('alert')).toHaveClass('alert-danger');
// assert we did NOT get redirected
- expect(history.location.pathname).toEqual(TEST_ROUTE);
+ expect(mockNavigate).not.toHaveBeenCalledWith();
});
});
@@ -108,20 +115,17 @@ describe('LicenseActivation', () => {
}
const mockActivateUserLicense = jest.fn();
- const { history } = renderWithRouter(
+ render(
,
- {
- route: TEST_ROUTE,
- },
);
await waitFor(() => {
expect(mockActivateUserLicense).toHaveBeenCalledWith(!!redirectedFrom);
- expect(history.location.pathname).toEqual(redirectedFrom ?? `/${TEST_ENTERPRISE_SLUG}`);
+ expect(mockNavigate).toHaveBeenCalledWith(redirectedFrom ?? `/${TEST_ENTERPRISE_SLUG}`);
});
});
});
diff --git a/src/components/license-activation/tests/LicenseActivationPage.test.jsx b/src/components/license-activation/tests/LicenseActivationPage.test.jsx
index 477b0e46ec..e58d7f2fb3 100644
--- a/src/components/license-activation/tests/LicenseActivationPage.test.jsx
+++ b/src/components/license-activation/tests/LicenseActivationPage.test.jsx
@@ -3,12 +3,10 @@ import { screen } from '@testing-library/react';
import { AppContext } from '@edx/frontend-platform/react';
import '@testing-library/jest-dom/extend-expect';
-import { Route } from 'react-router-dom';
-
-import { renderWithRouter } from '../../../utils/tests';
import LicenseActivationPage from '../LicenseActivationPage';
import { UserSubsidyContext } from '../../enterprise-user-subsidy';
import { LICENSE_STATUS } from '../../enterprise-user-subsidy/data/constants';
+import { renderWithRouter } from '../../../utils/tests';
const TEST_USER_ID = 1;
@@ -28,11 +26,16 @@ jest.mock('../LicenseActivationErrorAlert', () => ({
__esModule: true,
default: () => '
',
}));
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useParams: () => ({
+ activationKey: '00000000-0000-0000-0000-000000000000',
+ }),
+}));
const TEST_ENTERPRISE_UUID = 'test-enterprise-uuid';
const TEST_ENTERPRISE_SLUG = 'test-enterprise-slug';
const TEST_ACTIVATION_KEY = '00000000-0000-0000-0000-000000000000';
-const TEST_ROUTE = `/${TEST_ENTERPRISE_SLUG}/licenses/${TEST_ACTIVATION_KEY}/activate`;
const LicenseActivationPageWithContext = ({
initialUserSubsidyState = {
@@ -53,29 +56,27 @@ const LicenseActivationPageWithContext = ({
}}
>
-
-
-
+
);
describe('
', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
it.each(
[undefined, { status: LICENSE_STATUS.ACTIVATED }],
)('should redirect if the user has no license to activate', (subscriptionLicense) => {
- const { history } = renderWithRouter(
-
,
- {
- route: TEST_ROUTE,
- },
);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}`);
+ expect(window.location.pathname).toContain(`/${TEST_ENTERPRISE_SLUG}`);
});
it('should render error alert if attempting to activate a license that does not belong to the user', () => {
@@ -87,9 +88,6 @@ describe('
', () => {
},
}}
/>,
- {
- route: TEST_ROUTE,
- },
);
expect(screen.getByText('
')).toBeInTheDocument();
@@ -104,9 +102,6 @@ describe('
', () => {
},
}}
/>,
- {
- route: TEST_ROUTE,
- },
);
expect(screen.getByText('
')).toBeInTheDocument();
});
diff --git a/src/components/my-career/AddJobRole.jsx b/src/components/my-career/AddJobRole.jsx
index 2d2c9b7c52..d614eb681f 100644
--- a/src/components/my-career/AddJobRole.jsx
+++ b/src/components/my-career/AddJobRole.jsx
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
-import { useHistory, useLocation } from 'react-router-dom';
+import { useNavigate, useLocation } from 'react-router-dom';
import {
Alert, Row, breakpoints, MediaQuery, useToggle, TransitionReplace, Button, Icon,
} from '@edx/paragon';
@@ -23,8 +23,8 @@ const addIcon = () => (
);
const AddJobRole = ({ submitClickHandler }) => {
- const { state } = useLocation();
- const history = useHistory();
+ const { pathname, state } = useLocation();
+ const navigate = useNavigate();
const [isEditable, setIsEditable] = useState(false);
const [isActivationAlertOpen, , closeActivationAlert] = useToggle(!!state?.activationSuccess);
@@ -32,9 +32,9 @@ const AddJobRole = ({ submitClickHandler }) => {
if (state?.activationSuccess) {
const updatedLocationState = { ...state };
delete updatedLocationState.activationSuccess;
- history.replace({ ...history.location, state: updatedLocationState });
+ navigate(pathname, { state: updatedLocationState, replace: true });
}
- }, [history, state]);
+ }, [navigate, pathname, state]);
const addRoleClickHandler = () => {
setIsEditable(true);
diff --git a/src/components/my-career/SkillsRecommendationCourses.jsx b/src/components/my-career/SkillsRecommendationCourses.jsx
index 884fc31d7e..bdbf9a6fe8 100644
--- a/src/components/my-career/SkillsRecommendationCourses.jsx
+++ b/src/components/my-career/SkillsRecommendationCourses.jsx
@@ -1,7 +1,7 @@
import React, {
useContext, useMemo, useState, useEffect,
} from 'react';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import PropTypes from 'prop-types';
import { v4 as uuidv4 } from 'uuid';
import { AppContext } from '@edx/frontend-platform/react';
@@ -23,7 +23,7 @@ const SkillsRecommendationCourses = ({ index, subCategoryName, subCategorySkills
redeemableLearnerCreditPolicies,
} = useContext(UserSubsidyContext);
const { catalogsForSubsidyRequests } = useContext(SubsidyRequestsContext);
- const history = useHistory();
+ const navigate = useNavigate();
const searchCatalogs = useSearchCatalogs({
subscriptionPlan,
@@ -98,10 +98,12 @@ const SkillsRecommendationCourses = ({ index, subCategoryName, subCategorySkills
className="mt-3"
onClick={() => {
if (subCategorySkills.length > 0) {
- history.push({
- pathname: `/${enterpriseConfig.slug}/search`,
- search: `showAll=1&content_type=course&skill_names=${subCategorySkills.join('&skill_names=')}`,
- });
+ navigate(
+ `/${enterpriseConfig.slug}/search`,
+ {
+ search: `showAll=1&content_type=course&skill_names=${subCategorySkills.join('&skill_names=')}`,
+ },
+ );
}
}}
>
diff --git a/src/components/my-career/tests/AddJobRole.test.jsx b/src/components/my-career/tests/AddJobRole.test.jsx
index 8e15454f54..f02b5e8a95 100644
--- a/src/components/my-career/tests/AddJobRole.test.jsx
+++ b/src/components/my-career/tests/AddJobRole.test.jsx
@@ -20,10 +20,12 @@ jest.mock('@edx/frontend-platform/i18n', () => ({
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: () => ({
+ pathname: '',
state: {
activationSuccess: true,
},
}),
+ useNavigate: () => jest.fn(),
}));
// eslint-disable-next-line no-console
diff --git a/src/components/pathway-progress/PathwayProgressCard.jsx b/src/components/pathway-progress/PathwayProgressCard.jsx
index 0732497aa9..9dcd832e6f 100644
--- a/src/components/pathway-progress/PathwayProgressCard.jsx
+++ b/src/components/pathway-progress/PathwayProgressCard.jsx
@@ -2,17 +2,17 @@ import React, { useContext } from 'react';
import { Card, Truncate } from '@edx/paragon';
import PropTypes from 'prop-types';
import cardFallbackImg from '@edx/brand/paragon/images/card-imagecap-fallback.png';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { getProgressFromSteps } from './data/utils';
import { ProgressCategoryBubbles } from '../progress-category-bubbles';
const PathwayProgressCard = ({ pathway: { learnerPathwayProgress } }) => {
const progress = getProgressFromSteps(learnerPathwayProgress.steps);
- const history = useHistory();
+ const navigate = useNavigate();
const { enterpriseConfig: { slug } } = useContext(AppContext);
const redirectToProgressDetailPage = () => {
- history.push(`/${slug}/pathway/${learnerPathwayProgress.uuid}/progress`);
+ navigate(`/${slug}/pathway/${learnerPathwayProgress.uuid}/progress`);
};
return (
({
...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockedPush,
- }),
+ useNavigate: () => mockedNavigate,
useLocation: jest.fn(),
}));
@@ -48,7 +45,7 @@ const userSubsidyState = {
const pathwayData = camelCaseObject(LearnerPathwayProgressData[0]);
describe('', () => {
it('renders all data related to pathway progress correctly', () => {
- const { getByAltText } = render(', () => {
});
it('redirects to correct page when clicked', () => {
- const { container } = render();
userEvent.click(container.firstElementChild);
- expect(mockedPush).toHaveBeenCalledWith('/test-enterprise-slug/pathway/0a017cbe-0f1c-4e5f-9095-2101823fac93/progress');
+ expect(mockedNavigate).toHaveBeenCalledWith('/test-enterprise-slug/pathway/0a017cbe-0f1c-4e5f-9095-2101823fac93/progress');
});
});
diff --git a/src/components/pathway-progress/tests/PathwayProgressListingPage.test.jsx b/src/components/pathway-progress/tests/PathwayProgressListingPage.test.jsx
index 9aa1bfc3ec..877f71ff55 100644
--- a/src/components/pathway-progress/tests/PathwayProgressListingPage.test.jsx
+++ b/src/components/pathway-progress/tests/PathwayProgressListingPage.test.jsx
@@ -73,7 +73,7 @@ describe('', () => {
useInProgressPathwaysData.mockImplementation(() => ([camelCaseObject(learnerPathwayData), null]));
await act(async () => {
- render(
+ renderWithRouter(
', () => {
useInProgressPathwaysData.mockImplementation(() => ([[], null]));
await act(async () => {
- const { history } = renderWithRouter(
+ renderWithRouter(
,
);
userEvent.click(screen.getByText('Explore pathways'));
- expect(history.location.pathname).toEqual(`/${initialAppState.enterpriseConfig.slug}/search`);
- expect(history.location.search).toEqual(`?content_type=${CONTENT_TYPE_PATHWAY}`);
+ expect(window.location.pathname).toEqual(`/${initialAppState.enterpriseConfig.slug}/search`);
+ expect(window.location.search).toEqual(`?content_type=${CONTENT_TYPE_PATHWAY}`);
});
});
diff --git a/src/components/pathway/SearchPathwayCard.jsx b/src/components/pathway/SearchPathwayCard.jsx
index 96bd20dbcc..67aa055874 100644
--- a/src/components/pathway/SearchPathwayCard.jsx
+++ b/src/components/pathway/SearchPathwayCard.jsx
@@ -1,7 +1,7 @@
import React, { useContext, useMemo } from 'react';
import PropTypes from 'prop-types';
import cardFallbackImg from '@edx/brand/paragon/images/card-imagecap-fallback.png';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { getConfig } from '@edx/frontend-platform/config';
import { camelCaseObject } from '@edx/frontend-platform/utils';
@@ -52,7 +52,7 @@ const SearchPathwayCard = ({
...rest
}) => {
const { enterpriseConfig: { uuid: enterpriseCustomerUUID, slug } } = useContext(AppContext);
- const history = useHistory();
+ const navigate = useNavigate();
const pathway = useMemo(() => {
if (!hit) {
@@ -95,7 +95,7 @@ const SearchPathwayCard = ({
pathwayUUID: pathwayUuid,
},
);
- history.push(linkToPathway);
+ navigate(linkToPathway);
};
return (
diff --git a/src/components/pathway/tests/SearchPathwayCard.test.jsx b/src/components/pathway/tests/SearchPathwayCard.test.jsx
index e3b8b62503..e1a9bea07d 100644
--- a/src/components/pathway/tests/SearchPathwayCard.test.jsx
+++ b/src/components/pathway/tests/SearchPathwayCard.test.jsx
@@ -18,6 +18,12 @@ jest.mock('@edx/frontend-enterprise-utils', () => {
});
});
+const mockedNavigate = jest.fn();
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useNavigate: () => mockedNavigate,
+}));
+
const SearchPathwayCardWithAppContext = (props) => (
', () => {
+ beforeEach(() => {
+ mockedNavigate.mockClear();
+ });
+
test('renders the correct data', () => {
- const { container, history } = renderWithRouter();
+ const { container } = renderWithRouter();
expect(screen.getByText(TEST_TITLE)).toBeInTheDocument();
@@ -60,8 +70,7 @@ describe('', () => {
const cardEl = screen.getByTestId('search-pathway-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
expect(sendEnterpriseTrackEvent).toHaveBeenCalledWith(
TEST_ENTERPRISE_UUID,
PATHWAY_SEARCH_EVENT_NAME,
@@ -72,16 +81,15 @@ describe('', () => {
});
test('handles card click', () => {
- const { history } = renderWithRouter();
+ renderWithRouter();
const cardEl = screen.getByTestId('search-pathway-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
});
test('renders the correct data when clicked from skills quiz page', () => {
const propsForSkillQuiz = { ...defaultProps, isSkillQuizResult: true };
- const { container, history } = renderWithRouter();
+ const { container } = renderWithRouter();
expect(screen.getByText(TEST_TITLE)).toBeInTheDocument();
@@ -94,8 +102,7 @@ describe('', () => {
const cardEl = screen.getByTestId('search-pathway-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/search/${TEST_PATHWAY_UUID}`);
expect(sendEnterpriseTrackEvent).toHaveBeenCalledWith(
TEST_ENTERPRISE_UUID,
PATHWAY_SKILL_QUIZ_EVENT_NAME,
@@ -123,7 +130,7 @@ describe('', () => {
});
test('renders the loading state', () => {
- const { container, history } = renderWithRouter();
+ const { container } = renderWithRouter();
// ensure `Card` was passed `isLoading` by asserting each `Card` subcomponent
// is treated as a skeleton instead, indicated by `aria-busy="true"`.
@@ -132,6 +139,6 @@ describe('', () => {
// does not do anything when clicked
const cardEl = screen.getByTestId('search-pathway-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(1);
+ expect(mockedNavigate).not.toHaveBeenCalled();
});
});
diff --git a/src/components/program-progress/ProgramListingCard.jsx b/src/components/program-progress/ProgramListingCard.jsx
index 2642c05fab..64532475ca 100644
--- a/src/components/program-progress/ProgramListingCard.jsx
+++ b/src/components/program-progress/ProgramListingCard.jsx
@@ -4,7 +4,7 @@ import {
import React, { useContext, useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import cardFallbackImg from '@edx/brand/paragon/images/card-imagecap-fallback.png';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
@@ -14,10 +14,10 @@ import { ProgressCategoryBubbles } from '../progress-category-bubbles';
const ProgramListingCard = ({ program }) => {
const { enterpriseConfig } = useContext(AppContext);
const [windowWidth, setWindowWidth] = useState(window.innerWidth);
- const history = useHistory();
+ const navigate = useNavigate();
const handleCardClick = () => {
- history.push(`/${enterpriseConfig.slug}/program/${program.uuid}/progress`);
+ navigate(`/${enterpriseConfig.slug}/program/${program.uuid}/progress`);
};
useEffect(() => {
diff --git a/src/components/program-progress/ProgramProgressRedirect.jsx b/src/components/program-progress/ProgramProgressRedirect.jsx
index 2673263ff7..acd1d8900e 100644
--- a/src/components/program-progress/ProgramProgressRedirect.jsx
+++ b/src/components/program-progress/ProgramProgressRedirect.jsx
@@ -1,12 +1,12 @@
import React, { useContext } from 'react';
-import { Redirect, useParams } from 'react-router-dom';
+import { Navigate, useParams } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
const ProgramProgressRedirect = () => {
const { enterpriseConfig } = useContext(AppContext);
const { programUUID } = useParams();
- return ;
+ return ;
};
export default ProgramProgressRedirect;
diff --git a/src/components/program-progress/tests/ProgramListingCard.test.jsx b/src/components/program-progress/tests/ProgramListingCard.test.jsx
index 85d197cd09..047c6061a6 100644
--- a/src/components/program-progress/tests/ProgramListingCard.test.jsx
+++ b/src/components/program-progress/tests/ProgramListingCard.test.jsx
@@ -10,12 +10,10 @@ import { UserSubsidyContext } from '../../enterprise-user-subsidy';
import ProgramListingCard from '../ProgramListingCard';
-const mockedPush = jest.fn();
+const mockedNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
- useHistory: () => ({
- push: mockedPush,
- }),
+ useNavigate: () => mockedNavigate,
useLocation: jest.fn(),
}));
@@ -139,6 +137,6 @@ describe('', () => {
programData={dummyProgramData}
/>);
userEvent.click(container.firstElementChild);
- expect(mockedPush).toHaveBeenCalledWith('/test-enterprise-slug/program/test-uuid/progress');
+ expect(mockedNavigate).toHaveBeenCalledWith('/test-enterprise-slug/program/test-uuid/progress');
});
});
diff --git a/src/components/program-progress/tests/ProgramListingPage.test.jsx b/src/components/program-progress/tests/ProgramListingPage.test.jsx
index e78fccf512..db63f5b35f 100644
--- a/src/components/program-progress/tests/ProgramListingPage.test.jsx
+++ b/src/components/program-progress/tests/ProgramListingPage.test.jsx
@@ -156,15 +156,15 @@ describe('', () => {
useLearnerProgramsListData.mockImplementation(() => ([[], null]));
await act(async () => {
- const { history } = renderWithRouter(
+ renderWithRouter(
,
);
userEvent.click(screen.getByText('Explore programs'));
- expect(history.location.pathname).toEqual(`/${initialAppState.enterpriseConfig.slug}/search`);
- expect(history.location.search).toEqual(`?content_type=${CONTENT_TYPE_PROGRAM}`);
+ expect(window.location.pathname).toEqual(`/${initialAppState.enterpriseConfig.slug}/search`);
+ expect(window.location.search).toEqual(`?content_type=${CONTENT_TYPE_PROGRAM}`);
});
});
diff --git a/src/components/search/Search.jsx b/src/components/search/Search.jsx
index 2aaad3ea13..0290372069 100644
--- a/src/components/search/Search.jsx
+++ b/src/components/search/Search.jsx
@@ -1,7 +1,7 @@
import React, {
useContext, useMemo, useEffect,
} from 'react';
-import { useParams, useHistory } from 'react-router-dom';
+import { useParams, useNavigate } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { Configure, InstantSearch } from 'react-instantsearch-dom';
import { AppContext } from '@edx/frontend-platform/react';
@@ -39,7 +39,7 @@ import { useEnterpriseCuration } from './content-highlights/data';
const Search = () => {
const { pathwayUUID } = useParams();
- const history = useHistory();
+ const navigate = useNavigate();
const { refinements } = useContext(SearchContext);
const [isLearnerPathwayModalOpen, openLearnerPathwayModal, onClose] = useToggle(false);
const { enterpriseConfig, algolia } = useContext(AppContext);
@@ -127,7 +127,7 @@ const Search = () => {
learnerPathwayUuid={pathwayUUID}
isOpen={isLearnerPathwayModalOpen}
onClose={() => {
- history.push(`/${enterpriseConfig.slug}/search`);
+ navigate(`/${enterpriseConfig.slug}/search`);
onClose();
}}
/>
diff --git a/src/components/search/SearchCourseCard.jsx b/src/components/search/SearchCourseCard.jsx
index 8230088807..348ba39db9 100644
--- a/src/components/search/SearchCourseCard.jsx
+++ b/src/components/search/SearchCourseCard.jsx
@@ -1,7 +1,7 @@
import React, { useContext, useMemo } from 'react';
import PropTypes from 'prop-types';
import cardFallbackImg from '@edx/brand/paragon/images/card-imagecap-fallback.png';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { getConfig } from '@edx/frontend-platform/config';
import { camelCaseObject } from '@edx/frontend-platform/utils';
@@ -16,7 +16,7 @@ const SearchCourseCard = ({
key, hit, isLoading, ...rest
}) => {
const { enterpriseConfig: { slug, uuid } } = useContext(AppContext);
- const history = useHistory();
+ const navigate = useNavigate();
const eventName = useMemo(
() => {
@@ -86,7 +86,7 @@ const SearchCourseCard = ({
courseKey: course.key,
},
);
- history.push(linkToCourse);
+ navigate(linkToCourse);
};
return (
diff --git a/src/components/search/SearchProgramCard.jsx b/src/components/search/SearchProgramCard.jsx
index c5aab5f36d..b87b038805 100644
--- a/src/components/search/SearchProgramCard.jsx
+++ b/src/components/search/SearchProgramCard.jsx
@@ -1,7 +1,7 @@
import React, { useContext, useMemo } from 'react';
import PropTypes from 'prop-types';
import cardFallbackImg from '@edx/brand/paragon/images/card-imagecap-fallback.png';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { camelCaseObject } from '@edx/frontend-platform/utils';
@@ -38,7 +38,7 @@ export const ProgramType = ({ type }) => {
};
const SearchProgramCard = ({ hit, isLoading, ...rest }) => {
- const history = useHistory();
+ const navigate = useNavigate();
const { enterpriseConfig: { slug, uuid } } = useContext(AppContext);
const program = useMemo(() => {
if (!hit) {
@@ -92,7 +92,7 @@ const SearchProgramCard = ({ hit, isLoading, ...rest }) => {
programUuid,
},
);
- history.push(linkToProgram);
+ navigate(linkToProgram);
};
return (
diff --git a/src/components/search/content-highlights/HighlightedContentCard.jsx b/src/components/search/content-highlights/HighlightedContentCard.jsx
index d0fdf68dc3..a2acc24d06 100644
--- a/src/components/search/content-highlights/HighlightedContentCard.jsx
+++ b/src/components/search/content-highlights/HighlightedContentCard.jsx
@@ -1,6 +1,6 @@
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { Card, Truncate } from '@edx/paragon';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
@@ -20,7 +20,7 @@ const HighlightedContentCard = ({
uuid: enterpriseUUID,
},
} = useContext(AppContext);
- const history = useHistory();
+ const navigate = useNavigate();
const {
variant,
@@ -40,7 +40,7 @@ const HighlightedContentCard = ({
// do nothing
return;
}
- history.push(href);
+ navigate(href);
sendEnterpriseTrackEvent(
enterpriseUUID,
'edx.ui.enterprise.learner_portal.search.content_highlights.card_carousel.item.clicked',
diff --git a/src/components/search/content-highlights/tests/ContentHighlightSet.test.jsx b/src/components/search/content-highlights/tests/ContentHighlightSet.test.jsx
index 6544e3d9d5..9fcaa921c3 100644
--- a/src/components/search/content-highlights/tests/ContentHighlightSet.test.jsx
+++ b/src/components/search/content-highlights/tests/ContentHighlightSet.test.jsx
@@ -1,9 +1,10 @@
-import { render, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import ContentHighlightSet from '../ContentHighlightSet';
+import { renderWithRouter } from '../../../../utils/tests';
const defaultAppContextValue = {
enterpriseConfig: { uuid: 'test-uuid' },
@@ -43,7 +44,7 @@ describe('ContentHighlightSet', () => {
});
it('renders stuff', () => {
- render();
+ renderWithRouter();
expect(screen.getByText(mockHighlightSetTitle)).toBeInTheDocument();
expect(screen.getByText(mockHighlightedContentItemTitle)).toBeInTheDocument();
diff --git a/src/components/search/tests/SearchCourseCard.test.jsx b/src/components/search/tests/SearchCourseCard.test.jsx
index 5ef891e27f..271bccc8dd 100644
--- a/src/components/search/tests/SearchCourseCard.test.jsx
+++ b/src/components/search/tests/SearchCourseCard.test.jsx
@@ -10,6 +10,12 @@ import * as courseSearchUtils from '../utils';
import { renderWithRouter } from '../../../utils/tests';
import { TEST_ENTERPRISE_SLUG, TEST_IMAGE_URL } from './constants';
+const mockedNavigate = jest.fn();
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useNavigate: () => mockedNavigate,
+}));
+
const SearchCourseCardWithAppContext = (props) => (
', () => {
+ beforeEach(() => {
+ mockedNavigate.mockClear();
+ });
+
test('renders the correct data', () => {
const { container } = renderWithRouter();
@@ -60,15 +70,14 @@ describe('', () => {
});
test('handles card click', () => {
- const { history } = renderWithRouter();
+ renderWithRouter();
const cardEl = screen.getByTestId('search-course-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}?`);
});
test('renders the loading state', () => {
- const { container, history } = renderWithRouter();
+ const { container } = renderWithRouter();
// ensure `Card` was passed `isLoading` by asserting each `Card` subcomponent
// is treated as a skeleton instead, indicated by `aria-busy="true"`.
@@ -77,7 +86,7 @@ describe('', () => {
// does not do anything when clicked
const cardEl = screen.getByTestId('search-course-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(1);
+ expect(mockedNavigate).not.toHaveBeenCalled();
});
test('render course_length field in place of course text', () => {
diff --git a/src/components/search/tests/SearchProgramCard.test.jsx b/src/components/search/tests/SearchProgramCard.test.jsx
index 4db06d698e..17d75bd190 100644
--- a/src/components/search/tests/SearchProgramCard.test.jsx
+++ b/src/components/search/tests/SearchProgramCard.test.jsx
@@ -21,6 +21,12 @@ jest.mock('@edx/frontend-enterprise-utils', () => ({
sendEnterpriseTrackEvent: jest.fn(),
}));
+const mockedNavigate = jest.fn();
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useNavigate: () => mockedNavigate,
+}));
+
const SearchProgramCardWithAppContext = (props) => (
', () => {
});
test('handles card click', () => {
- const { history } = renderWithRouter();
+ renderWithRouter();
const cardEl = screen.getByTestId('search-program-card');
userEvent.click(cardEl);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toEqual(`/${TEST_ENTERPRISE_SLUG}/program/${PROGRAM_UUID}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/program/${PROGRAM_UUID}`);
});
test.each(Object.keys(programTypes))('renders the correct program type: %s', (type) => {
diff --git a/src/components/site-header/SiteHeaderLogos.jsx b/src/components/site-header/SiteHeaderLogos.jsx
index 0669f67f36..04d9019c25 100644
--- a/src/components/site-header/SiteHeaderLogos.jsx
+++ b/src/components/site-header/SiteHeaderLogos.jsx
@@ -1,12 +1,12 @@
import React, { useContext } from 'react';
-import { Link, useRouteMatch } from 'react-router-dom';
+import { Link, useMatch } from 'react-router-dom';
import edXLogo from '@edx/brand/logo.svg';
import { Stack } from '@edx/paragon';
import { AppContext } from '@edx/frontend-platform/react';
import { COURSE_TYPE_PARTNER_LOGOS } from '../course/data/constants';
const SiteHeaderLogos = () => {
- const courseTypeMatch = useRouteMatch('/:enterpriseSlug/:courseType');
+ const courseTypeMatch = useMatch('/:enterpriseSlug/:courseType/*');
const courseType = courseTypeMatch?.params?.courseType;
const { enterpriseConfig } = useContext(AppContext);
const courseTypePartnerLogo = courseType && COURSE_TYPE_PARTNER_LOGOS[courseType];
diff --git a/src/components/site-header/SiteHeaderNavMenu.jsx b/src/components/site-header/SiteHeaderNavMenu.jsx
index a4843b10f9..37a0cc94d8 100644
--- a/src/components/site-header/SiteHeaderNavMenu.jsx
+++ b/src/components/site-header/SiteHeaderNavMenu.jsx
@@ -12,10 +12,10 @@ const SiteHeaderNavMenu = () => {
return (
<>
-
+
Dashboard
-
+
Find a Course
>
diff --git a/src/components/site-header/tests/SiteHeader.test.jsx b/src/components/site-header/tests/SiteHeader.test.jsx
index 3b89cd0a2e..0c8eb6e64c 100644
--- a/src/components/site-header/tests/SiteHeader.test.jsx
+++ b/src/components/site-header/tests/SiteHeader.test.jsx
@@ -1,10 +1,11 @@
import React from 'react';
-import { screen } from '@testing-library/react';
+import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import { breakpoints } from '@edx/paragon';
import userEvent from '@testing-library/user-event';
import { AppContext } from '@edx/frontend-platform/react';
+import { MemoryRouter } from 'react-router-dom';
import SiteHeader from '../SiteHeader';
import { renderWithRouter } from '../../../utils/tests';
@@ -103,11 +104,10 @@ describe('', () => {
}])('renders getSmarter logo when on /executive-education-2u path', ({
route,
}) => {
- renderWithRouter(
- ,
- {
- route,
- },
+ render(
+
+ ,
+ ,
);
const getSmarterLogo = screen.queryByTestId('partner-header-logo-image-id');
diff --git a/src/components/skills-quiz/CourseCard.jsx b/src/components/skills-quiz/CourseCard.jsx
index 746824701d..f5879b1554 100644
--- a/src/components/skills-quiz/CourseCard.jsx
+++ b/src/components/skills-quiz/CourseCard.jsx
@@ -2,7 +2,7 @@ import React, { useContext, useMemo } from 'react';
import {
Badge, Card, Stack, Truncate,
} from '@edx/paragon';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import PropTypes from 'prop-types';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
@@ -18,7 +18,7 @@ import { MAX_VISIBLE_SKILLS_COURSE, SKILL_NAME_CUTOFF_LIMIT } from './constants'
const CourseCard = ({
isLoading, course, allSkills,
}) => {
- const history = useHistory();
+ const navigate = useNavigate();
const { enterpriseConfig } = useContext(AppContext);
const { slug, uuid } = enterpriseConfig;
const partnerDetails = useMemo(() => {
@@ -47,7 +47,7 @@ const CourseCard = ({
{ userId, enterprise: slug, selectedCourse: course.key },
);
- history.push(linkToCourse(course, slug));
+ navigate(linkToCourse(course, slug));
};
return (
diff --git a/src/components/skills-quiz/SearchProgramCard.jsx b/src/components/skills-quiz/SearchProgramCard.jsx
index 651d349f35..e97ad43155 100644
--- a/src/components/skills-quiz/SearchProgramCard.jsx
+++ b/src/components/skills-quiz/SearchProgramCard.jsx
@@ -3,7 +3,7 @@ import React, {
} from 'react';
import PropTypes from 'prop-types';
import { v4 as uuidv4 } from 'uuid';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { camelCaseObject } from '@edx/frontend-platform/utils';
@@ -34,7 +34,7 @@ const linkToProgram = (program, slug, enterpriseUUID, programUuid) => {
};
const SearchProgramCard = ({ index }) => {
- const history = useHistory();
+ const navigate = useNavigate();
const { enterpriseConfig } = useContext(AppContext);
const { slug, uuid } = enterpriseConfig;
const {
@@ -161,7 +161,7 @@ const SearchProgramCard = ({ index }) => {
programUuid: programUuids[program.aggregationKey].uuid,
},
);
- history.push(url);
+ navigate(url);
};
if (hitCount === 0) {
diff --git a/src/components/skills-quiz/SkillsQuizPage.jsx b/src/components/skills-quiz/SkillsQuizPage.jsx
index 9e9e3dc0ff..7ee088e1f6 100644
--- a/src/components/skills-quiz/SkillsQuizPage.jsx
+++ b/src/components/skills-quiz/SkillsQuizPage.jsx
@@ -1,14 +1,14 @@
import React from 'react';
import { getConfig } from '@edx/frontend-platform/config';
-import { Redirect } from 'react-router-dom';
+import { Navigate } from 'react-router-dom';
import SkillsQuiz from './SkillsQuiz';
const SkillsQuizPage = () => {
const config = getConfig();
if (!config.ENABLE_SKILLS_QUIZ) {
- return ;
+ return ;
}
return ;
};
diff --git a/src/components/skills-quiz/SkillsQuizStepper.jsx b/src/components/skills-quiz/SkillsQuizStepper.jsx
index f7131c344e..e0f40a1545 100644
--- a/src/components/skills-quiz/SkillsQuizStepper.jsx
+++ b/src/components/skills-quiz/SkillsQuizStepper.jsx
@@ -7,7 +7,7 @@ import algoliasearch from 'algoliasearch/lite';
import { Configure, InstantSearch } from 'react-instantsearch-dom';
import { getConfig } from '@edx/frontend-platform/config';
import { SearchContext } from '@edx/frontend-enterprise-catalog-search';
-import { useHistory } from 'react-router-dom';
+import { useNavigate } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
@@ -72,7 +72,7 @@ const SkillsQuizStepper = () => {
const { name: jobs, current_job: currentJob } = refinements;
const { enterpriseConfig } = useContext(AppContext);
- const history = useHistory();
+ const navigate = useNavigate();
const goalNotDefault = goal !== GOAL_DROPDOWN_DEFAULT_OPTION;
const goalExceptImproveAndJobSelected = goalNotDefault && checkValidGoalAndJobSelected(goal, jobs, false);
@@ -80,7 +80,7 @@ const SkillsQuizStepper = () => {
const canContinueToRecommendedCourses = goalExceptImproveAndJobSelected || improveGoalAndCurrentJobSelected;
const closeSkillsQuiz = () => {
- history.push(`/${enterpriseConfig.slug}/search`);
+ navigate(`/${enterpriseConfig.slug}/search`);
sendEnterpriseTrackEvent(
enterpriseConfig.uuid,
'edx.ui.enterprise.learner_portal.skills_quiz.done.clicked',
diff --git a/src/components/skills-quiz/tests/SearchCourseCard.test.jsx b/src/components/skills-quiz/tests/SearchCourseCard.test.jsx
index 08cef8d973..6f99625e5e 100644
--- a/src/components/skills-quiz/tests/SearchCourseCard.test.jsx
+++ b/src/components/skills-quiz/tests/SearchCourseCard.test.jsx
@@ -24,6 +24,12 @@ jest.mock('@edx/frontend-enterprise-utils', () => ({
sendEnterpriseTrackEvent: jest.fn(),
}));
+const mockedNavigate = jest.fn();
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useNavigate: () => mockedNavigate,
+}));
+
const TEST_COURSE_KEY = 'test-course-key';
const TEST_TITLE = 'Test Title';
const TEST_CARD_IMG_URL = 'https://fake.image';
@@ -122,7 +128,7 @@ const SearchCourseCardWithContext = ({
describe('', () => {
test('renders the correct data', async () => {
- const { container, history } = renderWithRouter(
+ const { container } = renderWithRouter(
,
@@ -144,8 +150,7 @@ describe('', () => {
// handles click
userEvent.click(searchCourseCard);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toContain(`${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}`);
});
test('renders the correct data with skills', async () => {
diff --git a/src/components/skills-quiz/tests/SearchProgramCard.test.jsx b/src/components/skills-quiz/tests/SearchProgramCard.test.jsx
index 59395c55e1..5aa635b1d5 100644
--- a/src/components/skills-quiz/tests/SearchProgramCard.test.jsx
+++ b/src/components/skills-quiz/tests/SearchProgramCard.test.jsx
@@ -26,6 +26,12 @@ jest.mock('@edx/frontend-enterprise-utils', () => ({
sendEnterpriseTrackEvent: jest.fn(),
}));
+const mockedNavigate = jest.fn();
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useNavigate: () => mockedNavigate,
+}));
+
const PROGRAM_UUID = 'a9cbdeb6-5fc0-44ef-97f7-9ed605a149db';
const PROGRAM_TITLE = 'Intro to BatVerse';
const PROGRAM_TYPE_DISPLAYED = 'MicroMasters® Program';
@@ -129,7 +135,7 @@ const SearchProgramCardWithContext = ({
describe('', () => {
test('renders the correct data', async () => {
- const { container, history } = renderWithRouter(
+ const { container } = renderWithRouter(
,
@@ -153,8 +159,7 @@ describe('', () => {
// handles click
userEvent.click(searchProgramCard);
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toContain(`${TEST_ENTERPRISE_SLUG}/program/${PROGRAM_UUID}`);
+ expect(mockedNavigate).toHaveBeenCalledWith(`/${TEST_ENTERPRISE_SLUG}/program/${PROGRAM_UUID}`);
});
test('renders the correct data with skills', async () => {
diff --git a/src/components/skills-quiz/tests/SkillsCourses.test.jsx b/src/components/skills-quiz/tests/SkillsCourses.test.jsx
index e1f33fce68..2e81e3a44c 100644
--- a/src/components/skills-quiz/tests/SkillsCourses.test.jsx
+++ b/src/components/skills-quiz/tests/SkillsCourses.test.jsx
@@ -119,7 +119,7 @@ const SkillsCoursesWithContext = ({
describe('', () => {
test('renders the correct data', async () => {
- const { container, history } = renderWithRouter(
+ const { container } = renderWithRouter(
,
@@ -139,8 +139,7 @@ describe('', () => {
});
userEvent.click(screen.getByTestId('skills-quiz-course-card'));
- expect(history.entries).toHaveLength(2);
- expect(history.location.pathname).toContain(`/${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}`);
+ expect(window.location.pathname).toContain(`/${TEST_ENTERPRISE_SLUG}/course/${TEST_COURSE_KEY}`);
});
test('renders an alert in case of no courses returned', async () => {
diff --git a/src/utils/tests.jsx b/src/utils/tests.jsx
index 032c831c20..f773188f37 100644
--- a/src/utils/tests.jsx
+++ b/src/utils/tests.jsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { Router } from 'react-router-dom';
+import { BrowserRouter as Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import dayjs from 'dayjs';
// eslint-disable-next-line import/no-extraneous-dependencies