Skip to content

Commit

Permalink
fix: fixed course rerun route (openedx#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed May 9, 2024
1 parent e0fb41d commit a88066a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/studio-home/card-item/CardItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -50,7 +51,7 @@ describe('<CardItem />', () => {
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);
});
Expand All @@ -63,7 +64,7 @@ describe('<CardItem />', () => {
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);
});
Expand Down
5 changes: 3 additions & 2 deletions src/studio-home/card-item/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -69,7 +70,7 @@ const CardItem = ({
/>
<Dropdown.Menu>
{isShowRerunLink && (
<Dropdown.Item href={rerunLink}>
<Dropdown.Item href={trimSlashes(rerunLink)}>
{messages.btnReRunText.defaultMessage}
</Dropdown.Item>
)}
Expand All @@ -83,7 +84,7 @@ const CardItem = ({
{isShowRerunLink && (
<Hyperlink
className="small"
destination={rerunLink}
destination={trimSlashes(rerunLink)}
key={`action-row-rerunLink-${courseKey}`}
>
{intl.formatMessage(messages.btnReRunText)}
Expand Down
7 changes: 7 additions & 0 deletions src/studio-home/card-item/utils.js
Original file line number Diff line number Diff line change
@@ -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, '');

0 comments on commit a88066a

Please sign in to comment.