[ADF-4544] Cloud Task From - Refresh the buttons and form after an action is complete (#4726)

* [ADF-4544] Reloaded task on action

* [ADF-4544] Changed routing in demo component

* [ADF-4544] Added tests
This commit is contained in:
Deepak Paul
2019-05-31 14:37:08 +05:30
committed by Eugenio Romano
parent 892172150e
commit f27846ec5b
6 changed files with 95 additions and 16 deletions

View File

@@ -7,9 +7,7 @@
[appName]="appName" [appName]="appName"
[taskId]="taskId" [taskId]="taskId"
(cancelClick)="goBack()" (cancelClick)="goBack()"
(taskClaimed)="onClaimTask()"
(taskCompleted)="onTaskCompleted()" (taskCompleted)="onTaskCompleted()"
(taskUnclaimed)="onUnclaimTask()"
(formSaved)="onFormSaved()"> (formSaved)="onFormSaved()">
</adf-cloud-task-form> </adf-cloud-task-form>
</div> </div>

View File

@@ -50,18 +50,6 @@ export class TaskDetailsCloudDemoComponent {
this.router.navigate([`/cloud/${this.appName}/`]); this.router.navigate([`/cloud/${this.appName}/`]);
} }
onCompletedTask() {
this.goBack();
}
onUnclaimTask() {
this.goBack();
}
onClaimTask() {
this.goBack();
}
onTaskCompleted() { onTaskCompleted() {
this.goBack(); this.goBack();
} }

View File

@@ -1,4 +1,4 @@
<div *ngIf="taskDetails"> <div *ngIf="!loading; else loadingTemplate">
<adf-cloud-form *ngIf="hasForm(); else withoutForm" <adf-cloud-form *ngIf="hasForm(); else withoutForm"
[appName]="appName" [appName]="appName"
[taskId]="taskId" [taskId]="taskId"
@@ -61,3 +61,9 @@
</mat-card> </mat-card>
</ng-template> </ng-template>
</div> </div>
<ng-template #loadingTemplate>
<div fxLayout="row" fxLayoutAlign="center stretch">
<mat-spinner></mat-spinner>
</div>
</ng-template>

View File

@@ -347,6 +347,80 @@ describe('TaskFormCloudComponent', () => {
component.onError({}); component.onError({});
}); });
it('should emit taskCompleted when task is completed', () => {
spyOn(taskCloudService, 'completeTask').and.returnValue(of({}));
const reloadSpy = spyOn(component, 'loadTask').and.callThrough();
component.appName = 'app1';
component.taskId = 'task1';
component.loadTask();
fixture.detectChanges();
const completeBtn = debugElement.query(By.css('[adf-cloud-complete-task]'));
completeBtn.nativeElement.click();
expect(reloadSpy).toHaveBeenCalled();
});
it('should emit taskClaimed when task is claimed', () => {
spyOn(taskCloudService, 'claimTask').and.returnValue(of({}));
const reloadSpy = spyOn(component, 'loadTask').and.callThrough();
taskDetails.status = 'CREATED';
getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails)));
component.appName = 'app1';
component.taskId = 'task1';
component.loadTask();
fixture.detectChanges();
const claimBtn = debugElement.query(By.css('[adf-cloud-claim-task]'));
claimBtn.nativeElement.click();
expect(reloadSpy).toHaveBeenCalled();
});
it('should emit taskUnclaimed when task is unclaimed', () => {
spyOn(taskCloudService, 'unclaimTask').and.returnValue(of({}));
const reloadSpy = spyOn(component, 'loadTask').and.callThrough();
taskDetails.status = 'ASSIGNED';
getTaskSpy.and.returnValue(of(new TaskDetailsCloudModel(taskDetails)));
component.appName = 'app1';
component.taskId = 'task1';
component.loadTask();
fixture.detectChanges();
const unclaimBtn = debugElement.query(By.css('[adf-cloud-unclaim-task]'));
unclaimBtn.nativeElement.click();
expect(reloadSpy).toHaveBeenCalled();
});
it('should show loading template while task data is being loaded', () => {
component.loading = true;
fixture.detectChanges();
const loadingTemplate = debugElement.query(By.css('mat-spinner'));
expect(loadingTemplate).toBeDefined();
});
it('should not show loading template while task data is not being loaded', () => {
component.loading = false;
component.appName = 'app1';
component.taskId = 'task1';
component.loadTask();
fixture.detectChanges();
const loadingTemplate = debugElement.query(By.css('mat-spinner'));
expect(loadingTemplate).toBeNull();
});
}); });
}); });

View File

@@ -91,6 +91,8 @@ export class TaskFormCloudComponent implements OnChanges {
taskDetails: TaskDetailsCloudModel; taskDetails: TaskDetailsCloudModel;
loading: boolean = false;
constructor( constructor(
private taskCloudService: TaskCloudService, private taskCloudService: TaskCloudService,
private formRenderingService: FormRenderingService) { private formRenderingService: FormRenderingService) {
@@ -114,11 +116,17 @@ export class TaskFormCloudComponent implements OnChanges {
} }
loadTask() { loadTask() {
this.loading = true;
this.taskCloudService.getTaskById(this.appName, this.taskId).subscribe((details: TaskDetailsCloudModel) => { this.taskCloudService.getTaskById(this.appName, this.taskId).subscribe((details: TaskDetailsCloudModel) => {
this.taskDetails = details; this.taskDetails = details;
this.loading = false;
}); });
} }
private reloadTask() {
this.loadTask();
}
hasForm(): boolean { hasForm(): boolean {
return this.taskDetails && !!this.taskDetails.formKey; return this.taskDetails && !!this.taskDetails.formKey;
} }
@@ -140,14 +148,17 @@ export class TaskFormCloudComponent implements OnChanges {
} }
onCompleteTask() { onCompleteTask() {
this.reloadTask();
this.taskCompleted.emit(this.taskId); this.taskCompleted.emit(this.taskId);
} }
onClaimTask() { onClaimTask() {
this.reloadTask();
this.taskClaimed.emit(this.taskId); this.taskClaimed.emit(this.taskId);
} }
onUnclaimTask() { onUnclaimTask() {
this.reloadTask();
this.taskUnclaimed.emit(this.taskId); this.taskUnclaimed.emit(this.taskId);
} }

View File

@@ -23,6 +23,7 @@ import { TaskDirectiveModule } from '../directives/task-directive.module';
import { TaskFormCloudComponent } from './components/task-form-cloud.component'; import { TaskFormCloudComponent } from './components/task-form-cloud.component';
import { CoreModule } from '@alfresco/adf-core'; import { CoreModule } from '@alfresco/adf-core';
import { FlexLayoutModule } from '@angular/flex-layout';
@NgModule({ @NgModule({
imports: [ imports: [
@@ -30,7 +31,8 @@ import { CoreModule } from '@alfresco/adf-core';
CommonModule, CommonModule,
MaterialModule, MaterialModule,
FormCloudModule, FormCloudModule,
TaskDirectiveModule TaskDirectiveModule,
FlexLayoutModule
], ],
declarations: [ declarations: [
TaskFormCloudComponent TaskFormCloudComponent