test fixes

This commit is contained in:
lotte
2018-07-25 14:16:27 +02:00
parent 1906f07be3
commit df37e339ee
14 changed files with 155 additions and 131 deletions

View File

@@ -22,5 +22,4 @@ import {
@renderFacetFor(FilterType.boolean) @renderFacetFor(FilterType.boolean)
export class SearchBooleanFilterComponent extends SearchFacetFilterComponent implements OnInit { export class SearchBooleanFilterComponent extends SearchFacetFilterComponent implements OnInit {
currentPage: Observable<number>;
} }

View File

@@ -1,8 +1,8 @@
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { FILTER_CONFIG, SearchFilterService, SELECTED_VALUES } from '../search-filter.service'; import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service';
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model'; import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
import { FilterType } from '../../../search-service/filter-type.model'; import { FilterType } from '../../../search-service/filter-type.model';
import { FacetValue } from '../../../search-service/facet-value.model'; import { FacetValue } from '../../../search-service/facet-value.model';
@@ -15,9 +15,9 @@ import { PaginatedList } from '../../../../core/data/paginated-list';
import { SearchOptions } from '../../../search-options.model'; import { SearchOptions } from '../../../search-options.model';
import { RouterStub } from '../../../../shared/testing/router-stub'; import { RouterStub } from '../../../../shared/testing/router-stub';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { PageInfo } from '../../../../core/shared/page-info.model'; import { PageInfo } from '../../../../core/shared/page-info.model';
import { SearchFacetFilterComponent } from './search-facet-filter.component'; import { SearchFacetFilterComponent } from './search-facet-filter.component';
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
describe('SearchFacetFilterComponent', () => { describe('SearchFacetFilterComponent', () => {
let comp: SearchFacetFilterComponent; let comp: SearchFacetFilterComponent;
@@ -64,10 +64,11 @@ describe('SearchFacetFilterComponent', () => {
providers: [ providers: [
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: SearchService, useValue: new SearchServiceStub(searchLink) },
{ provide: Router, useValue: new RouterStub() }, { provide: Router, useValue: new RouterStub() },
{ provide: FILTER_CONFIG, useValue: new SearchFilterConfig()}, { provide: FILTER_CONFIG, useValue: new SearchFilterConfig() },
{ provide: SELECTED_VALUES, useValue: {} }, { provide: RemoteDataBuildService, useValue: {aggregate: () => Observable.of({})} },
{ {
provide: SearchFilterService, useValue: { provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => Observable.of(selectedValues),
isFilterActiveWithValue: (paramName: string, filterValue: string) => true, isFilterActiveWithValue: (paramName: string, filterValue: string) => true,
getPage: (paramName: string) => page, getPage: (paramName: string) => page,
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
@@ -91,8 +92,7 @@ describe('SearchFacetFilterComponent', () => {
comp = fixture.componentInstance; // SearchPageComponent test instance comp = fixture.componentInstance; // SearchPageComponent test instance
comp.filterConfig = mockFilterConfig; comp.filterConfig = mockFilterConfig;
comp.filterValues = [mockValues]; comp.filterValues = [mockValues];
comp.filterValues$ = new BehaviorSubject(comp.filterValues); // comp.filterValues$ = new BehaviorSubject({});
comp.selectedValues = selectedValues;
filterService = (comp as any).filterService; filterService = (comp as any).filterService;
searchService = (comp as any).searchService; searchService = (comp as any).searchService;
spyOn(searchService, 'getFacetValuesFor').and.returnValue(mockValues); spyOn(searchService, 'getFacetValuesFor').and.returnValue(mockValues);
@@ -125,14 +125,14 @@ describe('SearchFacetFilterComponent', () => {
describe('when the getAddParams method is called wih a value', () => { describe('when the getAddParams method is called wih a value', () => {
it('should return the selectedValue list with the new parameter value', () => { it('should return the selectedValue list with the new parameter value', () => {
const result = comp.getAddParams(value3); const result = comp.getAddParams(value3);
expect(result[mockFilterConfig.paramName]).toEqual([value1, value2, value3]); result.subscribe((r) => expect(r[mockFilterConfig.paramName]).toEqual([value1, value2, value3]));
}); });
}); });
describe('when the getRemoveParams method is called wih a value', () => { describe('when the getRemoveParams method is called wih a value', () => {
it('should return the selectedValue list with the parameter value left out', () => { it('should return the selectedValue list with the parameter value left out', () => {
const result = comp.getRemoveParams(value1); const result = comp.getRemoveParams(value1);
expect(result[mockFilterConfig.paramName]).toEqual([value2]); result.subscribe((r) => expect(r[mockFilterConfig.paramName]).toEqual([value2]));
}); });
}); });
@@ -170,7 +170,7 @@ describe('SearchFacetFilterComponent', () => {
}); });
describe('when the getCurrentUrl method is called', () => { describe('when the getCurrentUrl method is called', () => {
const url = 'test.url/test' const url = 'test.url/test';
beforeEach(() => { beforeEach(() => {
router.navigateByUrl(url); router.navigateByUrl(url);
}); });
@@ -183,7 +183,7 @@ describe('SearchFacetFilterComponent', () => {
describe('when the onSubmit method is called with data', () => { describe('when the onSubmit method is called with data', () => {
const searchUrl = '/search/path'; const searchUrl = '/search/path';
const testValue = 'test'; const testValue = 'test';
const data = testValue ; const data = testValue;
beforeEach(() => { beforeEach(() => {
spyOn(comp, 'getSearchLink').and.returnValue(searchUrl); spyOn(comp, 'getSearchLink').and.returnValue(searchUrl);
comp.onSubmit(data); comp.onSubmit(data);
@@ -198,48 +198,20 @@ describe('SearchFacetFilterComponent', () => {
}); });
describe('when updateFilterValueList is called', () => { describe('when updateFilterValueList is called', () => {
const cPage = 10;
const searchOptions = new SearchOptions(); const searchOptions = new SearchOptions();
beforeEach(() => { beforeEach(() => {
// spyOn(searchService, 'getFacetValuesFor'); Already spied upon
comp.currentPage = Observable.of(cPage);
comp.updateFilterValueList(searchOptions);
});
it('should call getFacetValuesFor on the searchService with the correct parameters', () => {
expect(searchService.getFacetValuesFor).toHaveBeenCalledWith(mockFilterConfig, cPage, searchOptions);
});
});
describe('when updateFilterValueList is called and pageChange is set to true', () => {
const searchOptions = new SearchOptions();
beforeEach(() => {
comp.pageChange = true;
spyOn(comp, 'showFirstPageOnly'); spyOn(comp, 'showFirstPageOnly');
comp.updateFilterValueList(searchOptions); comp.updateFilterValueList(searchOptions)
}); });
it('should not call showFirstPageOnly on the component', () => { it('should call showFirstPageOnly and empty the filter', () => {
expect(comp.showFirstPageOnly).not.toHaveBeenCalled(); expect(comp.animationState).toEqual('loading');
}); expect((comp as any).collapseNextUpdate).toBeTruthy();
expect(comp.filter).toEqual('');
it('should set pageChange to false', () => {
expect(comp.pageChange).toBeFalsy();
}); });
}); });
describe('when updateFilterValueList is called and pageChange is set to false', () => {
const searchOptions = new SearchOptions();
beforeEach(() => {
comp.pageChange = false;
spyOn(comp, 'showFirstPageOnly');
comp.updateFilterValueList(searchOptions);
});
it('should call showFirstPageOnly on the component', () => {
expect(comp.showFirstPageOnly).toHaveBeenCalled();
});
});
describe('when findSuggestions is called with query \'test\'', () => { describe('when findSuggestions is called with query \'test\'', () => {
const query = 'test'; const query = 'test';
beforeEach(() => { beforeEach(() => {

View File

@@ -33,7 +33,6 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
currentPage: Observable<number>; currentPage: Observable<number>;
isLastPage$: BehaviorSubject<boolean> = new BehaviorSubject(false); isLastPage$: BehaviorSubject<boolean> = new BehaviorSubject(false);
filter: string; filter: string;
pageChange = false;
private subs: Subscription[] = []; private subs: Subscription[] = [];
filterSearchResults: Observable<any[]> = Observable.of([]); filterSearchResults: Observable<any[]> = Observable.of([]);
selectedValues: Observable<string[]>; selectedValues: Observable<string[]>;
@@ -55,11 +54,12 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
this.subs.push(searchOptions.subscribe((options) => this.updateFilterValueList(options))); this.subs.push(searchOptions.subscribe((options) => this.updateFilterValueList(options)));
const facetValues = Observable.combineLatest(searchOptions, this.currentPage, (options, page) => { const facetValues = Observable.combineLatest(searchOptions, this.currentPage, (options, page) => {
return {values: this.searchService.getFacetValuesFor(this.filterConfig, page, options), page: page}; return {
values: this.searchService.getFacetValuesFor(this.filterConfig, page, options),
page: page
};
}); });
this.subs.push(facetValues.subscribe((facetOutcome) => { this.subs.push(facetValues.subscribe((facetOutcome) => {
const newValues$ = facetOutcome.values; const newValues$ = facetOutcome.values;
@@ -86,7 +86,6 @@ export class SearchFacetFilterComponent implements OnInit, OnDestroy {
} }
updateFilterValueList(options: SearchOptions) { updateFilterValueList(options: SearchOptions) {
// this.showFirstPageOnly();
this.animationState = 'loading'; this.animationState = 'loading';
this.collapseNextUpdate = true; this.collapseNextUpdate = true;
this.filter = ''; this.filter = '';

View File

@@ -42,6 +42,10 @@ describe('SearchFilterService', () => {
addQueryParameterValue: (param: string, value: string) => { addQueryParameterValue: (param: string, value: string) => {
}, },
getQueryParameterValues: (param: string) => { getQueryParameterValues: (param: string) => {
return Observable.of({});
},
getQueryParamsWithPrefix: (param: string) => {
return Observable.of({});
} }
/* tslint:enable:no-empty */ /* tslint:enable:no-empty */
}; };

View File

@@ -23,5 +23,4 @@ import {
@renderFacetFor(FilterType.hierarchy) @renderFacetFor(FilterType.hierarchy)
export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent implements OnInit { export class SearchHierarchyFilterComponent extends SearchFacetFilterComponent implements OnInit {
currentPage: Observable<number>;
} }

View File

@@ -2,7 +2,7 @@ import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { FILTER_CONFIG, SearchFilterService, SELECTED_VALUES } from '../search-filter.service'; import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service';
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model'; import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
import { FilterType } from '../../../search-service/filter-type.model'; import { FilterType } from '../../../search-service/filter-type.model';
import { FacetValue } from '../../../search-service/facet-value.model'; import { FacetValue } from '../../../search-service/facet-value.model';
@@ -13,13 +13,13 @@ import { SearchServiceStub } from '../../../../shared/testing/search-service-stu
import { RemoteData } from '../../../../core/data/remote-data'; import { RemoteData } from '../../../../core/data/remote-data';
import { PaginatedList } from '../../../../core/data/paginated-list'; import { PaginatedList } from '../../../../core/data/paginated-list';
import { RouterStub } from '../../../../shared/testing/router-stub'; import { RouterStub } from '../../../../shared/testing/router-stub';
import { ActivatedRoute, Router } from '@angular/router'; import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { PageInfo } from '../../../../core/shared/page-info.model'; import { PageInfo } from '../../../../core/shared/page-info.model';
import { SearchRangeFilterComponent } from './search-range-filter.component'; import { SearchRangeFilterComponent } from './search-range-filter.component';
import { MockActivatedRoute } from '../../../../shared/mocks/mock-active-router'; import { RouteService } from '../../../../shared/services/route.service';
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
describe('SearchFacetFilterComponent', () => { describe('SearchRangeFilterComponent', () => {
let comp: SearchRangeFilterComponent; let comp: SearchRangeFilterComponent;
let fixture: ComponentFixture<SearchRangeFilterComponent>; let fixture: ComponentFixture<SearchRangeFilterComponent>;
const minSuffix = '.min'; const minSuffix = '.min';
@@ -55,12 +55,11 @@ describe('SearchFacetFilterComponent', () => {
]; ];
const searchLink = '/search'; const searchLink = '/search';
const selectedValues = [value1]; const selectedValues = Observable.of([value1]);
let filterService; let filterService;
let searchService; let searchService;
let router; let router;
const page = Observable.of(0); const page = Observable.of(0);
const activatedRouteStub = new MockActivatedRoute();
const mockValues = Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), values))); const mockValues = Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), values)));
beforeEach(async(() => { beforeEach(async(() => {
@@ -70,11 +69,12 @@ describe('SearchFacetFilterComponent', () => {
providers: [ providers: [
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) }, { provide: SearchService, useValue: new SearchServiceStub(searchLink) },
{ provide: Router, useValue: new RouterStub() }, { provide: Router, useValue: new RouterStub() },
{ provide: FILTER_CONFIG, useValue: mockFilterConfig}, { provide: FILTER_CONFIG, useValue: mockFilterConfig },
{ provide: SELECTED_VALUES, useValue: selectedValues }, { provide: RemoteDataBuildService, useValue: {aggregate: () => Observable.of({})} },
{ provide: ActivatedRoute, useValue: activatedRouteStub }, { provide: RouteService, useValue: {getQueryParameterValue: () => Observable.of({})} },
{ {
provide: SearchFilterService, useValue: { provide: SearchFilterService, useValue: {
getSelectedValuesForFilter: () => selectedValues,
isFilterActiveWithValue: (paramName: string, filterValue: string) => true, isFilterActiveWithValue: (paramName: string, filterValue: string) => true,
getPage: (paramName: string) => page, getPage: (paramName: string) => page,
/* tslint:disable:no-empty */ /* tslint:disable:no-empty */
@@ -97,7 +97,6 @@ describe('SearchFacetFilterComponent', () => {
fixture = TestBed.createComponent(SearchRangeFilterComponent); fixture = TestBed.createComponent(SearchRangeFilterComponent);
comp = fixture.componentInstance; // SearchPageComponent test instance comp = fixture.componentInstance; // SearchPageComponent test instance
comp.filterValues = [mockValues]; comp.filterValues = [mockValues];
comp.filterValues$ = new BehaviorSubject(comp.filterValues);
filterService = (comp as any).filterService; filterService = (comp as any).filterService;
searchService = (comp as any).searchService; searchService = (comp as any).searchService;
spyOn(searchService, 'getFacetValuesFor').and.returnValue(mockValues); spyOn(searchService, 'getFacetValuesFor').and.returnValue(mockValues);
@@ -107,32 +106,40 @@ describe('SearchFacetFilterComponent', () => {
describe('when the getAddParams method is called wih a value', () => { describe('when the getAddParams method is called wih a value', () => {
it('should return the selectedValue list with the new parameter value', () => { it('should return the selectedValue list with the new parameter value', () => {
const result = comp.getAddParams(value3); const result$ = comp.getAddParams(value3);
result$.subscribe((result) => {
expect(result[mockFilterConfig.paramName + minSuffix]).toEqual(['1990']); expect(result[mockFilterConfig.paramName + minSuffix]).toEqual(['1990']);
expect(result[mockFilterConfig.paramName + maxSuffix]).toEqual(['1992']); expect(result[mockFilterConfig.paramName + maxSuffix]).toEqual(['1992']);
}); });
}); });
});
describe('when the getRemoveParams method is called wih a value', () => { describe('when the getRemoveParams method is called wih a value', () => {
it('should return the selectedValue list with the parameter value left out', () => { it('should return the selectedValue list with the parameter value left out', () => {
const result = comp.getRemoveParams(value1); const result$ = comp.getRemoveParams(value1);
result$.subscribe((result) => {
expect(result[mockFilterConfig.paramName + minSuffix]).toBeNull(); expect(result[mockFilterConfig.paramName + minSuffix]).toBeNull();
expect(result[mockFilterConfig.paramName + maxSuffix]).toBeNull(); expect(result[mockFilterConfig.paramName + maxSuffix]).toBeNull();
}); });
});
}); });
describe('when the onSubmit method is called with data', () => { describe('when the onSubmit method is called with data', () => {
const searchUrl = '/search/path'; const searchUrl = '/search/path';
comp.range = [1900, 1950];
// const data = { [mockFilterConfig.paramName + minSuffix]: '1900', [mockFilterConfig.paramName + maxSuffix]: '1950' }; // const data = { [mockFilterConfig.paramName + minSuffix]: '1900', [mockFilterConfig.paramName + maxSuffix]: '1950' };
beforeEach(() => { beforeEach(() => {
comp.range = [1900, 1950];
spyOn(comp, 'getSearchLink').and.returnValue(searchUrl); spyOn(comp, 'getSearchLink').and.returnValue(searchUrl);
comp.onSubmit(); comp.onSubmit();
}); });
it('should call navigate on the router with the right searchlink and parameters', () => { it('should call navigate on the router with the right searchlink and parameters', () => {
expect(router.navigate).toHaveBeenCalledWith([searchUrl], { expect(router.navigate).toHaveBeenCalledWith([searchUrl], {
queryParams: { [mockFilterConfig.paramName + minSuffix]: ['1900'], [mockFilterConfig.paramName + maxSuffix]: ['1950']}, queryParams: {
[mockFilterConfig.paramName + minSuffix]: [1900],
[mockFilterConfig.paramName + maxSuffix]: [1950]
},
queryParamsHandling: 'merge' queryParamsHandling: 'merge'
}); });
}); });

View File

@@ -1,5 +1,5 @@
import { isPlatformBrowser } from '@angular/common'; import { isPlatformBrowser } from '@angular/common';
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core'; import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service'; import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
import { FilterType } from '../../../search-service/filter-type.model'; import { FilterType } from '../../../search-service/filter-type.model';
import { renderFacetFor } from '../search-filter-type-decorator'; import { renderFacetFor } from '../search-filter-type-decorator';
@@ -10,9 +10,12 @@ import {
import { SearchFilterConfig } from '../../../search-service/search-filter-config.model'; import { SearchFilterConfig } from '../../../search-service/search-filter-config.model';
import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service'; import { FILTER_CONFIG, SearchFilterService } from '../search-filter.service';
import { SearchService } from '../../../search-service/search.service'; import { SearchService } from '../../../search-service/search.service';
import { ActivatedRoute, Router } from '@angular/router'; import { Router } from '@angular/router';
import * as moment from 'moment'; import * as moment from 'moment';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { RouteService } from '../../../../shared/services/route.service';
import { hasValue } from '../../../../shared/empty.util';
import { Subscription } from 'rxjs/Subscription';
/** /**
* This component renders a simple item page. * This component renders a simple item page.
@@ -32,10 +35,11 @@ const rangeDelimiter = '-';
}) })
@renderFacetFor(FilterType.range) @renderFacetFor(FilterType.range)
export class SearchRangeFilterComponent extends SearchFacetFilterComponent implements OnInit { export class SearchRangeFilterComponent extends SearchFacetFilterComponent implements OnInit, OnDestroy {
min = 1950; min = 1950;
max = 2018; max = 2018;
range; range;
sub: Subscription;
constructor(protected searchService: SearchService, constructor(protected searchService: SearchService,
protected filterService: SearchFilterService, protected filterService: SearchFilterService,
@@ -43,18 +47,22 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
protected rdbs: RemoteDataBuildService, protected rdbs: RemoteDataBuildService,
@Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig, @Inject(FILTER_CONFIG) public filterConfig: SearchFilterConfig,
@Inject(PLATFORM_ID) private platformId: any, @Inject(PLATFORM_ID) private platformId: any,
private route: ActivatedRoute) { private route: RouteService) {
super(searchService, filterService, rdbs, router, filterConfig); super(searchService, filterService, rdbs, router, filterConfig);
} }
ngOnInit(): void { ngOnInit(): void {
super.ngOnInit(); super.ngOnInit();
this.min = moment(this.filterConfig.minValue, dateFormats).year() || this.min; this.min = moment(this.filterConfig.minValue, dateFormats).year() || this.min;
this.max = moment(this.filterConfig.maxValue, dateFormats).year() || this.max; this.max = moment(this.filterConfig.maxValue, dateFormats).year() || this.max;
const iniMin = this.route.snapshot.queryParams[this.filterConfig.paramName + minSuffix] || this.min; const iniMin = this.route.getQueryParameterValue(this.filterConfig.paramName + minSuffix).startWith(undefined);
const iniMax = this.route.snapshot.queryParams[this.filterConfig.paramName + maxSuffix] || this.max; const iniMax = this.route.getQueryParameterValue(this.filterConfig.paramName + maxSuffix).startWith(undefined);
this.range = [iniMin, iniMax]; this.sub = Observable.combineLatest(iniMin, iniMax, (min, max) => {
const minimum = hasValue(min) ? min : this.min;
const maximum = hasValue(max) ? max : this.max;
return [minimum, maximum]
}).subscribe((minmax) => this.range = minmax);
} }
getAddParams(value: string) { getAddParams(value: string) {
@@ -79,7 +87,6 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
); );
} }
onSubmit() { onSubmit() {
const newMin = this.range[0] !== this.min ? [this.range[0]] : null; const newMin = this.range[0] !== this.min ? [this.range[0]] : null;
const newMax = this.range[1] !== this.max ? [this.range[1]] : null; const newMax = this.range[1] !== this.max ? [this.range[1]] : null;
@@ -101,4 +108,9 @@ export class SearchRangeFilterComponent extends SearchFacetFilterComponent imple
return isPlatformBrowser(this.platformId); return isPlatformBrowser(this.platformId);
} }
ngOnDestroy() {
if (hasValue(this.sub)) {
this.sub.unsubscribe();
}
}
} }

View File

@@ -23,5 +23,4 @@ import { renderFacetFor } from '../search-filter-type-decorator';
@renderFacetFor(FilterType.text) @renderFacetFor(FilterType.text)
export class SearchTextFilterComponent extends SearchFacetFilterComponent implements OnInit { export class SearchTextFilterComponent extends SearchFacetFilterComponent implements OnInit {
currentPage: Observable<number>;
} }

View File

@@ -8,6 +8,8 @@ import { FormsModule } from '@angular/forms';
import { SearchServiceStub } from '../../shared/testing/search-service-stub'; import { SearchServiceStub } from '../../shared/testing/search-service-stub';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { Params } from '@angular/router'; import { Params } from '@angular/router';
import { ObjectKeysPipe } from '../../shared/utils/object-keys-pipe';
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
describe('SearchLabelsComponent', () => { describe('SearchLabelsComponent', () => {
let comp: SearchLabelsComponent; let comp: SearchLabelsComponent;
@@ -30,9 +32,10 @@ describe('SearchLabelsComponent', () => {
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule], imports: [TranslateModule.forRoot(), NoopAnimationsModule, FormsModule],
declarations: [SearchLabelsComponent], declarations: [SearchLabelsComponent, ObjectKeysPipe],
providers: [ providers: [
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) } { provide: SearchService, useValue: new SearchServiceStub(searchLink) },
{ provide: SearchFilterService, useValue: {getCurrentFrontendFilters : () => Observable.of({})} }
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).overrideComponent(SearchLabelsComponent, { }).overrideComponent(SearchLabelsComponent, {

View File

@@ -38,7 +38,8 @@ describe('SearchPageComponent', () => {
const mockResults = Observable.of(['test', 'data']); const mockResults = Observable.of(['test', 'data']);
const searchServiceStub = jasmine.createSpyObj('SearchService', { const searchServiceStub = jasmine.createSpyObj('SearchService', {
search: mockResults, search: mockResults,
getSearchLink: '/search' getSearchLink: '/search',
getScopes: Observable.of(['test-scope'])
}); });
const queryParam = 'test query'; const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
@@ -91,7 +92,11 @@ describe('SearchPageComponent', () => {
useValue: jasmine.createSpyObj('SearchFilterService', { useValue: jasmine.createSpyObj('SearchFilterService', {
getPaginatedSearchOptions: hot('a', { getPaginatedSearchOptions: hot('a', {
a: paginatedSearchOptions a: paginatedSearchOptions
}) }),
getCurrentScope: hot('a', {
a: 'test-id'
}),
}) })
}, },
], ],

View File

@@ -26,6 +26,8 @@ import {
} from '../../core/cache/response-cache.models'; } from '../../core/cache/response-cache.models';
import { SearchQueryResponse } from './search-query-response.model'; import { SearchQueryResponse } from './search-query-response.model';
import { SearchFilterConfig } from './search-filter-config.model'; import { SearchFilterConfig } from './search-filter-config.model';
import { CollectionDataService } from '../../core/data/collection-data.service';
import { CommunityDataService } from '../../core/data/community-data.service';
@Component({ template: '' }) @Component({ template: '' })
class DummyComponent { class DummyComponent {
@@ -54,6 +56,8 @@ describe('SearchService', () => {
{ provide: RequestService, useValue: getMockRequestService() }, { provide: RequestService, useValue: getMockRequestService() },
{ provide: RemoteDataBuildService, useValue: {} }, { provide: RemoteDataBuildService, useValue: {} },
{ provide: HALEndpointService, useValue: {} }, { provide: HALEndpointService, useValue: {} },
{ provide: CommunityDataService, useValue: {}},
{ provide: CollectionDataService, useValue: {}},
SearchService SearchService
], ],
}); });
@@ -109,6 +113,8 @@ describe('SearchService', () => {
{ provide: RequestService, useValue: getMockRequestService() }, { provide: RequestService, useValue: getMockRequestService() },
{ provide: RemoteDataBuildService, useValue: remoteDataBuildService }, { provide: RemoteDataBuildService, useValue: remoteDataBuildService },
{ provide: HALEndpointService, useValue: halService }, { provide: HALEndpointService, useValue: halService },
{ provide: CommunityDataService, useValue: {}},
{ provide: CollectionDataService, useValue: {}},
SearchService SearchService
], ],
}); });

View File

@@ -11,6 +11,8 @@ import { SearchSidebarService } from '../search-sidebar/search-sidebar.service';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe'; import { EnumKeysPipe } from '../../shared/utils/enum-keys-pipe';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
import { hot } from 'jasmine-marbles';
describe('SearchSettingsComponent', () => { describe('SearchSettingsComponent', () => {
@@ -23,13 +25,21 @@ describe('SearchSettingsComponent', () => {
pagination.currentPage = 1; pagination.currentPage = 1;
pagination.pageSize = 10; pagination.pageSize = 10;
const sort: SortOptions = new SortOptions('score', SortDirection.DESC); const sort: SortOptions = new SortOptions('score', SortDirection.DESC);
const mockResults = [ 'test', 'data' ]; const mockResults = ['test', 'data'];
const searchServiceStub = { const searchServiceStub = {
searchOptions: { pagination: pagination, sort: sort }, searchOptions: { pagination: pagination, sort: sort },
search: () => mockResults search: () => mockResults
}; };
const queryParam = 'test query'; const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const paginatedSearchOptions = {
query: queryParam,
scope: scopeParam,
pagination,
sort
};
const activatedRouteStub = { const activatedRouteStub = {
queryParams: Observable.of({ queryParams: Observable.of({
query: queryParam, query: queryParam,
@@ -41,12 +51,12 @@ describe('SearchSettingsComponent', () => {
isCollapsed: Observable.of(true), isCollapsed: Observable.of(true),
collapse: () => this.isCollapsed = Observable.of(true), collapse: () => this.isCollapsed = Observable.of(true),
expand: () => this.isCollapsed = Observable.of(false) expand: () => this.isCollapsed = Observable.of(false)
} };
beforeEach(async(() => { beforeEach(async(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ TranslateModule.forRoot(), RouterTestingModule.withRoutes([]) ], imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([])],
declarations: [ SearchSettingsComponent, EnumKeysPipe ], declarations: [SearchSettingsComponent, EnumKeysPipe],
providers: [ providers: [
{ provide: SearchService, useValue: searchServiceStub }, { provide: SearchService, useValue: searchServiceStub },
@@ -55,8 +65,20 @@ describe('SearchSettingsComponent', () => {
provide: SearchSidebarService, provide: SearchSidebarService,
useValue: sidebarService useValue: sidebarService
}, },
{
provide: SearchFilterService,
useValue: jasmine.createSpyObj('SearchFilterService', {
getPaginatedSearchOptions: hot('a', {
a: paginatedSearchOptions
}),
getCurrentScope: hot('a', {
a: 'test-id'
}),
})
},
], ],
schemas: [ NO_ERRORS_SCHEMA ] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();
})); }));
@@ -77,15 +99,18 @@ describe('SearchSettingsComponent', () => {
const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings')); const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings'));
expect(orderSetting).toBeDefined(); expect(orderSetting).toBeDefined();
const childElements = orderSetting.query(By.css('.form-control')).children; const childElements = orderSetting.query(By.css('.form-control')).children;
expect(childElements.length).toEqual(2); expect(childElements.length).toEqual(comp.searchOptionPossibilities.length);
}); });
it('it should show the size settings with the respective selectable options', () => { it('it should show the size settings with the respective selectable options', () => {
(comp as any).filterService.getPaginatedSearchOptions().first().subscribe((options) => {
fixture.detectChanges()
const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings'));
expect(pageSizeSetting).toBeDefined(); expect(pageSizeSetting).toBeDefined();
const childElements = pageSizeSetting.query(By.css('.form-control')).children; const childElements = pageSizeSetting.query(By.css('.form-control')).children;
expect(childElements.length).toEqual(7); expect(childElements.length).toEqual(options.pagination.pageSizeOptions.length);
}
)
}); });
it('should have the proper order value selected by default', () => { it('should have the proper order value selected by default', () => {

View File

@@ -1,11 +1,9 @@
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { SearchService } from '../search-service/search.service'; import { SearchService } from '../search-service/search.service';
import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model'; import { SortDirection, SortOptions } from '../../core/cache/models/sort-options.model';
import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; import { ActivatedRoute, NavigationExtras, Router } from '@angular/router';
import { PaginatedSearchOptions } from '../paginated-search-options.model'; import { PaginatedSearchOptions } from '../paginated-search-options.model';
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service'; import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
import { hasValue } from '../../shared/empty.util';
import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'ds-search-settings', selector: 'ds-search-settings',
@@ -25,8 +23,6 @@ export class SearchSettingsComponent implements OnInit {
public pageSize; public pageSize;
@Input() public pageSizeOptions; @Input() public pageSizeOptions;
private sub: Subscription;
private scope: string;
query: string; query: string;
page: number; page: number;
direction: SortDirection; direction: SortDirection;
@@ -49,10 +45,9 @@ export class SearchSettingsComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
this.filterService.getPaginatedSearchOptions(this.defaults).first().subscribe((options) => { this.filterService.getPaginatedSearchOptions(this.defaults).subscribe((options) => {
this.direction = options.sort.direction; this.direction = options.sort.direction;
this.field = options.sort.field; this.field = options.sort.field;
this.pageSize = options.pagination.pageSize;
this.searchOptions = options; this.searchOptions = options;
this.pageSize = options.pagination.pageSize; this.pageSize = options.pagination.pageSize;
this.pageSizeOptions = options.pagination.pageSizeOptions this.pageSizeOptions = options.pagination.pageSizeOptions
@@ -81,6 +76,4 @@ export class SearchSettingsComponent implements OnInit {
}; };
this.router.navigate([ '/search' ], navigationExtras); this.router.navigate([ '/search' ], navigationExtras);
} }
} }

View File

@@ -34,7 +34,8 @@ describe('LoadingComponent (inline template)', () => {
fixture = TestBed.createComponent(LoadingComponent); fixture = TestBed.createComponent(LoadingComponent);
comp = fixture.componentInstance; // LoadingComponent test instance comp = fixture.componentInstance; // LoadingComponent test instance
comp.message = 'test message';
fixture.detectChanges();
// query for the message <label> by CSS element selector // query for the message <label> by CSS element selector
de = fixture.debugElement.query(By.css('label')); de = fixture.debugElement.query(By.css('label'));
el = de.nativeElement; el = de.nativeElement;