diff --git a/DigitalLearningSolutions.Web/Scripts/learningPortal/available.ts b/DigitalLearningSolutions.Web/Scripts/learningPortal/available.ts index 6220291965..bfd9abb793 100644 --- a/DigitalLearningSolutions.Web/Scripts/learningPortal/available.ts +++ b/DigitalLearningSolutions.Web/Scripts/learningPortal/available.ts @@ -1,4 +1,4 @@ import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate'; // eslint-disable-next-line no-new -new SearchSortAndPaginate('/LearningPortal/AllAvailableItems'); +new SearchSortAndPaginate('LearningPortal/AllAvailableItems'); diff --git a/DigitalLearningSolutions.Web/Scripts/learningPortal/completed.ts b/DigitalLearningSolutions.Web/Scripts/learningPortal/completed.ts index e404d66cd2..9730ebcf06 100644 --- a/DigitalLearningSolutions.Web/Scripts/learningPortal/completed.ts +++ b/DigitalLearningSolutions.Web/Scripts/learningPortal/completed.ts @@ -1,4 +1,4 @@ import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate'; // eslint-disable-next-line no-new -new SearchSortAndPaginate('/LearningPortal/AllCompletedItems'); +new SearchSortAndPaginate('LearningPortal/AllCompletedItems'); diff --git a/DigitalLearningSolutions.Web/Scripts/learningPortal/current.ts b/DigitalLearningSolutions.Web/Scripts/learningPortal/current.ts index 63d64a9a7e..8f275dd4c7 100644 --- a/DigitalLearningSolutions.Web/Scripts/learningPortal/current.ts +++ b/DigitalLearningSolutions.Web/Scripts/learningPortal/current.ts @@ -1,4 +1,4 @@ import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate'; // eslint-disable-next-line no-new -new SearchSortAndPaginate('/LearningPortal/AllCurrentItems'); +new SearchSortAndPaginate('LearningPortal/AllCurrentItems'); diff --git a/DigitalLearningSolutions.Web/Scripts/searchSortAndPaginate/searchSortAndPaginate.ts b/DigitalLearningSolutions.Web/Scripts/searchSortAndPaginate/searchSortAndPaginate.ts index 3e8cf79695..c3940205db 100644 --- a/DigitalLearningSolutions.Web/Scripts/searchSortAndPaginate/searchSortAndPaginate.ts +++ b/DigitalLearningSolutions.Web/Scripts/searchSortAndPaginate/searchSortAndPaginate.ts @@ -11,6 +11,7 @@ export interface SearchableElement { export class SearchSortAndPaginate { private page: number; + // Route proved should be a relative path with no leading / constructor(route: string) { this.page = 1; SearchSortAndPaginate.getSearchableElements(route).then((allSearchableElements) => { @@ -67,6 +68,7 @@ export class SearchSortAndPaginate { } private static fetchAllSearchableElements(route: string): Promise { + const path = this.getPathForEndpoint(route); return new Promise((res) => { const request = new XMLHttpRequest(); @@ -74,7 +76,7 @@ export class SearchSortAndPaginate { res(request.responseXML); }; - request.open('GET', route, true); + request.open('GET', path, true); request.responseType = 'document'; request.send(); }); @@ -97,4 +99,11 @@ export class SearchSortAndPaginate { // This is required to polyfill the new elements in IE Details(); } + + private static getPathForEndpoint(endpoint: string): string { + const currentPath = window.location.pathname; + const endpointUrlParts = endpoint.split('/'); + const indexOfBaseUrl = currentPath.indexOf(endpointUrlParts[0]); + return `${currentPath.substring(0, indexOfBaseUrl)}${endpoint}`; + } } diff --git a/DigitalLearningSolutions.Web/Scripts/spec/searchSortAndPaginate.spec.ts b/DigitalLearningSolutions.Web/Scripts/spec/searchSortAndPaginate.spec.ts index 2e2331c23f..41cf4ea256 100644 --- a/DigitalLearningSolutions.Web/Scripts/spec/searchSortAndPaginate.spec.ts +++ b/DigitalLearningSolutions.Web/Scripts/spec/searchSortAndPaginate.spec.ts @@ -55,11 +55,30 @@ describe('getCourseCards', () => { global.window = { location: { pathname: '/LearningPortal/Current/1' } } as any; // When - SearchSortAndPaginate.getSearchableElements('/LearningPortal/test'); + SearchSortAndPaginate.getSearchableElements('LearningPortal/test'); // Then expect(mockOpen).toHaveBeenCalledWith('GET', '/LearningPortal/test', true); }); + + it('calls the correct url hosted in subdirectory', () => { + // Given + const mockOpen = jest.fn(); + createCourseCards(); + const mockXHR = { + open: mockOpen, + send: jest.fn(), + responseXML: document, + }; + global.XMLHttpRequest = jest.fn(() => mockXHR) as any; + global.window = { location: { pathname: '/dev/LearningPortal/Current/1' } } as any; + + // When + SearchSortAndPaginate.getSearchableElements('LearningPortal/test'); + + // Then + expect(mockOpen).toHaveBeenCalledWith('GET', '/dev/LearningPortal/test', true); + }); }); describe('displayCards', () => { diff --git a/DigitalLearningSolutions.Web/Scripts/trackingSystem/centreAdministrators.ts b/DigitalLearningSolutions.Web/Scripts/trackingSystem/centreAdministrators.ts index 050a4920d0..fdd353e204 100644 --- a/DigitalLearningSolutions.Web/Scripts/trackingSystem/centreAdministrators.ts +++ b/DigitalLearningSolutions.Web/Scripts/trackingSystem/centreAdministrators.ts @@ -1,4 +1,4 @@ import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate'; // eslint-disable-next-line no-new -new SearchSortAndPaginate('/TrackingSystem/Centre/Administrators/AllAdmins'); +new SearchSortAndPaginate('TrackingSystem/Centre/Administrators/AllAdmins'); diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/Centre/Administrator/Index.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/Centre/Administrator/Index.cshtml index c2d3f7e176..120c0765df 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/Centre/Administrator/Index.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/Centre/Administrator/Index.cshtml @@ -37,7 +37,7 @@
- +