mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
[CST-5668] Add test for orcid-page.component
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<div class="container">
|
<div *ngIf="item" class="container">
|
||||||
<div class="button-row bottom mb-3">
|
<div class="button-row bottom mb-3">
|
||||||
<div class="text-right">
|
<div class="text-right">
|
||||||
<a [routerLink]="getItemPage()" role="button" class="btn btn-outline-secondary"><i class="fas fa-arrow-left"></i> {{'item.orcid.return' | translate}}</a>
|
<a [routerLink]="getItemPage()" role="button" class="btn btn-outline-secondary" data-test="back-button">
|
||||||
|
<i class="fas fa-arrow-left"></i> {{'item.orcid.return' | translate}}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
113
src/app/item-page/orcid-page/orcid-page.component.spec.ts
Normal file
113
src/app/item-page/orcid-page/orcid-page.component.spec.ts
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||||
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
||||||
|
import { ResearcherProfileService } from '../../core/profile/researcher-profile.service';
|
||||||
|
import { OrcidPageComponent } from './orcid-page.component';
|
||||||
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
|
import { Item } from '../../core/shared/item.model';
|
||||||
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
|
import { TranslateLoaderMock } from '../../shared/mocks/translate-loader.mock';
|
||||||
|
|
||||||
|
fdescribe('OrcidPageComponent test suite', () => {
|
||||||
|
let comp: OrcidPageComponent;
|
||||||
|
let fixture: ComponentFixture<OrcidPageComponent>;
|
||||||
|
|
||||||
|
let authService: jasmine.SpyObj<AuthService>;
|
||||||
|
let routeStub: jasmine.SpyObj<ActivatedRouteStub>;
|
||||||
|
let routeData: any;
|
||||||
|
let researcherProfileService: jasmine.SpyObj<ResearcherProfileService>;
|
||||||
|
|
||||||
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
|
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
metadata: {
|
||||||
|
'dc.title': [
|
||||||
|
{
|
||||||
|
language: 'en_US',
|
||||||
|
value: 'test item'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const mockItemLinkedToOrcid: Item = Object.assign(new Item(), {
|
||||||
|
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
|
metadata: {
|
||||||
|
'dc.title': [
|
||||||
|
{
|
||||||
|
value: 'test item'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'dspace.orcid.authenticated': [
|
||||||
|
{
|
||||||
|
value: 'true'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
authService = jasmine.createSpyObj('authService', {
|
||||||
|
isAuthenticated: jasmine.createSpy('isAuthenticated'),
|
||||||
|
navigateByUrl: jasmine.createSpy('navigateByUrl')
|
||||||
|
});
|
||||||
|
|
||||||
|
routeData = {
|
||||||
|
dso: createSuccessfulRemoteDataObject(mockItem),
|
||||||
|
};
|
||||||
|
|
||||||
|
routeStub = Object.assign(new ActivatedRouteStub(), {
|
||||||
|
data: observableOf(routeData)
|
||||||
|
});
|
||||||
|
|
||||||
|
researcherProfileService = jasmine.createSpyObj('researcherProfileService', {
|
||||||
|
isLinkedToOrcid: jasmine.createSpy('isLinkedToOrcid')
|
||||||
|
});
|
||||||
|
|
||||||
|
void TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: TranslateLoaderMock
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
RouterTestingModule.withRoutes([])
|
||||||
|
],
|
||||||
|
declarations: [OrcidPageComponent],
|
||||||
|
providers: [
|
||||||
|
{ provide: ActivatedRoute, useValue: routeStub },
|
||||||
|
{ provide: ResearcherProfileService, useValue: researcherProfileService },
|
||||||
|
{ provide: AuthService, useValue: authService },
|
||||||
|
],
|
||||||
|
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(waitForAsync(() => {
|
||||||
|
fixture = TestBed.createComponent(OrcidPageComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
authService.isAuthenticated.and.returnValue(observableOf(true));
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
const btn = fixture.debugElement.queryAll(By.css('[data-test="back-button"]'));
|
||||||
|
expect(comp).toBeTruthy();
|
||||||
|
expect(btn.length).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call isLinkedToOrcid', () => {
|
||||||
|
comp.isLinkedToOrcid();
|
||||||
|
|
||||||
|
expect(researcherProfileService.isLinkedToOrcid).toHaveBeenCalledWith(comp.item);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Reference in New Issue
Block a user