Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate';

// eslint-disable-next-line no-new
new SearchSortAndPaginate('/LearningPortal/AllAvailableItems');
new SearchSortAndPaginate('LearningPortal/AllAvailableItems');
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate';

// eslint-disable-next-line no-new
new SearchSortAndPaginate('/LearningPortal/AllCompletedItems');
new SearchSortAndPaginate('LearningPortal/AllCompletedItems');
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SearchSortAndPaginate } from '../searchSortAndPaginate/searchSortAndPaginate';

// eslint-disable-next-line no-new
new SearchSortAndPaginate('/LearningPortal/AllCurrentItems');
new SearchSortAndPaginate('LearningPortal/AllCurrentItems');
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -67,14 +68,15 @@ export class SearchSortAndPaginate {
}

private static fetchAllSearchableElements(route: string): Promise<Document | null> {
const path = this.getPathForEndpoint(route);
return new Promise((res) => {
const request = new XMLHttpRequest();

request.onload = () => {
res(request.responseXML);
};

request.open('GET', route, true);
request.open('GET', path, true);
request.responseType = 'document';
request.send();
});
Expand All @@ -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}`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<form method="get" role="search" asp-action="Index" asp-route-page="@Model.Page">

<div class="nhsuk-grid-row">
<vc:search-box label="Search administrators" asp-controller="Administrator" asp-action="Index" containing-page-model="@Model" />
<vc:search-box label="Search administrators" asp-controller="Administrator" asp-action="Index" searchable-page-view-model="@Model" />
</div>

<div class="nhsuk-grid-row">
Expand Down