fixes for existing tested

This commit is contained in:
Lotte Hofstede
2018-04-05 08:49:36 +02:00
parent a232127422
commit 79caf1533c
9 changed files with 56 additions and 168 deletions

View File

@@ -32,7 +32,7 @@
[action]="getCurrentUrl()">
<input type="text" [(ngModel)]="filter" [name]="filterConfig.paramName" class="form-control"
aria-label="New filter input"
[placeholder]="'search.filters.filter.' + filterConfig.name + '.placeholder'| translate"/>
[placeholder]="'search.filters.filter.' + filterConfig.name + '.placeholder'| translate" [ngModelOptions]="{standalone: true}"/>
<input type="submit" class="d-none"/>
</form>
</div>

View File

@@ -159,28 +159,6 @@ describe('SearchFilterService', () => {
});
});
describe('when the getQueryParamsWithout method is called', () => {
beforeEach(() => {
spyOn(routeServiceStub, 'removeQueryParameterValue');
service.getQueryParamsWithout(mockFilterConfig, value1);
});
it('should call removeQueryParameterValue on the route service with the same parameters', () => {
expect(routeServiceStub.removeQueryParameterValue).toHaveBeenCalledWith(mockFilterConfig.paramName, value1);
});
});
describe('when the getQueryParamsWith method is called', () => {
beforeEach(() => {
spyOn(routeServiceStub, 'addQueryParameterValue');
service.getQueryParamsWith(mockFilterConfig, value1);
});
it('should call addQueryParameterValue on the route service with the same parameters', () => {
expect(routeServiceStub.addQueryParameterValue).toHaveBeenCalledWith(mockFilterConfig.paramName, value1);
});
});
describe('when the getSelectedValuesForFilter method is called', () => {
beforeEach(() => {
spyOn(routeServiceStub, 'getQueryParameterValues');
@@ -192,14 +170,4 @@ describe('SearchFilterService', () => {
});
});
describe('when the uiSearchRoute method is called', () => {
let link: string;
beforeEach(() => {
link = service.searchLink;
});
it('should return the value of uiSearchRoute in the search service', () => {
expect(link).toEqual(searchServiceStub.uiSearchRoute);
});
});
});

View File

