mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
[CST-5339] Tests (WIP)
This commit is contained in:
@@ -0,0 +1,89 @@
|
|||||||
|
import { OrcidQueueComponent } from './orcid-queue.component';
|
||||||
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { TranslateLoaderMock } from '../../../shared/mocks/translate-loader.mock';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { OrcidQueueService } from '../../../core/orcid/orcid-queue.service';
|
||||||
|
import { PaginationService } from '../../../core/pagination/pagination.service';
|
||||||
|
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
|
import { OrcidHistoryService } from '../../../core/orcid/orcid-history.service';
|
||||||
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
|
import { ActivatedRouteStub } from '../../../shared/testing/active-router.stub';
|
||||||
|
import { OrcidQueue } from '../../../core/orcid/model/orcid-queue.model';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
|
import { createPaginatedList } from '../../../shared/testing/utils.test';
|
||||||
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
|
|
||||||
|
fdescribe('OrcidQueueComponent test suite', () => {
|
||||||
|
let comp: OrcidQueueComponent;
|
||||||
|
let fixture: ComponentFixture<OrcidQueueComponent>;
|
||||||
|
let orcidQueueService: OrcidQueueService;
|
||||||
|
|
||||||
|
const testOwnerId = 'test-owner-id';
|
||||||
|
|
||||||
|
const routeParams: Params = {'id': testOwnerId};
|
||||||
|
|
||||||
|
const activatedRouteStub = new ActivatedRouteStub(routeParams);
|
||||||
|
|
||||||
|
function orcidQueueElement(id: number) {
|
||||||
|
return Object.assign(new OrcidQueue(), {
|
||||||
|
'id': id,
|
||||||
|
'ownerId': testOwnerId,
|
||||||
|
'entityId': `test-entity-${id}`,
|
||||||
|
'description': `test description ${id}`,
|
||||||
|
'recordType': 'Publication',
|
||||||
|
'operation': 'INSERT',
|
||||||
|
'type': 'orcidqueue',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const orcidQueueElements = [orcidQueueElement(1), orcidQueueElement(2)];
|
||||||
|
|
||||||
|
const orcidQueueServiceMock = {
|
||||||
|
searchByOwnerId(id) {
|
||||||
|
return createSuccessfulRemoteDataObject$<PaginatedList<OrcidQueue>>(createPaginatedList<OrcidQueue>(orcidQueueElements));
|
||||||
|
},
|
||||||
|
clearFindByOwnerRequests() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
void TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: TranslateLoaderMock
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
RouterTestingModule.withRoutes([])
|
||||||
|
],
|
||||||
|
declarations: [OrcidQueueComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: OrcidQueueService, useValue: orcidQueueServiceMock },
|
||||||
|
{ provide: OrcidHistoryService, useValue: {} },
|
||||||
|
{ provide: PaginationService, useValue: new PaginationServiceStub() },
|
||||||
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
|
{ provide: ActivatedRoute, useValue: activatedRouteStub },
|
||||||
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
|
||||||
|
orcidQueueService = TestBed.inject(OrcidQueueService);
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
fixture = TestBed.createComponent(OrcidQueueComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(comp).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -25,7 +25,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Pagination config used to display the list
|
* Pagination config used to display the list
|
||||||
*/
|
*/
|
||||||
public paginationOptions: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
public paginationOptions: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
||||||
id: 'oqp',
|
id: 'oqp',
|
||||||
pageSize: 5
|
pageSize: 5
|
||||||
});
|
});
|
||||||
@@ -57,7 +57,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
|
|||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private orcidHistoryService: OrcidHistoryService,
|
private orcidHistoryService: OrcidHistoryService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.updateList();
|
this.updateList();
|
||||||
@@ -81,7 +81,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* Return the list of orcid queue records
|
* Return the list of orcid queue records
|
||||||
*/
|
*/
|
||||||
getList(): Observable<RemoteData<PaginatedList<OrcidQueue>>> {
|
getList(): Observable<RemoteData<PaginatedList<OrcidQueue>>> {
|
||||||
return this.list$.asObservable();
|
return this.list$.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,6 +54,7 @@ export class ActivatedRouteStub {
|
|||||||
get snapshot() {
|
get snapshot() {
|
||||||
return {
|
return {
|
||||||
params: this.testParams,
|
params: this.testParams,
|
||||||
|
paramMap: convertToParamMap(this.params),
|
||||||
queryParamMap: convertToParamMap(this.testParams)
|
queryParamMap: convertToParamMap(this.testParams)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user