diff --git a/lib/process-services/task-list/components/task-details.component.html b/lib/process-services/task-list/components/task-details.component.html index d91272b024..39a387b172 100644 --- a/lib/process-services/task-list/components/task-details.component.html +++ b/lib/process-services/task-list/components/task-details.component.html @@ -28,7 +28,7 @@ [showTitle]="showFormTitle" [showRefreshButton]="showFormRefreshButton" [showCompleteButton]="showFormCompleteButton" - [disableCompleteButton]="!isCompleteButtonVisible()" + [disableCompleteButton]="!isCompleteButtonEnabled()" [showSaveButton]="isSaveButtonVisible()" [readOnly]="readOnlyForm" [fieldValidators]="fieldValidators" @@ -45,7 +45,7 @@ {{ 'ADF_TASK_LIST.DETAILS.MESSAGES.CLAIM' | translate }} diff --git a/lib/process-services/task-list/components/task-details.component.spec.ts b/lib/process-services/task-list/components/task-details.component.spec.ts index c481946788..357dcda125 100644 --- a/lib/process-services/task-list/components/task-details.component.spec.ts +++ b/lib/process-services/task-list/components/task-details.component.spec.ts @@ -24,7 +24,7 @@ import { Observable } from 'rxjs/Observable'; import { FormModule, FormModel, FormOutcomeEvent, FormOutcomeModel, FormService } from '@alfresco/adf-core'; import { CommentProcessService, LogService } from '@alfresco/adf-core'; -import { PeopleProcessService, UserProcessModel } from '@alfresco/adf-core'; +import { PeopleProcessService, UserProcessModel, AuthenticationService } from '@alfresco/adf-core'; import { TaskDetailsModel } from '../models/task-details.model'; import { noDataMock, taskDetailsMock, taskFormMock, tasksMock } from '../../mock'; import { TaskListService } from './../services/tasklist.service'; @@ -52,6 +52,7 @@ describe('TaskDetailsComponent', () => { let completeTaskSpy: jasmine.Spy; let logService: LogService; let commentProcessService: CommentProcessService; + let authService: AuthenticationService; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -67,7 +68,8 @@ describe('TaskDetailsComponent', () => { providers: [ TaskListService, PeopleProcessService, - CommentProcessService + CommentProcessService, + AuthenticationService ], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); @@ -83,6 +85,7 @@ describe('TaskDetailsComponent', () => { service = fixture.debugElement.injector.get(TaskListService); formService = fixture.debugElement.injector.get(FormService); commentProcessService = TestBed.get(CommentProcessService); + authService = TestBed.get(AuthenticationService); getTaskDetailsSpy = spyOn(service, 'getTaskDetails').and.returnValue(Observable.of(taskDetailsMock)); spyOn(formService, 'getTaskForm').and.returnValue(Observable.of(taskFormMock)); @@ -146,6 +149,30 @@ describe('TaskDetailsComponent', () => { }); })); + it('should display complete button when task without form is assigned to current user', async(() => { + spyOn(authService, 'getBpmUsername').and.returnValue(taskDetailsMock.assignee.email); + taskDetailsMock.formKey = undefined; + component.taskId = '123'; + fixture.detectChanges(); + fixture.whenStable().then(() => { + const completeBtn = fixture.nativeElement.querySelector('button'); + expect(completeBtn).toBeDefined(); + expect(completeBtn.disabled).toBeFalsy(); + expect(completeBtn.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.COMPLETE'); + }); + })); + + it('should not display complete button when task without form is not assigned to current user', async(() => { + spyOn(authService, 'getBpmUsername').and.returnValue(''); + component.taskId = '123'; + taskDetailsMock.formKey = undefined; + fixture.detectChanges(); + fixture.whenStable().then(() => { + const completeBtn = fixture.nativeElement.querySelector('.activiti-task-details__action-button'); + expect(completeBtn).toBeNull(); + }); + })); + describe('change detection', () => { let change = new SimpleChange('123', '456', true); diff --git a/lib/process-services/task-list/components/task-details.component.ts b/lib/process-services/task-list/components/task-details.component.ts index 46aa58ccd0..fb755113fe 100644 --- a/lib/process-services/task-list/components/task-details.component.ts +++ b/lib/process-services/task-list/components/task-details.component.ts @@ -292,10 +292,14 @@ export class TaskDetailsComponent implements OnInit, OnChanges { return this.taskDetails.assignee.email === this.authService.getBpmUsername(); } - isCompleteButtonVisible(): boolean { + isCompleteButtonEnabled(): boolean { return this.isAssignedToMe() || this.canInitiatorComplete(); } + isCompleteButtonVisible(): boolean { + return !this.hasFormKey() && this.isTaskActive() && this.isCompleteButtonEnabled(); + } + canInitiatorComplete(): boolean { return this.taskDetails.initiatorCanCompleteTask; }