Skip to content

Commit

Permalink
Merge 3f36e03 into 62ff2d3
Browse files Browse the repository at this point in the history
  • Loading branch information
LotteHofstede committed Mar 19, 2018
2 parents 62ff2d3 + 3f36e03 commit 4cdc1d4
Show file tree
Hide file tree
Showing 60 changed files with 728 additions and 430 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Expand Up @@ -51,7 +51,7 @@ module.exports = function (config) {
*/
files: [{
pattern: './spec-bundle.js',
watched: false
watched: false,
}],

/*
Expand Down
13 changes: 13 additions & 0 deletions src/app/+search-page/normalized-search-result.model.ts
@@ -0,0 +1,13 @@
import { autoserialize } from 'cerialize';
import { Metadatum } from '../core/shared/metadatum.model';
import { ListableObject } from '../shared/object-collection/shared/listable-object.model';

export class NormalizedSearchResult implements ListableObject {

@autoserialize
dspaceObject: string;

@autoserialize
hitHighlights: Metadatum[];

}
Expand Up @@ -6,8 +6,6 @@ import { FacetValue } from '../../search-service/facet-value.model';
import { SearchFilterService } from './search-filter.service';
import { Observable } from 'rxjs/Observable';
import { slide } from '../../../shared/animations/slide';
import { RouteService } from '../../../shared/route.service';
import { first } from 'rxjs/operator/first';

/**
* This component renders a simple item page.
Expand Down
Expand Up @@ -46,7 +46,7 @@ describe('SearchFilterService', () => {
};

const searchServiceStub: any = {
searchLink: '/search'
uiSearchRoute: '/search'
};

beforeEach(() => {
Expand Down Expand Up @@ -192,14 +192,14 @@ describe('SearchFilterService', () => {
});
});

describe('when the searchLink method is called', () => {
describe('when the uiSearchRoute method is called', () => {
let link: string;
beforeEach(() => {
link = service.searchLink;
});

it('should return the value of searchLink in the search service', () => {
expect(link).toEqual(searchServiceStub.searchLink);
it('should return the value of uiSearchRoute in the search service', () => {
expect(link).toEqual(searchServiceStub.uiSearchRoute);
});
});
});
Expand Up @@ -46,7 +46,7 @@ export class SearchFilterService {
}

get searchLink() {
return this.searchService.searchLink;
return this.searchService.uiSearchRoute;
}

isCollapsed(filterName: string): Observable<boolean> {
Expand Down
7 changes: 4 additions & 3 deletions src/app/+search-page/search-page.component.ts
Expand Up @@ -36,7 +36,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {

query: string;
scopeObjectRDObs: Observable<RemoteData<DSpaceObject>>;
resultsRDObs: Observable<RemoteData<Array<SearchResult<DSpaceObject>>>>;
resultsRDObs: Observable<RemoteData<Array<SearchResult<DSpaceObject>> | PaginatedList<SearchResult<DSpaceObject>>>>;
currentParams = {};
searchOptions: SearchOptions;
sortConfig: SortOptions;
Expand Down Expand Up @@ -89,14 +89,15 @@ export class SearchPageComponent implements OnInit, OnDestroy {
}
}

const sortDirection = +params.sortDirection || this.searchOptions.sort.direction;
const sortDirection = params.sortDirection || this.searchOptions.sort.direction;
const sortField = params.sortField || this.searchOptions.sort.field;
const pagination = Object.assign({},
this.searchOptions.pagination,
{ currentPage: page, pageSize: pageSize, pageSizeOptions: pageSizeOptions}
);
const sort = Object.assign({},
this.searchOptions.sort,
{ direction: sortDirection, field: params.sortField }
{ direction: sortDirection, field: sortField }
);

this.updateSearchResults({
Expand Down
47 changes: 47 additions & 0 deletions src/app/+search-page/search-service/search-query-response.model.ts
@@ -0,0 +1,47 @@
import { autoserialize, autoserializeAs } from 'cerialize';
import { PageInfo } from '../../core/shared/page-info.model';
import { NormalizedSearchResult } from '../normalized-search-result.model';

export class SearchQueryResponse {
@autoserialize
scope: string;

@autoserialize
query: string;

@autoserialize
appliedFilters: any[]; // TODO

@autoserialize
sort: any; // TODO

@autoserialize
configurationName: string;

@autoserialize
public type: string;

@autoserialize
page: PageInfo;

@autoserializeAs(NormalizedSearchResult)
objects: NormalizedSearchResult[];

@autoserialize
facets: any; // TODO

@autoserialize
self: string;

@autoserialize
next: string;

@autoserialize
previous: string;

@autoserialize
first: string;

@autoserialize
last: string;
}
@@ -0,0 +1,17 @@
import { GenericConstructor } from '../../core/shared/generic-constructor';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';

const searchResultMap = new Map();

export function searchResultFor(domainConstructor: GenericConstructor<ListableObject>) {
return function decorator(searchResult: any) {
if (!searchResult) {
return;
}
searchResultMap.set(domainConstructor, searchResult);
};
}

export function getSearchResultFor(domainConstructor: GenericConstructor<ListableObject>) {
return searchResultMap.get(domainConstructor);
}
133 changes: 98 additions & 35 deletions src/app/+search-page/search-service/search.service.spec.ts
Expand Up @@ -8,50 +8,113 @@ import { SearchService } from './search.service';
import { ItemDataService } from './../../core/data/item-data.service';
import { ViewMode } from '../../+search-page/search-options.model';
import { RouteService } from '../../shared/route.service';
import { GLOBAL_CONFIG } from '../../../config';
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
import { ActivatedRoute, Router } from '@angular/router';
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';

@Component({ template: '' })
class DummyComponent { }
class DummyComponent {
}

describe('SearchService', () => {
let searchService: SearchService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CommonModule,
RouterTestingModule.withRoutes([
{ path: 'search', component: DummyComponent, pathMatch: 'full' },
])
],
declarations: [
DummyComponent
],
providers: [
{ provide: ItemDataService, useValue: {} },
{ provide: RouteService, useValue: {} },
SearchService
],
describe('By default', () => {
let searchService: SearchService;
const router = new RouterStub();
const route = new ActivatedRouteStub();
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CommonModule,
RouterTestingModule.withRoutes([
{ path: 'search', component: DummyComponent, pathMatch: 'full' },
])
],
declarations: [
DummyComponent
],
providers: [
{ provide: ItemDataService, useValue: {} },
{ provide: RouteService, useValue: {} },
{ provide: ResponseCacheService, useValue: {} },
{ provide: RequestService, useValue: {} },
{ provide: ActivatedRoute, useValue: route },
{ provide: RemoteDataBuildService, useValue: {} },
{ provide: GLOBAL_CONFIG, useValue: {} },
{ provide: Router, useValue: router },
SearchService
],
});
searchService = TestBed.get(SearchService);
});
searchService = TestBed.get(SearchService);
});

it('should return list view mode by default', () => {
searchService.getViewMode().subscribe((viewMode) => {
expect(viewMode).toBe(ViewMode.List);
it('should return list view mode', () => {
searchService.getViewMode().subscribe((viewMode) => {
expect(viewMode).toBe(ViewMode.List);
});
});
});
describe('', () => {
let searchService: SearchService;
const router = new RouterStub();
const route = new ActivatedRouteStub();
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CommonModule,
RouterTestingModule.withRoutes([
{ path: 'search', component: DummyComponent, pathMatch: 'full' },
])
],
declarations: [
DummyComponent
],
providers: [
{ provide: ItemDataService, useValue: {} },
{ provide: RouteService, useValue: {} },
{ provide: ResponseCacheService, useValue: {} },
{ provide: RequestService, useValue: {} },
{ provide: ActivatedRoute, useValue: route },
{ provide: RemoteDataBuildService, useValue: {} },
{ provide: GLOBAL_CONFIG, useValue: {} },
{ provide: Router, useValue: router },
SearchService
],
});
searchService = TestBed.get(SearchService);
});

it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => {
searchService.setViewMode(ViewMode.List);
expect(router.navigate).toHaveBeenCalledWith(['/search'], {
queryParams: { view: ViewMode.List },
queryParamsHandling: 'merge'
});
});

it('should return the view mode set through setViewMode', fakeAsync(() => {
searchService.setViewMode(ViewMode.Grid)
tick();
let viewMode = ViewMode.List;
searchService.getViewMode().subscribe((mode) => viewMode = mode);
expect(viewMode).toBe(ViewMode.Grid);
it('should call the navigate method on the Router with view mode grid parameter as a parameter when setViewMode is called', () => {
searchService.setViewMode(ViewMode.Grid);
expect(router.navigate).toHaveBeenCalledWith(['/search'], {
queryParams: { view: ViewMode.Grid },
queryParamsHandling: 'merge'
});
});

searchService.setViewMode(ViewMode.List)
tick();
searchService.getViewMode().subscribe((mode) => viewMode = mode);
expect(viewMode).toBe(ViewMode.List);
}));
it('should return ViewMode.List when the viewMode is set to ViewMode.List in the ActivatedRoute', () => {
let viewMode = ViewMode.Grid;
route.testParams = { view: ViewMode.List };
searchService.getViewMode().subscribe((mode) => viewMode = mode);
expect(viewMode).toEqual(ViewMode.List);
});

it('should return ViewMode.Grid when the viewMode is set to ViewMode.Grid in the ActivatedRoute', () => {
let viewMode = ViewMode.List;
route.testParams = { view: ViewMode.Grid };
searchService.getViewMode().subscribe((mode) => viewMode = mode);
expect(viewMode).toEqual(ViewMode.Grid);
});
});
});

0 comments on commit 4cdc1d4

Please sign in to comment.