[CST-5339] Pass item as input - Tests

This commit is contained in:
Davide Negretti
2022-06-14 18:56:18 +02:00
parent adcef89c29
commit 3adf846786
4 changed files with 128 additions and 81 deletions

View File

@@ -10,4 +10,4 @@
<ds-orcid-auth *ngIf="(item | async)" [item]="(item | async)" (unlink)="updateItem()"></ds-orcid-auth> <ds-orcid-auth *ngIf="(item | async)" [item]="(item | async)" (unlink)="updateItem()"></ds-orcid-auth>
<ds-orcid-sync-setting *ngIf="(item | async) && isLinkedToOrcid()" [item]="(item | async)"></ds-orcid-sync-setting> <ds-orcid-sync-setting *ngIf="(item | async) && isLinkedToOrcid()" [item]="(item | async)"></ds-orcid-sync-setting>
<ds-orcid-queue *ngIf="isLinkedToOrcid()"></ds-orcid-queue> <ds-orcid-queue *ngIf="isLinkedToOrcid()" [item]="(item | async)"></ds-orcid-queue>

View File

@@ -1,9 +1,7 @@
<div class="container custom-accordion mb-4"> <div>
<ngb-accordion activeIds="queue">
<ngb-panel title="{{'person.orcid.registry.queue' | translate}}" id="queue">
<ng-template ngbPanelContent>
<div class="container">
<ds-loading *ngIf="(processing$ | async)"></ds-loading> <ds-loading *ngIf="(processing$ | async)"></ds-loading>
<div class="container">
<h2>{{ 'person.orcid.registry.queue' | translate }}</h2>
<ds-alert *ngIf="!(processing$ | async) && (getList() | async)?.payload?.totalElements == 0" <ds-alert *ngIf="!(processing$ | async) && (getList() | async)?.payload?.totalElements == 0"
[type]="AlertTypeEnum.Info"> [type]="AlertTypeEnum.Info">
@@ -24,7 +22,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let entry of (getList() | async)?.payload?.page"> <tr *ngFor="let entry of (getList() | async)?.payload?.page" data-test="orcidQueueElementRow">
<td class="text-center align-middle"> <td class="text-center align-middle">
<i [ngClass]="getIconClass(entry)" [ngbTooltip]="getIconTooltip(entry) | translate" <i [ngClass]="getIconClass(entry)" [ngbTooltip]="getIconTooltip(entry) | translate"
class="fa-2x" aria-hidden="true"></i> class="fa-2x" aria-hidden="true"></i>
@@ -54,7 +52,4 @@
</div> </div>
</ds-pagination> </ds-pagination>
</div> </div>
</ng-template>
</ngb-panel>
</ngb-accordion>
</div> </div>

View File

