mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Maurizio Vitale
parent
d02d79c771
commit
d3b9ae87b7
@@ -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>
|
||||||
|
@@ -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)));
|
||||||
|
@@ -95,14 +95,17 @@ export class TaskFormCloudComponent implements OnChanges {
|
|||||||
|
|
||||||
taskDetails: TaskDetailsCloudModel;
|
taskDetails: TaskDetailsCloudModel;
|
||||||
|
|
||||||
|
candidateUsers: string[] = [];
|
||||||
|
candidateGroups: string[] = [];
|
||||||
|
|
||||||
loading: boolean = false;
|
loading: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private taskCloudService: TaskCloudService,
|
private taskCloudService: TaskCloudService,
|
||||||
private formRenderingService: FormRenderingService) {
|
private formRenderingService: FormRenderingService) {
|
||||||
this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true);
|
this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileCloudWidgetComponent, true);
|
||||||
this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true);
|
this.formRenderingService.setComponentTypeResolver('dropdown', () => DropdownCloudWidgetComponent, true);
|
||||||
this.formRenderingService.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true);
|
this.formRenderingService.setComponentTypeResolver('date', () => DateCloudWidgetComponent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user