mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
AAE-32493 Add error handling for loading task (#10692)
* AAE-32493 Add error handling for loading task [ci:force] * AAE-32493 Improve units * AAE-32493 forkJoin observables together * AAE-32493 Remove duplicate loading cancel * AAE-32493 Complete task subscription on error
This commit is contained in:
parent
f7e521607c
commit
f8f72edeb9
@ -33,7 +33,7 @@ import { MatButtonHarness } from '@angular/material/button/testing';
|
|||||||
import { MatCardHarness } from '@angular/material/card/testing';
|
import { MatCardHarness } from '@angular/material/card/testing';
|
||||||
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
|
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
|
||||||
import { ProcessServiceCloudTestingModule } from 'lib/process-services-cloud/src/lib/testing/process-service-cloud.testing.module';
|
import { ProcessServiceCloudTestingModule } from 'lib/process-services-cloud/src/lib/testing/process-service-cloud.testing.module';
|
||||||
import { of } from 'rxjs';
|
import { of, throwError } from 'rxjs';
|
||||||
import { IdentityUserService } from '../../../../people/services/identity-user.service';
|
import { IdentityUserService } from '../../../../people/services/identity-user.service';
|
||||||
import { UserTaskCloudComponent } from './user-task-cloud.component';
|
import { UserTaskCloudComponent } from './user-task-cloud.component';
|
||||||
|
|
||||||
@ -60,6 +60,7 @@ describe('UserTaskCloudComponent', () => {
|
|||||||
let getCurrentUserSpy: jasmine.Spy;
|
let getCurrentUserSpy: jasmine.Spy;
|
||||||
let loader: HarnessLoader;
|
let loader: HarnessLoader;
|
||||||
let identityUserService: IdentityUserService;
|
let identityUserService: IdentityUserService;
|
||||||
|
let errorEmitSpy: jasmine.Spy;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@ -67,6 +68,7 @@ describe('UserTaskCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(UserTaskCloudComponent);
|
fixture = TestBed.createComponent(UserTaskCloudComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
errorEmitSpy = spyOn(component.error, 'emit');
|
||||||
loader = TestbedHarnessEnvironment.loader(fixture);
|
loader = TestbedHarnessEnvironment.loader(fixture);
|
||||||
taskCloudService = TestBed.inject(TaskCloudService);
|
taskCloudService = TestBed.inject(TaskCloudService);
|
||||||
identityUserService = TestBed.inject(IdentityUserService);
|
identityUserService = TestBed.inject(IdentityUserService);
|
||||||
@ -288,6 +290,15 @@ describe('UserTaskCloudComponent', () => {
|
|||||||
|
|
||||||
expect(getTaskSpy).not.toHaveBeenCalled();
|
expect(getTaskSpy).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit error when getTaskById fails', async () => {
|
||||||
|
getTaskSpy.and.returnValue(throwError(() => 'getTaskyById error'));
|
||||||
|
component.taskId = 'task1';
|
||||||
|
component.ngOnChanges({ appName: new SimpleChange(null, 'app1', false) });
|
||||||
|
await fixture.whenStable();
|
||||||
|
|
||||||
|
expect(errorEmitSpy).toHaveBeenCalledWith('getTaskyById error');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Events', () => {
|
describe('Events', () => {
|
||||||
@ -344,12 +355,11 @@ describe('UserTaskCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit error when error occurs', async () => {
|
it('should emit error when error occurs', async () => {
|
||||||
spyOn(component.error, 'emit').and.stub();
|
|
||||||
component.onError({});
|
component.onError({});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
|
|
||||||
expect(component.error.emit).toHaveBeenCalled();
|
expect(errorEmitSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload when task is completed', async () => {
|
it('should reload when task is completed', async () => {
|
||||||
|
@ -30,6 +30,7 @@ import { MatButtonModule } from '@angular/material/button';
|
|||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
import { TaskScreenCloudComponent } from '../../../../screen/components/screen-cloud/screen-cloud.component';
|
import { TaskScreenCloudComponent } from '../../../../screen/components/screen-cloud/screen-cloud.component';
|
||||||
import { CompleteTaskDirective } from './complete-task/complete-task.directive';
|
import { CompleteTaskDirective } from './complete-task/complete-task.directive';
|
||||||
|
import { catchError, EMPTY, forkJoin } from 'rxjs';
|
||||||
|
|
||||||
const TaskTypes = {
|
const TaskTypes = {
|
||||||
Form: 'form',
|
Form: 'form',
|
||||||
@ -251,18 +252,29 @@ export class UserTaskCloudComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
private loadTask(): void {
|
private loadTask(): void {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.taskCloudService
|
const tasks$ = this.taskCloudService.getTaskById(this.appName, this.taskId);
|
||||||
.getTaskById(this.appName, this.taskId)
|
const candidateUsers$ = this.taskCloudService.getCandidateUsers(this.appName, this.taskId);
|
||||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
const candidateGroups$ = this.taskCloudService.getCandidateGroups(this.appName, this.taskId);
|
||||||
.subscribe((details) => {
|
forkJoin({
|
||||||
this.taskDetails = details;
|
tasks: tasks$,
|
||||||
|
candidateUsers: candidateUsers$,
|
||||||
|
candidateGroups: candidateGroups$
|
||||||
|
})
|
||||||
|
.pipe(
|
||||||
|
takeUntilDestroyed(this.destroyRef),
|
||||||
|
catchError((error) => {
|
||||||
|
this.onError(error);
|
||||||
|
return EMPTY;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.subscribe(({ tasks, candidateGroups, candidateUsers }) => {
|
||||||
|
this.taskDetails = tasks;
|
||||||
this.getTaskType();
|
this.getTaskType();
|
||||||
|
this.candidateUsers = candidateUsers;
|
||||||
|
this.candidateGroups = candidateGroups;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.onTaskLoaded.emit(this.taskDetails);
|
this.onTaskLoaded.emit(this.taskDetails);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.taskCloudService.getCandidateUsers(this.appName, this.taskId).subscribe((users) => (this.candidateUsers = users || []));
|
|
||||||
this.taskCloudService.getCandidateGroups(this.appName, this.taskId).subscribe((groups) => (this.candidateGroups = groups || []));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public switchToDisplayMode(newDisplayMode?: string): void {
|
public switchToDisplayMode(newDisplayMode?: string): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user