mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 21:43:04 +00:00
98211: Added tests
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AdvancedWorkflowActionPageComponent } from './advanced-workflow-action-page.component';
|
||||
import { ActivatedRoute, convertToParamMap } from '@angular/router';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
describe('AdvancedWorkflowActionPageComponent', () => {
|
||||
let component: AdvancedWorkflowActionPageComponent;
|
||||
@@ -7,9 +9,24 @@ describe('AdvancedWorkflowActionPageComponent', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
AdvancedWorkflowActionPageComponent,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
snapshot: {
|
||||
queryParams: convertToParamMap({
|
||||
workflow: 'testaction',
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
|
@@ -1,16 +1,60 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdvancedWorkflowActionRatingReviewerComponent } from './advanced-workflow-action-rating-reviewer.component';
|
||||
import { ActivatedRoute, convertToParamMap } from '@angular/router';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { routeServiceStub } from '../../../shared/testing/route-service.stub';
|
||||
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
|
||||
import { WorkflowItemDataService } from '../../../core/submission/workflowitem-data.service';
|
||||
import { ClaimedTaskDataServiceStub } from '../../../shared/testing/claimed-task-data-service.stub';
|
||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||
import { WorkflowActionDataServiceStub } from '../../../shared/testing/workflow-action-data-service.stub';
|
||||
import { WorkflowItemDataServiceStub } from '../../../shared/testing/workflow-item-data-service.stub';
|
||||
|
||||
const workflowId = '1';
|
||||
|
||||
describe('AdvancedWorkflowActionRatingReviewerComponent', () => {
|
||||
let component: AdvancedWorkflowActionRatingReviewerComponent;
|
||||
let fixture: ComponentFixture<AdvancedWorkflowActionRatingReviewerComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let workflowActionDataService: WorkflowItemDataServiceStub;
|
||||
let workflowItemDataService: WorkflowItemDataServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
workflowActionDataService = new WorkflowActionDataServiceStub();
|
||||
workflowItemDataService = new WorkflowItemDataServiceStub();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AdvancedWorkflowActionRatingReviewerComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [
|
||||
AdvancedWorkflowActionRatingReviewerComponent,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
data: observableOf({
|
||||
id: workflowId,
|
||||
}),
|
||||
snapshot: {
|
||||
queryParams: convertToParamMap({
|
||||
workflow: 'testaction',
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: WorkflowActionDataService, useValue: workflowActionDataService },
|
||||
{ provide: WorkflowItemDataService, useValue: workflowItemDataService },
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -1,16 +1,66 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdvancedWorkflowActionSelectReviewerComponent } from './advanced-workflow-action-select-reviewer.component';
|
||||
import { ActivatedRoute, convertToParamMap } from '@angular/router';
|
||||
import { WorkflowItemDataService } from '../../../core/submission/workflowitem-data.service';
|
||||
import { WorkflowItemDataServiceStub } from '../../../shared/testing/workflow-item-data-service.stub';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { WorkflowActionDataServiceStub } from '../../../shared/testing/workflow-action-data-service.stub';
|
||||
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { routeServiceStub } from '../../../shared/testing/route-service.stub';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
|
||||
import { ClaimedTaskDataServiceStub } from '../../../shared/testing/claimed-task-data-service.stub';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
|
||||
const workflowId = '1';
|
||||
|
||||
describe('AdvancedWorkflowActionSelectReviewerComponent', () => {
|
||||
let component: AdvancedWorkflowActionSelectReviewerComponent;
|
||||
let fixture: ComponentFixture<AdvancedWorkflowActionSelectReviewerComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let workflowActionDataService: WorkflowItemDataServiceStub;
|
||||
let workflowItemDataService: WorkflowItemDataServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
workflowActionDataService = new WorkflowActionDataServiceStub();
|
||||
workflowItemDataService = new WorkflowItemDataServiceStub();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AdvancedWorkflowActionSelectReviewerComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
AdvancedWorkflowActionSelectReviewerComponent,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
data: observableOf({
|
||||
id: workflowId,
|
||||
}),
|
||||
snapshot: {
|
||||
queryParams: convertToParamMap({
|
||||
workflow: 'testaction',
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: WorkflowActionDataService, useValue: workflowActionDataService },
|
||||
{ provide: WorkflowItemDataService, useValue: workflowItemDataService },
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -1,25 +1,126 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AdvancedWorkflowActionComponent } from './advanced-workflow-action.component';
|
||||
import { Component } from '@angular/core';
|
||||
import { MockComponent } from 'ng-mocks';
|
||||
import { DSOSelectorComponent } from '../../../shared/dso-selector/dso-selector/dso-selector.component';
|
||||
import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.service';
|
||||
import { ClaimedTaskDataServiceStub } from '../../../shared/testing/claimed-task-data-service.stub';
|
||||
import { ActivatedRoute, convertToParamMap } from '@angular/router';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import { WorkflowItemDataService } from '../../../core/submission/workflowitem-data.service';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
|
||||
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { RouteService } from '../../../core/services/route.service';
|
||||
import { routeServiceStub } from '../../../shared/testing/route-service.stub';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { WorkflowActionDataServiceStub } from '../../../shared/testing/workflow-action-data-service.stub';
|
||||
import { ProcessTaskResponse } from '../../../core/tasks/models/process-task-response';
|
||||
import { WorkflowItemDataServiceStub } from '../../../shared/testing/workflow-item-data-service.stub';
|
||||
|
||||
const workflowId = '1';
|
||||
|
||||
describe('AdvancedWorkflowActionComponent', () => {
|
||||
let component: AdvancedWorkflowActionComponent;
|
||||
let fixture: ComponentFixture<AdvancedWorkflowActionComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let workflowActionDataService: WorkflowActionDataServiceStub;
|
||||
let workflowItemDataService: WorkflowItemDataServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
workflowActionDataService = new WorkflowActionDataServiceStub();
|
||||
workflowItemDataService = new WorkflowItemDataServiceStub();
|
||||
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ AdvancedWorkflowActionComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
RouterTestingModule,
|
||||
],
|
||||
declarations: [
|
||||
TestComponent,
|
||||
MockComponent(DSOSelectorComponent),
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: {
|
||||
data: observableOf({
|
||||
id: workflowId,
|
||||
}),
|
||||
snapshot: {
|
||||
queryParams: convertToParamMap({
|
||||
workflow: 'testaction',
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RouteService, useValue: routeServiceStub },
|
||||
{ provide: WorkflowActionDataService, useValue: workflowActionDataService },
|
||||
{ provide: WorkflowItemDataService, useValue: workflowItemDataService },
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdvancedWorkflowActionComponent);
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.ngOnInit();
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
describe('sendRequest', () => {
|
||||
it('should return true if the request succeeded', () => {
|
||||
spyOn(claimedTaskDataService, 'submitTask').and.returnValue(observableOf(new ProcessTaskResponse(true, 200)));
|
||||
spyOn(workflowActionDataService, 'findById');
|
||||
|
||||
const result = component.sendRequest(workflowId);
|
||||
|
||||
expect(claimedTaskDataService.submitTask).toHaveBeenCalledWith('1', {
|
||||
'submit_test': true,
|
||||
});
|
||||
result.subscribe((value: boolean) => {
|
||||
expect(value).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return false if the request didn\'t succeeded', () => {
|
||||
spyOn(claimedTaskDataService, 'submitTask').and.returnValue(observableOf(new ProcessTaskResponse(false, 404)));
|
||||
spyOn(workflowActionDataService, 'findById');
|
||||
|
||||
const result = component.sendRequest(workflowId);
|
||||
|
||||
expect(claimedTaskDataService.submitTask).toHaveBeenCalledWith('1', {
|
||||
'submit_test': true,
|
||||
});
|
||||
result.subscribe((value: boolean) => {
|
||||
expect(value).toBeFalse();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@Component({
|
||||
selector: 'ds-test-cmp',
|
||||
template: ''
|
||||
})
|
||||
class TestComponent extends AdvancedWorkflowActionComponent {
|
||||
|
||||
createBody(): any {
|
||||
return {
|
||||
'submit_test': true,
|
||||
};
|
||||
}
|
||||
|
||||
getType(): string {
|
||||
return 'testaction';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,15 +1,24 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { AdvancedWorkflowActionsLoaderComponent } from './advanced-workflow-actions-loader.component';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouterStub } from '../../../shared/testing/router.stub';
|
||||
|
||||
describe('AdvancedWorkflowActionsLoaderComponent', () => {
|
||||
let component: AdvancedWorkflowActionsLoaderComponent;
|
||||
let fixture: ComponentFixture<AdvancedWorkflowActionsLoaderComponent>;
|
||||
|
||||
let router: RouterStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
router = new RouterStub();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
AdvancedWorkflowActionsLoaderComponent,
|
||||
],
|
||||
providers: [
|
||||
{ provide: Router, useValue: router },
|
||||
],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user