fix: BadOraLocationResponse error (#168)

Refactor the locationId constant for subdirectory-based deployments.

Exclude the MFE's `PUBLIC_PATH` from the constant.
This commit is contained in:
Eugene Dyudyunov
2023-04-18 20:06:01 +03:00
committed by GitHub
parent 559c335aa3
commit 5fa0c1ab66
2 changed files with 4 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
import { getConfig } from '@edx/frontend-platform';
export const routePath = `${getConfig().PUBLIC_PATH}:courseId`;
export const locationId = window.location.pathname.slice(1);
export const locationId = window.location.pathname.replace(getConfig().PUBLIC_PATH, '');

View File

@@ -4,7 +4,7 @@ import * as constants from './app';
jest.unmock('./app');
jest.mock('@edx/frontend-platform', () => {
const PUBLIC_PATH = 'test-public-path';
const PUBLIC_PATH = '/test-public-path/';
return {
getConfig: () => ({ PUBLIC_PATH }),
PUBLIC_PATH,
@@ -17,8 +17,8 @@ describe('app constants', () => {
});
test('locationId returns trimmed pathname', () => {
const old = window.location;
window.location = { pathName: '/somePath.jpg' };
expect(constants.locationId).toEqual(window.location.pathname.slice(1));
window.location = { pathName: `${platform.PUBLIC_PATH}somePath.jpg` };
expect(constants.locationId).toEqual(window.location.pathname.replace(platform.PUBLIC_PATH, ''));
window.location = old;
});
});