mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
[TLC-337] Unit tests for register DOI component
This commit is contained in:
@@ -0,0 +1,106 @@
|
|||||||
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { Item } from '../../../core/shared/item.model';
|
||||||
|
import { RouterStub } from '../../../shared/testing/router.stub';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { ItemRegisterDoiComponent } from './item-registerdoi.component';
|
||||||
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
|
import { IdentifierDataService } from '../../../core/data/identifier-data.service';
|
||||||
|
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
|
||||||
|
|
||||||
|
let comp: ItemRegisterDoiComponent;
|
||||||
|
let fixture: ComponentFixture<ItemRegisterDoiComponent>;
|
||||||
|
|
||||||
|
let mockItem;
|
||||||
|
let itemPageUrl;
|
||||||
|
let routerStub;
|
||||||
|
let mockItemDataService: ItemDataService;
|
||||||
|
let mockIdentifierDataService: IdentifierDataService;
|
||||||
|
let routeStub;
|
||||||
|
let notificationsServiceStub;
|
||||||
|
|
||||||
|
describe('ItemRegisterDoiComponent', () => {
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
|
||||||
|
mockItem = Object.assign(new Item(), {
|
||||||
|
id: 'fake-id',
|
||||||
|
handle: 'fake/handle',
|
||||||
|
lastModified: '2018',
|
||||||
|
isWithdrawn: true
|
||||||
|
});
|
||||||
|
|
||||||
|
itemPageUrl = `fake-url/${mockItem.id}`;
|
||||||
|
routerStub = Object.assign(new RouterStub(), {
|
||||||
|
url: `${itemPageUrl}/edit`
|
||||||
|
});
|
||||||
|
|
||||||
|
mockIdentifierDataService = jasmine.createSpyObj('mockIdentifierDataService', {
|
||||||
|
getIdentifierDataFor: createSuccessfulRemoteDataObject$({"identifiers": []}),
|
||||||
|
getIdentifierRegistrationConfiguration: createSuccessfulRemoteDataObject$("true")
|
||||||
|
});
|
||||||
|
|
||||||
|
mockItemDataService = jasmine.createSpyObj('mockItemDataService', {
|
||||||
|
registerDOI: createSuccessfulRemoteDataObject$(mockItem)
|
||||||
|
});
|
||||||
|
|
||||||
|
routeStub = {
|
||||||
|
data: observableOf({
|
||||||
|
dso: createSuccessfulRemoteDataObject(Object.assign(new Item(), {
|
||||||
|
id: 'fake-id'
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
notificationsServiceStub = new NotificationsServiceStub();
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [CommonModule, FormsModule, RouterTestingModule.withRoutes([]), TranslateModule.forRoot(), NgbModule],
|
||||||
|
declarations: [ItemRegisterDoiComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
|
{ provide: Router, useValue: routerStub },
|
||||||
|
{ provide: ItemDataService, useValue: mockItemDataService },
|
||||||
|
{ provide: IdentifierDataService, useValue: mockIdentifierDataService},
|
||||||
|
{ provide: NotificationsService, useValue: notificationsServiceStub }
|
||||||
|
], schemas: [
|
||||||
|
CUSTOM_ELEMENTS_SCHEMA
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ItemRegisterDoiComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render a page with messages based on the \'registerdoi\' messageKey', () => {
|
||||||
|
const header = fixture.debugElement.query(By.css('h2')).nativeElement;
|
||||||
|
expect(header.innerHTML).toContain('item.edit.registerdoi.header');
|
||||||
|
const description = fixture.debugElement.query(By.css('p')).nativeElement;
|
||||||
|
expect(description.innerHTML).toContain('item.edit.registerdoi.description');
|
||||||
|
const confirmButton = fixture.debugElement.query(By.css('button.perform-action')).nativeElement;
|
||||||
|
expect(confirmButton.innerHTML).toContain('item.edit.registerdoi.confirm');
|
||||||
|
const cancelButton = fixture.debugElement.query(By.css('button.cancel')).nativeElement;
|
||||||
|
expect(cancelButton.innerHTML).toContain('item.edit.registerdoi.cancel');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('performAction', () => {
|
||||||
|
it('should call registerDOI function from the ItemDataService', () => {
|
||||||
|
spyOn(comp, 'processRestResponse');
|
||||||
|
comp.performAction();
|
||||||
|
expect(mockItemDataService.registerDOI).toHaveBeenCalledWith(comp.item.id);
|
||||||
|
expect(comp.processRestResponse).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -85,7 +85,8 @@ export class ItemRegisterDoiComponent extends AbstractSimpleItemActionComponent
|
|||||||
this.itemDataService.registerDOI(this.item.id).pipe(getFirstCompletedRemoteData()).subscribe(
|
this.itemDataService.registerDOI(this.item.id).pipe(getFirstCompletedRemoteData()).subscribe(
|
||||||
(response: RemoteData<Item>) => {
|
(response: RemoteData<Item>) => {
|
||||||
this.processing = false;
|
this.processing = false;
|
||||||
this.router.navigateByUrl(getItemEditRoute(this.item));
|
//this.router.navigateByUrl(getItemEditRoute(this.item));
|
||||||
|
this.processRestResponse(response);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,14 @@ import { Item } from '../../../core/shared/item.model';
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { createSuccessfulRemoteDataObject } from '../../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||||
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
|
||||||
|
import { IdentifierDataService } from '../../../core/data/identifier-data.service';
|
||||||
|
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
|
||||||
|
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
|
||||||
|
|
||||||
|
let mockIdentifierDataService: IdentifierDataService;
|
||||||
|
let mockConfigurationDataService: ConfigurationDataService;
|
||||||
|
|
||||||
describe('ItemStatusComponent', () => {
|
describe('ItemStatusComponent', () => {
|
||||||
let comp: ItemStatusComponent;
|
let comp: ItemStatusComponent;
|
||||||
@@ -28,6 +34,20 @@ describe('ItemStatusComponent', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockIdentifierDataService = jasmine.createSpyObj('mockIdentifierDataService', {
|
||||||
|
getIdentifierDataFor: createSuccessfulRemoteDataObject$({"identifiers": []}),
|
||||||
|
getIdentifierRegistrationConfiguration: createSuccessfulRemoteDataObject$("true")
|
||||||
|
});
|
||||||
|
|
||||||
|
mockConfigurationDataService = jasmine.createSpyObj('configurationDataService', {
|
||||||
|
findByPropertyName: createSuccessfulRemoteDataObject$(Object.assign(new ConfigurationProperty(), {
|
||||||
|
name: 'identifiers.item-status.register',
|
||||||
|
values: [
|
||||||
|
'true'
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
const itemPageUrl = `/items/${mockItem.uuid}`;
|
const itemPageUrl = `/items/${mockItem.uuid}`;
|
||||||
|
|
||||||
const routeStub = {
|
const routeStub = {
|
||||||
@@ -50,6 +70,8 @@ describe('ItemStatusComponent', () => {
|
|||||||
{ provide: ActivatedRoute, useValue: routeStub },
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationService },
|
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||||
|
{ provide: IdentifierDataService, useValue: mockIdentifierDataService },
|
||||||
|
{ provide: ConfigurationDataService, useValue: mockConfigurationDataService }
|
||||||
], schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
], schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
Reference in New Issue
Block a user