From d3b9ae87b7c875da63e4dccc9adc00d702b3e184 Mon Sep 17 00:00:00 2001 From: arditdomi <32884230+arditdomi@users.noreply.github.com> Date: Wed, 30 Oct 2019 15:55:01 +0000 Subject: [PATCH] [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 --- .../components/task-form-cloud.component.html | 2 +- .../task-form-cloud.component.spec.ts | 35 ++++++----------- .../components/task-form-cloud.component.ts | 39 +++++++++++++++++-- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html index 3e95ba8b80..6bf69edd0a 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.html @@ -57,7 +57,7 @@ (success)="onClaimTask()"> {{'ADF_CLOUD_TASK_FORM.EMPTY_FORM.BUTTONS.CLAIM' | translate}} - diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts index 7021c8a5c2..e19fa2a8b7 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.spec.ts @@ -15,11 +15,11 @@ * 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 { of } from 'rxjs'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { setupTestBed, IdentityUserService } from '@alfresco/adf-core'; +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { IdentityUserService, setupTestBed } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../testing/process-service-cloud.testing.module'; import { TaskCloudModule } from '../../task-cloud.module'; import { TaskDirectiveModule } from '../../directives/task-directive.module'; @@ -64,6 +64,8 @@ describe('TaskFormCloudComponent', () => { getCurrentUserSpy = spyOn(identityUserService, 'getCurrentUserInfo').and.returnValue({ username: 'admin.adf' }); taskCloudService = TestBed.get(TaskCloudService); 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); debugElement = fixture.debugElement; @@ -119,15 +121,18 @@ describe('TaskFormCloudComponent', () => { 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.taskId = 'task1'; component.loadTask(); fixture.detectChanges(); + fixture.whenStable().then(() => { 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(); }); - 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) => { component.appName = 'app1'; component.taskId = 'task1'; @@ -384,6 +370,7 @@ describe('TaskFormCloudComponent', () => { it('should emit taskUnclaimed when task is unclaimed', () => { spyOn(taskCloudService, 'unclaimTask').and.returnValue(of({})); const reloadSpy = spyOn(component, 'loadTask').and.callThrough(); + spyOn(component, 'hasCandidateUsers').and.returnValue(true); taskDetails.status = 'ASSIGNED'; getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails))); diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts index 23bc24c259..da5cf13cf1 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts @@ -95,14 +95,17 @@ export class TaskFormCloudComponent implements OnChanges { taskDetails: TaskDetailsCloudModel; + candidateUsers: string[] = []; + candidateGroups: string[] = []; + loading: boolean = false; constructor( private taskCloudService: TaskCloudService, private formRenderingService: FormRenderingService) { - this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true); - this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); - this.formRenderingService.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true); + this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true); + this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true); + this.formRenderingService.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true); } ngOnChanges(changes: SimpleChanges) { @@ -126,6 +129,19 @@ export class TaskFormCloudComponent implements OnChanges { this.taskDetails = details; 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() { @@ -144,6 +160,23 @@ export class TaskFormCloudComponent implements OnChanges { 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 { return !this.readOnly && this.taskCloudService.canUnclaimTask(this.taskDetails); }