fix: decodeURIComponent for locationId
Squashed commit of the following: commit af4d469ef241a504112dceda2cb94bff24ba4a9c Author: Vu Nguyen <vu.nguyen@dmttek.com> Date: Wed Oct 4 11:27:58 2023 +0700 update test cases commit d0c28fb99bede979fbcc8f57036ecb8027996772 Merge: 1f4d50b5492520Author: vunguyen-dmt <34919039+vunguyen-dmt@users.noreply.github.com> Date: Wed Oct 4 11:22:24 2023 +0700 Merge branch 'openedx:master' into fix_location_id_error commit 1f4d50b36514a6e4e9e575b938bf93b81317a21c Merge: a280a35 eb73457 Author: Vu Nguyen <vu.nguyen@dmttek.com> Date: Fri Jul 21 03:45:05 2023 +0700 Merge branch 'fix_location_id_error' of https://github.com/vunguyen-dmt/frontend-app-ora-grading into fix_location_id_error commit a280a350fcf595dd2011018d113467a9cd88cd61 Author: Vu Nguyen <vu.nguyen@dmttek.com> Date: Fri Jul 21 03:44:28 2023 +0700 fix: decodeURIComponent for locationId commit eb734574bd0daae0c2523904763a8d755baa31f3 Author: Vu Nguyen <vu.nguyen@dmttek.com> Date: Fri Jul 21 03:41:28 2023 +0700 update src/data/constants/app.test.js commit 513dd324a5adc7312ac92c30164e0120784acd4b Merge: e89984678ada8cAuthor: vunguyen-dmt <34919039+vunguyen-dmt@users.noreply.github.com> Date: Wed Jul 19 16:12:14 2023 +0700 Merge branch 'master' into fix_location_id_error commit e8998461de8ba9cbbe00a1726ad6266bde5d5ef5 Author: Vu Nguyen <vu.nguyen@dmttek.com> Date: Thu Jun 8 10:29:45 2023 +0700 fix: decodeURIComponent for locationId
This commit is contained in:
committed by
leangseu-edx
parent
cc11ce0f81
commit
c644da3dcc
@@ -1,4 +1,4 @@
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
|
||||
export const routePath = () => `${getConfig().PUBLIC_PATH}:courseId`;
|
||||
export const locationId = () => window.location.pathname.replace(getConfig().PUBLIC_PATH, '');
|
||||
export const locationId = () => decodeURIComponent(window.location.pathname).replace(getConfig().PUBLIC_PATH, '');
|
||||
|
||||
@@ -15,10 +15,29 @@ describe('app constants', () => {
|
||||
test('route path draws from public path and adds courseId', () => {
|
||||
expect(constants.routePath()).toEqual(`${platform.PUBLIC_PATH}:courseId`);
|
||||
});
|
||||
test('locationId returns trimmed pathname', () => {
|
||||
const old = window.location;
|
||||
window.location = { pathName: `${platform.PUBLIC_PATH}somePath.jpg` };
|
||||
expect(constants.locationId()).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
|
||||
window.location = old;
|
||||
describe('locationId', () => {
|
||||
const domain = 'https://example.com';
|
||||
|
||||
test('returns trimmed pathname', () => {
|
||||
const old = window.location;
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: new URL(`${domain}${platform.PUBLIC_PATH}somePath.jpg`),
|
||||
writable: true,
|
||||
});
|
||||
expect(constants.locationId()).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
|
||||
window.location = old;
|
||||
});
|
||||
test('handle none-standard characters pathName', () => {
|
||||
const old = window.location;
|
||||
const noneStandardPath = `${platform.PUBLIC_PATH}ORG+%C4%90+2023`;
|
||||
const expectedPath = `${platform.PUBLIC_PATH}ORG+Đ+2023`;
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: new URL(`${domain}${noneStandardPath}`),
|
||||
writable: true,
|
||||
});
|
||||
expect(noneStandardPath).not.toEqual(expectedPath);
|
||||
expect(constants.locationId()).toEqual(expectedPath.replace(platform.PUBLIC_PATH, ''));
|
||||
window.location = old;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user