From a88066a2c5424601a76f5aacada0a9b17c568729 Mon Sep 17 00:00:00 2001 From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com> Date: Thu, 9 May 2024 19:51:22 +0300 Subject: [PATCH] fix: fixed course rerun route (#993) --- src/studio-home/card-item/CardItem.test.jsx | 5 +++-- src/studio-home/card-item/index.jsx | 5 +++-- src/studio-home/card-item/utils.js | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/studio-home/card-item/utils.js diff --git a/src/studio-home/card-item/CardItem.test.jsx b/src/studio-home/card-item/CardItem.test.jsx index dfd5d12df1..74eb6e870c 100644 --- a/src/studio-home/card-item/CardItem.test.jsx +++ b/src/studio-home/card-item/CardItem.test.jsx @@ -8,6 +8,7 @@ import { initializeMockApp, getConfig } from '@edx/frontend-platform'; import { studioHomeMock } from '../__mocks__'; import messages from '../messages'; import initializeStore from '../../store'; +import { trimSlashes } from './utils'; import CardItem from '.'; jest.mock('react-redux', () => ({ @@ -50,7 +51,7 @@ describe('', () => { const courseTitleLink = getByText(props.displayName); expect(courseTitleLink).toHaveAttribute('href', `${getConfig().STUDIO_BASE_URL}${props.url}`); const btnReRunCourse = getByText(messages.btnReRunText.defaultMessage); - expect(btnReRunCourse).toHaveAttribute('href', props.rerunLink); + expect(btnReRunCourse).toHaveAttribute('href', trimSlashes(props.rerunLink)); const viewLiveLink = getByText(messages.viewLiveBtnText.defaultMessage); expect(viewLiveLink).toHaveAttribute('href', props.lmsLink); }); @@ -63,7 +64,7 @@ describe('', () => { const dropDownMenu = getByTestId('toggle-dropdown'); fireEvent.click(dropDownMenu); const btnReRunCourse = getByText(messages.btnReRunText.defaultMessage); - expect(btnReRunCourse).toHaveAttribute('href', props.rerunLink); + expect(btnReRunCourse).toHaveAttribute('href', trimSlashes(props.rerunLink)); const viewLiveLink = getByText(messages.viewLiveBtnText.defaultMessage); expect(viewLiveLink).toHaveAttribute('href', props.lmsLink); }); diff --git a/src/studio-home/card-item/index.jsx b/src/studio-home/card-item/index.jsx index 18c8bd5593..f495794d80 100644 --- a/src/studio-home/card-item/index.jsx +++ b/src/studio-home/card-item/index.jsx @@ -15,6 +15,7 @@ import { getConfig } from '@edx/frontend-platform'; import { COURSE_CREATOR_STATES } from '../../constants'; import { getStudioHomeData } from '../data/selectors'; import messages from '../messages'; +import { trimSlashes } from './utils'; const CardItem = ({ intl, @@ -69,7 +70,7 @@ const CardItem = ({ /> {isShowRerunLink && ( - + {messages.btnReRunText.defaultMessage} )} @@ -83,7 +84,7 @@ const CardItem = ({ {isShowRerunLink && ( {intl.formatMessage(messages.btnReRunText)} diff --git a/src/studio-home/card-item/utils.js b/src/studio-home/card-item/utils.js new file mode 100644 index 0000000000..8bbc7c2e25 --- /dev/null +++ b/src/studio-home/card-item/utils.js @@ -0,0 +1,7 @@ +/** + * Removes leading and trailing slashes from a string. + * @param {string} str - The string to trim. + * @returns {string} The trimmed string. + */ +// eslint-disable-next-line import/prefer-default-export +export const trimSlashes = (str) => str.replace(/^\/|\/$/g, '');