diff --git a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts index bf069eee60..e629925e28 100644 --- a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.spec.ts @@ -10,6 +10,10 @@ import { FilterType } from '../../../search-service/filter-type.model'; import { FacetValue } from '../../../search-service/facet-value.model'; import { FormsModule } from '@angular/forms'; import { Observable } from 'rxjs/Observable'; +import { SearchService } from '../../../search-service/search.service'; +import { SearchServiceStub } from '../../../../shared/testing/search-service-stub'; +import { RemoteData } from '../../../../core/data/remote-data'; +import { PaginatedList } from '../../../../core/data/paginated-list'; describe('SearchFacetFilterComponent', () => { let comp: SearchFacetFilterComponent; @@ -40,29 +44,31 @@ describe('SearchFacetFilterComponent', () => { search: '' } ]; + + const searchLink = '/search'; + const selectedValues = [value1, value2]; let filterService; - const page = Observable.of(0) + const page = Observable.of(0); beforeEach(async(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, FormsModule], declarations: [SearchFacetFilterComponent], providers: [ + { provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { - provide: SearchFilterService, - useValue: { - isFilterActiveWithValue: (paramName: string, filterValue: string) => true, - getQueryParamsWith: (paramName: string, filterValue: string) => '', - getQueryParamsWithout: (paramName: string, filterValue: string) => '', - getPage: (paramName: string) => page, - /* tslint:disable:no-empty */ - incrementPage: (filterName: string) => { - }, - resetPage: (filterName: string) => { - }, - /* tslint:enable:no-empty */ - searchLink: '/search', - } - }, + provide: SearchFilterService, useValue: { + isFilterActiveWithValue: (paramName: string, filterValue: string) => true, + getPage: (paramName: string) => page, + /* tslint:disable:no-empty */ + incrementPage: (filterName: string) => { + }, + resetPage: (filterName: string) => { + }, + getSearchOptions: () => Observable.of({}), + + /* tslint:enable:no-empty */ + } + } ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(SearchFacetFilterComponent, { @@ -74,7 +80,8 @@ describe('SearchFacetFilterComponent', () => { fixture = TestBed.createComponent(SearchFacetFilterComponent); comp = fixture.componentInstance; // SearchPageComponent test instance comp.filterConfig = mockFilterConfig; - comp.filterValues = values; + comp.filterValues = [Observable.of(new RemoteData(false, false, true, null, new PaginatedList(null, values)))]; + comp.selectedValues = selectedValues; filterService = (comp as any).filterService; fixture.detectChanges(); }); @@ -97,64 +104,24 @@ describe('SearchFacetFilterComponent', () => { }); it('should return the value of the searchLink variable in the filter service', () => { - expect(link).toEqual(filterService.searchLink); + expect(link).toEqual(searchLink); }); }); - describe('when the getQueryParamsWith method is called wih a value', () => { - beforeEach(() => { - spyOn(filterService, 'getQueryParamsWith'); - comp.getQueryParamsWith(values[1].value); - }); - - it('should call getQueryParamsWith on the filterService with the correct filter parameter name and the passed value', () => { - expect(filterService.getQueryParamsWith).toHaveBeenCalledWith(mockFilterConfig, values[1].value) + describe('when the getAddParams method is called wih a value', () => { + it('should return the selectedValueq list with the new parameter value', () => { + const result = comp.getAddParams(value3); + expect(result).toEqual({[mockFilterConfig.paramName]: [value1, value2, value3]}); }); }); - describe('when the getQueryParamsWithout method is called wih a value', () => { - beforeEach(() => { - spyOn(filterService, 'getQueryParamsWithout'); - comp.getQueryParamsWithout(values[1].value); - }); - - it('should call getQueryParamsWithout on the filterService with the correct filter parameter name and the passed value', () => { - expect(filterService.getQueryParamsWithout).toHaveBeenCalledWith(mockFilterConfig, values[1].value) + describe('when the getRemoveParams method is called wih a value', () => { + it('should return the selectedValueq list with the parameter value left out', () => { + const result = comp.getRemoveParams(value1); + expect(result).toEqual({[mockFilterConfig.paramName]: [value2]}); }); }); - describe('when the facetCount method is triggered when there are less items than the amount of pages should display', () => { - let count: Observable; - beforeEach(() => { - comp.currentPage = Observable.of(3); - // 2 x 3 = 6, there are only 3 values - count = comp.facetCount; - }); - - it('should return the correct number of items shown (this equals the total amount of values for this filter)', () => { - const sub = count.subscribe((c) => expect(c).toBe(values.length)); - sub.unsubscribe(); - }); - }); - - describe('when the facetCount method is triggered when there are more items than the amount of pages should display', () => { - let count: Observable; - beforeEach(() => { - comp.currentPage = Observable.of(1); - // 2 x 1 = 2, there are more than 2 (3) items - count = comp.facetCount; - }); - - it('should return the correct number of items shown (this equals the page count x page size)', () => { - const sub = count.subscribe((c) => { - const subsub = comp.currentPage.subscribe((currentPage) => { - expect(c).toBe(currentPage * mockFilterConfig.pageSize); - }); - subsub.unsubscribe() - }); - sub.unsubscribe(); - }); - }); describe('when the showMore method is called', () => { beforeEach(() => { diff --git a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts index c7941ec5dc..60b7b13b0d 100644 --- a/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts +++ b/src/app/+search-page/search-filters/search-filter/search-facet-filter/search-facet-filter.component.ts @@ -102,7 +102,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy { isLastPage(): Observable { return Observable.of(false); - // return this.filterValues.flatMap((map) => map.pop().map((rd: RemoteData>) => rd.payload.currentPage >= rd.payload.totalPages)); + // return this.filterValues$.flatMap((map) => map.pop().map((rd: RemoteData>) => rd.payload.currentPage >= rd.payload.totalPages)); } getRemoveParams(value: string) { diff --git a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts index 853f8b0f68..0ab1e4319d 100644 --- a/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts +++ b/src/app/+search-page/search-filters/search-filter/search-filter.service.spec.ts @@ -50,7 +50,7 @@ describe('SearchFilterService', () => { }; beforeEach(() => { - service = new SearchFilterService(store, routeServiceStub, searchServiceStub); + service = new SearchFilterService(store, routeServiceStub); }); describe('when the initialCollapse method is triggered', () => { diff --git a/src/app/+search-page/search-filters/search-filters.component.html b/src/app/+search-page/search-filters/search-filters.component.html index 09782b68d4..566450b7f5 100644 --- a/src/app/+search-page/search-filters/search-filters.component.html +++ b/src/app/+search-page/search-filters/search-filters.component.html @@ -4,4 +4,4 @@ -{{"search.filters.reset" | translate}} \ No newline at end of file +{{"search.filters.reset" | translate}} \ No newline at end of file diff --git a/src/app/+search-page/search-filters/search-filters.component.ts b/src/app/+search-page/search-filters/search-filters.component.ts index 808ce3be67..517b2e1e59 100644 --- a/src/app/+search-page/search-filters/search-filters.component.ts +++ b/src/app/+search-page/search-filters/search-filters.component.ts @@ -3,6 +3,7 @@ import { SearchService } from '../search-service/search.service'; import { RemoteData } from '../../core/data/remote-data'; import { SearchFilterConfig } from '../search-service/search-filter-config.model'; import { Observable } from 'rxjs/Observable'; +import { SearchFilterService } from './search-filter/search-filter.service'; /** * This component renders a simple item page. @@ -18,12 +19,10 @@ import { Observable } from 'rxjs/Observable'; export class SearchFiltersComponent { filters: Observable>; - constructor(private searchService: SearchService) { + clearParams; + constructor(private searchService: SearchService, private filterService: SearchFilterService) { this.filters = searchService.getConfig(); - } - - getClearFiltersQueryParams(): any { - return this.searchService.getClearFiltersQueryParams(); + this.clearParams = filterService.getCurrentFilters().map((filters) => {Object.keys(filters).forEach((f) => filters[f] = null); return filters;}); } getSearchLink() { diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index d72610695d..8cd041eabb 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -17,6 +17,7 @@ import { ActivatedRoute } from '@angular/router'; import { By } from '@angular/platform-browser'; import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; +import { SearchFilterService } from './search-filters/search-filter/search-filter.service'; describe('SearchPageComponent', () => { let comp: SearchPageComponent; @@ -89,6 +90,10 @@ describe('SearchPageComponent', () => { provide: SearchSidebarService, useValue: sidebarService }, + { + provide: SearchFilterService, + useValue: {} + }, ], schemas: [NO_ERRORS_SCHEMA] }).overrideComponent(SearchPageComponent, { diff --git a/src/app/+search-page/search-service/search.service.spec.ts b/src/app/+search-page/search-service/search.service.spec.ts index f8a1d73ae1..5f9f67390b 100644 --- a/src/app/+search-page/search-service/search.service.spec.ts +++ b/src/app/+search-page/search-service/search.service.spec.ts @@ -15,6 +15,7 @@ import { RequestService } from '../../core/data/request.service'; import { ResponseCacheService } from '../../core/cache/response-cache.service'; import { ActivatedRouteStub } from '../../shared/testing/active-router-stub'; import { RouterStub } from '../../shared/testing/router-stub'; +import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; @Component({ template: '' }) class DummyComponent { @@ -37,14 +38,12 @@ describe('SearchService', () => { DummyComponent ], providers: [ - { provide: ItemDataService, useValue: {} }, - { provide: RouteService, useValue: {} }, + { provide: Router, useValue: router }, + { provide: ActivatedRoute, useValue: route }, { provide: ResponseCacheService, useValue: {} }, { provide: RequestService, useValue: {} }, - { provide: ActivatedRoute, useValue: route }, { provide: RemoteDataBuildService, useValue: {} }, - { provide: GLOBAL_CONFIG, useValue: {} }, - { provide: Router, useValue: router }, + { provide: HALEndpointService, useValue: {} }, SearchService ], }); @@ -73,14 +72,12 @@ describe('SearchService', () => { DummyComponent ], providers: [ - { provide: ItemDataService, useValue: {} }, - { provide: RouteService, useValue: {} }, + { provide: Router, useValue: router }, + { provide: ActivatedRoute, useValue: route }, { provide: ResponseCacheService, useValue: {} }, { provide: RequestService, useValue: {} }, - { provide: ActivatedRoute, useValue: route }, { provide: RemoteDataBuildService, useValue: {} }, - { provide: GLOBAL_CONFIG, useValue: {} }, - { provide: Router, useValue: router }, + { provide: HALEndpointService, useValue: {} }, SearchService ], }); diff --git a/src/app/+search-page/search-service/search.service.ts b/src/app/+search-page/search-service/search.service.ts index 2ef69e8578..134ae657a1 100644 --- a/src/app/+search-page/search-service/search.service.ts +++ b/src/app/+search-page/search-service/search.service.ts @@ -23,7 +23,6 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service'; import { URLCombiner } from '../../core/url-combiner/url-combiner'; import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; -import { RouteService } from '../../shared/route.service'; import { NormalizedSearchResult } from '../normalized-search-result.model'; import { SearchOptions } from '../search-options.model'; import { SearchResult } from '../search-result.model'; @@ -37,7 +36,6 @@ import { getSearchResultFor } from './search-result-element-decorator'; import { ListableObject } from '../../shared/object-collection/shared/listable-object.model'; import { FacetValueResponseParsingService } from '../../core/data/facet-value-response-parsing.service'; import { FacetConfigResponseParsingService } from '../../core/data/facet-config-response-parsing.service'; -import { SearchFilterService } from '../search-filters/search-filter/search-filter.service'; import { PaginatedSearchOptions } from '../paginated-search-options.model'; @Injectable() @@ -206,7 +204,6 @@ export class SearchService implements OnDestroy { } getFacetValuesFor(filterConfig: SearchFilterConfig, valuePage: number, searchOptions?: SearchOptions): Observable>> { - console.log('facetvalues'); const requestObs = this.halService.getEndpoint(this.facetValueLinkPathPrefix + filterConfig.name).pipe( map((url: string) => { const args: string[] = [`page=${valuePage - 1}`, `size=${filterConfig.pageSize}`]; @@ -268,20 +265,6 @@ export class SearchService implements OnDestroy { this.router.navigate([this.uiSearchRoute], navigationExtras); } - getClearFiltersQueryParams(): any { - const params = {}; - this.sub = this.route.queryParamMap - .subscribe((pmap) => { - pmap.keys - .filter((key) => this.config - .findIndex((conf: SearchFilterConfig) => conf.paramName === key) < 0) - .forEach((key) => { - params[key] = pmap.get(key); - }) - }); - return params; - } - getSearchLink() { return this.uiSearchRoute; } diff --git a/src/app/core/browse/browse.service.spec.ts b/src/app/core/browse/browse.service.spec.ts index 2385948b2f..2e9163fbac 100644 --- a/src/app/core/browse/browse.service.spec.ts +++ b/src/app/core/browse/browse.service.spec.ts @@ -3,11 +3,11 @@ import { getMockResponseCacheService } from '../../shared/mocks/mock-response-ca import { BrowseService } from './browse.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { RequestService } from '../data/request.service'; -import { GlobalConfig } from '../../../config'; import { hot, cold, getTestScheduler } from 'jasmine-marbles'; import { BrowseDefinition } from '../shared/browse-definition.model'; import { BrowseEndpointRequest } from '../data/request.models'; import { TestScheduler } from 'rxjs/Rx'; +import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub'; describe('BrowseService', () => { let scheduler: TestScheduler; @@ -15,8 +15,8 @@ describe('BrowseService', () => { let responseCache: ResponseCacheService; let requestService: RequestService; - const envConfig = {} as GlobalConfig; const browsesEndpointURL = 'https://rest.api/browses'; + const halService: any = new HALEndpointServiceStub(browsesEndpointURL); const browseDefinitions = [ Object.assign(new BrowseDefinition(), { metadataBrowse: false, @@ -91,7 +91,7 @@ describe('BrowseService', () => { return new BrowseService( responseCache, requestService, - envConfig + halService ); } @@ -106,7 +106,7 @@ describe('BrowseService', () => { responseCache = initMockResponseCacheService(true); requestService = getMockRequestService(); service = initTestService(); - spyOn(service, 'getEndpoint').and + spyOn(halService, 'getEndpoint').and .returnValue(hot('--a-', { a: browsesEndpointURL })); }); @@ -171,7 +171,7 @@ describe('BrowseService', () => { responseCache = initMockResponseCacheService(true); requestService = getMockRequestService(); service = initTestService(); - spyOn(service, 'getEndpoint').and + spyOn(halService, 'getEndpoint').and .returnValue(hot('----')); const metadatumKey = 'dc.date.issued'; @@ -188,7 +188,7 @@ describe('BrowseService', () => { responseCache = initMockResponseCacheService(false); requestService = getMockRequestService(); service = initTestService(); - spyOn(service, 'getEndpoint').and + spyOn(halService, 'getEndpoint').and .returnValue(hot('--a-', { a: browsesEndpointURL })); const metadatumKey = 'dc.date.issued'; diff --git a/src/app/core/config/config.service.spec.ts b/src/app/core/config/config.service.spec.ts index 3cdb22948f..4b05d5c929 100644 --- a/src/app/core/config/config.service.spec.ts +++ b/src/app/core/config/config.service.spec.ts @@ -1,11 +1,12 @@ import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/Rx'; -import { GlobalConfig } from '../../../config'; import { getMockRequestService } from '../../shared/mocks/mock-request.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { ConfigService } from './config.service'; import { RequestService } from '../data/request.service'; import { ConfigRequest, FindAllOptions } from '../data/request.models'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; +import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub'; const LINK_NAME = 'test'; const BROWSE = 'search/findByCollection'; @@ -17,8 +18,7 @@ class TestService extends ConfigService { constructor( protected responseCache: ResponseCacheService, protected requestService: RequestService, - protected EnvConfig: GlobalConfig - ) { + protected halService: HALEndpointService) { super(); } } @@ -28,8 +28,8 @@ describe('ConfigService', () => { let service: TestService; let responseCache: ResponseCacheService; let requestService: RequestService; + let halService: any; - const envConfig = {} as GlobalConfig; const findOptions: FindAllOptions = new FindAllOptions(); const scopeName = 'traditional'; @@ -51,7 +51,7 @@ describe('ConfigService', () => { return new TestService( responseCache, requestService, - envConfig + halService ); } @@ -60,8 +60,7 @@ describe('ConfigService', () => { requestService = getMockRequestService(); service = initTestService(); scheduler = getTestScheduler(); - spyOn(service, 'getEndpoint').and - .returnValue(hot('--a-', { a: serviceEndpoint })); + halService = new HALEndpointServiceStub(configEndpoint); }); describe('getConfigByHref', () => { diff --git a/src/app/core/data/comcol-data.service.spec.ts b/src/app/core/data/comcol-data.service.spec.ts index cf43482ba5..b5727fb22f 100644 --- a/src/app/core/data/comcol-data.service.spec.ts +++ b/src/app/core/data/comcol-data.service.spec.ts @@ -13,6 +13,7 @@ import { CommunityDataService } from './community-data.service'; import { FindByIDRequest } from './request.models'; import { RequestService } from './request.service'; import { NormalizedObject } from '../cache/models/normalized-object.model'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; const LINK_NAME = 'test'; @@ -21,7 +22,6 @@ class NormalizedTestObject extends NormalizedObject { } class TestService extends ComColDataService { - protected linkPath = LINK_NAME; constructor( protected responseCache: ResponseCacheService, @@ -30,7 +30,9 @@ class TestService extends ComColDataService { protected store: Store, protected EnvConfig: GlobalConfig, protected cds: CommunityDataService, - protected objectCache: ObjectCacheService + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected linkPath: string ) { super(); } @@ -44,6 +46,7 @@ describe('ComColDataService', () => { let requestService: RequestService; let cds: CommunityDataService; let objectCache: ObjectCacheService; + const halService: any = {}; const rdbService = {} as RemoteDataBuildService; const store = {} as Store; @@ -90,7 +93,9 @@ describe('ComColDataService', () => { store, EnvConfig, cds, - objectCache + objectCache, + halService, + LINK_NAME ); } @@ -154,24 +159,5 @@ describe('ComColDataService', () => { }); }); - describe('if the scope is not specified', () => { - beforeEach(() => { - cds = initMockCommunityDataService(); - requestService = getMockRequestService(); - objectCache = initMockObjectCacheService(); - responseCache = initMockResponseCacheService(true); - service = initTestService(); - }); - - it('should return this.getEndpoint()', () => { - spyOn(service, 'getEndpoint').and.returnValue(cold('--e-', { e: serviceEndpoint })); - - const result = service.getScopedEndpoint(undefined); - const expected = cold('--f-', { f: serviceEndpoint }); - - expect(result).toBeObservable(expected); - }); - }); - }); }); diff --git a/src/app/core/data/item-data.service.spec.ts b/src/app/core/data/item-data.service.spec.ts index 7d610bfaae..4d0dc8aec3 100644 --- a/src/app/core/data/item-data.service.spec.ts +++ b/src/app/core/data/item-data.service.spec.ts @@ -1,24 +1,23 @@ import { Store } from '@ngrx/store'; import { cold, getTestScheduler } from 'jasmine-marbles'; import { TestScheduler } from 'rxjs/Rx'; -import { GlobalConfig } from '../../../config/global-config.interface'; import { BrowseService } from '../browse/browse.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { ResponseCacheService } from '../cache/response-cache.service'; import { CoreState } from '../core.reducers'; import { ItemDataService } from './item-data.service'; import { RequestService } from './request.service'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; describe('ItemDataService', () => { let scheduler: TestScheduler; let service: ItemDataService; let bs: BrowseService; - const requestService = {} as RequestService; const responseCache = {} as ResponseCacheService; const rdbService = {} as RemoteDataBuildService; const store = {} as Store; - const EnvConfig = {} as GlobalConfig; + const halEndpointService = {} as HALEndpointService; const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39'; const browsesEndpoint = 'https://rest.api/discover/browses'; @@ -42,8 +41,8 @@ describe('ItemDataService', () => { requestService, rdbService, store, - EnvConfig, - bs + bs, + halEndpointService ); } @@ -74,21 +73,5 @@ describe('ItemDataService', () => { expect(result).toBeObservable(expected); }); }); - - describe('if the scope is not specified', () => { - beforeEach(() => { - bs = initMockBrowseService(true); - service = initTestService(); - spyOn(service, 'getEndpoint').and.returnValue(cold('--b-', { b: serviceEndpoint })) - }); - - it('should return this.getEndpoint()', () => { - const result = service.getScopedEndpoint(undefined); - const expected = cold('--c-', { c: serviceEndpoint }); - - expect(result).toBeObservable(expected); - }); - }); - }); }); diff --git a/src/app/core/metadata/metadata.service.spec.ts b/src/app/core/metadata/metadata.service.spec.ts index 4182587cc7..f8f36a358e 100644 --- a/src/app/core/metadata/metadata.service.spec.ts +++ b/src/app/core/metadata/metadata.service.spec.ts @@ -33,7 +33,7 @@ import { Item } from '../../core/shared/item.model'; import { MockItem } from '../../shared/mocks/mock-item'; import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader'; import { BrowseService } from '../browse/browse.service'; -import { PageInfo } from '../shared/page-info.model'; +import { HALEndpointService } from '../shared/hal-endpoint.service'; /* tslint:disable:max-classes-per-file */ @Component({ @@ -114,6 +114,7 @@ describe('MetadataService', () => { { provide: RequestService, useValue: requestService }, { provide: RemoteDataBuildService, useValue: remoteDataBuildService }, { provide: GLOBAL_CONFIG, useValue: ENV_CONFIG }, + { provide: HALEndpointService, useValue: {}}, Meta, Title, ItemDataService, diff --git a/src/app/core/shared/hal-endpoint.service.spec.ts b/src/app/core/shared/hal-endpoint.service.spec.ts index 7c73e15fab..479e15b52a 100644 --- a/src/app/core/shared/hal-endpoint.service.spec.ts +++ b/src/app/core/shared/hal-endpoint.service.spec.ts @@ -15,15 +15,15 @@ describe('HALEndpointService', () => { const endpointMap = { test: 'https://rest.api/test', }; + const linkPath = 'test'; /* tslint:disable:no-shadowed-variable */ class TestService extends HALEndpointService { - protected linkPath = 'test'; - constructor(protected responseCache: ResponseCacheService, - protected requestService: RequestService, - protected EnvConfig: GlobalConfig) { - super(); + constructor(private responseCache: ResponseCacheService, + private requestService: RequestService, + private EnvConfig: GlobalConfig) { + super(responseCache, requestService, EnvConfig); } } @@ -83,17 +83,16 @@ describe('HALEndpointService', () => { it('should return the endpoint URL for the service\'s linkPath', () => { spyOn(service as any, 'getEndpointAt').and .returnValue(hot('a-', { a: 'https://rest.api/test' })); - const result = service.getEndpoint(); + const result = service.getEndpoint(linkPath); const expected = cold('b-', { b: endpointMap.test }); expect(result).toBeObservable(expected); }); it('should return undefined for a linkPath that isn\'t in the endpoint map', () => { - (service as any).linkPath = 'unknown'; spyOn(service as any, 'getEndpointAt').and .returnValue(hot('a-', { a: undefined })); - const result = service.getEndpoint(); + const result = service.getEndpoint('unknown'); const expected = cold('b-', { b: undefined }); expect(result).toBeObservable(expected); }); @@ -113,7 +112,7 @@ describe('HALEndpointService', () => { spyOn(service as any, 'getRootEndpointMap').and .returnValue(hot('----')); - const result = service.isEnabledOnRestApi(); + const result = service.isEnabledOnRestApi(linkPath); const expected = cold('b---', { b: undefined }); expect(result).toBeObservable(expected); }); @@ -121,8 +120,7 @@ describe('HALEndpointService', () => { it('should return true if the service\'s linkPath is in the endpoint map', () => { spyOn(service as any, 'getRootEndpointMap').and .returnValue(hot('--a-', { a: endpointMap })); - - const result = service.isEnabledOnRestApi(); + const result = service.isEnabledOnRestApi(linkPath); const expected = cold('b-c-', { b: undefined, c: true }); expect(result).toBeObservable(expected); }); @@ -131,8 +129,7 @@ describe('HALEndpointService', () => { spyOn(service as any, 'getRootEndpointMap').and .returnValue(hot('--a-', { a: endpointMap })); - (service as any).linkPath = 'unknown'; - const result = service.isEnabledOnRestApi(); + const result = service.isEnabledOnRestApi('unknown'); const expected = cold('b-c-', { b: undefined, c: false }); expect(result).toBeObservable(expected); }); diff --git a/src/app/core/shared/hal-endpoint.service.ts b/src/app/core/shared/hal-endpoint.service.ts index c81c3c792d..3bedeb9915 100644 --- a/src/app/core/shared/hal-endpoint.service.ts +++ b/src/app/core/shared/hal-endpoint.service.ts @@ -14,12 +14,9 @@ import { GLOBAL_CONFIG } from '../../../config'; @Injectable() export class HALEndpointService { - protected linkPath: string; - constructor(private responseCache: ResponseCacheService, private requestService: RequestService, @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig) { - } protected getRootHref(): string { @@ -41,9 +38,7 @@ export class HALEndpointService { } public getEndpoint(linkPath: string): Observable { - const test = this.getEndpointAt(...linkPath.split('/')); - // test.subscribe((test) => console.log(linkPath, test)); - return test; + return this.getEndpointAt(...linkPath.split('/')); } private getEndpointAt(...path: string[]): Observable { diff --git a/src/app/shared/route.service.spec.ts b/src/app/shared/route.service.spec.ts index 00b7d78be6..b134771b3e 100644 --- a/src/app/shared/route.service.spec.ts +++ b/src/app/shared/route.service.spec.ts @@ -67,50 +67,36 @@ describe('RouteService', () => { }); }); - describe('addQueryParameterValue', () => { - it('should return a list of values that contains the added value when a new value is added and the parameter did not exist yet', () => { - service.resolveRouteWithParameterValue(nonExistingParamName, nonExistingParamValue).subscribe((params) => { - expect(params[nonExistingParamName]).toContain(nonExistingParamValue); + describe('getQueryParameterValues', () => { + it('should return a list of values when the parameter exists', () => { + service.getQueryParameterValues(paramName2).subscribe((params) => { + expect(params).toEqual([paramValue2a, paramValue2b]); }); }); - it('should return a list of values that contains the existing values and the added value when a new value is added and the parameter already has values', () => { - service.resolveRouteWithParameterValue(paramName1, nonExistingParamValue).subscribe((params) => { - const values = params[paramName1]; - expect(values).toContain(paramValue1); - expect(values).toContain(nonExistingParamValue); + + it('should return an empty array when the parameter does not exists', () => { + service.getQueryParameterValues(nonExistingParamName).subscribe((params) => { + expect(params).toEqual([]); }); }); }); - describe('removeQueryParameterValue', () => { - it('should return a list of values that does not contain the removed value when the parameter value exists', () => { - service.resolveRouteWithoutParameterValue(paramName2, paramValue2a).subscribe((params) => { - const values = params[paramName2]; - expect(values).toContain(paramValue2b); - expect(values).not.toContain(paramValue2a); + describe('getQueryParameterValue', () => { + it('should return a single value when the parameter exists', () => { + service.getQueryParameterValue(paramName1).subscribe((params) => { + expect(params).toEqual(paramValue1); }); }); - it('should return a list of values that does contain all existing values when the removed parameter does not exist', () => { - service.resolveRouteWithoutParameterValue(paramName2, nonExistingParamValue).subscribe((params) => { - const values = params[paramName2]; - expect(values).toContain(paramValue2a); - expect(values).toContain(paramValue2b); + it('should return only the first value when the parameter exists', () => { + service.getQueryParameterValue(paramName2).subscribe((params) => { + expect(params).toEqual(paramValue2a); }); }); - }); - describe('getWithoutParameter', () => { - it('should return a list of values that does not contain any values for the parameter anymore when the parameter exists', () => { - service.resolveRouteWithoutParameter(paramName2).subscribe((params) => { - const values = params[paramName2]; - expect(values).toEqual({}); - }); - }); - it('should return a list of values that does not contain any values for the parameter when the parameter does not exist', () => { - service.resolveRouteWithoutParameter(nonExistingParamName).subscribe((params) => { - const values = params[nonExistingParamName]; - expect(values).toEqual({}); + it('should return undefined when the parameter exists', () => { + service.getQueryParameterValue(nonExistingParamName).subscribe((params) => { + expect(params).toBeNull(); }); }); }); diff --git a/src/app/shared/testing/hal-endpoint-service-stub.ts b/src/app/shared/testing/hal-endpoint-service-stub.ts new file mode 100644 index 0000000000..e7dbe8bea1 --- /dev/null +++ b/src/app/shared/testing/hal-endpoint-service-stub.ts @@ -0,0 +1,11 @@ +import { Observable } from 'rxjs/Observable'; +import { ViewMode } from '../../+search-page/search-options.model'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; + +export class HALEndpointServiceStub { + + constructor(private url: string) {}; + getEndpoint(path: string) { + return Observable.of(this.url + '/' + path); + } +} diff --git a/src/app/shared/testing/search-service-stub.ts b/src/app/shared/testing/search-service-stub.ts index 23b2004827..7ad0d871ce 100644 --- a/src/app/shared/testing/search-service-stub.ts +++ b/src/app/shared/testing/search-service-stub.ts @@ -9,7 +9,7 @@ export class SearchServiceStub { viewMode = this.subject.asObservable(); - constructor() { + constructor(private searchLink: string = '/search') { this.setViewMode(ViewMode.List); } @@ -21,6 +21,10 @@ export class SearchServiceStub { this.testViewMode = viewMode; } + getFacetValuesFor() { + return null; + } + get testViewMode(): ViewMode { return this._viewMode; } @@ -29,4 +33,8 @@ export class SearchServiceStub { this._viewMode = viewMode; this.subject.next(viewMode); } + + getSearchLink() { + return this.searchLink; + } } diff --git a/src/tsconfig.test.json b/src/tsconfig.test.json index 079eabc561..712ad1ab1c 100644 --- a/src/tsconfig.test.json +++ b/src/tsconfig.test.json @@ -1,4 +1,4 @@ -yarn add{ +{ "extends": "../tsconfig.json", "compilerOptions": { "sourceMap": true