diff --git a/src/app/core/shared/search/search.service.spec.ts b/src/app/core/shared/search/search.service.spec.ts index 9399065ddf..fe5b495ab0 100644 --- a/src/app/core/shared/search/search.service.spec.ts +++ b/src/app/core/shared/search/search.service.spec.ts @@ -26,6 +26,8 @@ import { SearchConfigurationService } from './search-configuration.service'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; import { RequestEntry } from '../../data/request-entry.model'; import { Angulartics2 } from 'angulartics2'; +import { SearchFilterConfig } from '../../../shared/search/models/search-filter-config.model'; +import anything = jasmine.anything; @Component({ template: '' }) class DummyComponent { @@ -36,7 +38,7 @@ describe('SearchService', () => { let searchService: SearchService; const router = new RouterStub(); const route = new ActivatedRouteStub(); - const searchConfigService = {paginationID: 'page-id'}; + const searchConfigService = { paginationID: 'page-id' }; beforeEach(() => { TestBed.configureTestingModule({ imports: [ @@ -103,7 +105,8 @@ describe('SearchService', () => { }; const paginationService = new PaginationServiceStub(); - const searchConfigService = {paginationID: 'page-id'}; + const searchConfigService = { paginationID: 'page-id' }; + const requestService = getMockRequestService(); beforeEach(() => { TestBed.configureTestingModule({ @@ -119,7 +122,7 @@ describe('SearchService', () => { providers: [ { provide: Router, useValue: router }, { provide: RouteService, useValue: routeServiceStub }, - { provide: RequestService, useValue: getMockRequestService() }, + { provide: RequestService, useValue: requestService }, { provide: RemoteDataBuildService, useValue: remoteDataBuildService }, { provide: HALEndpointService, useValue: halService }, { provide: CommunityDataService, useValue: {} }, @@ -138,13 +141,13 @@ describe('SearchService', () => { it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.ListElement); - expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.ListElement } + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.ListElement } ); }); it('should call the navigate method on the Router with view mode grid parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.GridElement); - expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.GridElement } + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.GridElement } ); }); @@ -191,5 +194,23 @@ describe('SearchService', () => { expect((searchService as any).rdb.buildFromHref).toHaveBeenCalledWith(endPoint); }); }); + + describe('when getFacetValuesFor is called with a filterQuery', () => { + it('should add the encoded filterQuery to the args list', () => { + jasmine.getEnv().allowRespy(true); + const spyRequest = spyOn((searchService as any), 'request').and.stub(); + spyOn(requestService, 'send').and.returnValue(true); + const searchFilterConfig = new SearchFilterConfig(); + searchFilterConfig._links = { + self: { + href: 'https://demo.dspace.org/', + }, + }; + + searchService.getFacetValuesFor(searchFilterConfig, 1, undefined, 'filter&Query'); + + expect(spyRequest).toHaveBeenCalledWith(anything(), 'https://demo.dspace.org?page=0&size=5&prefix=filter%26Query'); + }); + }); }); }); diff --git a/src/app/core/shared/search/search.service.ts b/src/app/core/shared/search/search.service.ts index c8ce4b0348..2b1c6a573b 100644 --- a/src/app/core/shared/search/search.service.ts +++ b/src/app/core/shared/search/search.service.ts @@ -271,7 +271,7 @@ export class SearchService implements OnDestroy { let href; let args: string[] = []; if (hasValue(filterQuery)) { - args.push(`prefix=${filterQuery}`); + args.push(`prefix=${encodeURIComponent(filterQuery)}`); } if (hasValue(searchOptions)) { searchOptions = Object.assign(new PaginatedSearchOptions({}), searchOptions, {