mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
Fixed unit tests
This commit is contained in:
@@ -28,6 +28,7 @@ describe('MetadataFieldFormComponent', () => {
|
||||
const registryServiceStub = {
|
||||
getActiveMetadataField: () => observableOf(undefined),
|
||||
createOrUpdateMetadataField: (field: MetadataField) => observableOf(field),
|
||||
cancelEditMetadataField: () => {},
|
||||
cancelEditMetadataSchema: () => {},
|
||||
};
|
||||
const formBuilderServiceStub = {
|
||||
@@ -62,6 +63,11 @@ describe('MetadataFieldFormComponent', () => {
|
||||
registryService = s;
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
component = null;
|
||||
registryService = null
|
||||
})
|
||||
|
||||
describe('when submitting the form', () => {
|
||||
const element = 'fakeElement';
|
||||
const qualifier = 'fakeQualifier';
|
||||
|
@@ -17,7 +17,8 @@ import { Router } from '@angular/router';
|
||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||
import { SearchFacetFilterComponent } from './search-facet-filter.component';
|
||||
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
|
||||
import { SearchConfigurationService } from '../../../search-service/search-configuration.service';
|
||||
import { SearchConfigurationServiceStub } from '../../../../shared/testing/search-configuration-service-stub';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component';
|
||||
|
||||
describe('SearchFacetFilterComponent', () => {
|
||||
let comp: SearchFacetFilterComponent;
|
||||
@@ -69,7 +70,7 @@ describe('SearchFacetFilterComponent', () => {
|
||||
{ provide: Router, useValue: new RouterStub() },
|
||||
{ provide: FILTER_CONFIG, useValue: new SearchFilterConfig() },
|
||||
{ provide: RemoteDataBuildService, useValue: {aggregate: () => observableOf({})} },
|
||||
{ provide: SearchConfigurationService, useValue: {searchOptions: observableOf({})} },
|
||||
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
|
||||
{
|
||||
provide: SearchFilterService, useValue: {
|
||||
getSelectedValuesForFilter: () => observableOf(selectedValues),
|
||||
|
@@ -11,6 +11,8 @@ import { SearchFilterComponent } from './search-filter.component';
|
||||
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
|
||||
import { FilterType } from '../../search-service/filter-type.model';
|
||||
import { SearchConfigurationService } from '../../search-service/search-configuration.service';
|
||||
import { SearchConfigurationServiceStub } from '../../../shared/testing/search-configuration-service-stub';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
|
||||
|
||||
describe('SearchFilterComponent', () => {
|
||||
let comp: SearchFilterComponent;
|
||||
@@ -54,8 +56,6 @@ describe('SearchFilterComponent', () => {
|
||||
getFacetValuesFor: (filter) => mockResults
|
||||
};
|
||||
|
||||
const searchConfigServiceStub = {};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule],
|
||||
@@ -66,7 +66,7 @@ describe('SearchFilterComponent', () => {
|
||||
provide: SearchFilterService,
|
||||
useValue: mockFilterService
|
||||
},
|
||||
{ provide: SearchConfigurationService, useValue: searchConfigServiceStub },
|
||||
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(SearchFilterComponent, {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, Inject, Input, OnInit } from '@angular/core';
|
||||
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
import { filter, first, map, startWith, switchMap, take } from 'rxjs/operators';
|
||||
@@ -9,6 +9,7 @@ import { slide } from '../../../shared/animations/slide';
|
||||
import { isNotEmpty } from '../../../shared/empty.util';
|
||||
import { SearchService } from '../../search-service/search.service';
|
||||
import { SearchConfigurationService } from '../../search-service/search-configuration.service';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../../+my-dspace-page/my-dspace-page.component';
|
||||
|
||||
@Component({
|
||||
selector: 'ds-search-filter',
|
||||
@@ -46,7 +47,10 @@ export class SearchFilterComponent implements OnInit {
|
||||
*/
|
||||
active$: Observable<boolean>;
|
||||
|
||||
constructor(private filterService: SearchFilterService, private searchService: SearchService, private searchConfigService: SearchConfigurationService) {
|
||||
constructor(
|
||||
private filterService: SearchFilterService,
|
||||
private searchService: SearchService,
|
||||
@Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -14,6 +14,7 @@ import { SearchFilterConfig } from '../../search-service/search-filter-config.mo
|
||||
import { FilterType } from '../../search-service/filter-type.model';
|
||||
import { ActivatedRouteStub } from '../../../shared/testing/active-router-stub';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { routeServiceStub } from '../../../shared/testing/route-service-stub';
|
||||
|
||||
describe('SearchFilterService', () => {
|
||||
let service: SearchFilterService;
|
||||
@@ -34,24 +35,6 @@ describe('SearchFilterService', () => {
|
||||
select: observableOf(true)
|
||||
});
|
||||
|
||||
const routeServiceStub: any = {
|
||||
/* tslint:disable:no-empty */
|
||||
hasQueryParamWithValue: (param: string, value: string) => {
|
||||
},
|
||||
hasQueryParam: (param: string) => {
|
||||
},
|
||||
removeQueryParameterValue: (param: string, value: string) => {
|
||||
},
|
||||
addQueryParameterValue: (param: string, value: string) => {
|
||||
},
|
||||
getQueryParameterValues: (param: string) => {
|
||||
return observableOf({});
|
||||
},
|
||||
getQueryParamsWithPrefix: (param: string) => {
|
||||
return observableOf({});
|
||||
}
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
||||
const activatedRoute: any = new ActivatedRouteStub();
|
||||
const searchServiceStub: any = {
|
||||
uiSearchRoute: '/search'
|
||||
|
@@ -19,6 +19,8 @@ import { SearchRangeFilterComponent } from './search-range-filter.component';
|
||||
import { RouteService } from '../../../../shared/services/route.service';
|
||||
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
|
||||
import { SearchConfigurationService } from '../../../search-service/search-configuration.service';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../../../+my-dspace-page/my-dspace-page.component';
|
||||
import { SearchConfigurationServiceStub } from '../../../../shared/testing/search-configuration-service-stub';
|
||||
|
||||
describe('SearchRangeFilterComponent', () => {
|
||||
let comp: SearchRangeFilterComponent;
|
||||
@@ -76,9 +78,7 @@ describe('SearchRangeFilterComponent', () => {
|
||||
{ provide: FILTER_CONFIG, useValue: mockFilterConfig },
|
||||
{ provide: RemoteDataBuildService, useValue: {aggregate: () => observableOf({})} },
|
||||
{ provide: RouteService, useValue: {getQueryParameterValue: () => observableOf({})} },
|
||||
{ provide: SearchConfigurationService, useValue: {
|
||||
searchOptions: observableOf({}) }
|
||||
},
|
||||
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
|
||||
{
|
||||
provide: SearchFilterService, useValue: {
|
||||
getSelectedValuesForFilter: () => selectedValues,
|
||||
|
@@ -7,13 +7,15 @@ 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 { SearchConfigurationService } from '../search-service/search-configuration.service';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
|
||||
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service-stub';
|
||||
|
||||
describe('SearchFiltersComponent', () => {
|
||||
let comp: SearchFiltersComponent;
|
||||
let fixture: ComponentFixture<SearchFiltersComponent>;
|
||||
let searchService: SearchService;
|
||||
|
||||
const searchServiceStub = {
|
||||
/* tslint:disable:no-empty */
|
||||
getConfig: () =>
|
||||
@@ -30,17 +32,13 @@ describe('SearchFiltersComponent', () => {
|
||||
[]
|
||||
};
|
||||
|
||||
const searchConfigServiceStub = jasmine.createSpyObj('SearchConfigurationService', {
|
||||
getCurrentFrontendFilters: observableOf({})
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule],
|
||||
declarations: [SearchFiltersComponent],
|
||||
providers: [
|
||||
{ provide: SearchService, useValue: searchServiceStub },
|
||||
{ provide: SearchConfigurationService, useValue: searchConfigServiceStub },
|
||||
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() },
|
||||
{ provide: SearchFilterService, useValue: searchFiltersStub },
|
||||
|
||||
],
|
||||
|
@@ -40,8 +40,8 @@ export class SearchFiltersComponent implements OnInit {
|
||||
*/
|
||||
constructor(
|
||||
private searchService: SearchService,
|
||||
@Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService,
|
||||
private filterService: SearchFilterService) {
|
||||
private filterService: SearchFilterService,
|
||||
@Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) {
|
||||
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,8 @@ import { Observable, of as observableOf } from 'rxjs';
|
||||
import { Params } from '@angular/router';
|
||||
import { ObjectKeysPipe } from '../../shared/utils/object-keys-pipe';
|
||||
import { SearchConfigurationService } from '../search-service/search-configuration.service';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
|
||||
import { SearchConfigurationServiceStub } from '../../shared/testing/search-configuration-service-stub';
|
||||
|
||||
describe('SearchLabelsComponent', () => {
|
||||
let comp: SearchLabelsComponent;
|
||||
@@ -35,7 +37,8 @@ describe('SearchLabelsComponent', () => {
|
||||
declarations: [SearchLabelsComponent, ObjectKeysPipe],
|
||||
providers: [
|
||||
{ provide: SearchService, useValue: new SearchServiceStub(searchLink) },
|
||||
{ provide: SearchConfigurationService, useValue: {getCurrentFrontendFilters : () => observableOf({})} }
|
||||
{ provide: SEARCH_CONFIG_SERVICE, useValue: new SearchConfigurationServiceStub() }
|
||||
// { provide: SearchConfigurationService, useValue: {getCurrentFrontendFilters : () => observableOf({})} }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(SearchLabelsComponent, {
|
||||
|
@@ -4,7 +4,7 @@ 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 { cold } from 'jasmine-marbles';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
|
||||
import { CommunityDataService } from '../core/data/community-data.service';
|
||||
@@ -20,11 +20,17 @@ import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
||||
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
|
||||
import { SearchConfigurationService } from './search-service/search-configuration.service';
|
||||
import { RemoteData } from '../core/data/remote-data';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../+my-dspace-page/my-dspace-page.component';
|
||||
import { RouteService } from '../shared/services/route.service';
|
||||
import { routeServiceStub } from '../shared/testing/route-service-stub';
|
||||
import { SearchConfigurationServiceStub } from '../shared/testing/search-configuration-service-stub';
|
||||
import { PaginatedSearchOptions } from './paginated-search-options.model';
|
||||
|
||||
describe('SearchPageComponent', () => {
|
||||
let comp: SearchPageComponent;
|
||||
let fixture: ComponentFixture<SearchPageComponent>;
|
||||
let searchServiceObject: SearchService;
|
||||
let searchConfigurationServiceObject: SearchConfigurationService;
|
||||
const store: Store<SearchPageComponent> = jasmine.createSpyObj('store', {
|
||||
/* tslint:disable:no-empty */
|
||||
dispatch: {},
|
||||
@@ -42,15 +48,23 @@ describe('SearchPageComponent', () => {
|
||||
getSearchLink: '/search',
|
||||
getScopes: observableOf(['test-scope'])
|
||||
});
|
||||
const configurationParam = 'default';
|
||||
const queryParam = 'test query';
|
||||
const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f';
|
||||
const paginatedSearchOptions = {
|
||||
const paginatedSearchOptions = new PaginatedSearchOptions({
|
||||
configuration: configurationParam,
|
||||
query: queryParam,
|
||||
scope: scopeParam,
|
||||
pagination,
|
||||
sort
|
||||
};
|
||||
});
|
||||
const activatedRouteStub = {
|
||||
snapshot: {
|
||||
queryParamMap: new Map([
|
||||
['query', queryParam],
|
||||
['scope', scopeParam]
|
||||
])
|
||||
},
|
||||
queryParams: observableOf({
|
||||
query: queryParam,
|
||||
scope: scopeParam
|
||||
@@ -73,6 +87,7 @@ describe('SearchPageComponent', () => {
|
||||
useValue: jasmine.createSpyObj('communityService', ['findById', 'findAll'])
|
||||
},
|
||||
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{
|
||||
provide: Store, useValue: store
|
||||
},
|
||||
@@ -92,13 +107,8 @@ describe('SearchPageComponent', () => {
|
||||
provide: SearchFilterService,
|
||||
useValue: {}
|
||||
}, {
|
||||
provide: SearchConfigurationService,
|
||||
useValue: {
|
||||
paginatedSearchOptions: hot('a', {
|
||||
a: paginatedSearchOptions
|
||||
}),
|
||||
getCurrentScope: (a) => observableOf('test-id')
|
||||
}
|
||||
provide: SEARCH_CONFIG_SERVICE,
|
||||
useValue: new SearchConfigurationServiceStub()
|
||||
},
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
@@ -112,25 +122,21 @@ describe('SearchPageComponent', () => {
|
||||
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||
fixture.detectChanges();
|
||||
searchServiceObject = (comp as any).service;
|
||||
searchConfigurationServiceObject = (comp as any).searchConfigService;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
comp = null;
|
||||
searchServiceObject = null;
|
||||
searchConfigurationServiceObject = null;
|
||||
});
|
||||
|
||||
it('should get the scope and query from the route parameters', () => {
|
||||
|
||||
searchConfigurationServiceObject.paginatedSearchOptions.next(paginatedSearchOptions);
|
||||
expect(comp.searchOptions$).toBeObservable(cold('b', {
|
||||
b: paginatedSearchOptions
|
||||
}));
|
||||
});
|
||||
|
||||
describe('when the closeSidebar event is emitted clicked in mobile view', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(comp, 'closeSidebar');
|
||||
const closeSidebarButton = fixture.debugElement.query(By.css('#search-sidebar-sm'));
|
||||
closeSidebarButton.triggerEventHandler('toggleSidebar', null);
|
||||
});
|
||||
|
||||
it('should trigger the closeSidebar function', () => {
|
||||
expect(comp.closeSidebar).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -177,4 +183,4 @@ describe('SearchPageComponent', () => {
|
||||
});
|
||||
|
||||
});
|
||||
})
|
||||
});
|
||||
|
@@ -53,7 +53,7 @@ export class SearchPageComponent implements OnInit {
|
||||
/**
|
||||
* The current relevant scopes
|
||||
*/
|
||||
scopeListRD$: Observable<DSpaceObject[]>;
|
||||
scopeListRD$: Observable<DSpaceObject[]> = new BehaviorSubject(null);
|
||||
|
||||
/**
|
||||
* Emits true if were on a small screen
|
||||
@@ -86,9 +86,9 @@ export class SearchPageComponent implements OnInit {
|
||||
.subscribe((results) => {
|
||||
this.resultsRD$.next(results);
|
||||
});
|
||||
this.scopeListRD$ = this.searchConfigService.getCurrentScope('').pipe(
|
||||
/* this.scopeListRD$ = this.searchConfigService.getCurrentScope('').pipe(
|
||||
switchMap((scopeId) => this.service.getScopes(scopeId))
|
||||
);
|
||||
);*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -87,8 +87,8 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
.pipe(getSucceededRemoteData())
|
||||
.subscribe((defRD) => {
|
||||
const defs = defRD.payload;
|
||||
this.paginatedSearchOptions = new BehaviorSubject<SearchOptions>(defs);
|
||||
this.searchOptions = new BehaviorSubject<PaginatedSearchOptions>(defs);
|
||||
this.paginatedSearchOptions = new BehaviorSubject<PaginatedSearchOptions>(defs);
|
||||
this.searchOptions = new BehaviorSubject<SearchOptions>(defs);
|
||||
|
||||
this.subs.push(this.subscribeToSearchOptions(defs));
|
||||
this.subs.push(this.subscribeToPaginatedSearchOptions(defs));
|
||||
@@ -129,7 +129,7 @@ export class SearchConfigurationService implements OnDestroy {
|
||||
*/
|
||||
getCurrentDSOType(): Observable<DSpaceObjectType> {
|
||||
return this.routeService.getQueryParameterValue('dsoType').pipe(
|
||||
filter((type) => hasValue(type) && hasValue(DSpaceObjectType[type.toUpperCase()])),
|
||||
filter((type) => isNotEmpty(type) && hasValue(DSpaceObjectType[type.toUpperCase()])),
|
||||
map((type) => DSpaceObjectType[type.toUpperCase()]),);
|
||||
}
|
||||
|
||||
|
@@ -6,27 +6,25 @@ import { Component } from '@angular/core';
|
||||
|
||||
import { SearchService } from './search.service';
|
||||
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
||||
import { ActivatedRoute, Router, UrlTree } from '@angular/router';
|
||||
import { Router, UrlTree } from '@angular/router';
|
||||
import { RequestService } from '../../core/data/request.service';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
import { RouterStub } from '../../shared/testing/router-stub';
|
||||
import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||
import { Observable, combineLatest as observableCombineLatest } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
|
||||
import { PaginatedSearchOptions } from '../paginated-search-options.model';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { RequestEntry } from '../../core/data/request.reducer';
|
||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||
import {
|
||||
FacetConfigSuccessResponse,
|
||||
SearchSuccessResponse
|
||||
} from '../../core/cache/response.models';
|
||||
import { FacetConfigSuccessResponse, SearchSuccessResponse } from '../../core/cache/response.models';
|
||||
import { SearchQueryResponse } from './search-query-response.model';
|
||||
import { SearchFilterConfig } from './search-filter-config.model';
|
||||
import { CommunityDataService } from '../../core/data/community-data.service';
|
||||
import { ViewMode } from '../../core/shared/view-mode.model';
|
||||
import { DSpaceObjectDataService } from '../../core/data/dspace-object-data.service';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { RouteService } from '../../shared/services/route.service';
|
||||
import { routeServiceStub } from '../../shared/testing/route-service-stub';
|
||||
|
||||
@Component({ template: '' })
|
||||
class DummyComponent {
|
||||
@@ -50,7 +48,7 @@ describe('SearchService', () => {
|
||||
],
|
||||
providers: [
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: RequestService, useValue: getMockRequestService() },
|
||||
{ provide: RemoteDataBuildService, useValue: {} },
|
||||
{ provide: HALEndpointService, useValue: {} },
|
||||
@@ -71,7 +69,7 @@ describe('SearchService', () => {
|
||||
describe('', () => {
|
||||
let searchService: SearchService;
|
||||
const router = new RouterStub();
|
||||
const route = new ActivatedRouteStub();
|
||||
let routeService;
|
||||
|
||||
const halService = {
|
||||
/* tslint:disable:no-empty */
|
||||
@@ -107,7 +105,7 @@ describe('SearchService', () => {
|
||||
],
|
||||
providers: [
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: RequestService, useValue: getMockRequestService() },
|
||||
{ provide: RemoteDataBuildService, useValue: remoteDataBuildService },
|
||||
{ provide: HALEndpointService, useValue: halService },
|
||||
@@ -117,6 +115,7 @@ describe('SearchService', () => {
|
||||
],
|
||||
});
|
||||
searchService = TestBed.get(SearchService);
|
||||
routeService = TestBed.get(RouteService);
|
||||
const urlTree = Object.assign(new UrlTree(), { root: { children: { primary: 'search' } } });
|
||||
router.parseUrl.and.returnValue(urlTree);
|
||||
});
|
||||
@@ -139,14 +138,19 @@ describe('SearchService', () => {
|
||||
|
||||
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 };
|
||||
spyOn(routeService, 'getQueryParamMap').and.returnValue(observableOf(new Map([
|
||||
[ '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 };
|
||||
spyOn(routeService, 'getQueryParamMap').and.returnValue(observableOf(new Map([
|
||||
[ 'view', ViewMode.Grid ],
|
||||
])));
|
||||
searchService.getViewMode().subscribe((mode) => viewMode = mode);
|
||||
expect(viewMode).toEqual(ViewMode.Grid);
|
||||
});
|
||||
|
@@ -74,7 +74,6 @@ export class SearchService implements OnDestroy {
|
||||
private sub;
|
||||
|
||||
constructor(private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private routeService: RouteService,
|
||||
protected requestService: RequestService,
|
||||
private rdb: RemoteDataBuildService,
|
||||
|
@@ -14,8 +14,8 @@ import { By } from '@angular/platform-browser';
|
||||
import { SearchFilterService } from '../search-filters/search-filter/search-filter.service';
|
||||
import { hot } from 'jasmine-marbles';
|
||||
import { VarDirective } from '../../shared/utils/var.directive';
|
||||
import { SearchConfigurationService } from '../search-service/search-configuration.service';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { SEARCH_CONFIG_SERVICE } from '../../+my-dspace-page/my-dspace-page.component';
|
||||
|
||||
describe('SearchSettingsComponent', () => {
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('SearchSettingsComponent', () => {
|
||||
useValue: {}
|
||||
},
|
||||
{
|
||||
provide: SearchConfigurationService,
|
||||
provide: SEARCH_CONFIG_SERVICE,
|
||||
useValue: {
|
||||
paginatedSearchOptions: hot('a', {
|
||||
a: paginatedSearchOptions
|
||||
|
@@ -228,8 +228,8 @@ describe('AuthNavMenuComponent', () => {
|
||||
fixture.destroy();
|
||||
component = null;
|
||||
});
|
||||
it('should render logout dropdown menu', () => {
|
||||
const logoutDropdownMenu = deNavMenuItem.query(By.css('ul[id=logoutDropdownMenu]'));
|
||||
it('should render UserMenuComponent component', () => {
|
||||
const logoutDropdownMenu = deNavMenuItem.query(By.css('ds-user-menu'));
|
||||
expect(logoutDropdownMenu.nativeElement).toBeDefined();
|
||||
});
|
||||
})
|
||||
|
@@ -4,7 +4,10 @@ export class MockRouter {
|
||||
public events = observableOf({});
|
||||
public routerState = {
|
||||
snapshot: {
|
||||
url: ''
|
||||
url: '',
|
||||
root: {
|
||||
queryParamMap: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -15,4 +18,8 @@ export class MockRouter {
|
||||
setRoute(route) {
|
||||
this.routerState.snapshot.url = route;
|
||||
}
|
||||
|
||||
setParams(paramsMap) {
|
||||
this.routerState.snapshot.root.queryParamMap = paramsMap;
|
||||
}
|
||||
}
|
||||
|
@@ -262,7 +262,7 @@ describe('Pagination component', () => {
|
||||
|
||||
changePage(testFixture, 3);
|
||||
tick();
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 'ASC', sortField: 'dc.title' }, queryParamsHandling: 'merge' });
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: '3', pageSize: 10, sortDirection: 'ASC', sortField: 'dc.title' }, queryParamsHandling: 'merge' });
|
||||
|
||||
}));
|
||||
|
||||
|
@@ -29,6 +29,9 @@ describe('RouteService', () => {
|
||||
select: jasmine.createSpy('select')
|
||||
});
|
||||
|
||||
const router = new MockRouter();
|
||||
router.setParams(convertToParamMap(paramObject));
|
||||
|
||||
paramObject[paramName1] = paramValue1;
|
||||
paramObject[paramName2] = [paramValue2a, paramValue2b];
|
||||
|
||||
@@ -42,7 +45,7 @@ describe('RouteService', () => {
|
||||
queryParamMap: observableOf(convertToParamMap(paramObject))
|
||||
},
|
||||
},
|
||||
{ provide: Router, useValue: new MockRouter() },
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: Store, useValue: store },
|
||||
]
|
||||
});
|
||||
|
26
src/app/shared/testing/route-service-stub.ts
Normal file
26
src/app/shared/testing/route-service-stub.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||
|
||||
export const routeServiceStub: any = {
|
||||
/* tslint:disable:no-empty */
|
||||
hasQueryParamWithValue: (param: string, value: string) => {
|
||||
},
|
||||
hasQueryParam: (param: string) => {
|
||||
},
|
||||
removeQueryParameterValue: (param: string, value: string) => {
|
||||
},
|
||||
addQueryParameterValue: (param: string, value: string) => {
|
||||
},
|
||||
getQueryParameterValues: (param: string) => {
|
||||
return observableOf({});
|
||||
},
|
||||
getQueryParamsWithPrefix: (param: string) => {
|
||||
return observableOf({});
|
||||
},
|
||||
getQueryParamMap: () => {
|
||||
return observableOf(new Map())
|
||||
},
|
||||
getQueryParameterValue: () => {
|
||||
return observableOf({})
|
||||
}
|
||||
/* tslint:enable:no-empty */
|
||||
};
|
16
src/app/shared/testing/search-configuration-service-stub.ts
Normal file
16
src/app/shared/testing/search-configuration-service-stub.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { BehaviorSubject, of as observableOf } from 'rxjs';
|
||||
|
||||
export class SearchConfigurationServiceStub {
|
||||
|
||||
private searchOptions: BehaviorSubject<any> = new BehaviorSubject<any>({});
|
||||
private paginatedSearchOptions: BehaviorSubject<any> = new BehaviorSubject<any>({});
|
||||
|
||||
getCurrentFrontendFilters() {
|
||||
return observableOf([]);
|
||||
}
|
||||
|
||||
getCurrentScope(a) {
|
||||
return observableOf('test-id')
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user