Skip to content

Commit

Permalink
refactor: handle relative proctoring link (openedx#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored May 7, 2024
1 parent de408b5 commit 087c82c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/course-outline/card-header/CardHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ const CardHeader = ({
const cardHeaderRef = useRef(null);
const [isManageTagsDrawerOpen, openManageTagsDrawer, closeManageTagsDrawer] = useToggle(false);

// Use studio url as base if proctoringExamConfigurationLink is a relative link
const fullProctoringExamConfigurationLink = () => (
proctoringExamConfigurationLink && new URL(proctoringExamConfigurationLink, getConfig().STUDIO_BASE_URL).href
);

const isDisabledPublish = (status === ITEM_BADGE_STATUS.live
|| status === ITEM_BADGE_STATUS.publishedNotLive) && !hasChanges;

Expand Down Expand Up @@ -156,8 +161,8 @@ const CardHeader = ({
<Dropdown.Item
as={Hyperlink}
target="_blank"
destination={proctoringExamConfigurationLink}
href={proctoringExamConfigurationLink}
destination={fullProctoringExamConfigurationLink()}
href={fullProctoringExamConfigurationLink()}
externalLinkTitle={intl.formatMessage(messages.proctoringLinkTooltip)}
>
{intl.formatMessage(messages.menuProctoringLinkText)}
Expand Down
21 changes: 19 additions & 2 deletions src/course-outline/card-header/CardHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,31 @@ describe('<CardHeader />', () => {
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 () => {
Expand Down

0 comments on commit 087c82c

Please sign in to comment.