[ADF-2320] Complete button is visible on an involved task (#3033)

* * [ADF-2320] Conditionally showing Complete button for task without form

* * [ADF-2320] Refactored the coditions
This commit is contained in:
Deepak Paul 2018-03-08 15:32:41 +05:30 committed by Eugenio Romano
parent 6afdbcad7c
commit 1fade9b23b
3 changed files with 36 additions and 5 deletions

View File

@ -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 }}
</div>
<button mat-raised-button class="activiti-task-details__action-button"
*ngIf="!hasFormKey() && isTaskActive()" (click)="onComplete()">
*ngIf="isCompleteButtonVisible()" (click)="onComplete()">
{{ 'ADF_TASK_LIST.DETAILS.BUTTON.COMPLETE' | translate }}
</button>
</div>

View File

@ -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);

View File

@ -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;
}