fixed some tests

This commit is contained in:
Lotte Hofstede
2018-04-04 14:25:57 +02:00
parent 86fcf44977
commit a232127422
19 changed files with 128 additions and 211 deletions

View File

@@ -10,6 +10,10 @@ import { FilterType } from '../../../search-service/filter-type.model';
import { FacetValue } from '../../../search-service/facet-value.model'; import { FacetValue } from '../../../search-service/facet-value.model';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { Observable } from 'rxjs/Observable'; 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', () => { describe('SearchFacetFilterComponent', () => {
let comp: SearchFacetFilterComponent; let comp: SearchFacetFilterComponent;
@@ -40,29 +44,31 @@ describe('SearchFacetFilterComponent', () => {
search: '' search: ''
} }
]; ];
const searchLink = '/search';
const selectedValues = [value1, value2];
let filterService; let filterService;
const page = Observable.of(0) const page = Observable.of(0);
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, FormsModule], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, FormsModule],
declarations: [SearchFacetFilterComponent], declarations: [SearchFacetFilterComponent],
providers: [ providers: [
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) },
{ {
provide: SearchFilterService, provide: SearchFilterService, useValue: {
useValue: {
isFilterActiveWithValue: (paramName: string, filterValue: string) => true, isFilterActiveWithValue: (paramName: string, filterValue: string) => true,
getQueryParamsWith: (paramName: string, filterValue: string) => '',
getQueryParamsWithout: (paramName: string, filterValue: string) => '',
getPage: (paramName: string) => page, getPage: (paramName: string) => page,
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
incrementPage: (filterName: string) => { incrementPage: (filterName: string) => {
}, },
resetPage: (filterName: string) => { resetPage: (filterName: string) => {
}, },
getSearchOptions: () => Observable.of({}),
/* tslint:enable:no-empty */ /* tslint:enable:no-empty */
searchLink: '/search',
} }
}, }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(SearchFacetFilterComponent, { }).overrideComponent(SearchFacetFilterComponent, {
@@ -74,7 +80,8 @@ describe('SearchFacetFilterComponent', () => {
fixture = TestBed.createComponent(SearchFacetFilterComponent); fixture = TestBed.createComponent(SearchFacetFilterComponent);
comp = fixture.componentInstance; // SearchPageComponent test instance comp = fixture.componentInstance; // SearchPageComponent test instance
comp.filterConfig = mockFilterConfig; 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; filterService = (comp as any).filterService;
fixture.detectChanges(); fixture.detectChanges();
}); });
@@ -97,64 +104,24 @@ describe('SearchFacetFilterComponent', () => {
}); });
it('should return the value of the searchLink variable in the filter service', () => { 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', () => { describe('when the getAddParams method is called wih a value', () => {
beforeEach(() => { it('should return the selectedValueq list with the new parameter value', () => {
spyOn(filterService, 'getQueryParamsWith'); const result = comp.getAddParams(value3);
comp.getQueryParamsWith(values[1].value); expect(result).toEqual({[mockFilterConfig.paramName]: [value1, value2, value3]});
});
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 getQueryParamsWithout method is called wih a value', () => { describe('when the getRemoveParams method is called wih a value', () => {
beforeEach(() => { it('should return the selectedValueq list with the parameter value left out', () => {
spyOn(filterService, 'getQueryParamsWithout'); const result = comp.getRemoveParams(value1);
comp.getQueryParamsWithout(values[1].value); expect(result).toEqual({[mockFilterConfig.paramName]: [value2]});
});
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 facetCount method is triggered when there are less items than the amount of pages should display', () => {
let count: Observable<number>;
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<number>;
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', () => { describe('when the showMore method is called', () => {
beforeEach(() => { beforeEach(() => {

View File

@@ -102,7 +102,7 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
isLastPage(): Observable<boolean> { isLastPage(): Observable<boolean> {
return Observable.of(false); return Observable.of(false);
// return this.filterValues.flatMap((map) => map.pop().map((rd: RemoteData<PaginatedList<FacetValue>>) => rd.payload.currentPage >= rd.payload.totalPages)); // return this.filterValues$.flatMap((map) => map.pop().map((rd: RemoteData<PaginatedList<FacetValue>>) => rd.payload.currentPage >= rd.payload.totalPages));
} }
getRemoveParams(value: string) { getRemoveParams(value: string) {

View File

@@ -50,7 +50,7 @@ describe('SearchFilterService', () => {
}; };
beforeEach(() => { beforeEach(() => {
service = new SearchFilterService(store, routeServiceStub, searchServiceStub); service = new SearchFilterService(store, routeServiceStub);
}); });
describe('when the initialCollapse method is triggered', () => { describe('when the initialCollapse method is triggered', () => {

View File

@@ -4,4 +4,4 @@
<ds-search-filter class="d-block mb-3 p-3" [filter]="filter"></ds-search-filter> <ds-search-filter class="d-block mb-3 p-3" [filter]="filter"></ds-search-filter>
</div> </div>
</div> </div>
<a class="btn btn-primary" [routerLink]="[getSearchLink()]" [queryParams]="getClearFiltersQueryParams()" role="button">{{"search.filters.reset" | translate}}</a> <a class="btn btn-primary" [routerLink]="[getSearchLink()]" [queryParams]="clearParams | async" queryParamsHandling="merge" role="button">{{"search.filters.reset" | translate}}</a>

View File

@@ -3,6 +3,7 @@ import { SearchService } from '../search-service/search.service';
import { RemoteData } from '../../core/data/remote-data'; import { RemoteData } from '../../core/data/remote-data';
import { SearchFilterConfig } from '../search-service/search-filter-config.model'; import { SearchFilterConfig } from '../search-service/search-filter-config.model';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { SearchFilterService } from './search-filter/search-filter.service';
/** /**
* This component renders a simple item page. * This component renders a simple item page.
@@ -18,12 +19,10 @@ import { Observable } from 'rxjs/Observable';
export class SearchFiltersComponent { export class SearchFiltersComponent {
filters: Observable<RemoteData<SearchFilterConfig[]>>; filters: Observable<RemoteData<SearchFilterConfig[]>>;
constructor(private searchService: SearchService) { clearParams;
constructor(private searchService: SearchService, private filterService: SearchFilterService) {
this.filters = searchService.getConfig(); this.filters = searchService.getConfig();
} this.clearParams = filterService.getCurrentFilters().map((filters) => {Object.keys(filters).forEach((f) => filters[f] = null); return filters;});
getClearFiltersQueryParams(): any {
return this.searchService.getClearFiltersQueryParams();
} }
getSearchLink() { getSearchLink() {

View File

@@ -17,6 +17,7 @@ import { ActivatedRoute } from '@angular/router';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
import { SearchSidebarService } from './search-sidebar/search-sidebar.service'; import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
describe('SearchPageComponent', () => { describe('SearchPageComponent', () => {
let comp: SearchPageComponent; let comp: SearchPageComponent;
@@ -89,6 +90,10 @@ describe('SearchPageComponent', () => {
provide: SearchSidebarService, provide: SearchSidebarService,
useValue: sidebarService useValue: sidebarService
}, },
{
provide: SearchFilterService,
useValue: {}
},
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(SearchPageComponent, { }).overrideComponent(SearchPageComponent, {

View File

@@ -15,6 +15,7 @@ import { RequestService } from '../../core/data/request.service';
import { ResponseCacheService } from '../../core/cache/response-cache.service'; import { ResponseCacheService } from '../../core/cache/response-cache.service';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub'; import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
import { RouterStub } from '../../shared/testing/router-stub'; import { RouterStub } from '../../shared/testing/router-stub';
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
@Component({ template: '' }) @Component({ template: '' })
class DummyComponent { class DummyComponent {
@@ -37,14 +38,12 @@ describe('SearchService', () => {
DummyComponent DummyComponent
], ],
providers: [ providers: [
{ provide: ItemDataService, useValue: {} }, { provide: Router, useValue: router },
{ provide: RouteService, useValue: {} }, { provide: ActivatedRoute, useValue: route },
{ provide: ResponseCacheService, useValue: {} }, { provide: ResponseCacheService, useValue: {} },
{ provide: RequestService, useValue: {} }, { provide: RequestService, useValue: {} },
{ provide: ActivatedRoute, useValue: route },
{ provide: RemoteDataBuildService, useValue: {} }, { provide: RemoteDataBuildService, useValue: {} },
{ provide: GLOBAL_CONFIG, useValue: {} }, { provide: HALEndpointService, useValue: {} },
{ provide: Router, useValue: router },
SearchService SearchService
], ],
}); });
@@ -73,14 +72,12 @@ describe('SearchService', () => {
DummyComponent DummyComponent
], ],
providers: [ providers: [
{ provide: ItemDataService, useValue: {} }, { provide: Router, useValue: router },
{ provide: RouteService, useValue: {} }, { provide: ActivatedRoute, useValue: route },
{ provide: ResponseCacheService, useValue: {} }, { provide: ResponseCacheService, useValue: {} },
{ provide: RequestService, useValue: {} }, { provide: RequestService, useValue: {} },
{ provide: ActivatedRoute, useValue: route },
{ provide: RemoteDataBuildService, useValue: {} }, { provide: RemoteDataBuildService, useValue: {} },
{ provide: GLOBAL_CONFIG, useValue: {} }, { provide: HALEndpointService, useValue: {} },
{ provide: Router, useValue: router },
SearchService SearchService
], ],
}); });

View File

@@ -23,7 +23,6 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
import { URLCombiner } from '../../core/url-combiner/url-combiner'; import { URLCombiner } from '../../core/url-combiner/url-combiner';
import { hasValue, isNotEmpty } from '../../shared/empty.util'; import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
import { RouteService } from '../../shared/route.service';
import { NormalizedSearchResult } from '../normalized-search-result.model'; import { NormalizedSearchResult } from '../normalized-search-result.model';
import { SearchOptions } from '../search-options.model'; import { SearchOptions } from '../search-options.model';
import { SearchResult } from '../search-result.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 { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { FacetValueResponseParsingService } from '../../core/data/facet-value-response-parsing.service'; import { FacetValueResponseParsingService } from '../../core/data/facet-value-response-parsing.service';
import { FacetConfigResponseParsingService } from '../../core/data/facet-config-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'; import { PaginatedSearchOptions } from '../paginated-search-options.model';
@Injectable() @Injectable()
@@ -206,7 +204,6 @@ export class SearchService implements OnDestroy {
} }
getFacetValuesFor(filterConfig: SearchFilterConfig, valuePage: number, searchOptions?: SearchOptions): Observable<RemoteData<PaginatedList<FacetValue>>> { getFacetValuesFor(filterConfig: SearchFilterConfig, valuePage: number, searchOptions?: SearchOptions): Observable<RemoteData<PaginatedList<FacetValue>>> {
console.log('facetvalues');
const requestObs = this.halService.getEndpoint(this.facetValueLinkPathPrefix + filterConfig.name).pipe( const requestObs = this.halService.getEndpoint(this.facetValueLinkPathPrefix + filterConfig.name).pipe(
map((url: string) => { map((url: string) => {
const args: string[] = [`page=${valuePage - 1}`, `size=${filterConfig.pageSize}`]; const args: string[] = [`page=${valuePage - 1}`, `size=${filterConfig.pageSize}`];
@@ -268,20 +265,6 @@ export class SearchService implements OnDestroy {
this.router.navigate([this.uiSearchRoute], navigationExtras); 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() { getSearchLink() {
return this.uiSearchRoute; return this.uiSearchRoute;
} }

View File

@@ -3,11 +3,11 @@ import { getMockResponseCacheService } from '../../shared/mocks/mock-response-ca
import { BrowseService } from './browse.service'; import { BrowseService } from './browse.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
import { GlobalConfig } from '../../../config';
import { hot, cold, getTestScheduler } from 'jasmine-marbles'; import { hot, cold, getTestScheduler } from 'jasmine-marbles';
import { BrowseDefinition } from '../shared/browse-definition.model'; import { BrowseDefinition } from '../shared/browse-definition.model';
import { BrowseEndpointRequest } from '../data/request.models'; import { BrowseEndpointRequest } from '../data/request.models';
import { TestScheduler } from 'rxjs/Rx'; import { TestScheduler } from 'rxjs/Rx';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
describe('BrowseService', () => { describe('BrowseService', () => {
let scheduler: TestScheduler; let scheduler: TestScheduler;
@@ -15,8 +15,8 @@ describe('BrowseService', () => {
let responseCache: ResponseCacheService; let responseCache: ResponseCacheService;
let requestService: RequestService; let requestService: RequestService;
const envConfig = {} as GlobalConfig;
const browsesEndpointURL = 'https://rest.api/browses'; const browsesEndpointURL = 'https://rest.api/browses';
const halService: any = new HALEndpointServiceStub(browsesEndpointURL);
const browseDefinitions = [ const browseDefinitions = [
Object.assign(new BrowseDefinition(), { Object.assign(new BrowseDefinition(), {
metadataBrowse: false, metadataBrowse: false,
@@ -91,7 +91,7 @@ describe('BrowseService', () => {
return new BrowseService( return new BrowseService(
responseCache, responseCache,
requestService, requestService,
envConfig halService
); );
} }
@@ -106,7 +106,7 @@ describe('BrowseService', () => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = getMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(halService, 'getEndpoint').and
.returnValue(hot('--a-', { a: browsesEndpointURL })); .returnValue(hot('--a-', { a: browsesEndpointURL }));
}); });
@@ -171,7 +171,7 @@ describe('BrowseService', () => {
responseCache = initMockResponseCacheService(true); responseCache = initMockResponseCacheService(true);
requestService = getMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(halService, 'getEndpoint').and
.returnValue(hot('----')); .returnValue(hot('----'));
const metadatumKey = 'dc.date.issued'; const metadatumKey = 'dc.date.issued';
@@ -188,7 +188,7 @@ describe('BrowseService', () => {
responseCache = initMockResponseCacheService(false); responseCache = initMockResponseCacheService(false);
requestService = getMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
spyOn(service, 'getEndpoint').and spyOn(halService, 'getEndpoint').and
.returnValue(hot('--a-', { a: browsesEndpointURL })); .returnValue(hot('--a-', { a: browsesEndpointURL }));
const metadatumKey = 'dc.date.issued'; const metadatumKey = 'dc.date.issued';

View File

@@ -1,11 +1,12 @@
import { cold, getTestScheduler, hot } from 'jasmine-marbles'; import { cold, getTestScheduler, hot } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/Rx'; import { TestScheduler } from 'rxjs/Rx';
import { GlobalConfig } from '../../../config';
import { getMockRequestService } from '../../shared/mocks/mock-request.service'; import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { ConfigService } from './config.service'; import { ConfigService } from './config.service';
import { RequestService } from '../data/request.service'; import { RequestService } from '../data/request.service';
import { ConfigRequest, FindAllOptions } from '../data/request.models'; 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 LINK_NAME = 'test';
const BROWSE = 'search/findByCollection'; const BROWSE = 'search/findByCollection';
@@ -17,8 +18,7 @@ class TestService extends ConfigService {
constructor( constructor(
protected responseCache: ResponseCacheService, protected responseCache: ResponseCacheService,
protected requestService: RequestService, protected requestService: RequestService,
protected EnvConfig: GlobalConfig protected halService: HALEndpointService) {
) {
super(); super();
} }
} }
@@ -28,8 +28,8 @@ describe('ConfigService', () => {
let service: TestService; let service: TestService;
let responseCache: ResponseCacheService; let responseCache: ResponseCacheService;
let requestService: RequestService; let requestService: RequestService;
let halService: any;
const envConfig = {} as GlobalConfig;
const findOptions: FindAllOptions = new FindAllOptions(); const findOptions: FindAllOptions = new FindAllOptions();
const scopeName = 'traditional'; const scopeName = 'traditional';
@@ -51,7 +51,7 @@ describe('ConfigService', () => {
return new TestService( return new TestService(
responseCache, responseCache,
requestService, requestService,
envConfig halService
); );
} }
@@ -60,8 +60,7 @@ describe('ConfigService', () => {
requestService = getMockRequestService(); requestService = getMockRequestService();
service = initTestService(); service = initTestService();
scheduler = getTestScheduler(); scheduler = getTestScheduler();
spyOn(service, 'getEndpoint').and halService = new HALEndpointServiceStub(configEndpoint);
.returnValue(hot('--a-', { a: serviceEndpoint }));
}); });
describe('getConfigByHref', () => { describe('getConfigByHref', () => {

View File

@@ -13,6 +13,7 @@ import { CommunityDataService } from './community-data.service';
import { FindByIDRequest } from './request.models'; import { FindByIDRequest } from './request.models';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import { NormalizedObject } from '../cache/models/normalized-object.model'; import { NormalizedObject } from '../cache/models/normalized-object.model';
import { HALEndpointService } from '../shared/hal-endpoint.service';
const LINK_NAME = 'test'; const LINK_NAME = 'test';
@@ -21,7 +22,6 @@ class NormalizedTestObject extends NormalizedObject {
} }
class TestService extends ComColDataService<NormalizedTestObject, any> { class TestService extends ComColDataService<NormalizedTestObject, any> {
protected linkPath = LINK_NAME;
constructor( constructor(
protected responseCache: ResponseCacheService, protected responseCache: ResponseCacheService,
@@ -30,7 +30,9 @@ class TestService extends ComColDataService<NormalizedTestObject, any> {
protected store: Store<CoreState>, protected store: Store<CoreState>,
protected EnvConfig: GlobalConfig, protected EnvConfig: GlobalConfig,
protected cds: CommunityDataService, protected cds: CommunityDataService,
protected objectCache: ObjectCacheService protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected linkPath: string
) { ) {
super(); super();
} }
@@ -44,6 +46,7 @@ describe('ComColDataService', () => {
let requestService: RequestService; let requestService: RequestService;
let cds: CommunityDataService; let cds: CommunityDataService;
let objectCache: ObjectCacheService; let objectCache: ObjectCacheService;
const halService: any = {};
const rdbService = {} as RemoteDataBuildService; const rdbService = {} as RemoteDataBuildService;
const store = {} as Store<CoreState>; const store = {} as Store<CoreState>;
@@ -90,7 +93,9 @@ describe('ComColDataService', () => {
store, store,
EnvConfig, EnvConfig,
cds, 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);
});
});
}); });
}); });

View File

@@ -1,24 +1,23 @@
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { cold, getTestScheduler } from 'jasmine-marbles'; import { cold, getTestScheduler } from 'jasmine-marbles';
import { TestScheduler } from 'rxjs/Rx'; import { TestScheduler } from 'rxjs/Rx';
import { GlobalConfig } from '../../../config/global-config.interface';
import { BrowseService } from '../browse/browse.service'; import { BrowseService } from '../browse/browse.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ResponseCacheService } from '../cache/response-cache.service'; import { ResponseCacheService } from '../cache/response-cache.service';
import { CoreState } from '../core.reducers'; import { CoreState } from '../core.reducers';
import { ItemDataService } from './item-data.service'; import { ItemDataService } from './item-data.service';
import { RequestService } from './request.service'; import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
describe('ItemDataService', () => { describe('ItemDataService', () => {
let scheduler: TestScheduler; let scheduler: TestScheduler;
let service: ItemDataService; let service: ItemDataService;
let bs: BrowseService; let bs: BrowseService;
const requestService = {} as RequestService; const requestService = {} as RequestService;
const responseCache = {} as ResponseCacheService; const responseCache = {} as ResponseCacheService;
const rdbService = {} as RemoteDataBuildService; const rdbService = {} as RemoteDataBuildService;
const store = {} as Store<CoreState>; const store = {} as Store<CoreState>;
const EnvConfig = {} as GlobalConfig; const halEndpointService = {} as HALEndpointService;
const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39'; const scopeID = '4af28e99-6a9c-4036-a199-e1b587046d39';
const browsesEndpoint = 'https://rest.api/discover/browses'; const browsesEndpoint = 'https://rest.api/discover/browses';
@@ -42,8 +41,8 @@ describe('ItemDataService', () => {
requestService, requestService,
rdbService, rdbService,
store, store,
EnvConfig, bs,
bs halEndpointService
); );
} }
@@ -74,21 +73,5 @@ describe('ItemDataService', () => {
expect(result).toBeObservable(expected); 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);
});
});
}); });
}); });

View File

@@ -33,7 +33,7 @@ import { Item } from '../../core/shared/item.model';
import { MockItem } from '../../shared/mocks/mock-item'; import { MockItem } from '../../shared/mocks/mock-item';
import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader'; import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader';
import { BrowseService } from '../browse/browse.service'; 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 */ /* tslint:disable:max-classes-per-file */
@Component({ @Component({
@@ -114,6 +114,7 @@ describe('MetadataService', () => {
{ provide: RequestService, useValue: requestService }, { provide: RequestService, useValue: requestService },
{ provide: RemoteDataBuildService, useValue: remoteDataBuildService }, { provide: RemoteDataBuildService, useValue: remoteDataBuildService },
{ provide: GLOBAL_CONFIG, useValue: ENV_CONFIG }, { provide: GLOBAL_CONFIG, useValue: ENV_CONFIG },
{ provide: HALEndpointService, useValue: {}},
Meta, Meta,
Title, Title,
ItemDataService, ItemDataService,

View File

@@ -15,15 +15,15 @@ describe('HALEndpointService', () => {
const endpointMap = { const endpointMap = {
test: 'https://rest.api/test', test: 'https://rest.api/test',
}; };
const linkPath = 'test';
/* tslint:disable:no-shadowed-variable */ /* tslint:disable:no-shadowed-variable */
class TestService extends HALEndpointService { class TestService extends HALEndpointService {
protected linkPath = 'test';
constructor(protected responseCache: ResponseCacheService, constructor(private responseCache: ResponseCacheService,
protected requestService: RequestService, private requestService: RequestService,
protected EnvConfig: GlobalConfig) { private EnvConfig: GlobalConfig) {
super(); super(responseCache, requestService, EnvConfig);
} }
} }
@@ -83,17 +83,16 @@ describe('HALEndpointService', () => {
it('should return the endpoint URL for the service\'s linkPath', () => { it('should return the endpoint URL for the service\'s linkPath', () => {
spyOn(service as any, 'getEndpointAt').and spyOn(service as any, 'getEndpointAt').and
.returnValue(hot('a-', { a: 'https://rest.api/test' })); .returnValue(hot('a-', { a: 'https://rest.api/test' }));
const result = service.getEndpoint(); const result = service.getEndpoint(linkPath);
const expected = cold('b-', { b: endpointMap.test }); const expected = cold('b-', { b: endpointMap.test });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
it('should return undefined for a linkPath that isn\'t in the endpoint map', () => { 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 spyOn(service as any, 'getEndpointAt').and
.returnValue(hot('a-', { a: undefined })); .returnValue(hot('a-', { a: undefined }));
const result = service.getEndpoint(); const result = service.getEndpoint('unknown');
const expected = cold('b-', { b: undefined }); const expected = cold('b-', { b: undefined });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
@@ -113,7 +112,7 @@ describe('HALEndpointService', () => {
spyOn(service as any, 'getRootEndpointMap').and spyOn(service as any, 'getRootEndpointMap').and
.returnValue(hot('----')); .returnValue(hot('----'));
const result = service.isEnabledOnRestApi(); const result = service.isEnabledOnRestApi(linkPath);
const expected = cold('b---', { b: undefined }); const expected = cold('b---', { b: undefined });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
@@ -121,8 +120,7 @@ describe('HALEndpointService', () => {
it('should return true if the service\'s linkPath is in the endpoint map', () => { it('should return true if the service\'s linkPath is in the endpoint map', () => {
spyOn(service as any, 'getRootEndpointMap').and spyOn(service as any, 'getRootEndpointMap').and
.returnValue(hot('--a-', { a: endpointMap })); .returnValue(hot('--a-', { a: endpointMap }));
const result = service.isEnabledOnRestApi(linkPath);
const result = service.isEnabledOnRestApi();
const expected = cold('b-c-', { b: undefined, c: true }); const expected = cold('b-c-', { b: undefined, c: true });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });
@@ -131,8 +129,7 @@ describe('HALEndpointService', () => {
spyOn(service as any, 'getRootEndpointMap').and spyOn(service as any, 'getRootEndpointMap').and
.returnValue(hot('--a-', { a: endpointMap })); .returnValue(hot('--a-', { a: endpointMap }));
(service as any).linkPath = 'unknown'; const result = service.isEnabledOnRestApi('unknown');
const result = service.isEnabledOnRestApi();
const expected = cold('b-c-', { b: undefined, c: false }); const expected = cold('b-c-', { b: undefined, c: false });
expect(result).toBeObservable(expected); expect(result).toBeObservable(expected);
}); });

View File

@@ -14,12 +14,9 @@ import { GLOBAL_CONFIG } from '../../../config';
@Injectable() @Injectable()
export class HALEndpointService { export class HALEndpointService {
protected linkPath: string;
constructor(private responseCache: ResponseCacheService, constructor(private responseCache: ResponseCacheService,
private requestService: RequestService, private requestService: RequestService,
@Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig) { @Inject(GLOBAL_CONFIG) private EnvConfig: GlobalConfig) {
} }
protected getRootHref(): string { protected getRootHref(): string {
@@ -41,9 +38,7 @@ export class HALEndpointService {
} }
public getEndpoint(linkPath: string): Observable<string> { public getEndpoint(linkPath: string): Observable<string> {
const test = this.getEndpointAt(...linkPath.split('/')); return this.getEndpointAt(...linkPath.split('/'));
// test.subscribe((test) => console.log(linkPath, test));
return test;
} }
private getEndpointAt(...path: string[]): Observable<string> { private getEndpointAt(...path: string[]): Observable<string> {

View File

@@ -67,50 +67,36 @@ describe('RouteService', () => {
}); });
}); });
describe('addQueryParameterValue', () => { describe('getQueryParameterValues', () => {
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', () => { it('should return a list of values when the parameter exists', () => {
service.resolveRouteWithParameterValue(nonExistingParamName, nonExistingParamValue).subscribe((params) => { service.getQueryParameterValues(paramName2).subscribe((params) => {
expect(params[nonExistingParamName]).toContain(nonExistingParamValue); 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) => { it('should return an empty array when the parameter does not exists', () => {
const values = params[paramName1]; service.getQueryParameterValues(nonExistingParamName).subscribe((params) => {
expect(values).toContain(paramValue1); expect(params).toEqual([]);
expect(values).toContain(nonExistingParamValue);
}); });
}); });
}); });
describe('removeQueryParameterValue', () => { describe('getQueryParameterValue', () => {
it('should return a list of values that does not contain the removed value when the parameter value exists', () => { it('should return a single value when the parameter exists', () => {
service.resolveRouteWithoutParameterValue(paramName2, paramValue2a).subscribe((params) => { service.getQueryParameterValue(paramName1).subscribe((params) => {
const values = params[paramName2]; expect(params).toEqual(paramValue1);
expect(values).toContain(paramValue2b);
expect(values).not.toContain(paramValue2a);
}); });
}); });
it('should return a list of values that does contain all existing values when the removed parameter does not exist', () => { it('should return only the first value when the parameter exists', () => {
service.resolveRouteWithoutParameterValue(paramName2, nonExistingParamValue).subscribe((params) => { service.getQueryParameterValue(paramName2).subscribe((params) => {
const values = params[paramName2]; expect(params).toEqual(paramValue2a);
expect(values).toContain(paramValue2a);
expect(values).toContain(paramValue2b);
});
}); });
}); });
describe('getWithoutParameter', () => { it('should return undefined when the parameter exists', () => {
it('should return a list of values that does not contain any values for the parameter anymore when the parameter exists', () => { service.getQueryParameterValue(nonExistingParamName).subscribe((params) => {
service.resolveRouteWithoutParameter(paramName2).subscribe((params) => { expect(params).toBeNull();
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({});
}); });
}); });
}); });

View File

@@ -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);
}
}

View File

@@ -9,7 +9,7 @@ export class SearchServiceStub {
viewMode = this.subject.asObservable(); viewMode = this.subject.asObservable();
constructor() { constructor(private searchLink: string = '/search') {
this.setViewMode(ViewMode.List); this.setViewMode(ViewMode.List);
} }
@@ -21,6 +21,10 @@ export class SearchServiceStub {
this.testViewMode = viewMode; this.testViewMode = viewMode;
} }
getFacetValuesFor() {
return null;
}
get testViewMode(): ViewMode { get testViewMode(): ViewMode {
return this._viewMode; return this._viewMode;
} }
@@ -29,4 +33,8 @@ export class SearchServiceStub {
this._viewMode = viewMode; this._viewMode = viewMode;
this.subject.next(viewMode); this.subject.next(viewMode);
} }
getSearchLink() {
return this.searchLink;
}
} }

View File

@@ -1,4 +1,4 @@
yarn add{ {
"extends": "../tsconfig.json", "extends": "../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"sourceMap": true "sourceMap": true