@@ -10,13 +10,12 @@ import { PaginationServiceStub } from '../../../shared/testing/pagination-servic
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub'; import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
import { OrcidHistoryService } from '../../../core/orcid/orcid-history.service'; 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 { OrcidQueue } from '../../../core/orcid/model/orcid-queue.model';
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
import { createPaginatedList } from '../../../shared/testing/utils.test'; import { createPaginatedList } from '../../../shared/testing/utils.test';
import { PaginatedList } from '../../../core/data/paginated-list.model'; import { PaginatedList } from '../../../core/data/paginated-list.model';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { Item } from '../../../core/shared/item.model';
fdescribe('OrcidQueueComponent test suite', () => { fdescribe('OrcidQueueComponent test suite', () => {
@@ -27,9 +26,63 @@ fdescribe('OrcidQueueComponent test suite', () => {
const testOwnerId = 'test-owner-id'; const testOwnerId = 'test-owner-id';
const routeParams: Params = {'id': testOwnerId}; const mockItemLinkedToOrcid: Item = Object.assign(new Item(), {
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
const activatedRouteStub = new ActivatedRouteStub(routeParams); metadata: {
'dc.title': [{
value: 'test person'
}],
'dspace.entity.type': [{
'value': 'Person'
}],
'dspace.object.owner': [{
'value': 'test person',
'language': null,
'authority': 'deced3e7-68e2-495d-bf98-7c44fc33b8ff',
'confidence': 600,
'place': 0
}],
'dspace.orcid.authenticated': [{
'value': '2022-06-10T15:15:12.952872',
'language': null,
'authority': null,
'confidence': -1,
'place': 0
}],
'dspace.orcid.scope': [{
'value': '/authenticate',
'language': null,
'authority': null,
'confidence': -1,
'place': 0
}, {
'value': '/read-limited',
'language': null,
'authority': null,
'confidence': -1,
'place': 1
}, {
'value': '/activities/update',
'language': null,
'authority': null,
'confidence': -1,
'place': 2
}, {
'value': '/person/update',
'language': null,
'authority': null,
'confidence': -1,
'place': 3
}],
'person.identifier.orcid': [{
'value': 'orcid-id',
'language': null,
'authority': null,
'confidence': -1,
'place': 0
}]
}
});
function orcidQueueElement(id: number) { function orcidQueueElement(id: number) {
return Object.assign(new OrcidQueue(), { return Object.assign(new OrcidQueue(), {
@@ -45,14 +98,8 @@ fdescribe('OrcidQueueComponent test suite', () => {
const orcidQueueElements = [orcidQueueElement(1), orcidQueueElement(2)]; const orcidQueueElements = [orcidQueueElement(1), orcidQueueElement(2)];
const orcidQueueServiceMock = { const orcidQueueServiceSpy = jasmine.createSpyObj('orcidQueueService', ['searchByOwnerId', 'clearFindByOwnerRequests']);
searchByOwnerId(id) { orcidQueueServiceSpy.searchByOwnerId.and.returnValue(createSuccessfulRemoteDataObject$<PaginatedList<OrcidQueue>>(createPaginatedList<OrcidQueue>(orcidQueueElements)));
return createSuccessfulRemoteDataObject$<PaginatedList<OrcidQueue>>(createPaginatedList<OrcidQueue>(orcidQueueElements));
},
clearFindByOwnerRequests() {
return null;
}
};
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
void TestBed.configureTestingModule({ void TestBed.configureTestingModule({
@@ -67,11 +114,10 @@ fdescribe('OrcidQueueComponent test suite', () => {
], ],
declarations: [OrcidQueueComponent], declarations: [OrcidQueueComponent],
providers: [ providers: [
{ provide: OrcidQueueService, useValue: orcidQueueServiceMock }, { provide: OrcidQueueService, useValue: orcidQueueServiceSpy },
{ provide: OrcidHistoryService, useValue: {} }, { provide: OrcidHistoryService, useValue: {} },
{ provide: PaginationService, useValue: new PaginationServiceStub() }, { provide: PaginationService, useValue: new PaginationServiceStub() },
{ provide: NotificationsService, useValue: new NotificationsServiceStub() }, { provide: NotificationsService, useValue: new NotificationsServiceStub() },
{ provide: ActivatedRoute, useValue: activatedRouteStub },
], ],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();
@@ -82,6 +128,7 @@ fdescribe('OrcidQueueComponent test suite', () => {
beforeEach(() => { beforeEach(() => {
fixture = TestBed.createComponent(OrcidQueueComponent); fixture = TestBed.createComponent(OrcidQueueComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.item = mockItemLinkedToOrcid;
debugElement = fixture.debugElement; debugElement = fixture.debugElement;
fixture.detectChanges(); fixture.detectChanges();
}); });
@@ -90,9 +137,9 @@ fdescribe('OrcidQueueComponent test suite', () => {
expect(component).toBeTruthy(); expect(component).toBeTruthy();
}); });
it('should ...', () => { it('should show the ORCID queue elements', () => {
const table = debugElement.queryAll(By.css('table')); const table = debugElement.queryAll(By.css('[data-test="orcidQueueElementRow"]'));
expect(table.length).toBe(1); expect(table.length).toBe(2);
}); });
}); });

View File

@@ -1,5 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs'; import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators'; import { switchMap, tap } from 'rxjs/operators';
@@ -15,6 +14,7 @@ import { hasValue } from '../../../shared/empty.util';
import { NotificationsService } from '../../../shared/notifications/notifications.service'; import { NotificationsService } from '../../../shared/notifications/notifications.service';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
import { AlertType } from '../../../shared/alert/aletr-type'; import { AlertType } from '../../../shared/alert/aletr-type';
import { Item } from '../../../core/shared/item.model';
@Component({ @Component({
selector: 'ds-orcid-queue', selector: 'ds-orcid-queue',
@@ -22,6 +22,12 @@ import { AlertType } from '../../../shared/alert/aletr-type';
styleUrls: ['./orcid-queue.component.scss'] styleUrls: ['./orcid-queue.component.scss']
}) })
export class OrcidQueueComponent implements OnInit, OnDestroy { export class OrcidQueueComponent implements OnInit, OnDestroy {
/**
* The item for which showing the orcid settings
*/
@Input() item: Item;
/** /**
* Pagination config used to display the list * Pagination config used to display the list
*/ */
@@ -54,7 +60,6 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
constructor(private orcidQueueService: OrcidQueueService, constructor(private orcidQueueService: OrcidQueueService,
protected translateService: TranslateService, protected translateService: TranslateService,
private paginationService: PaginationService, private paginationService: PaginationService,
private route: ActivatedRoute,
private notificationsService: NotificationsService, private notificationsService: NotificationsService,
private orcidHistoryService: OrcidHistoryService, private orcidHistoryService: OrcidHistoryService,
) { } ) { }
@@ -67,7 +72,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
this.subs.push( this.subs.push(
this.paginationService.getCurrentPagination(this.paginationOptions.id, this.paginationOptions).pipe( this.paginationService.getCurrentPagination(this.paginationOptions.id, this.paginationOptions).pipe(
tap(() => this.processing$.next(true)), tap(() => this.processing$.next(true)),
switchMap((config: PaginationComponentOptions) => this.orcidQueueService.searchByOwnerId(this.route.snapshot.paramMap.get('id'), config)), switchMap((config: PaginationComponentOptions) => this.orcidQueueService.searchByOwnerId(this.item.id, config)),
getFirstCompletedRemoteData() getFirstCompletedRemoteData()
).subscribe((result: RemoteData<PaginatedList<OrcidQueue>>) => { ).subscribe((result: RemoteData<PaginatedList<OrcidQueue>>) => {
this.processing$.next(false); this.processing$.next(false);
@@ -236,7 +241,7 @@ export class OrcidQueueComponent implements OnInit, OnDestroy {
} }
private getUnauthorizedErrorContent(): Observable<string> { private getUnauthorizedErrorContent(): Observable<string> {
return this.orcidQueueService.getOrcidAuthorizeUrl(this.route.snapshot.paramMap.get('id')).pipe( return this.orcidQueueService.getOrcidAuthorizeUrl(this.item.id).pipe(
switchMap((authorizeUrl) => this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.content', { orcid : authorizeUrl})) switchMap((authorizeUrl) => this.translateService.get('person.page.orcid.sync-queue.send.unauthorized-error.content', { orcid : authorizeUrl}))
); );
} }