mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
45621: adding more tests
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
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 { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { SearchFacetFilterComponent } from './search-facet-filter.component';
|
||||||
|
import { SearchFilterService } from '../search-filter.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
describe('SearchFacetFilterComponent', () => {
|
||||||
|
let comp: SearchFacetFilterComponent;
|
||||||
|
let fixture: ComponentFixture<SearchFacetFilterComponent>;
|
||||||
|
const filterService: Store<SearchFilterService> = jasmine.createSpyObj('filterService', {
|
||||||
|
isFilterActiveWithValue: (paramName: string, filterValue: string) => true,
|
||||||
|
getQueryParamsWith: (paramName: string, filterValue: string) => '',
|
||||||
|
getQueryParamsWithout: (paramName: string, filterValue: string) => '',
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule],
|
||||||
|
declarations: [SearchFacetFilterComponent],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: Router, useValue: {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: SearchFilterService,
|
||||||
|
useValue: filterService
|
||||||
|
},
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(SearchFacetFilterComponent, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SearchFacetFilterComponent);
|
||||||
|
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -18,7 +18,7 @@ import { isNotEmpty } from '../../../../shared/empty.util';
|
|||||||
templateUrl: './search-facet-filter.component.html',
|
templateUrl: './search-facet-filter.component.html',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class SidebarFacetFilterComponent implements OnInit {
|
export class SearchFacetFilterComponent implements OnInit {
|
||||||
@Input() filterValues: FacetValue[];
|
@Input() filterValues: FacetValue[];
|
||||||
@Input() filterConfig: SearchFilterConfig;
|
@Input() filterConfig: SearchFilterConfig;
|
||||||
@Input() selectedValues: string[];
|
@Input() selectedValues: string[];
|
||||||
|
@@ -0,0 +1,113 @@
|
|||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
|
||||||
|
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 { Observable } from 'rxjs/Observable';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { SearchFilterService } from './search-filter.service';
|
||||||
|
import { SearchService } from '../../search-service/search.service';
|
||||||
|
import { SearchFilterComponent } from './search-filter.component';
|
||||||
|
import { SearchFilterConfig } from '../../search-service/search-filter-config.model';
|
||||||
|
import { FilterType } from '../../search-service/filter-type.model';
|
||||||
|
|
||||||
|
describe('SearchFilterComponent', () => {
|
||||||
|
let comp: SearchFilterComponent;
|
||||||
|
let fixture: ComponentFixture<SearchFilterComponent>;
|
||||||
|
const filterName = 'test name'
|
||||||
|
const mockFilterConfig: SearchFilterConfig = Object.assign(new SearchFilterConfig(), {
|
||||||
|
name: filterName,
|
||||||
|
type: FilterType.text,
|
||||||
|
hasFacets: false,
|
||||||
|
isOpenByDefault: false
|
||||||
|
});
|
||||||
|
const mockFilterService = {
|
||||||
|
/* tslint:disable:no-empty */
|
||||||
|
toggle: (filter) => {
|
||||||
|
},
|
||||||
|
collapse: (filter) => {
|
||||||
|
},
|
||||||
|
expand: (filter) => {
|
||||||
|
},
|
||||||
|
initialCollapse: (filter) => {
|
||||||
|
},
|
||||||
|
initialExpand: (filter) => {
|
||||||
|
},
|
||||||
|
getSelectedValuesForFilter: (filter) => {
|
||||||
|
},
|
||||||
|
isFilterActive: (filter) => {
|
||||||
|
return Observable.of(true)
|
||||||
|
},
|
||||||
|
isCollapsed: (filter) => {
|
||||||
|
return Observable.of(true)
|
||||||
|
}
|
||||||
|
/* tslint:enable:no-empty */
|
||||||
|
|
||||||
|
};
|
||||||
|
let filterService;
|
||||||
|
const mockResults = Observable.of(['test', 'data']);
|
||||||
|
const searchServiceStub = {
|
||||||
|
getFacetValuesFor: (filter) => mockResults
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NoopAnimationsModule],
|
||||||
|
declarations: [SearchFilterComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: SearchService, useValue: searchServiceStub },
|
||||||
|
{
|
||||||
|
provide: SearchFilterService,
|
||||||
|
useValue: mockFilterService
|
||||||
|
},
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(SearchFilterComponent, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(SearchFilterComponent);
|
||||||
|
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||||
|
comp.filter = mockFilterConfig;
|
||||||
|
fixture.detectChanges();
|
||||||
|
filterService = (comp as any).filterService;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the toggle method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(filterService, 'toggle');
|
||||||
|
comp.toggle();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call toggle with the correct filter configuration name', () => {
|
||||||
|
expect(filterService.toggle).toHaveBeenCalledWith(mockFilterConfig.name)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the initialCollapse method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(filterService, 'initialCollapse');
|
||||||
|
comp.initialCollapse();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call initialCollapse with the correct filter configuration name', () => {
|
||||||
|
expect(filterService.initialCollapse).toHaveBeenCalledWith(mockFilterConfig.name)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the initialExpand method is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(filterService, 'initialExpand');
|
||||||
|
comp.initialExpand();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call initialCollapse with the correct filter configuration name', () => {
|
||||||
|
expect(filterService.initialExpand).toHaveBeenCalledWith(mockFilterConfig.name)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
@@ -22,7 +22,7 @@ import { first } from 'rxjs/operator/first';
|
|||||||
animations: [slide],
|
animations: [slide],
|
||||||
})
|
})
|
||||||
|
|
||||||
export class SidebarFilterComponent implements OnInit {
|
export class SearchFilterComponent implements OnInit {
|
||||||
@Input() filter: SearchFilterConfig;
|
@Input() filter: SearchFilterConfig;
|
||||||
filterValues: Observable<RemoteData<FacetValue[]>>;
|
filterValues: Observable<RemoteData<FacetValue[]>>;
|
||||||
|
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { async, TestBed } from '@angular/core/testing';
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { SearchFilterService } from './search-filter.service';
|
import { SearchFilterService } from './search-filter.service';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@@ -22,7 +21,7 @@ describe('SearchFilterService', () => {
|
|||||||
select: Observable.of(true)
|
select: Observable.of(true)
|
||||||
});
|
});
|
||||||
const routeService = new RouteService(null);
|
const routeService = new RouteService(null);
|
||||||
const searchService = new SearchService(null, null, null)
|
const searchService = new SearchService(null, null, null, null)
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
service = new SearchFilterService(store, routeService, searchService);
|
service = new SearchFilterService(store, routeService, searchService);
|
||||||
|
@@ -16,7 +16,7 @@ import { Observable } from 'rxjs/Observable';
|
|||||||
templateUrl: './search-filters.component.html',
|
templateUrl: './search-filters.component.html',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class SidebarFiltersComponent {
|
export class SearchFiltersComponent {
|
||||||
filters: Observable<RemoteData<SearchFilterConfig[]>>;
|
filters: Observable<RemoteData<SearchFilterConfig[]>>;
|
||||||
constructor(private searchService: SearchService) {
|
constructor(private searchService: SearchService) {
|
||||||
this.filters = searchService.getConfig();
|
this.filters = searchService.getConfig();
|
||||||
|
@@ -1,13 +1,11 @@
|
|||||||
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { SortOptions } from '../core/cache/models/sort-options.model';
|
|
||||||
import { CommunityDataService } from '../core/data/community-data.service';
|
import { CommunityDataService } from '../core/data/community-data.service';
|
||||||
import { RemoteData } from '../core/data/remote-data';
|
import { RemoteData } from '../core/data/remote-data';
|
||||||
import { Community } from '../core/shared/community.model';
|
import { Community } from '../core/shared/community.model';
|
||||||
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../core/shared/dspace-object.model';
|
||||||
import { isNotEmpty } from '../shared/empty.util';
|
import { isNotEmpty } from '../shared/empty.util';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.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';
|
||||||
import { SearchService } from './search-service/search.service';
|
import { SearchService } from './search-service/search.service';
|
||||||
|
@@ -13,9 +13,9 @@ import { SearchSidebarService } from './search-sidebar/search-sidebar.service';
|
|||||||
import { SearchSidebarEffects } from './search-sidebar/search-sidebar.effects';
|
import { SearchSidebarEffects } from './search-sidebar/search-sidebar.effects';
|
||||||
import { SearchSettingsComponent } from './search-settings/search-settings.component';
|
import { SearchSettingsComponent } from './search-settings/search-settings.component';
|
||||||
import { EffectsModule } from '@ngrx/effects';
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
import { SidebarFiltersComponent } from './search-filters/search-filters.component';
|
import { SearchFiltersComponent } from './search-filters/search-filters.component';
|
||||||
import { SidebarFilterComponent } from './search-filters/search-filter/search-filter.component';
|
import { SearchFilterComponent } from './search-filters/search-filter/search-filter.component';
|
||||||
import { SidebarFacetFilterComponent } from './search-filters/search-filter/search-facet-filter/search-facet-filter.component';
|
import { SearchFacetFilterComponent } from './search-filters/search-filter/search-facet-filter/search-facet-filter.component';
|
||||||
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
|
import { SearchFilterService } from './search-filters/search-filter/search-filter.service';
|
||||||
|
|
||||||
const effects = [
|
const effects = [
|
||||||
@@ -37,9 +37,9 @@ const effects = [
|
|||||||
ItemSearchResultListElementComponent,
|
ItemSearchResultListElementComponent,
|
||||||
CollectionSearchResultListElementComponent,
|
CollectionSearchResultListElementComponent,
|
||||||
CommunitySearchResultListElementComponent,
|
CommunitySearchResultListElementComponent,
|
||||||
SidebarFiltersComponent,
|
SearchFiltersComponent,
|
||||||
SidebarFilterComponent,
|
SearchFilterComponent,
|
||||||
SidebarFacetFilterComponent
|
SearchFacetFilterComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
SearchService,
|
SearchService,
|
||||||
|
@@ -7,6 +7,7 @@ import { Component } from '@angular/core';
|
|||||||
import { SearchService } from './search.service';
|
import { SearchService } from './search.service';
|
||||||
import { ItemDataService } from './../../core/data/item-data.service';
|
import { ItemDataService } from './../../core/data/item-data.service';
|
||||||
import { ViewMode } from '../../+search-page/search-options.model';
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
|
import { RouteService } from '../../shared/route.service';
|
||||||
|
|
||||||
@Component({ template: '' })
|
@Component({ template: '' })
|
||||||
class DummyComponent { }
|
class DummyComponent { }
|
||||||
@@ -27,6 +28,7 @@ describe('SearchService', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: ItemDataService, useValue: {} },
|
{ provide: ItemDataService, useValue: {} },
|
||||||
|
{ provide: RouteService, useValue: {} },
|
||||||
SearchService
|
SearchService
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@@ -231,9 +231,9 @@ export class SearchService implements OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getViewMode(): Observable<ViewMode> {
|
getViewMode(): Observable<ViewMode> {
|
||||||
return this.routeService.getQueryParameterValue('view').map((value) => {
|
return this.route.queryParams.map((params) => {
|
||||||
if (hasValue(value)) {
|
if (isNotEmpty(params.view) && hasValue(params.view)) {
|
||||||
return value as ViewMode;
|
return params.view;
|
||||||
} else {
|
} else {
|
||||||
return ViewMode.List;
|
return ViewMode.List;
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import { SearchSidebarEffects } from './search-sidebar.effects';
|
|||||||
describe('SearchSidebarEffects', () => {
|
describe('SearchSidebarEffects', () => {
|
||||||
let sidebarEffects: SearchSidebarEffects;
|
let sidebarEffects: SearchSidebarEffects;
|
||||||
let actions: Observable<any>;
|
let actions: Observable<any>;
|
||||||
|
const dummyURL = 'http://f4fb15e2-1bd3-4e63-8d0d-486ad8bc714a';
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -24,13 +25,12 @@ describe('SearchSidebarEffects', () => {
|
|||||||
|
|
||||||
describe('routeChange$', () => {
|
describe('routeChange$', () => {
|
||||||
|
|
||||||
it('should return a COLLAPSE action in response to an UPDATE_LOCATION action', () => {
|
it('should return a COLLAPSE action in response to an UPDATE_LOCATION action to a new route', () => {
|
||||||
actions = hot('--a-', { a: { type: fromRouter.ROUTER_NAVIGATION } });
|
actions = hot('--a-', { a: { type: fromRouter.ROUTER_NAVIGATION, payload: {routerState: {url: dummyURL}} } });
|
||||||
|
|
||||||
const expected = cold('--b-', { b: new SearchSidebarCollapseAction() });
|
const expected = cold('--b-', { b: new SearchSidebarCollapseAction() });
|
||||||
|
|
||||||
expect(sidebarEffects.routeChange$).toBeObservable(expected);
|
expect(sidebarEffects.routeChange$).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,4 +1,3 @@
|
|||||||
import { DebugElement } from '@angular/core';
|
|
||||||
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
||||||
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
@@ -6,12 +5,12 @@ import { MockTranslateLoader } from '../mocks/mock-translate-loader';
|
|||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
|
|
||||||
import { SearchService } from '../../+search-page/search-service/search.service';
|
import { SearchService } from '../../+search-page/search-service/search.service';
|
||||||
import { ItemDataService } from './../../core/data/item-data.service';
|
import { ItemDataService } from './../../core/data/item-data.service';
|
||||||
import { ViewModeSwitchComponent } from './view-mode-switch.component';
|
import { ViewModeSwitchComponent } from './view-mode-switch.component';
|
||||||
import { ViewMode } from '../../+search-page/search-options.model';
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
|
import { RouteService } from '../route.service';
|
||||||
|
|
||||||
@Component({ template: '' })
|
@Component({ template: '' })
|
||||||
class DummyComponent { }
|
class DummyComponent { }
|
||||||
@@ -42,6 +41,7 @@ describe('ViewModeSwitchComponent', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: ItemDataService, useValue: {} },
|
{ provide: ItemDataService, useValue: {} },
|
||||||
|
{ provide: RouteService, useValue: {} },
|
||||||
SearchService
|
SearchService
|
||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
Reference in New Issue
Block a user