[AAE-641] Hide Release button when the task is assigned to a single user (#5192)

* [AAE-641] Hide Release button when the task is assigned to a single user

* [AAE-641] Fix unit tests

* [AAE-641] Fix unit tests
This commit is contained in:
arditdomi
2019-10-30 15:55:01 +00:00
committed by Maurizio Vitale
parent d02d79c771
commit d3b9ae87b7
3 changed files with 48 additions and 28 deletions

View File

@@ -57,7 +57,7 @@
(success)="onClaimTask()"> (success)="onClaimTask()">
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.CLAIM' | translate}} {{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.CLAIM' | translate}}
</button> </button>
<button mat-button *ngIf="canUnclaimTask()" adf-cloud-unclaim-task [appName]="appName" [taskId]="taskId" <button mat-button *ngIf="hasCandidateUsersOrGroups()" adf-cloud-unclaim-task [appName]="appName" [taskId]="taskId"
(success)="onUnclaimTask()"> (success)="onUnclaimTask()">
{{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.UNCLAIM' | translate}} {{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.UNCLAIM' | translate}}
</button> </button>

View File

@@ -15,11 +15,11 @@
* limitations under the License. * limitations under the License.
*/ */
import { DebugElement, CUSTOM_ELEMENTS_SCHEMA, SimpleChange, Component } from '@angular/core'; import { Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement, SimpleChange } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { setupTestBed, IdentityUserService } from '@alfresco/adf-core'; import { IdentityUserService, setupTestBed } from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module';
import { TaskCloudModule } from '../../task-cloud.module'; import { TaskCloudModule } from '../../task-cloud.module';
import { TaskDirectiveModule } from '../../directives/task-directive.module'; import { TaskDirectiveModule } from '../../directives/task-directive.module';
@@ -64,6 +64,8 @@ describe('TaskFormCloudComponent', () => {
getCurrentUserSpy = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue({ username: 'admin.adf' }); getCurrentUserSpy = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue({ username: 'admin.adf' });
taskCloudService = TestBed.get(TaskCloudService); taskCloudService = TestBed.get(TaskCloudService);
getTaskSpy = spyOn(taskCloudService, 'getTaskById').and.returnValue(of(new TaskDetailsCloudModel(taskDetails))); getTaskSpy = spyOn(taskCloudService, 'getTaskById').and.returnValue(of(new TaskDetailsCloudModel(taskDetails)));
spyOn(taskCloudService, 'getCandidateGroups').and.returnValue(of([]));
spyOn(taskCloudService, 'getCandidateUsers').and.returnValue(of([]));
fixture = TestBed.createComponent(TaskFormCloudComponent); fixture = TestBed.createComponent(TaskFormCloudComponent);
debugElement = fixture.debugElement; debugElement = fixture.debugElement;
@@ -119,15 +121,18 @@ describe('TaskFormCloudComponent', () => {
describe('Claim/Unclaim buttons', () => { describe('Claim/Unclaim buttons', () => {
it('should show unclaim button when status is ASSIGNED', async(() => { it('should show release button when task has candidate users and is assigned to one of these users', async(() => {
spyOn(component, 'hasCandidateUsers').and.returnValue(true);
component.appName = 'app1'; component.appName = 'app1';
component.taskId = 'task1'; component.taskId = 'task1';
component.loadTask(); component.loadTask();
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]')); const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]'));
expect(unclaimBtn.nativeElement).toBeDefined(); expect(unclaimBtn).not.toBeNull();
}); });
})); }));
@@ -317,25 +322,6 @@ describe('TaskFormCloudComponent', () => {
claimBtn.nativeElement.click(); claimBtn.nativeElement.click();
}); });
it('should emit taskUnclaimed when task is unclaimed', (done) => {
spyOn(taskCloudService, 'unclaimTask').and.returnValue(of({}));
taskDetails.status = 'ASSIGNED';
getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails)));
component.appName = 'app1';
component.taskId = 'task1';
component.taskUnclaimed.subscribe(() => {
done();
});
component.loadTask();
fixture.detectChanges();
const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]'));
unclaimBtn.nativeElement.click();
});
it('should emit error when error occurs', (done) => { it('should emit error when error occurs', (done) => {
component.appName = 'app1'; component.appName = 'app1';
component.taskId = 'task1'; component.taskId = 'task1';
@@ -384,6 +370,7 @@ describe('TaskFormCloudComponent', () => {
it('should emit taskUnclaimed when task is unclaimed', () => { it('should emit taskUnclaimed when task is unclaimed', () => {
spyOn(taskCloudService, 'unclaimTask').and.returnValue(of({})); spyOn(taskCloudService, 'unclaimTask').and.returnValue(of({}));
const reloadSpy = spyOn(component, 'loadTask').and.callThrough(); const reloadSpy = spyOn(component, 'loadTask').and.callThrough();
spyOn(component, 'hasCandidateUsers').and.returnValue(true);
taskDetails.status = 'ASSIGNED'; taskDetails.status = 'ASSIGNED';
getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails))); getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails)));

View File

@@ -95,6 +95,9 @@ export class TaskFormCloudComponent implements OnChanges {
taskDetails: TaskDetailsCloudModel; taskDetails: TaskDetailsCloudModel;
candidateUsers: string[] = [];
candidateGroups: string[] = [];
loading: boolean = false; loading: boolean = false;
constructor( constructor(
@@ -126,6 +129,19 @@ export class TaskFormCloudComponent implements OnChanges {
this.taskDetails = details; this.taskDetails = details;
this.loading = false; this.loading = false;
}); });
this.taskCloudService.getCandidateUsers(this.appName, this.taskId).subscribe((users: string[]) => {
if (users) {
this.candidateUsers = users;
}
});
this.taskCloudService.getCandidateGroups(this.appName, this.taskId).subscribe((groups: string[]) => {
if (groups) {
this.candidateGroups = groups;
}
});
} }
private reloadTask() { private reloadTask() {
@@ -144,6 +160,23 @@ export class TaskFormCloudComponent implements OnChanges {
return !this.readOnly && this.taskCloudService.canClaimTask(this.taskDetails); return !this.readOnly && this.taskCloudService.canClaimTask(this.taskDetails);
} }
hasCandidateUsers(): boolean {
return this.candidateUsers.length !== 0;
}
hasCandidateGroups(): boolean {
return this.candidateGroups.length !== 0;
}
hasCandidateUsersOrGroups(): boolean {
let hasCandidateUsersOrGroups = false;
if (this.taskDetails.status === 'ASSIGNED') {
hasCandidateUsersOrGroups = this.hasCandidateUsers() || this.hasCandidateGroups();
}
return hasCandidateUsersOrGroups;
}
canUnclaimTask(): boolean { canUnclaimTask(): boolean {
return !this.readOnly && this.taskCloudService.canUnclaimTask(this.taskDetails); return !this.readOnly && this.taskCloudService.canUnclaimTask(this.taskDetails);
} }