finished tests

This commit is contained in:
lotte
2020-04-08 15:41:55 +02:00
parent d003400c16
commit e43f04e564
18 changed files with 383 additions and 23 deletions

View File

@@ -1,16 +1,59 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back.component';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterStub } from '../../shared/testing/router-stub';
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
import { RouteService } from '../../core/services/route.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { WorkflowItemDataService } from '../../core/submission/workflowitem-data.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service-stub';
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/testing/utils';
import { WorkflowItem } from '../../core/submission/models/workflowitem.model';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { VarDirective } from '../../shared/utils/var.directive';
import { of as observableOf } from 'rxjs';
import { WorkflowItemSendBackComponent } from './workflow-item-send-back.component';
describe('WorkflowItemSendBackComponent', () => {
let component: WorkflowItemSendBackComponent;
let fixture: ComponentFixture<WorkflowItemSendBackComponent>;
let wfiService;
let wfi;
let itemRD$;
let id;
function init() {
wfiService = jasmine.createSpyObj('workflowItemService', {
sendBack: observableOf(true)
});
itemRD$ = createSuccessfulRemoteDataObject$(itemRD$);
wfi = new WorkflowItem();
wfi.item = itemRD$;
id = 'de11b5e5-064a-4e98-a7ac-a1a6a65ddf80';
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
declarations: [ WorkflowItemSendBackComponent ]
imports: [TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: MockTranslateLoader
}
})],
declarations: [WorkflowItemSendBackComponent, VarDirective],
providers: [
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub({}, { wfi: createSuccessfulRemoteDataObject(wfi) }) },
{ provide: Router, useClass: RouterStub },
{ provide: RouteService, useValue: {} },
{ provide: NotificationsService, useClass: NotificationsServiceStub },
{ provide: WorkflowItemDataService, useValue: wfiService },
],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
.compileComponents();
}));
beforeEach(() => {
@@ -22,4 +65,9 @@ describe('WorkflowItemSendBackComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call sendBack on the workflow-item service when sendRequest is called', () => {
component.sendRequest(id);
expect(wfiService.sendBack).toHaveBeenCalledWith(id);
});
});

View File

@@ -11,6 +11,9 @@ import { TranslateService } from '@ngx-translate/core';
selector: 'ds-workflow-item-send-back',
templateUrl: '../workflow-item-action-page.component.html'
})
/**
* Component representing a page to send back a workflow item to the submitter
*/
export class WorkflowItemSendBackComponent extends WorkflowItemActionPageComponent {
constructor(protected route: ActivatedRoute,
protected workflowItemService: WorkflowItemDataService,
@@ -21,10 +24,17 @@ export class WorkflowItemSendBackComponent extends WorkflowItemActionPageCompone
super(route, workflowItemService, router, routeService, notificationsService, translationService);
}
/**
* Returns the type of page
*/
getType(): string {
return 'send-back';
}
/**
* Performs the action of this workflow item action page
* @param id The id of the WorkflowItem
*/
sendRequest(id: string): Observable<boolean> {
return this.workflowItemService.sendBack(id);
}