Skip to content

Commit

Permalink
refactor: handle relative proctoring link
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed May 2, 2024
1 parent 65f45f7 commit 03f362a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/course-outline/card-header/CardHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,12 +159,12 @@ const CardHeader = ({
iconAs={Icon}
/>
<Dropdown.Menu>
{isSequential && proctoringExamConfigurationLink && (
{isSequential && fullProctoringExamConfigurationLink && (
<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 03f362a

Please sign in to comment.