mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-19 07:53:02 +00:00
Added tests and comments
This commit is contained in:
@@ -0,0 +1,96 @@
|
|||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
|
||||||
|
import { Workflowitem } from '../../../../core/submission/models/workflowitem.model';
|
||||||
|
import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model';
|
||||||
|
import { EPersonMock } from '../../../testing/eperson-mock';
|
||||||
|
import { MyDSpaceItemStatusComponent } from './my-dspace-item-status.component';
|
||||||
|
import { MyDspaceItemStatusType } from './my-dspace-item-status-type';
|
||||||
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
let component: MyDSpaceItemStatusComponent;
|
||||||
|
let fixture: ComponentFixture<MyDSpaceItemStatusComponent>;
|
||||||
|
|
||||||
|
let mockResultObject: PoolTask;
|
||||||
|
|
||||||
|
const rdSumbitter = new RemoteData(false, false, true, null, EPersonMock);
|
||||||
|
const workflowitem = Object.assign(new Workflowitem(), { submitter: observableOf(rdSumbitter) });
|
||||||
|
const rdWorkflowitem = new RemoteData(false, false, true, null, workflowitem);
|
||||||
|
mockResultObject = Object.assign(new PoolTask(), { workflowitem: observableOf(rdWorkflowitem) });
|
||||||
|
|
||||||
|
describe('MyDSpaceItemStatusComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: MockTranslateLoader
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
declarations: [MyDSpaceItemStatusComponent],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(MyDSpaceItemStatusComponent, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(MyDSpaceItemStatusComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display badge', () => {
|
||||||
|
const badge = fixture.debugElement.query(By.css('span'));
|
||||||
|
expect(badge).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.REJECTED;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.REJECTED);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-danger');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.VALIDATION;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.VALIDATION);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-warning');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.WAITING_CONTROLLER;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.WAITING_CONTROLLER);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-info');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.IN_PROGRESS;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.IN_PROGRESS);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-primary');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.ACCEPTED;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.ACCEPTED);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init badge content and class', () => {
|
||||||
|
component.status = MyDspaceItemStatusType.WORKFLOW;
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(component.badgeContent).toBe(MyDspaceItemStatusType.WORKFLOW);
|
||||||
|
expect(component.badgeClass).toBe('text-light badge badge-info');
|
||||||
|
});
|
||||||
|
});
|
@@ -1,18 +1,34 @@
|
|||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { MyDspaceItemStatusType } from './my-dspace-item-status-type';
|
import { MyDspaceItemStatusType } from './my-dspace-item-status-type';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component represents a badge with mydspace item status
|
||||||
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-mydspace-item-status',
|
selector: 'ds-mydspace-item-status',
|
||||||
styleUrls: ['./my-dspace-item-status.component.scss'],
|
styleUrls: ['./my-dspace-item-status.component.scss'],
|
||||||
templateUrl: './my-dspace-item-status.component.html'
|
templateUrl: './my-dspace-item-status.component.html'
|
||||||
})
|
})
|
||||||
|
|
||||||
export class MyDSpaceItemStatusComponent implements OnInit {
|
export class MyDSpaceItemStatusComponent implements OnInit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This mydspace item status
|
||||||
|
*/
|
||||||
@Input() status: MyDspaceItemStatusType;
|
@Input() status: MyDspaceItemStatusType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This badge class
|
||||||
|
*/
|
||||||
public badgeClass: string;
|
public badgeClass: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This badge content
|
||||||
|
*/
|
||||||
public badgeContent: string;
|
public badgeContent: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize badge content and class
|
||||||
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.badgeContent = this.status;
|
this.badgeContent = this.status;
|
||||||
this.badgeClass = 'text-light badge ';
|
this.badgeClass = 'text-light badge ';
|
||||||
|
@@ -1,3 +1,3 @@
|
|||||||
<div class="mt-2 mb-2">
|
<div class="mt-2 mb-2">
|
||||||
<span class="text-muted">{{'submission.workflow.tasks.generic.submitter' | translate}} : <span class="badge badge-pill badge-light">{{(submitter | async)?.name}}</span></span>
|
<span class="text-muted">{{'submission.workflow.tasks.generic.submitter' | translate}} : <span class="badge badge-pill badge-light">{{(submitter$ | async)?.name}}</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -0,0 +1,68 @@
|
|||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { cold } from 'jasmine-marbles';
|
||||||
|
|
||||||
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
import { ItemSubmitterComponent } from './item-submitter.component';
|
||||||
|
import { Workflowitem } from '../../../../core/submission/models/workflowitem.model';
|
||||||
|
import { PoolTask } from '../../../../core/tasks/models/pool-task-object.model';
|
||||||
|
import { EPersonMock } from '../../../testing/eperson-mock';
|
||||||
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
let component: ItemSubmitterComponent;
|
||||||
|
let fixture: ComponentFixture<ItemSubmitterComponent>;
|
||||||
|
|
||||||
|
const compIndex = 1;
|
||||||
|
|
||||||
|
let mockResultObject: PoolTask;
|
||||||
|
|
||||||
|
const rdSumbitter = new RemoteData(false, false, true, null, EPersonMock);
|
||||||
|
const workflowitem = Object.assign(new Workflowitem(), { submitter: observableOf(rdSumbitter) });
|
||||||
|
const rdWorkflowitem = new RemoteData(false, false, true, null, workflowitem);
|
||||||
|
mockResultObject = Object.assign(new PoolTask(), { workflowitem: observableOf(rdWorkflowitem) });
|
||||||
|
|
||||||
|
describe('ItemSubmitterComponent', () => {
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot({
|
||||||
|
loader: {
|
||||||
|
provide: TranslateLoader,
|
||||||
|
useClass: MockTranslateLoader
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
declarations: [ItemSubmitterComponent],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(ItemSubmitterComponent, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
fixture = TestBed.createComponent(ItemSubmitterComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.object = mockResultObject;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init submitter properly', () => {
|
||||||
|
expect(component.submitter$).toBeObservable(cold('(b|)', {
|
||||||
|
b: EPersonMock
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show a badge with submitter name', () => {
|
||||||
|
const badge = fixture.debugElement.query(By.css('.badge'));
|
||||||
|
|
||||||
|
expect(badge).toBeDefined();
|
||||||
|
expect(badge.nativeElement.innerHTML).toBe(EPersonMock.name);
|
||||||
|
});
|
||||||
|
});
|
@@ -8,19 +8,31 @@ import { RemoteData } from '../../../../core/data/remote-data';
|
|||||||
import { isNotEmpty, isNotUndefined } from '../../../empty.util';
|
import { isNotEmpty, isNotUndefined } from '../../../empty.util';
|
||||||
import { Workflowitem } from '../../../../core/submission/models/workflowitem.model';
|
import { Workflowitem } from '../../../../core/submission/models/workflowitem.model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This component represents a badge with submitter information.
|
||||||
|
*/
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-item-submitter',
|
selector: 'ds-item-submitter',
|
||||||
styleUrls: ['./item-submitter.component.scss'],
|
styleUrls: ['./item-submitter.component.scss'],
|
||||||
templateUrl: './item-submitter.component.html'
|
templateUrl: './item-submitter.component.html'
|
||||||
})
|
})
|
||||||
|
|
||||||
export class ItemSubmitterComponent implements OnInit {
|
export class ItemSubmitterComponent implements OnInit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The target object
|
||||||
|
*/
|
||||||
@Input() object: any;
|
@Input() object: any;
|
||||||
|
|
||||||
submitter: Observable<EPerson>;
|
/**
|
||||||
|
* The Eperson object
|
||||||
|
*/
|
||||||
|
submitter$: Observable<EPerson>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize submitter object
|
||||||
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.submitter = (this.object.workflowitem as Observable<RemoteData<Workflowitem>>).pipe(
|
this.submitter$ = (this.object.workflowitem as Observable<RemoteData<Workflowitem>>).pipe(
|
||||||
filter((rd: RemoteData<Workflowitem>) => (rd.hasSucceeded && isNotUndefined(rd.payload))),
|
filter((rd: RemoteData<Workflowitem>) => (rd.hasSucceeded && isNotUndefined(rd.payload))),
|
||||||
flatMap((rd: RemoteData<Workflowitem>) => rd.payload.submitter as Observable<RemoteData<EPerson>>),
|
flatMap((rd: RemoteData<Workflowitem>) => rd.payload.submitter as Observable<RemoteData<EPerson>>),
|
||||||
find((rd: RemoteData<EPerson>) => rd.hasSucceeded && isNotEmpty(rd.payload)),
|
find((rd: RemoteData<EPerson>) => rd.hasSucceeded && isNotEmpty(rd.payload)),
|
||||||
|
Reference in New Issue
Block a user