From 03f362a08b57199f27e9d13eb3e0c11b26a51e54 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Thu, 2 May 2024 20:00:49 +0530 Subject: [PATCH] refactor: handle relative proctoring link --- src/course-outline/card-header/CardHeader.jsx | 13 +++++++++--- .../card-header/CardHeader.test.jsx | 21 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/course-outline/card-header/CardHeader.jsx b/src/course-outline/card-header/CardHeader.jsx index 065707b243..cde40885bc 100644 --- a/src/course-outline/card-header/CardHeader.jsx +++ b/src/course-outline/card-header/CardHeader.jsx @@ -61,6 +61,13 @@ const CardHeader = ({ const [titleValue, setTitleValue] = useState(title); const cardHeaderRef = useRef(null); const [isManageTagsDrawerOpen, openManageTagsDrawer, closeManageTagsDrawer] = useToggle(false); + let fullProctoringExamConfigurationLink = proctoringExamConfigurationLink; + + if (proctoringExamConfigurationLink && !( + proctoringExamConfigurationLink.indexOf('http://') === 0 || proctoringExamConfigurationLink.indexOf('https://') === 0 + )) { + fullProctoringExamConfigurationLink = new URL(proctoringExamConfigurationLink, getConfig().STUDIO_BASE_URL).href; + } const isDisabledPublish = (status === ITEM_BADGE_STATUS.live || status === ITEM_BADGE_STATUS.publishedNotLive) && !hasChanges; @@ -152,12 +159,12 @@ const CardHeader = ({ iconAs={Icon} /> - {isSequential && proctoringExamConfigurationLink && ( + {isSequential && fullProctoringExamConfigurationLink && ( {intl.formatMessage(messages.menuProctoringLinkText)} diff --git a/src/course-outline/card-header/CardHeader.test.jsx b/src/course-outline/card-header/CardHeader.test.jsx index c734300433..d589627173 100644 --- a/src/course-outline/card-header/CardHeader.test.jsx +++ b/src/course-outline/card-header/CardHeader.test.jsx @@ -265,14 +265,31 @@ describe('', () => { it('check if proctoringExamConfigurationLink is visible', async () => { const { findByText, findByTestId } = renderComponent({ ...cardHeaderProps, - proctoringExamConfigurationLink: 'https://localhost:8000/', + proctoringExamConfigurationLink: 'proctoringlink', isSequential: true, }); const menuButton = await findByTestId('subsection-card-header__menu-button'); await act(async () => fireEvent.click(menuButton)); - expect(await findByText(messages.menuProctoringLinkText.defaultMessage)).toBeInTheDocument(); + const element = await findByText(messages.menuProctoringLinkText.defaultMessage); + expect(element).toBeInTheDocument(); + expect(element.getAttribute('href')).toBe(`${getConfig().STUDIO_BASE_URL}/proctoringlink`); + }); + + it('check if proctoringExamConfigurationLink is absolute', async () => { + const { findByText, findByTestId } = renderComponent({ + ...cardHeaderProps, + proctoringExamConfigurationLink: 'http://localhost:9000/proctoringlink', + isSequential: true, + }); + + const menuButton = await findByTestId('subsection-card-header__menu-button'); + await act(async () => fireEvent.click(menuButton)); + + const element = await findByText(messages.menuProctoringLinkText.defaultMessage); + expect(element).toBeInTheDocument(); + expect(element.getAttribute('href')).toBe('http://localhost:9000/proctoringlink'); }); it('check if discussion enabled badge is visible', async () => {