mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Add tests for SearchService
This commit is contained in:
56
src/app/+search-page/search-service/search.service.spec.ts
Normal file
56
src/app/+search-page/search-service/search.service.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { SearchService } from './search.service';
|
||||||
|
import { ItemDataService } from './../../core/data/item-data.service';
|
||||||
|
import { ViewMode } from '../../+search-page/search-options.model';
|
||||||
|
|
||||||
|
@Component({ template: '' })
|
||||||
|
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: {} },
|
||||||
|
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 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);
|
||||||
|
|
||||||
|
searchService.setViewMode(ViewMode.List)
|
||||||
|
tick();
|
||||||
|
searchService.getViewMode().subscribe((mode) => viewMode = mode);
|
||||||
|
expect(viewMode).toBe(ViewMode.List);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
Reference in New Issue
Block a user