@@ -4,6 +4,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { SearchFilterService } from './search-filter/search-filter.service';
import { SearchFiltersComponent } from './search-filters.component';
import { SearchService } from '../search-service/search.service';
import { Observable } from 'rxjs/Observable';
@@ -22,6 +23,9 @@ describe('SearchFiltersComponent', () => {
}
/* tslint:enable:no-empty */
};
const searchFilterServiceStub = jasmine.createSpyObj('SearchFilterService', {
getCurrentFilters: Observable.of({})
});
beforeEach(async(() => {
TestBed.configureTestingModule({
@@ -29,6 +33,7 @@ describe('SearchFiltersComponent', () => {
declarations: [SearchFiltersComponent],
providers: [
{ provide: SearchService, useValue: searchServiceStub },
{ provide: SearchFilterService, useValue: searchFilterServiceStub },
],
schemas: [NO_ERRORS_SCHEMA]
@@ -44,17 +49,6 @@ describe('SearchFiltersComponent', () => {
searchService = (comp as any).searchService;
});
describe('when the getClearFiltersQueryParams method is called', () => {
beforeEach(() => {
spyOn(searchService, 'getClearFiltersQueryParams');
comp.getClearFiltersQueryParams();
});
it('should call getClearFiltersQueryParams on the searchService', () => {
expect(searchService.getClearFiltersQueryParams).toHaveBeenCalled()
});
});
describe('when the getSearchLink method is called', () => {
beforeEach(() => {
spyOn(searchService, 'getSearchLink');

View File

@@ -1,22 +1,22 @@
<div class="container">
<div class="search-page row">
<ds-search-sidebar *ngIf="!(isMobileView | async)" class="col-3 sidebar-md-sticky"
<ds-search-sidebar *ngIf="!(isMobileView$ | async)" class="col-3 sidebar-md-sticky"
id="search-sidebar"
[resultCount]="(resultsRDObs | async)?.pageInfo?.totalElements"></ds-search-sidebar>
[resultCount]="(resultsRD$ | async)?.pageInfo?.totalElements"></ds-search-sidebar>
<div class="col-12 col-md-9">
<ds-search-form id="search-form"
[query]="query"
[scope]="(scopeObjectRDObs | async)?.payload"
[query]="(searchOptions$ | async)?.query"
[scope]="(searchOptions$ | async)?.scope"
[currentParams]="currentParams"
[scopes]="(scopeListRDObs | async)?.payload?.page">
[scopes]="(scopeListRD$ | async)?.payload?.page">
</ds-search-form>
<div class="row">
<div id="search-body"
class="row-offcanvas row-offcanvas-left"
[@pushInOut]="(isSidebarCollapsed() | async) ? 'collapsed' : 'expanded'">
<ds-search-sidebar *ngIf="(isMobileView | async)" class="col-12"
<ds-search-sidebar *ngIf="(isMobileView$ | async)" class="col-12"
id="search-sidebar-sm"
[resultCount]="(resultsRDObs | async)?.pageInfo?.totalElements"
[resultCount]="(resultsRD$ | async)?.pageInfo?.totalElements"
(toggleSidebar)="closeSidebar()"
[ngClass]="{'active': !(isSidebarCollapsed() | async)}">
</ds-search-sidebar>
@@ -29,8 +29,8 @@
| translate}}
</button>
</div>
<ds-search-results [searchResults]="resultsRDObs | async"
[searchConfig]="searchOptions" [sortConfig]="sortConfig"></ds-search-results>
<ds-search-results [searchResults]="resultsRD$ | async"
[searchConfig]="searchOptions$ | async" [sortConfig]="sortConfig"></ds-search-results>
</div>
</div>
</div>

View File

@@ -4,12 +4,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Store } from '@ngrx/store';
import { TranslateModule } from '@ngx-translate/core';
import { cold, hot } from 'jasmine-marbles';
import { Observable } from 'rxjs/Observable';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { CommunityDataService } from '../core/data/community-data.service';
import { Community } from '../core/shared/community.model';
import { HostWindowService } from '../shared/host-window.service';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { PaginatedSearchOptions } from './paginated-search-options.model';
import { SearchPageComponent } from './search-page.component';
import { SearchService } from './search-service/search.service';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -35,12 +37,17 @@ describe('SearchPageComponent', () => {
pagination.pageSize = 10;
const sort: SortOptions = new SortOptions();
const mockResults = Observable.of(['test', 'data']);
const searchServiceStub = {
searchOptions:{ pagination: pagination, sort: sort },
search: () => mockResults
};
const searchServiceStub = jasmine.createSpyObj('SearchService', {
search: mockResults
});
const queryParam = 'test query';
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
const paginatedSearchOptions = {
query: queryParam,
scope: scopeParam,
pagination,
sort
};
const activatedRouteStub = {
queryParams: Observable.of({
query: queryParam,
@@ -51,20 +58,8 @@ describe('SearchPageComponent', () => {
isCollapsed: Observable.of(true),
collapse: () => this.isCollapsed = Observable.of(true),
expand: () => this.isCollapsed = Observable.of(false)
}
const mockCommunityList = [];
const communityDataServiceStub = {
findAll: () => Observable.of(mockCommunityList),
findById: () => Observable.of(new Community())
};
class RouterStub {
navigateByUrl(url: string) {
return url;
}
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule, NgbCollapseModule.forRoot()],
@@ -92,7 +87,11 @@ describe('SearchPageComponent', () => {
},
{
provide: SearchFilterService,
useValue: {}
useValue: jasmine.createSpyObj('SearchFilterService', {
getPaginatedSearchOptions: hot('a', {
a: paginatedSearchOptions
})
})
},
],
schemas: [NO_ERRORS_SCHEMA]
@@ -108,54 +107,10 @@ describe('SearchPageComponent', () => {
searchServiceObject = (comp as any).service;
});
it('should set the scope and query based on the route parameters', () => {
expect(comp.query).toBe(queryParam);
expect((comp as any).scope).toBe(scopeParam);
});
describe('when update search results is called', () => {
let paginationUpdate;
let sortUpdate;
beforeEach(() => {
paginationUpdate = Object.assign(
{},
new PaginationComponentOptions(),
{
currentPage: 5,
pageSize: 15
}
);
sortUpdate = Object.assign({},
new SortOptions(),
{
direction: SortDirection.Ascending,
field: 'test-field'
}
);
});
it('should call the search function of the search service with the right parameters', () => {
spyOn(searchServiceObject, 'search').and.callThrough();
(comp as any).updateSearchResults({
pagination: pagination,
sort: sort
});
expect(searchServiceObject.search).toHaveBeenCalledWith(queryParam, scopeParam, {
pagination: pagination,
sort: sort
});
});
it('should update the results', () => {
spyOn(searchServiceObject, 'search').and.callThrough();
(comp as any).updateSearchResults({});
expect(comp.resultsRDObs as any).toBe(mockResults);
});
it('should get the scope and query from the route parameters', () => {
expect(comp.searchOptions$).toBeObservable(cold('b', {
b: paginatedSearchOptions
}));
});
describe('when the closeSidebar event is emitted clicked in mobile view', () => {

View File

@@ -1,6 +1,6 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { flatMap, } from 'rxjs/operators';
import { SortOptions } from '../core/cache/models/sort-options.model';
import { CommunityDataService } from '../core/data/community-data.service';
import { PaginatedList } from '../core/data/paginated-list';
@@ -8,14 +8,12 @@ import { RemoteData } from '../core/data/remote-data';
import { Community } from '../core/shared/community.model';
import { DSpaceObject } from '../core/shared/dspace-object.model';
import { pushInOut } from '../shared/animations/push';
import { isNotEmpty } from '../shared/empty.util';
import { HostWindowService } from '../shared/host-window.service';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { SearchOptions, ViewMode } from './search-options.model';
import { PaginatedSearchOptions } from './paginated-search-options.model';
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
import { SearchResult } from './search-result.model';
import { SearchService } from './search-service/search.service';
import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
/**
* This component renders a simple item page.
@@ -30,19 +28,14 @@ import { SearchFilterService } from './search-filters/search-filter/search-filte
changeDetection: ChangeDetectionStrategy.OnPush,
animations: [pushInOut]
})
export class SearchPageComponent implements OnInit, OnDestroy {
export class SearchPageComponent implements OnInit {
private sub;
private scope: string;
query: string;
scopeObjectRDObs: Observable<RemoteData<DSpaceObject>>;
resultsRDObs: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
resultsRD$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
currentParams = {};
searchOptions: SearchOptions;
searchOptions$: Observable<PaginatedSearchOptions>;
sortConfig: SortOptions;
scopeListRDObs: Observable<RemoteData<PaginatedList<Community>>>;
isMobileView: Observable<boolean>;
scopeListRD$: Observable<RemoteData<PaginatedList<Community>>>;
isMobileView$: Observable<boolean>;
pageSize;
pageSizeOptions;
defaults = {
@@ -58,27 +51,19 @@ export class SearchPageComponent implements OnInit, OnDestroy {
private sidebarService: SearchSidebarService,
private windowService: HostWindowService,
private filterService: SearchFilterService) {
this.isMobileView = Observable.combineLatest(
this.isMobileView$ = Observable.combineLatest(
this.windowService.isXs(),
this.windowService.isSm(),
((isXs, isSm) => isXs || isSm)
);
this.scopeListRDObs = communityService.findAll();
this.scopeListRD$ = communityService.findAll();
}
ngOnInit(): void {
this.sub = this.filterService.getPaginatedSearchOptions(this.defaults).subscribe((options) => {
this.updateSearchResults(options);
});
}
private updateSearchResults(searchOptions) {
this.resultsRDObs = this.service.search(searchOptions);
this.searchOptions = searchOptions;
}
ngOnDestroy() {
this.sub.unsubscribe();
this.searchOptions$ = this.filterService.getPaginatedSearchOptions(this.defaults);
this.resultsRD$ = this.searchOptions$.pipe(
flatMap((searchOptions) => this.service.search(searchOptions))
);
}
public closeSidebar(): void {

View File

@@ -17,18 +17,6 @@ describe('HALEndpointService', () => {
};
const linkPath = 'test';
/* tslint:disable:no-shadowed-variable */
class TestService extends HALEndpointService {
constructor(private responseCache: ResponseCacheService,
private requestService: RequestService,
private EnvConfig: GlobalConfig) {
super(responseCache, requestService, EnvConfig);
}
}
/* tslint:enable:no-shadowed-variable */
describe('getRootEndpointMap', () => {
beforeEach(() => {
responseCache = jasmine.createSpyObj('responseCache', {
@@ -45,7 +33,7 @@ describe('HALEndpointService', () => {
rest: { baseUrl: 'https://rest.api/' }
} as any;
service = new TestService(
service = new HALEndpointService(
responseCache,
requestService,
envConfig
@@ -73,7 +61,7 @@ describe('HALEndpointService', () => {
rest: { baseUrl: 'https://rest.api/' }
} as any;
service = new TestService(
service = new HALEndpointService(
responseCache,
requestService,
envConfig
@@ -100,7 +88,7 @@ describe('HALEndpointService', () => {
describe('isEnabledOnRestApi', () => {
beforeEach(() => {
service = new TestService(
service = new HALEndpointService(
responseCache,
requestService,
envConfig

View File

@@ -69,7 +69,7 @@ describe('SearchFormComponent', () => {
fixture.detectChanges();
const testCommunity = objects[1];
comp.scope = testCommunity;
comp.scope = testCommunity.id;
fixture.detectChanges();
tick();

View File

@@ -22,10 +22,8 @@ export class SearchFormComponent {
@Input() scopes: DSpaceObject[];
@Input()
set scope(dso: DSpaceObject) {
if (hasValue(dso)) {
this.selectedId = dso.id;
}
set scope(id: string) {
this.selectedId = id;
}
constructor(private router: Router) {