Skip to content

Commit 057ae57

Browse files
fix: using relative path now
1 parent 538a6ba commit 057ae57

4 files changed

Lines changed: 20 additions & 23 deletions

File tree

src/optimizer-page/scan-results/BrokenLinkTable.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ describe('BrokenLinkTable', () => {
717717

718718
await waitFor(() => {
719719
expect(window.open).toHaveBeenCalledWith(
720-
'http://localhost/course/course-v1:TestX+Test101+2024/container/unit-1#block-1',
720+
'/course/course-v1:TestX+Test101+2024/container/unit-1#block-1',
721721
'_blank',
722722
);
723723
});

src/optimizer-page/scan-results/BrokenLinkTable.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ const BrokenLinkTable: FC<BrokenLinkTableProps> = ({
211211
return {
212212
Links: (
213213
<LinksCol
214-
block={{ url: buildBlockContainerUrl(courseId, unit.id, block.id), displayName: block.displayName || 'Go to block', id: block.id }}
214+
block={{
215+
url: buildBlockContainerUrl(courseId, unit.id, block.id),
216+
displayName: block.displayName || 'Go to block',
217+
id: block.id,
218+
}}
215219
href={displayLink}
216220
showIcon={false}
217221
showUpdateButton
@@ -240,7 +244,10 @@ const BrokenLinkTable: FC<BrokenLinkTableProps> = ({
240244
const blockBrokenLinks = block.brokenLinks.map((link) => ({
241245
Links: (
242246
<LinksCol
243-
block={{ url: buildBlockContainerUrl(courseId, unit.id, block.id), displayName: block.displayName || 'Go to block' }}
247+
block={{
248+
url: buildBlockContainerUrl(courseId, unit.id, block.id),
249+
displayName: block.displayName || 'Go to block',
250+
}}
244251
href={link}
245252
linkType={BROKEN}
246253
/>
@@ -256,7 +263,10 @@ const BrokenLinkTable: FC<BrokenLinkTableProps> = ({
256263
const blockLockedLinks = block.lockedLinks.map((link) => ({
257264
Links: (
258265
<LinksCol
259-
block={{ url: buildBlockContainerUrl(courseId, unit.id, block.id), displayName: block.displayName || 'Go to block' }}
266+
block={{
267+
url: buildBlockContainerUrl(courseId, unit.id, block.id),
268+
displayName: block.displayName || 'Go to block',
269+
}}
260270
href={link}
261271
linkType={LOCKED}
262272
/>
@@ -273,7 +283,10 @@ const BrokenLinkTable: FC<BrokenLinkTableProps> = ({
273283
const externalForbiddenLinks = block.externalForbiddenLinks.map((link) => ({
274284
Links: (
275285
<LinksCol
276-
block={{ url: buildBlockContainerUrl(courseId, unit.id, block.id), displayName: block.displayName || 'Go to block' }}
286+
block={{
287+
url: buildBlockContainerUrl(courseId, unit.id, block.id),
288+
displayName: block.displayName || 'Go to block',
289+
}}
277290
href={link}
278291
linkType={MANUAL}
279292
/>

src/optimizer-page/utils.test.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,7 @@ describe('buildBlockContainerUrl', () => {
114114
const result = buildBlockContainerUrl(courseId, unitId, blockId);
115115

116116
expect(result).toBe(
117-
`${window.location.origin}/course/${courseId}/container/${unitId}#${blockId}`,
117+
`/course/${courseId}/container/${unitId}#${blockId}`,
118118
);
119119
});
120-
121-
it('should return only the internal path when window is undefined', () => {
122-
const courseId = 'course-v1:Test+Course+2024';
123-
const unitId = 'unit123';
124-
const blockId = 'block456';
125-
126-
Object.defineProperty(globalThis, 'window', { value: undefined, configurable: true, writable: true });
127-
128-
const result = buildBlockContainerUrl(courseId, unitId, blockId);
129-
130-
Object.defineProperty(globalThis, 'window', { value: globalThis, configurable: true, writable: true });
131-
132-
expect(result).toBe(`/course/${courseId}/container/${unitId}#${blockId}`);
133-
});
134120
});

src/optimizer-page/utils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ export const buildBlockContainerUrl = (
88
): string => {
99
const path = `/course/${courseId}/container/${unitId}#${blockId}`;
1010
const internalPath = createCorrectInternalRoute(path);
11-
return typeof window !== 'undefined'
12-
? `${window.location.origin}${internalPath}`
13-
: internalPath;
11+
return internalPath;
1412
};
1513

1614
export const countBrokenLinks = (

0 commit comments

Comments
 (0)