mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1712] The <adf-task-header component displays a Requeue button for none pooled tasks (#2680)
* [ADF-1712] The <adf-task-header component displays a Requeue button for none pooled tasks . * Refactored task header component. * [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. * Changed method name .
This commit is contained in:
committed by
Eugenio Romano
parent
3ccccbec4e
commit
7cf0a1c839
@@ -4,7 +4,7 @@
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions class="adf-controls">
|
||||
<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 *ngIf="isTaskClaimedByCandidateMember()" 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="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>
|
||||
|
@@ -17,17 +17,17 @@
|
||||
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { CardViewUpdateService, UserProcessModel } from '@alfresco/adf-core';
|
||||
import { CardViewUpdateService } from '@alfresco/adf-core';
|
||||
import { BpmUserService } from '@alfresco/adf-core';
|
||||
import { MaterialModule } from '../../material.module';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import {
|
||||
completedTaskDetailsMock,
|
||||
taskDetailsMock,
|
||||
taskDetailsWithAssigneeMock,
|
||||
taskDetailsWithInvolvedGroupMock,
|
||||
taskDetailsWithInvolvedPeopleMock,
|
||||
taskDetailsWithOutAssigneeMock } from '../../mock';
|
||||
claimableTaskDetailsMock,
|
||||
claimedTaskDetailsMock,
|
||||
claimedByGroupMemberMock,
|
||||
taskDetailsWithOutCandidateGroup } from '../../mock';
|
||||
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import { TaskListService } from './../services/tasklist.service';
|
||||
@@ -128,7 +128,7 @@ describe('TaskHeaderComponent', () => {
|
||||
describe('Claiming', () => {
|
||||
|
||||
it('should display the claim button if no assignee', () => {
|
||||
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutAssigneeMock);
|
||||
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
|
||||
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
@@ -137,67 +137,69 @@ describe('TaskHeaderComponent', () => {
|
||||
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
|
||||
});
|
||||
|
||||
it('should display the claim button to the invovled group', () => {
|
||||
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutAssigneeMock);
|
||||
it('should display the claim button if the task is claimable', () => {
|
||||
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
|
||||
expect(component.isTaskClaimable()).toBeTruthy();
|
||||
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
|
||||
});
|
||||
|
||||
it('should not display the claim/requeue button if the task is not claimable ', () => {
|
||||
component.taskDetails = new TaskDetailsModel(taskDetailsWithOutCandidateGroup);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
|
||||
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
|
||||
expect(component.isTaskClaimable()).toBeFalsy();
|
||||
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
|
||||
expect(unclaimButton).toBeNull();
|
||||
expect(claimButton).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('should display the requeue button if the current logged-in user is a part of the invovled group', () => {
|
||||
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
|
||||
it('should display the requeue button if task is claimed by the current logged-in user', () => {
|
||||
component.taskDetails = new TaskDetailsModel(claimedTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
|
||||
expect(component.isTaskClaimedByCandidateMember()).toBeTruthy();
|
||||
expect(unclaimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.UNCLAIM');
|
||||
});
|
||||
|
||||
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;
|
||||
it('should not display the requeue button to logged in user if task is claimed by other candidate member', () => {
|
||||
component.taskDetails = new TaskDetailsModel(claimedByGroupMemberMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
|
||||
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
|
||||
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);
|
||||
it('should display the claime button if the task is claimable by candidates members', () => {
|
||||
component.taskDetails = new TaskDetailsModel(claimableTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
|
||||
expect(unclaimButton).toBeNull();
|
||||
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
|
||||
expect(component.isTaskClaimable()).toBeTruthy();
|
||||
expect(component.isTaskClaimedByCandidateMember()).toBeFalsy();
|
||||
expect(claimButton.nativeElement.innerText).toBe('ADF_TASK_LIST.DETAILS.BUTTON.CLAIM');
|
||||
});
|
||||
|
||||
it('should not display the requeue button if the task is completed', () => {
|
||||
component.taskDetails = new TaskDetailsModel(completedTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
let claimButton = fixture.debugElement.query(By.css('[data-automation-id="header-claim-button"]'));
|
||||
let unclaimButton = fixture.debugElement.query(By.css('[data-automation-id="header-unclaim-button"]'));
|
||||
expect(claimButton).toBeNull();
|
||||
expect(unclaimButton).toBeNull();
|
||||
});
|
||||
|
||||
it('should call the service\'s unclaim method on unclaiming', () => {
|
||||
spyOn(service, 'unclaimTask');
|
||||
component.taskDetails = new TaskDetailsModel(taskDetailsWithInvolvedGroupMock);
|
||||
component.taskDetails = new TaskDetailsModel(claimedTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
|
||||
@@ -210,7 +212,7 @@ describe('TaskHeaderComponent', () => {
|
||||
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.taskDetails = new TaskDetailsModel(claimedTaskDetailsMock);
|
||||
component.ngOnChanges({});
|
||||
fixture.detectChanges();
|
||||
component.unclaim.subscribe(() => { unclaimed = true; });
|
||||
|
@@ -197,31 +197,24 @@ export class TaskHeaderComponent implements OnChanges, OnInit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the task has involvedGroup
|
||||
* Return true if the user is a candidate member
|
||||
*/
|
||||
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;
|
||||
isCandidateMember() {
|
||||
return this.taskDetails.managerOfCandidateGroup || this.taskDetails.memberOfCandidateGroup || this.taskDetails.memberOfCandidateUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the task claimable
|
||||
*/
|
||||
public isTaskClaimable(): boolean {
|
||||
return !this.isCompleted() && (this.hasInvolvedGroup() || this.hasInvolvedPeople()) && !this.hasAssignee() ;
|
||||
return !this.hasAssignee() && this.isCandidateMember();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the task claimed by currentUser
|
||||
* Return true if the task claimed by candidate member.
|
||||
*/
|
||||
public isTaskClaimedByCurrentUser(): boolean {
|
||||
return !this.isCompleted() && (this.hasInvolvedGroup() || this.hasInvolvedPeople()) && this.isAssignedToCurrentUser();
|
||||
public isTaskClaimedByCandidateMember(): boolean {
|
||||
return this.isCandidateMember() && this.isAssignedToCurrentUser() && !this.isCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user