mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
68954: Tests + AoT build fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<button type="button"
|
<button type="button"
|
||||||
[className]="'btn btn-success ' + wrapperClass"
|
[className]="'btn btn-success'"
|
||||||
ngbTooltip="{{'submission.workflow.tasks.claimed.approve_help' | translate}}"
|
ngbTooltip="{{'submission.workflow.tasks.claimed.approve_help' | translate}}"
|
||||||
[disabled]="processing$ | async"
|
[disabled]="processing$ | async"
|
||||||
(click)="process()">
|
(click)="process()">
|
||||||
|
@@ -2,14 +2,23 @@ import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
import { ClaimedTaskActionsApproveComponent } from './claimed-task-actions-approve.component';
|
import { ClaimedTaskActionsApproveComponent } from './claimed-task-actions-approve.component';
|
||||||
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { ProcessTaskResponse } from '../../../../core/tasks/models/process-task-response';
|
||||||
|
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||||
|
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||||
|
|
||||||
let component: ClaimedTaskActionsApproveComponent;
|
let component: ClaimedTaskActionsApproveComponent;
|
||||||
let fixture: ComponentFixture<ClaimedTaskActionsApproveComponent>;
|
let fixture: ComponentFixture<ClaimedTaskActionsApproveComponent>;
|
||||||
|
|
||||||
describe('ClaimedTaskActionsApproveComponent', () => {
|
describe('ClaimedTaskActionsApproveComponent', () => {
|
||||||
|
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
|
||||||
|
const claimedTaskService = jasmine.createSpyObj('claimedTaskService', {
|
||||||
|
approveTask: observableOf(new ProcessTaskResponse(true))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -20,6 +29,9 @@ describe('ClaimedTaskActionsApproveComponent', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: ClaimedTaskDataService, useValue: claimedTaskService }
|
||||||
|
],
|
||||||
declarations: [ClaimedTaskActionsApproveComponent],
|
declarations: [ClaimedTaskActionsApproveComponent],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(ClaimedTaskActionsApproveComponent, {
|
}).overrideComponent(ClaimedTaskActionsApproveComponent, {
|
||||||
@@ -30,14 +42,10 @@ describe('ClaimedTaskActionsApproveComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ClaimedTaskActionsApproveComponent);
|
fixture = TestBed.createComponent(ClaimedTaskActionsApproveComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.object = object;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture = null;
|
|
||||||
component = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display approve button', () => {
|
it('should display approve button', () => {
|
||||||
const btn = fixture.debugElement.query(By.css('.btn-success'));
|
const btn = fixture.debugElement.query(By.css('.btn-success'));
|
||||||
|
|
||||||
@@ -45,7 +53,7 @@ describe('ClaimedTaskActionsApproveComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display spin icon when approve is pending', () => {
|
it('should display spin icon when approve is pending', () => {
|
||||||
component.processingApprove = true;
|
component.processing$.next(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const span = fixture.debugElement.query(By.css('.btn-success .fa-spin'));
|
const span = fixture.debugElement.query(By.css('.btn-success .fa-spin'));
|
||||||
@@ -53,13 +61,13 @@ describe('ClaimedTaskActionsApproveComponent', () => {
|
|||||||
expect(span).toBeDefined();
|
expect(span).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit approve event', () => {
|
it('should emit a successful processCompleted event', () => {
|
||||||
spyOn(component.approve, 'emit');
|
spyOn(component.processCompleted, 'emit');
|
||||||
|
|
||||||
component.confirmApprove();
|
component.process();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.approve.emit).toHaveBeenCalled();
|
expect(component.processCompleted.emit).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { async, ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { By } from '@angular/platform-browser';
|
|
||||||
|
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { cold } from 'jasmine-marbles';
|
import { cold } from 'jasmine-marbles';
|
||||||
@@ -16,11 +15,14 @@ import { ClaimedTaskDataService } from '../../../core/tasks/claimed-task-data.se
|
|||||||
import { ClaimedTaskActionsComponent } from './claimed-task-actions.component';
|
import { ClaimedTaskActionsComponent } from './claimed-task-actions.component';
|
||||||
import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model';
|
import { ClaimedTask } from '../../../core/tasks/models/claimed-task-object.model';
|
||||||
import { WorkflowItem } from '../../../core/submission/models/workflowitem.model';
|
import { WorkflowItem } from '../../../core/submission/models/workflowitem.model';
|
||||||
import { createSuccessfulRemoteDataObject } from '../../testing/utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../testing/utils';
|
||||||
import { getMockSearchService } from '../../mocks/mock-search-service';
|
import { getMockSearchService } from '../../mocks/mock-search-service';
|
||||||
import { getMockRequestService } from '../../mocks/mock-request.service';
|
import { getMockRequestService } from '../../mocks/mock-request.service';
|
||||||
import { RequestService } from '../../../core/data/request.service';
|
import { RequestService } from '../../../core/data/request.service';
|
||||||
import { SearchService } from '../../../core/shared/search/search.service';
|
import { SearchService } from '../../../core/shared/search/search.service';
|
||||||
|
import { WorkflowActionDataService } from '../../../core/data/workflow-action-data.service';
|
||||||
|
import { WorkflowAction } from '../../../core/tasks/models/workflow-action-object.model';
|
||||||
|
import { VarDirective } from '../../utils/var.directive';
|
||||||
|
|
||||||
let component: ClaimedTaskActionsComponent;
|
let component: ClaimedTaskActionsComponent;
|
||||||
let fixture: ComponentFixture<ClaimedTaskActionsComponent>;
|
let fixture: ComponentFixture<ClaimedTaskActionsComponent>;
|
||||||
@@ -30,15 +32,15 @@ let notificationsServiceStub: NotificationsServiceStub;
|
|||||||
let router: RouterStub;
|
let router: RouterStub;
|
||||||
|
|
||||||
let mockDataService;
|
let mockDataService;
|
||||||
|
|
||||||
let searchService;
|
let searchService;
|
||||||
|
|
||||||
let requestServce;
|
let requestServce;
|
||||||
|
let workflowActionService: WorkflowActionDataService;
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
let rdItem;
|
let rdItem;
|
||||||
let workflowitem;
|
let workflowitem;
|
||||||
let rdWorkflowitem;
|
let rdWorkflowitem;
|
||||||
|
let workflowAction;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
mockDataService = jasmine.createSpyObj('ClaimedTaskDataService', {
|
mockDataService = jasmine.createSpyObj('ClaimedTaskDataService', {
|
||||||
@@ -46,9 +48,7 @@ function init() {
|
|||||||
rejectTask: jasmine.createSpy('rejectTask'),
|
rejectTask: jasmine.createSpy('rejectTask'),
|
||||||
returnToPoolTask: jasmine.createSpy('returnToPoolTask'),
|
returnToPoolTask: jasmine.createSpy('returnToPoolTask'),
|
||||||
});
|
});
|
||||||
|
|
||||||
searchService = getMockSearchService();
|
searchService = getMockSearchService();
|
||||||
|
|
||||||
requestServce = getMockRequestService();
|
requestServce = getMockRequestService();
|
||||||
|
|
||||||
item = Object.assign(new Item(), {
|
item = Object.assign(new Item(), {
|
||||||
@@ -84,7 +84,11 @@ function init() {
|
|||||||
workflowitem = Object.assign(new WorkflowItem(), { item: observableOf(rdItem) });
|
workflowitem = Object.assign(new WorkflowItem(), { item: observableOf(rdItem) });
|
||||||
rdWorkflowitem = createSuccessfulRemoteDataObject(workflowitem);
|
rdWorkflowitem = createSuccessfulRemoteDataObject(workflowitem);
|
||||||
mockObject = Object.assign(new ClaimedTask(), { workflowitem: observableOf(rdWorkflowitem), id: '1234' });
|
mockObject = Object.assign(new ClaimedTask(), { workflowitem: observableOf(rdWorkflowitem), id: '1234' });
|
||||||
|
workflowAction = Object.assign(new WorkflowAction(), { id: 'action-1', options: ['option-1', 'option-2'] });
|
||||||
|
|
||||||
|
workflowActionService = jasmine.createSpyObj('workflowActionService', {
|
||||||
|
findById: createSuccessfulRemoteDataObject$(workflowAction)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('ClaimedTaskActionsComponent', () => {
|
describe('ClaimedTaskActionsComponent', () => {
|
||||||
@@ -99,14 +103,15 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
declarations: [ClaimedTaskActionsComponent],
|
declarations: [ClaimedTaskActionsComponent, VarDirective],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: Injector, useValue: {} },
|
{ provide: Injector, useValue: {} },
|
||||||
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
{ provide: NotificationsService, useValue: new NotificationsServiceStub() },
|
||||||
{ provide: Router, useValue: new RouterStub() },
|
{ provide: Router, useValue: new RouterStub() },
|
||||||
{ provide: ClaimedTaskDataService, useValue: mockDataService },
|
{ provide: ClaimedTaskDataService, useValue: mockDataService },
|
||||||
{ provide: SearchService, useValue: searchService },
|
{ provide: SearchService, useValue: searchService },
|
||||||
{ provide: RequestService, useValue: requestServce }
|
{ provide: RequestService, useValue: requestServce },
|
||||||
|
{ provide: WorkflowActionDataService, useValue: workflowActionService }
|
||||||
],
|
],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(ClaimedTaskActionsComponent, {
|
}).overrideComponent(ClaimedTaskActionsComponent, {
|
||||||
@@ -123,11 +128,6 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture = null;
|
|
||||||
component = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should init objects properly', () => {
|
it('should init objects properly', () => {
|
||||||
component.object = null;
|
component.object = null;
|
||||||
component.initObjects(mockObject);
|
component.initObjects(mockObject);
|
||||||
@@ -136,46 +136,14 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
|
|
||||||
expect(component.workflowitem$).toBeObservable(cold('(b|)', {
|
expect(component.workflowitem$).toBeObservable(cold('(b|)', {
|
||||||
b: rdWorkflowitem.payload
|
b: rdWorkflowitem.payload
|
||||||
}))
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display edit task button', () => {
|
it('should reload page on process completed', async(() => {
|
||||||
const btn = fixture.debugElement.query(By.css('.btn-info'));
|
|
||||||
|
|
||||||
expect(btn).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call approveTask method when approving a task', fakeAsync(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.approveTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.approve();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(mockDataService.approveTask).toHaveBeenCalledWith(mockObject.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display a success notification on approve success', async(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.approveTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.approve();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should reload page on approve success', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl');
|
spyOn(router, 'navigateByUrl');
|
||||||
router.url = 'test.url/test';
|
router.url = 'test.url/test';
|
||||||
mockDataService.approveTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.approve();
|
component.handleActionResponse(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
@@ -183,108 +151,8 @@ describe('ClaimedTaskActionsComponent', () => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should display an error notification on approve failure', async(() => {
|
it('should display an error notification on process failure', async(() => {
|
||||||
mockDataService.approveTask.and.returnValue(observableOf({hasSucceeded: false}));
|
component.handleActionResponse(false);
|
||||||
|
|
||||||
component.approve();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(notificationsServiceStub.error).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call rejectTask method when rejecting a task', fakeAsync(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.rejectTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.reject('test reject');
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(mockDataService.rejectTask).toHaveBeenCalledWith('test reject', mockObject.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display a success notification on reject success', async(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.rejectTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.reject('test reject');
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should reload page on reject success', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl');
|
|
||||||
router.url = 'test.url/test';
|
|
||||||
mockDataService.rejectTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.reject('test reject');
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('test.url/test');
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display an error notification on reject failure', async(() => {
|
|
||||||
mockDataService.rejectTask.and.returnValue(observableOf({hasSucceeded: false}));
|
|
||||||
|
|
||||||
component.reject('test reject');
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(notificationsServiceStub.error).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should call returnToPoolTask method when returning a task to pool', fakeAsync(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.returnToPoolTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.returnToPool();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(mockDataService.returnToPoolTask).toHaveBeenCalledWith( mockObject.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display a success notification on return to pool success', async(() => {
|
|
||||||
spyOn(component, 'reload');
|
|
||||||
mockDataService.returnToPoolTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.returnToPool();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(notificationsServiceStub.success).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should reload page on return to pool success', async(() => {
|
|
||||||
spyOn(router, 'navigateByUrl');
|
|
||||||
router.url = 'test.url/test';
|
|
||||||
mockDataService.returnToPoolTask.and.returnValue(observableOf({hasSucceeded: true}));
|
|
||||||
|
|
||||||
component.returnToPool();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith('test.url/test');
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should display an error notification on return to pool failure', async(() => {
|
|
||||||
mockDataService.returnToPoolTask.and.returnValue(observableOf({hasSucceeded: false}));
|
|
||||||
|
|
||||||
component.returnToPool();
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
|
@@ -3,13 +3,16 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { ClaimedTaskActionsEditMetadataComponent } from './claimed-task-actions-approve.component';
|
import { ClaimedTaskActionsEditMetadataComponent } from './claimed-task-actions-edit-metadata.component';
|
||||||
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||||
|
|
||||||
let component: ClaimedTaskActionsEditMetadataComponent;
|
let component: ClaimedTaskActionsEditMetadataComponent;
|
||||||
let fixture: ComponentFixture<ClaimedTaskActionsEditMetadataComponent>;
|
let fixture: ComponentFixture<ClaimedTaskActionsEditMetadataComponent>;
|
||||||
|
|
||||||
describe('ClaimedTaskActionsApproveComponent', () => {
|
describe('ClaimedTaskActionsEditMetadataComponent', () => {
|
||||||
|
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -30,36 +33,14 @@ describe('ClaimedTaskActionsApproveComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ClaimedTaskActionsEditMetadataComponent);
|
fixture = TestBed.createComponent(ClaimedTaskActionsEditMetadataComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.object = object;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
it('should display edit button', () => {
|
||||||
fixture = null;
|
const btn = fixture.debugElement.query(By.css('.btn-primary'));
|
||||||
component = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display approve button', () => {
|
|
||||||
const btn = fixture.debugElement.query(By.css('.btn-success'));
|
|
||||||
|
|
||||||
expect(btn).toBeDefined();
|
expect(btn).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display spin icon when approve is pending', () => {
|
|
||||||
component.processingApprove = true;
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
const span = fixture.debugElement.query(By.css('.btn-success .fa-spin'));
|
|
||||||
|
|
||||||
expect(span).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should emit approve event', () => {
|
|
||||||
spyOn(component.approve, 'emit');
|
|
||||||
|
|
||||||
component.confirmApprove();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(component.approve.emit).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<ng-template #rejectTipContent><p [innerHTML]="'submission.workflow.tasks.claimed.reject_help' | translate"></p></ng-template>
|
<ng-template #rejectTipContent><p [innerHTML]="'submission.workflow.tasks.claimed.reject_help' | translate"></p></ng-template>
|
||||||
<button [className]="'btn btn-danger ' + wrapperClass"
|
<button [className]="'btn btn-danger'"
|
||||||
[ngbTooltip]="rejectTipContent"
|
[ngbTooltip]="rejectTipContent"
|
||||||
[disabled]="processing$ | async"
|
[disabled]="processing$ | async"
|
||||||
(click)="openRejectModal(rejectModal)" >
|
(click)="openRejectModal(rejectModal)" >
|
||||||
|
@@ -8,6 +8,10 @@ import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
|||||||
|
|
||||||
import { ClaimedTaskActionsRejectComponent } from './claimed-task-actions-reject.component';
|
import { ClaimedTaskActionsRejectComponent } from './claimed-task-actions-reject.component';
|
||||||
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||||
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
|
import { ProcessTaskResponse } from '../../../../core/tasks/models/process-task-response';
|
||||||
|
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||||
|
|
||||||
let component: ClaimedTaskActionsRejectComponent;
|
let component: ClaimedTaskActionsRejectComponent;
|
||||||
let fixture: ComponentFixture<ClaimedTaskActionsRejectComponent>;
|
let fixture: ComponentFixture<ClaimedTaskActionsRejectComponent>;
|
||||||
@@ -15,6 +19,11 @@ let formBuilder: FormBuilder;
|
|||||||
let modalService: NgbModal;
|
let modalService: NgbModal;
|
||||||
|
|
||||||
describe('ClaimedTaskActionsRejectComponent', () => {
|
describe('ClaimedTaskActionsRejectComponent', () => {
|
||||||
|
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
|
||||||
|
const claimedTaskService = jasmine.createSpyObj('claimedTaskService', {
|
||||||
|
rejectTask: observableOf(new ProcessTaskResponse(true))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -29,6 +38,7 @@ describe('ClaimedTaskActionsRejectComponent', () => {
|
|||||||
],
|
],
|
||||||
declarations: [ClaimedTaskActionsRejectComponent],
|
declarations: [ClaimedTaskActionsRejectComponent],
|
||||||
providers: [
|
providers: [
|
||||||
|
{ provide: ClaimedTaskDataService, useValue: claimedTaskService },
|
||||||
FormBuilder,
|
FormBuilder,
|
||||||
NgbModal
|
NgbModal
|
||||||
],
|
],
|
||||||
@@ -43,17 +53,11 @@ describe('ClaimedTaskActionsRejectComponent', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
formBuilder = TestBed.get(FormBuilder);
|
formBuilder = TestBed.get(FormBuilder);
|
||||||
modalService = TestBed.get(NgbModal);
|
modalService = TestBed.get(NgbModal);
|
||||||
|
component.object = object;
|
||||||
component.modalRef = modalService.open('ok');
|
component.modalRef = modalService.open('ok');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture = null;
|
|
||||||
component = null;
|
|
||||||
modalService = null;
|
|
||||||
formBuilder = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should init reject form properly', () => {
|
it('should init reject form properly', () => {
|
||||||
expect(component.rejectForm).toBeDefined();
|
expect(component.rejectForm).toBeDefined();
|
||||||
expect(component.rejectForm instanceof FormGroup).toBeTruthy();
|
expect(component.rejectForm instanceof FormGroup).toBeTruthy();
|
||||||
@@ -67,7 +71,7 @@ describe('ClaimedTaskActionsRejectComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display spin icon when reject is pending', () => {
|
it('should display spin icon when reject is pending', () => {
|
||||||
component.processingReject = true;
|
component.processing$.next(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const span = fixture.debugElement.query(By.css('.btn-danger .fa-spin'));
|
const span = fixture.debugElement.query(By.css('.btn-danger .fa-spin'));
|
||||||
@@ -87,8 +91,8 @@ describe('ClaimedTaskActionsRejectComponent', () => {
|
|||||||
component.modalRef.close()
|
component.modalRef.close()
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call confirmReject on form submit', () => {
|
it('should call processCompleted on form submit', () => {
|
||||||
spyOn(component.reject, 'emit');
|
spyOn(component.processCompleted, 'emit');
|
||||||
|
|
||||||
const btn = fixture.debugElement.query(By.css('.btn-danger'));
|
const btn = fixture.debugElement.query(By.css('.btn-danger'));
|
||||||
btn.nativeElement.click();
|
btn.nativeElement.click();
|
||||||
@@ -100,9 +104,6 @@ describe('ClaimedTaskActionsRejectComponent', () => {
|
|||||||
form.dispatchEvent(new Event('ngSubmit'));
|
form.dispatchEvent(new Event('ngSubmit'));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
expect(component.processCompleted.emit).toHaveBeenCalled();
|
||||||
expect(component.reject.emit).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<button type="button"
|
<button type="button"
|
||||||
[className]="'btn btn-secondary ' + wrapperClass"
|
[className]="'btn btn-secondary'"
|
||||||
ngbTooltip="{{'submission.workflow.tasks.claimed.return_help' | translate}}"
|
ngbTooltip="{{'submission.workflow.tasks.claimed.return_help' | translate}}"
|
||||||
[disabled]="processing$ | async"
|
[disabled]="processing$ | async"
|
||||||
(click)="process()">
|
(click)="process()">
|
||||||
|
@@ -5,11 +5,20 @@ import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
|||||||
|
|
||||||
import { ClaimedTaskActionsReturnToPoolComponent } from './claimed-task-actions-return-to-pool.component';
|
import { ClaimedTaskActionsReturnToPoolComponent } from './claimed-task-actions-return-to-pool.component';
|
||||||
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
import { MockTranslateLoader } from '../../../mocks/mock-translate-loader';
|
||||||
|
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||||
|
import { of as observableOf } from 'rxjs/internal/observable/of';
|
||||||
|
import { ProcessTaskResponse } from '../../../../core/tasks/models/process-task-response';
|
||||||
|
import { ClaimedTaskDataService } from '../../../../core/tasks/claimed-task-data.service';
|
||||||
|
|
||||||
let component: ClaimedTaskActionsReturnToPoolComponent;
|
let component: ClaimedTaskActionsReturnToPoolComponent;
|
||||||
let fixture: ComponentFixture<ClaimedTaskActionsReturnToPoolComponent>;
|
let fixture: ComponentFixture<ClaimedTaskActionsReturnToPoolComponent>;
|
||||||
|
|
||||||
describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
||||||
|
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
|
||||||
|
const claimedTaskService = jasmine.createSpyObj('claimedTaskService', {
|
||||||
|
returnToPoolTask: observableOf(new ProcessTaskResponse(true))
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -20,6 +29,9 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: ClaimedTaskDataService, useValue: claimedTaskService }
|
||||||
|
],
|
||||||
declarations: [ClaimedTaskActionsReturnToPoolComponent],
|
declarations: [ClaimedTaskActionsReturnToPoolComponent],
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(ClaimedTaskActionsReturnToPoolComponent, {
|
}).overrideComponent(ClaimedTaskActionsReturnToPoolComponent, {
|
||||||
@@ -30,14 +42,10 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ClaimedTaskActionsReturnToPoolComponent);
|
fixture = TestBed.createComponent(ClaimedTaskActionsReturnToPoolComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.object = object;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
fixture = null;
|
|
||||||
component = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should display return to pool button', () => {
|
it('should display return to pool button', () => {
|
||||||
const btn = fixture.debugElement.query(By.css('.btn-secondary'));
|
const btn = fixture.debugElement.query(By.css('.btn-secondary'));
|
||||||
|
|
||||||
@@ -45,7 +53,7 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should display spin icon when return to pool action is pending', () => {
|
it('should display spin icon when return to pool action is pending', () => {
|
||||||
component.processingReturnToPool = true;
|
component.processing$.next(true);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const span = fixture.debugElement.query(By.css('.btn-secondary .fa-spin'));
|
const span = fixture.debugElement.query(By.css('.btn-secondary .fa-spin'));
|
||||||
@@ -53,13 +61,13 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => {
|
|||||||
expect(span).toBeDefined();
|
expect(span).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit return to pool event', () => {
|
it('should emit a successful processCompleted event', () => {
|
||||||
spyOn(component.returnToPool, 'emit');
|
spyOn(component.processCompleted, 'emit');
|
||||||
|
|
||||||
component.confirmReturnToPool();
|
component.process();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.returnToPool.emit).toHaveBeenCalled();
|
expect(component.processCompleted.emit).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
import { getComponentByWorkflowTaskOption, rendersWorkflowTaskOption } from './claimed-task-actions-decorator';
|
||||||
|
|
||||||
|
describe('ClaimedTaskActions decorator function', () => {
|
||||||
|
const option1 = 'test_option_1';
|
||||||
|
const option2 = 'test_option_2';
|
||||||
|
const option3 = 'test_option_3';
|
||||||
|
|
||||||
|
/* tslint:disable:max-classes-per-file */
|
||||||
|
class Test1Action {};
|
||||||
|
class Test2Action {};
|
||||||
|
class Test3Action {};
|
||||||
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
rendersWorkflowTaskOption(option1)(Test1Action);
|
||||||
|
rendersWorkflowTaskOption(option2)(Test2Action);
|
||||||
|
rendersWorkflowTaskOption(option3)(Test3Action);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('If there\'s an exact match', () => {
|
||||||
|
it('should return the matching class', () => {
|
||||||
|
const component = getComponentByWorkflowTaskOption(option1);
|
||||||
|
expect(component).toEqual(Test1Action);
|
||||||
|
|
||||||
|
const component2 = getComponentByWorkflowTaskOption(option2);
|
||||||
|
expect(component2).toEqual(Test2Action);
|
||||||
|
|
||||||
|
const component3 = getComponentByWorkflowTaskOption(option3);
|
||||||
|
expect(component3).toEqual(Test3Action);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('If there\'s no match', () => {
|
||||||
|
it('should return unidentified', () => {
|
||||||
|
const component = getComponentByWorkflowTaskOption('non-existing-option');
|
||||||
|
expect(component).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,47 @@
|
|||||||
|
import { ClaimedTaskActionsLoaderComponent } from './claimed-task-actions-loader.component';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { ChangeDetectionStrategy, Component, ComponentFactoryResolver, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { spyOnExported } from '../../../testing/utils';
|
||||||
|
import * as decorators from './claimed-task-actions-decorator';
|
||||||
|
import { ClaimedTaskActionsDirective } from './claimed-task-actions.directive';
|
||||||
|
import { ClaimedTask } from '../../../../core/tasks/models/claimed-task-object.model';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { ClaimedTaskActionsEditMetadataComponent } from '../edit-metadata/claimed-task-actions-edit-metadata.component';
|
||||||
|
|
||||||
|
describe('ClaimedTaskActionsLoaderComponent', () => {
|
||||||
|
let comp: ClaimedTaskActionsLoaderComponent;
|
||||||
|
let fixture: ComponentFixture<ClaimedTaskActionsLoaderComponent>;
|
||||||
|
|
||||||
|
const option = 'test_option';
|
||||||
|
const object = Object.assign(new ClaimedTask(), { id: 'claimed-task-1' });
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [TranslateModule.forRoot()],
|
||||||
|
declarations: [ClaimedTaskActionsLoaderComponent, ClaimedTaskActionsEditMetadataComponent, ClaimedTaskActionsDirective],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA],
|
||||||
|
providers: [ComponentFactoryResolver]
|
||||||
|
}).overrideComponent(ClaimedTaskActionsLoaderComponent, {
|
||||||
|
set: {
|
||||||
|
changeDetection: ChangeDetectionStrategy.Default,
|
||||||
|
entryComponents: [ClaimedTaskActionsEditMetadataComponent]
|
||||||
|
}
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
fixture = TestBed.createComponent(ClaimedTaskActionsLoaderComponent);
|
||||||
|
comp = fixture.componentInstance;
|
||||||
|
|
||||||
|
comp.object = object;
|
||||||
|
comp.option = option;
|
||||||
|
spyOnExported(decorators, 'getComponentByWorkflowTaskOption').and.returnValue(ClaimedTaskActionsEditMetadataComponent);
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('When the component is rendered', () => {
|
||||||
|
it('should call the getComponentByWorkflowTaskOption function with the right option', () => {
|
||||||
|
expect(decorators.getComponentByWorkflowTaskOption).toHaveBeenCalledWith(option);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user