[ADF-1712] The <adf-task-header component displays a Requeue button for none pooled tasks (#2628)

* [ADF-1712] The <adf-task-header component displays a Requeue button for none pooled tasks.

* Refactored task-header component.
* Added test cases.

* [ADF-1712] The <adf-task-header component displays a Requeue button for none pooled tasks.

* Refactored task header component.
* Refactored test cases.

* [ADF-1712 ] The <adf-task-header component displays a Requeue button for none pooled tasks.

* Refactored header component.
* Test cases for the changes have been added.

* [ ADF-1712 ] The <adf-task-header component displays a Requeue button for none pooled tasks.

* Refactored header component, renamed method names.
* Added test cases.

* * Refactored isComplete method.
This commit is contained in:
siva kumar 2017-11-09 21:49:52 +05:30 committed by Maurizio Vitale
parent 1e0b20517c
commit 34f51e3558
6 changed files with 311 additions and 40 deletions

View File

@ -45,12 +45,122 @@ export let taskDetailsMock = new TaskDetailsModel({
'adhocTaskCanBeReassigned': false,
'taskDefinitionKey': 'sid-DDECD9E4-0299-433F-9193-C3D905C3EEBE',
'executionId': '86',
'involvedGroups': [],
'involvedPeople': [],
'memberOfCandidateUsers': false,
'managerOfCandidateGroup': false,
'memberOfCandidateGroup': false
});
export let completedTaskDetailsMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
'category': null,
'assignee': {'id': 1001, 'firstName': 'Wilbur', 'lastName': 'Adams', 'email': 'wilbur@app.activiti.com'},
'created': '2016-11-03T15:25:42.749+0000',
'dueDate': null,
'endDate': '2016-11-03T15:25:42.749+0000',
'duration': null,
'priority': 50,
'parentTaskId': null,
'parentTaskName': null,
'processInstanceId': '86',
'processInstanceName': null,
'processDefinitionId': 'TranslationProcess:2:8',
'processDefinitionName': 'Translation Process',
'involvedGroups': [],
'involvedPeople': []
});
export let taskDetailsWithOutAssigneeMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
'category': null,
'assignee': null,
'created': '2016-11-03T15:25:42.749+0000',
'dueDate': null,
'endDate': null,
'duration': null,
'priority': 50,
'parentTaskId': null,
'parentTaskName': null,
'processInstanceId': '86',
'processInstanceName': null,
'processDefinitionId': 'TranslationProcess:2:8',
'processDefinitionName': 'Translation Process',
'involvedGroups': [{'id': 7007, 'name': 'group1', 'externalId': null, 'status': 'active', 'groups': null},
{'id': 8008, 'name': 'group2', 'externalId': null, 'status': 'active', 'groups': null}],
'involvedPeople': []
});
export let taskDetailsWithInvolvedGroupMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
'category': null,
'assignee': {'id': 1001, 'firstName': 'Wilbur', 'lastName': 'Adams', 'email': 'wilbur@app.activiti.com'},
'created': '2016-11-03T15:25:42.749+0000',
'dueDate': null,
'endDate': null,
'duration': null,
'priority': 50,
'parentTaskId': null,
'parentTaskName': null,
'processInstanceId': '86',
'processInstanceName': null,
'processDefinitionId': 'TranslationProcess:2:8',
'processDefinitionName': 'Translation Process',
'involvedGroups': [{'id': 7007, 'name': 'group1', 'externalId': null, 'status': 'active', 'groups': null},
{'id': 8008, 'name': 'group2', 'externalId': null, 'status': 'active', 'groups': null}],
'involvedPeople': []
});
export let taskDetailsWithInvolvedPeopleMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
'category': null,
'assignee': {'id': 1001, 'firstName': 'Wilbur', 'lastName': 'Adams', 'email': 'wilbur@app.activiti.com'},
'created': '2016-11-03T15:25:42.749+0000',
'dueDate': null,
'endDate': null,
'duration': null,
'priority': 50,
'parentTaskId': null,
'parentTaskName': null,
'processInstanceId': '86',
'processInstanceName': null,
'processDefinitionId': 'TranslationProcess:2:8',
'processDefinitionName': 'Translation Process',
'involvedGroups': [],
'involvedPeople': [{'id': 1001, 'firstName': 'Wilbur', 'lastName': 'Adams', 'email': 'wilbur@app.activiti.com'},
{'id': 111, 'firstName': 'fake-first-name', 'lastName': 'fake-last-name', 'email': 'fake@app.activiti.com'}]
});
export let taskDetailsWithAssigneeMock = new TaskDetailsModel({
'id': '91',
'name': 'Request translation',
'description': null,
'category': null,
'assignee': {'id': 111, 'firstName': 'fake-first-name', 'lastName': 'fake-last-name', 'email': 'fake@app.activiti.com'},
'created': '2016-11-03T15:25:42.749+0000',
'dueDate': null,
'endDate': null,
'duration': null,
'priority': 50,
'parentTaskId': null,
'parentTaskName': null,
'processInstanceId': '86',
'processInstanceName': null,
'processDefinitionId': 'TranslationProcess:2:8',
'processDefinitionName': 'Translation Process',
'involvedGroups': [],
'involvedPeople': [{'id': 1001, 'firstName': 'Wilbur', 'lastName': 'Adams', 'email': 'wilbur@app.activiti.com'},
{'id': 111, 'firstName': 'fake-first-name', 'lastName': 'fake-last-name', 'email': 'fake@app.activiti.com'}]
});
export let taskFormMock = new TaskDetailsModel({
'id': 4,
'name': 'Translation request',

View File

@ -4,9 +4,9 @@
</mat-card-content>
<mat-card-actions class="adf-controls">
<button *ngIf="isAssignedToMe()" mat-button data-automation-id="header-unclaim-button" id="unclaim-task" (click)="unclaimTask(taskDetails.id)" class="adf-claim-controls">{{ 'ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM' | translate }}
<button *ngIf="isTaskClaimedByCurrentUser()" mat-button data-automation-id="header-unclaim-button" id="unclaim-task" (click)="unclaimTask(taskDetails.id)" class="adf-claim-controls">{{ 'ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM' | translate }}
</button>
<button *ngIf="!isAssignedToMe()" mat-button data-automation-id="header-claim-button" id="claim-task" (click)="claimTask(taskDetails.id)" class="adf-claim-controls">{{ 'ADF_TASK_LIST.DETAILS.BUTTON.CLAIM' | translate }}
<button *ngIf="isTaskClaimable()" mat-button data-automation-id="header-claim-button" id="claim-task" (click)="claimTask(taskDetails.id)" class="adf-claim-controls">{{ 'ADF_TASK_LIST.DETAILS.BUTTON.CLAIM' | translate }}
</button>
</mat-card-actions>
</mat-card>

View File

@ -19,12 +19,20 @@ import { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AppConfigService, CardViewUpdateService, CoreModule, TranslationService, UserProcessModel } from 'ng2-alfresco-core';
import { BpmUserService } from 'ng2-alfresco-userinfo';
import { Observable } from 'rxjs/Rx';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { TaskDetailsModel } from '../models/task-details.model';
import { taskDetailsMock } from './../assets/task-details.mock';
import {
completedTaskDetailsMock,
taskDetailsMock,
taskDetailsWithAssigneeMock,
taskDetailsWithInvolvedGroupMock,
taskDetailsWithInvolvedPeopleMock,
taskDetailsWithOutAssigneeMock
} from './../assets/task-details.mock';
import { TaskListService } from './../services/tasklist.service';
import { TaskHeaderComponent } from './task-header.component';
@ -34,6 +42,22 @@ describe('TaskHeaderComponent', () => {
let component: TaskHeaderComponent;
let fixture: ComponentFixture<TaskHeaderComponent>;
let debugElement: DebugElement;
let userBpmService: BpmUserService;
let getCurrentUserInfoSpy: jasmine.Spy;
let fakeBpmAssignedUser = {
id: 1001,
apps: [],
capabilities: 'fake-capability',
company: 'fake-company',
created: 'fake-create-date',
email: 'wilbur@app.activiti.com',
externalId: 'fake-external-id',
firstName: 'Wilbur',
lastName: 'Adams',
fullname: 'Wilbur Adams',
groups: []
};
beforeEach(async(() => {
TestBed.configureTestingModule({
@ -45,20 +69,21 @@ describe('TaskHeaderComponent', () => {
],
providers: [
TaskListService,
BpmUserService,
CardViewUpdateService,
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TaskHeaderComponent);
component = fixture.componentInstance;
service = TestBed.get(TaskListService);
userBpmService = TestBed.get(BpmUserService);
debugElement = fixture.debugElement;
getCurrentUserInfoSpy = spyOn(userBpmService, 'getCurrentUserInfo').and.returnValue(Observable.of(fakeBpmAssignedUser));
component.taskDetails = new TaskDetailsModel(taskDetailsMock);
});
@ -111,7 +136,7 @@ describe('TaskHeaderComponent', () => {
describe('Claiming', () => {
it('should display the claim button if no assignee', () => {
component.taskDetails.assignee = null;
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutAssigneeMock);
component.ngOnChanges({});
fixture.detectChanges();
@ -119,45 +144,90 @@ describe('TaskHeaderComponent', () => {
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
});
describe('Unclaim', () => {
const batman = new UserProcessModel({ id : 1, email: 'bruce.wayne@gotham.com', firstName: 'Bruce', lastName: 'Wayne', userImage: 'batman.jpg' });
let taskListService;
beforeEach(() => {
taskListService = TestBed.get(TaskListService);
component.taskDetails.assignee = batman;
component.taskDetails.id = 'repair-batmobile';
it('should display the claim button to the invovled group', () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutAssigneeMock);
component.ngOnChanges({});
fixture.detectChanges();
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
});
});
it('should display the requeue button if there is assignee', () => {
it('should display the requeue button if the current logged-in user is a part of the invovled group', () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
});
it('should call the service\'s unclaim method on unclaiming' , () => {
spyOn(taskListService, 'unclaimTask');
it('should display the requeue button if the current logged-in user is a part of the invovled people', () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedPeopleMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
});
it('should not display the claim/requeue button if the current logged-in user is not part of the group', () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
});
it('should not display the requeue button if the task is assigned to others', () => {
const batman = new UserProcessModel({ id : 1, email: 'bruce.wayne@gotham.com', firstName: 'Bruce', lastName: 'Wayne', userImage: 'batman.jpg' });
component.taskDetails.assignee = batman;
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton).toBeNull();
});
it('should not display the requeue button if the task is assigned to others in a group', () => {
component.taskDetails = new TaskDetailsModel(taskDetailsWithAssigneeMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton).toBeNull();
});
it('should not display the requeue button if the task is completed', () => {
component.taskDetails = new TaskDetailsModel(completedTaskDetailsMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
expect(unclaimButton).toBeNull();
});
it('should call the service\'s unclaim method on unclaiming', () => {
spyOn(service, 'unclaimTask');
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
component.ngOnChanges({});
fixture.detectChanges();
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
unclaimButton.triggerEventHandler('click', {});
expect(taskListService.unclaimTask).toHaveBeenCalledWith('repair-batmobile');
expect(service.unclaimTask).toHaveBeenCalledWith('91');
});
it('should trigger the unclaim event on successfull unclaiming', () => {
let unclaimed: boolean = false;
spyOn(service, 'unclaimTask').and.returnValue(Observable.of(true));
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
component.ngOnChanges({});
fixture.detectChanges();
component.unclaim.subscribe(() => { unclaimed = true; });
spyOn(taskListService, 'unclaimTask').and.returnValue(Observable.of(true));
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
unclaimButton.triggerEventHandler('click', {});
expect(unclaimed).toBeTruthy();
});
});
it('should display due date', () => {
component.taskDetails.dueDate = new Date('2016-11-03');

View File

@ -15,8 +15,9 @@
* limitations under the License.
*/
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { CardViewDateItemModel, CardViewItem, CardViewMapItemModel, CardViewTextItemModel, LogService } from 'ng2-alfresco-core';
import { BpmUserService } from 'ng2-alfresco-userinfo';
import { TaskDetailsModel } from '../models/task-details.model';
import { TaskListService } from './../services/tasklist.service';
@ -25,7 +26,7 @@ import { TaskListService } from './../services/tasklist.service';
templateUrl: './task-header.component.html',
styleUrls: ['./task-header.component.scss']
})
export class TaskHeaderComponent implements OnChanges {
export class TaskHeaderComponent implements OnChanges, OnInit {
@Input()
formName: string = null;
@ -39,13 +40,20 @@ export class TaskHeaderComponent implements OnChanges {
@Output()
unclaim: EventEmitter<any> = new EventEmitter<any>();
private currentUserId: number;
properties: CardViewItem [];
inEdit: boolean = false;
constructor(private activitiTaskService: TaskListService,
private bpmUserService: BpmUserService,
private logService: LogService) {
}
ngOnInit() {
this.getCurrentUserId();
}
ngOnChanges(changes: SimpleChanges) {
this.refreshData();
}
@ -148,6 +156,15 @@ export class TaskHeaderComponent implements OnChanges {
}
}
/**
* Return the bpmUser
*/
private getCurrentUserId(): void {
this.bpmUserService.getCurrentUserInfo().subscribe((res) => {
this.currentUserId = res ? +res.id : null;
});
}
/**
* Return the process parent information
*/
@ -161,14 +178,49 @@ export class TaskHeaderComponent implements OnChanges {
* Does the task have an assignee
*/
public hasAssignee(): boolean {
return (this.taskDetails && this.taskDetails.assignee) ? true : false;
return !!this.taskDetails.assignee ? true : false;
}
/**
* Is the task assigned to the currently loggedin user
* Returns true if the task is assigne to logged in user
*/
isAssignedToMe(): boolean {
return this.taskDetails.assignee ? true : false;
public isAssignedTo(userId): boolean {
return this.hasAssignee() ? this.taskDetails.assignee.id === userId : false;
}
/**
* Return true if the task assigned
*/
public isAssignedToCurrentUser(): boolean {
return this.hasAssignee() && this.isAssignedTo(this.currentUserId);
}
/**
* Return true if the task has involvedGroup
*/
public hasInvolvedGroup(): boolean {
return this.taskDetails.involvedGroups.length > 0 ? true : false;
}
/**
* Return true if the task has involvedPeople
*/
public hasInvolvedPeople(): boolean {
return this.taskDetails.involvedPeople.length > 0 ? true : false;
}
/**
* Return true if the task claimable
*/
public isTaskClaimable(): boolean {
return !this.isCompleted() && (this.hasInvolvedGroup() || this.hasInvolvedPeople()) && !this.hasAssignee() ;
}
/**
* Return true if the task claimed by currentUser
*/
public isTaskClaimedByCurrentUser(): boolean {
return !this.isCompleted() && (this.hasInvolvedGroup() || this.hasInvolvedPeople()) && this.isAssignedToCurrentUser();
}
/**
@ -207,7 +259,7 @@ export class TaskHeaderComponent implements OnChanges {
/**
* Returns true if the task is completed
*/
isCompleted() {
return !!this.taskDetails.endDate;
isCompleted(): boolean {
return this.taskDetails && !!this.taskDetails.endDate;
}
}

View File

@ -24,6 +24,7 @@
*/
import { TaskRepresentation } from 'alfresco-js-api';
import { UserProcessModel } from 'ng2-alfresco-core';
import { UserGroupModel } from './user-group.model';
export class TaskDetailsModel implements TaskRepresentation {
id: string;
@ -43,6 +44,7 @@ export class TaskDetailsModel implements TaskRepresentation {
managerOfCandidateGroup: boolean;
memberOfCandidateGroup: boolean;
memberOfCandidateUsers: boolean;
involvedGroups: UserGroupModel [];
involvedPeople: UserProcessModel [];
parentTaskId: string;
parentTaskName: string;
@ -77,6 +79,7 @@ export class TaskDetailsModel implements TaskRepresentation {
this.managerOfCandidateGroup = !!obj.managerOfCandidateGroup;
this.memberOfCandidateGroup = !!obj.memberOfCandidateGroup;
this.memberOfCandidateUsers = !!obj.memberOfCandidateUsers;
this.involvedGroups = obj.involvedGroups;
this.involvedPeople = obj.involvedPeople;
this.parentTaskId = obj.parentTaskId || null;
this.parentTaskName = obj.parentTaskName || null;

View File

@ -0,0 +1,36 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This object represent the process service user group.*
*/
export class UserGroupModel {
id: number;
name: string;
externalId: string;
status: string;
groups: any = {};
constructor(obj?: any) {
this.id = obj && obj.id;
this.name = obj && obj.name;
this.externalId = obj && obj.externalId;
this.status = obj && obj.status;
this.groups = obj && obj.groups;
}
}