test fixes

This commit is contained in:
Lotte Hofstede
2018-03-15 16:15:02 +01:00
parent e374f9ec1f
commit 6c2a249fdd
11 changed files with 164 additions and 100 deletions

View File

@@ -4,19 +4,12 @@ import { By } from '@angular/platform-browser';
import { MockTranslateLoader } from '../mocks/mock-translate-loader';
import { RouterTestingModule } from '@angular/router/testing';
import { Component } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { SearchService } from '../../+search-page/search-service/search.service';
import { ItemDataService } from './../../core/data/item-data.service';
import { ViewModeSwitchComponent } from './view-mode-switch.component';
import { ViewMode } from '../../+search-page/search-options.model';
import { RouteService } from '../route.service';
import { ResponseCacheService } from '../../core/cache/response-cache.service';
import { RequestService } from '../../core/data/request.service';
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
import { ActivatedRoute } from '@angular/router';
import { GLOBAL_CONFIG } from '../../../config';
import { ActivatedRouteStub } from '../testing/active-router-stub';
import { SearchServiceStub } from '../testing/search-service-stub';
@Component({ template: '' })
class DummyComponent { }
@@ -24,10 +17,9 @@ class DummyComponent { }
describe('ViewModeSwitchComponent', () => {
let comp: ViewModeSwitchComponent;
let fixture: ComponentFixture<ViewModeSwitchComponent>;
let searchService: SearchService;
const searchService = new SearchServiceStub();
let listButton: HTMLElement;
let gridButton: HTMLElement;
let route = new ActivatedRouteStub();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
@@ -46,15 +38,10 @@ describe('ViewModeSwitchComponent', () => {
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: {} },
SearchService
{ provide: SearchService, useValue: searchService },
],
}).overrideComponent(ViewModeSwitchComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents();
}));
@@ -65,12 +52,10 @@ describe('ViewModeSwitchComponent', () => {
const debugElements = fixture.debugElement.queryAll(By.css('a'));
listButton = debugElements[0].nativeElement;
gridButton = debugElements[1].nativeElement;
searchService = fixture.debugElement.injector.get(SearchService);
});
it('should set list button as active when on list mode', fakeAsync(() => {
searchService.setViewMode(ViewMode.List);
route = new ActivatedRouteStub([{view: ViewMode.List}])
tick();
fixture.detectChanges();
expect(comp.currentMode).toBe(ViewMode.List);
@@ -80,7 +65,6 @@ describe('ViewModeSwitchComponent', () => {
it('should set grid button as active when on grid mode', fakeAsync(() => {
searchService.setViewMode(ViewMode.Grid);
route = new ActivatedRouteStub([{view: ViewMode.Grid}])
tick();
fixture.detectChanges();
expect(comp.currentMode).toBe(ViewMode.Grid);