mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
98211: Added tests
This commit is contained in:
@@ -13,4 +13,20 @@ import { ClaimedTaskActionsAbstractComponent } from './claimed-task-actions-abst
|
||||
template: ''
|
||||
})
|
||||
export abstract class AdvancedClaimedTaskActionsAbstractComponent extends ClaimedTaskActionsAbstractComponent {
|
||||
|
||||
workflowType: string;
|
||||
|
||||
/**
|
||||
* Route to the workflow's task page
|
||||
*/
|
||||
workflowTaskPageRoute: string;
|
||||
|
||||
openAdvancedClaimedTaskTab(): void {
|
||||
void this.router.navigate([this.workflowTaskPageRoute], {
|
||||
queryParams: {
|
||||
workflow: this.workflowType,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<button class="btn btn-primary" ngbTooltip="{{ 'submission.workflow.generic.' + option + '-help' | translate }}"
|
||||
[routerLink]="workflowTaskPageRoute" [queryParams]="{ workflow: workflowType }">
|
||||
<button (click)="openAdvancedClaimedTaskTab()" class="ratingReviewerAction btn btn-primary"
|
||||
ngbTooltip="{{ 'submission.workflow.generic.' + option + '-help' | translate }}">
|
||||
<i class="fa fa-user"></i> {{ 'submission.workflow.generic.' + option | translate}}
|
||||
</button>
|
||||
|
@@ -2,26 +2,85 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
AdvancedClaimedTaskActionRatingReviewerComponent
|
||||
} from './advanced-claimed-task-action-rating-reviewer.component';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||
import { ClaimedTaskDataServiceStub } from '../../../testing/claimed-task-data-service.stub';
|
||||
import { NotificationsServiceStub } from '../../../testing/notifications-service.stub';
|
||||
import { RouterStub } from '../../../testing/router.stub';
|
||||
import { SearchServiceStub } from '../../../testing/search-service.stub';
|
||||
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||
import { NotificationsService } from '../../../notifications/notifications.service';
|
||||
import { RequestService } from '../../../../core/data/request.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
import { Location } from '@angular/common';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import {
|
||||
ADVANCED_WORKFLOW_ACTION_RATING_REVIEWER
|
||||
} from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-rating-reviewer/advanced-workflow-action-rating-reviewer.component';
|
||||
|
||||
describe('AdvancedClaimedTaskActionsRatingReviewerComponent', () => {
|
||||
const taskId = 'claimed-task-1';
|
||||
|
||||
describe('AdvancedClaimedTaskActionRatingReviewerComponent', () => {
|
||||
const object = Object.assign(new ClaimedTask(), { id: taskId });
|
||||
let component: AdvancedClaimedTaskActionRatingReviewerComponent;
|
||||
let fixture: ComponentFixture<AdvancedClaimedTaskActionRatingReviewerComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let router: RouterStub;
|
||||
let searchService: SearchServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
router = new RouterStub();
|
||||
searchService = new SearchServiceStub();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
AdvancedClaimedTaskActionRatingReviewerComponent,
|
||||
],
|
||||
providers: [
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: SearchService, useValue: searchService },
|
||||
Location,
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdvancedClaimedTaskActionRatingReviewerComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.object = object;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
afterEach(() => {
|
||||
fixture.debugElement.nativeElement.remove();
|
||||
});
|
||||
|
||||
it('should display select reviewer button', () => {
|
||||
const btn = fixture.debugElement.query(By.css('.ratingReviewerAction'));
|
||||
|
||||
expect(btn).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should navigate to the advanced workflow page when clicked', () => {
|
||||
fixture.debugElement.query(By.css('.ratingReviewerAction')).nativeElement.click();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith([`/workflowitems/${taskId}/advanced`], {
|
||||
queryParams: {
|
||||
workflow: ADVANCED_WORKFLOW_ACTION_RATING_REVIEWER,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<button class="btn btn-primary" ngbTooltip="{{ 'submission.workflow.generic.' + option + '-help' | translate }}"
|
||||
[routerLink]="workflowTaskPageRoute" [queryParams]="{ workflow: workflowType }">
|
||||
<button (click)="openAdvancedClaimedTaskTab()" class="selectReviewerAction btn btn-primary"
|
||||
ngbTooltip="{{ 'submission.workflow.generic.' + option + '-help' | translate }}">
|
||||
<i class="fa fa-user"></i> {{ 'submission.workflow.generic.' + option | translate}}
|
||||
</button>
|
||||
|
@@ -2,26 +2,87 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
AdvancedClaimedTaskActionSelectReviewerComponent
|
||||
} from './advanced-claimed-task-action-select-reviewer.component';
|
||||
import { Router } from '@angular/router';
|
||||
import { RouterStub } from '../../../testing/router.stub';
|
||||
import { NotificationsServiceStub } from '../../../testing/notifications-service.stub';
|
||||
import { NotificationsService } from '../../../notifications/notifications.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { SearchServiceStub } from '../../../testing/search-service.stub';
|
||||
import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
import { RequestService } from '../../../../core/data/request.service';
|
||||
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||
import { ClaimedTaskDataServiceStub } from '../../../testing/claimed-task-data-service.stub';
|
||||
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { Location } from '@angular/common';
|
||||
import {
|
||||
ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER
|
||||
} from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-select-reviewer/advanced-workflow-action-select-reviewer.component';
|
||||
|
||||
describe('AdvancedClaimedTaskActionsSelectReviewerComponent', () => {
|
||||
const taskId = 'claimed-task-1';
|
||||
|
||||
describe('AdvancedClaimedTaskActionSelectReviewerComponent', () => {
|
||||
const object = Object.assign(new ClaimedTask(), { id: taskId });
|
||||
let component: AdvancedClaimedTaskActionSelectReviewerComponent;
|
||||
let fixture: ComponentFixture<AdvancedClaimedTaskActionSelectReviewerComponent>;
|
||||
|
||||
let claimedTaskDataService: ClaimedTaskDataServiceStub;
|
||||
let notificationService: NotificationsServiceStub;
|
||||
let router: RouterStub;
|
||||
let searchService: SearchServiceStub;
|
||||
|
||||
beforeEach(async () => {
|
||||
claimedTaskDataService = new ClaimedTaskDataServiceStub();
|
||||
notificationService = new NotificationsServiceStub();
|
||||
router = new RouterStub();
|
||||
searchService = new SearchServiceStub();
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
],
|
||||
declarations: [
|
||||
AdvancedClaimedTaskActionSelectReviewerComponent,
|
||||
NgbTooltip,
|
||||
],
|
||||
providers: [
|
||||
{ provide: ClaimedTaskDataService, useValue: claimedTaskDataService },
|
||||
{ provide: NotificationsService, useValue: notificationService },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: Router, useValue: router },
|
||||
{ provide: SearchService, useValue: searchService },
|
||||
Location,
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(AdvancedClaimedTaskActionSelectReviewerComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.object = object;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
afterEach(() => {
|
||||
fixture.debugElement.nativeElement.remove();
|
||||
});
|
||||
|
||||
it('should display select reviewer button', () => {
|
||||
const btn = fixture.debugElement.query(By.css('.selectReviewerAction'));
|
||||
|
||||
expect(btn).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should navigate to the advanced workflow page when clicked', () => {
|
||||
fixture.debugElement.query(By.css('.selectReviewerAction')).nativeElement.click();
|
||||
|
||||
expect(router.navigate).toHaveBeenCalledWith([`/workflowitems/${taskId}/advanced`], {
|
||||
queryParams: {
|
||||
workflow: ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -10,8 +10,10 @@ import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
import { RequestService } from '../../../../core/data/request.service';
|
||||
import { getAdvancedWorkflowRoute } from '../../../../workflowitems-edit-page/workflowitems-edit-page-routing-paths';
|
||||
import {
|
||||
ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER, WORKFLOW_ADVANCED_TASK_OPTION_SELECT_REVIEWER
|
||||
ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER,
|
||||
WORKFLOW_ADVANCED_TASK_OPTION_SELECT_REVIEWER
|
||||
} from '../../../../workflowitems-edit-page/advanced-workflow-action/advanced-workflow-action-select-reviewer/advanced-workflow-action-select-reviewer.component';
|
||||
|
||||
@rendersWorkflowTaskOption(WORKFLOW_ADVANCED_TASK_OPTION_SELECT_REVIEWER)
|
||||
@Component({
|
||||
selector: 'ds-advanced-claimed-task-action-select-reviewer',
|
||||
@@ -27,11 +29,6 @@ export class AdvancedClaimedTaskActionSelectReviewerComponent extends AdvancedCl
|
||||
|
||||
workflowType = ADVANCED_WORKFLOW_ACTION_SELECT_REVIEWER;
|
||||
|
||||
/**
|
||||
* Route to the workflow's task page
|
||||
*/
|
||||
workflowTaskPageRoute: string;
|
||||
|
||||
constructor(
|
||||
protected injector: Injector,
|
||||
protected router: Router,
|
||||
|
10
src/app/shared/testing/claimed-task-data-service.stub.ts
Normal file
10
src/app/shared/testing/claimed-task-data-service.stub.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Observable, EMPTY } from 'rxjs';
|
||||
import { ProcessTaskResponse } from '../../core/tasks/models/process-task-response';
|
||||
|
||||
export class ClaimedTaskDataServiceStub {
|
||||
|
||||
public submitTask(_scopeId: string, _body: any): Observable<ProcessTaskResponse> {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
}
|
12
src/app/shared/testing/data-service.stub.ts
Normal file
12
src/app/shared/testing/data-service.stub.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { FollowLinkConfig } from '../utils/follow-link-config.model';
|
||||
import { Observable, EMPTY } from 'rxjs';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { CacheableObject } from '../../core/cache/object-cache.reducer';
|
||||
|
||||
export abstract class DataServiceStub<T extends CacheableObject> {
|
||||
|
||||
findById(_id: string, _useCachedVersionIfAvailable = true, _reRequestOnStale = true, ..._linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<T>> {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
}
|
15
src/app/shared/testing/workflow-action-data-service.stub.ts
Normal file
15
src/app/shared/testing/workflow-action-data-service.stub.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { FindListOptions } from '../../core/data/request.models';
|
||||
import { FollowLinkConfig } from '../utils/follow-link-config.model';
|
||||
import { WorkspaceItem } from '../../core/submission/models/workspaceitem.model';
|
||||
import { Observable, EMPTY } from 'rxjs';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
|
||||
import { DataServiceStub } from './data-service.stub';
|
||||
|
||||
export class WorkflowActionDataServiceStub extends DataServiceStub<WorkflowItem> {
|
||||
|
||||
public findByItem(_uuid: string, _useCachedVersionIfAvailable = false, _reRequestOnStale = true, _options: FindListOptions = {}, ..._linksToFollow: FollowLinkConfig<WorkspaceItem>[]): Observable<RemoteData<WorkspaceItem>> {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
import { DataServiceStub } from './data-service.stub';
|
||||
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
|
||||
|
||||
export class WorkflowItemDataServiceStub extends DataServiceStub<WorkflowItem> {
|
||||
}
|
@@ -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