mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 04:53:06 +00:00
55693: CollectionItemMapperComponent test intermediate
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
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 {
|
export class ActivatedRouteStub {
|
||||||
|
|
||||||
private _testParams?: any;
|
private _testParams?: any;
|
||||||
|
private _testData?: any;
|
||||||
// ActivatedRoute.params is Observable
|
// ActivatedRoute.params is Observable
|
||||||
private subject?: BehaviorSubject<any> = new BehaviorSubject(this.testParams);
|
private subject?: BehaviorSubject<any> = new BehaviorSubject(this.testParams);
|
||||||
|
private dataSubject?: BehaviorSubject<any> = new BehaviorSubject(this.testData);
|
||||||
|
|
||||||
params = this.subject.asObservable();
|
params = this.subject.asObservable();
|
||||||
queryParams = this.subject.asObservable();
|
queryParams = this.subject.asObservable();
|
||||||
queryParamMap = this.subject.asObservable().map((params: Params) => convertToParamMap(params));
|
queryParamMap = this.subject.asObservable().map((params: Params) => convertToParamMap(params));
|
||||||
|
data = this.dataSubject.asObservable();
|
||||||
|
|
||||||
constructor(params?: Params) {
|
constructor(params?: Params, data?: any) {
|
||||||
if (params) {
|
if (params) {
|
||||||
this.testParams = params;
|
this.testParams = params;
|
||||||
} else {
|
} else {
|
||||||
this.testParams = {};
|
this.testParams = {};
|
||||||
}
|
}
|
||||||
|
if (data) {
|
||||||
|
this.testData = data;
|
||||||
|
} else {
|
||||||
|
this.testData = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test parameters
|
// Test parameters
|
||||||
@@ -30,6 +38,16 @@ export class ActivatedRouteStub {
|
|||||||
this.subject.next(params);
|
this.subject.next(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test data
|
||||||
|
get testData() {
|
||||||
|
return this._testParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
set testData(data: {}) {
|
||||||
|
this._testData = data;
|
||||||
|
this.dataSubject.next(data);
|
||||||
|
}
|
||||||
|
|
||||||
// ActivatedRoute.snapshot.params
|
// ActivatedRoute.snapshot.params
|
||||||
get snapshot() {
|
get snapshot() {
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user