Skip to content
Snippets Groups Projects
Commit e1c734e1 authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

55693: CollectionItemMapperComponent test intermediate

parent 0a8a6bb7
No related branches found
No related tags found
No related merge requests found
import { CollectionItemMapperComponent } from './collection-item-mapper.component';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { SearchFormComponent } from '../../shared/search-form/search-form.component';
import { SearchPageModule } from '../../+search-page/search-page.module';
import { ObjectCollectionComponent } from '../../shared/object-collection/object-collection.component';
import { ItemSelectComponent } from '../../shared/item-select/item-select.component';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
import { RouterStub } from '../../shared/testing/router-stub';
import { SearchConfigurationService } from '../../+search-page/search-service/search-configuration.service';
import { SearchService } from '../../+search-page/search-service/search.service';
import { SearchServiceStub } from '../../shared/testing/search-service-stub';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
import { ItemDataService } from '../../core/data/item-data.service';
import { FormsModule } from '@angular/forms';
import { SharedModule } from '../../shared/shared.module';
import { Collection } from '../../core/shared/collection.model';
fdescribe('CollectionItemMapperComponent', () => {
let comp: CollectionItemMapperComponent;
let fixture: ComponentFixture<CollectionItemMapperComponent>;
let route: ActivatedRoute;
let router: Router;
let searchConfigService: SearchConfigurationService;
let searchService: SearchService;
let notificationsService: NotificationsService;
let itemDataService: ItemDataService;
const searchConfigServiceStub = {
};
const itemDataServiceStub = {
};
const mockCollection: Collection = Object.assign(new Collection(), {
metadata: [
{
key: 'dc.title',
language: 'en_US',
value: 'Test title'
}]
});
const activatedRouteStub = new ActivatedRouteStub({}, { collection: mockCollection });
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [CommonModule, FormsModule, SharedModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule.forRoot()],
declarations: [CollectionItemMapperComponent],
providers: [
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useValue: new RouterStub() },
{ provide: SearchConfigurationService, useValue: searchConfigServiceStub },
{ provide: SearchService, useValue: new SearchServiceStub() },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: ItemDataService, useValue: itemDataServiceStub },
{ provide: TranslateService, useValue: {} }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CollectionItemMapperComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
route = (comp as any).route;
router = (comp as any).router;
searchConfigService = (comp as any).searchConfigService;
searchService = (comp as any).searchService;
notificationsService = (comp as any).notificationsService;
itemDataService = (comp as any).itemDataService;
});
it('should test', () => {
});
});
......@@ -5,19 +5,27 @@ import { BehaviorSubject } from 'rxjs/BehaviorSubject';
export class ActivatedRouteStub {
private _testParams?: any;
private _testData?: any;
// ActivatedRoute.params is Observable
private subject?: BehaviorSubject<any> = new BehaviorSubject(this.testParams);
private dataSubject?: BehaviorSubject<any> = new BehaviorSubject(this.testData);
params = this.subject.asObservable();
queryParams = this.subject.asObservable();
queryParamMap = this.subject.asObservable().map((params: Params) => convertToParamMap(params));
data = this.dataSubject.asObservable();
constructor(params?: Params) {
constructor(params?: Params, data?: any) {
if (params) {
this.testParams = params;
} else {
this.testParams = {};
}
if (data) {
this.testData = data;
} else {
this.testData = {};
}
}
// Test parameters
......@@ -30,6 +38,16 @@ export class ActivatedRouteStub {
this.subject.next(params);
}
// Test data
get testData() {
return this._testParams;
}
set testData(data: {}) {
this._testData = data;
this.dataSubject.next(data);
}
// ActivatedRoute.snapshot.params
get snapshot() {
return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment