mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4979] TaskHeaderCloudComponent Add error emit when appName or taskId is not provided (#5236)
* [ADF-4979] Add error emit when appName or taskId are not provided in TaskHeaderCloudComponent * [ADF-4979] Modify @Output description * [ADF-4979] Remove unused onObservable complete code
This commit is contained in:
committed by
Maurizio Vitale
parent
63d640425e
commit
878b49fea1
@@ -4,22 +4,18 @@
|
||||
{{ 'APP_LAYOUT.TASK_HEADER_CLOUD.APP_NAME_INPUT' | translate }}
|
||||
<input matInput
|
||||
[type]="'text'"
|
||||
[formControl]="appNameFormControl">
|
||||
[formControl]="appNameFormControl"
|
||||
(change)="updateTaskHeader()">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field class="app-taskId-input">
|
||||
{{ 'APP_LAYOUT.TASK_HEADER_CLOUD.TASK_ID_INPUT' | translate }}
|
||||
<input matInput
|
||||
[type]="'text'"
|
||||
[formControl]="taskIdFormControl">
|
||||
[formControl]="taskIdFormControl"
|
||||
(change)="updateTaskHeader()">
|
||||
</mat-form-field>
|
||||
|
||||
<button mat-button *ngIf="appNameFormControl.value && taskIdFormControl.value"
|
||||
class="app-find-task-button"
|
||||
(click)="updateTaskHeader()">
|
||||
{{ 'APP_LAYOUT.TASK_HEADER_CLOUD.FIND_TASK_BUTTON' | translate }}
|
||||
</button>
|
||||
|
||||
<mat-error *ngIf="errorMessage">{{errorMessage}}</mat-error>
|
||||
|
||||
<div>
|
||||
|
@@ -44,6 +44,6 @@ export class TaskHeaderCloudDemoComponent {
|
||||
}
|
||||
|
||||
onError(error) {
|
||||
this.errorMessage = error.message;
|
||||
this.errorMessage = error;
|
||||
}
|
||||
}
|
||||
|
@@ -260,15 +260,45 @@ describe('TaskHeaderCloudComponent', () => {
|
||||
fixture = TestBed.createComponent(TaskHeaderCloudComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = TestBed.get(TaskCloudService);
|
||||
spyOn(service, 'getTaskById').and.returnValue(throwError('Task not found error'));
|
||||
});
|
||||
|
||||
it('should emit an error when getTaskById returns an error', async(() => {
|
||||
const taskErrorSpy = spyOn(component.taskError, 'emit');
|
||||
component.loadTaskDetailsById(component.appName, component.taskId);
|
||||
fixture.detectChanges();
|
||||
expect(taskErrorSpy).toHaveBeenCalledWith('Task not found error');
|
||||
it('should emit an error when task can not be found', async(() => {
|
||||
spyOn(service, 'getTaskById').and.returnValue(throwError('Task not found'));
|
||||
|
||||
component.error.subscribe((error) => {
|
||||
expect(error).toEqual('Task not found');
|
||||
});
|
||||
|
||||
component.appName = 'appName';
|
||||
component.taskId = 'taskId';
|
||||
component.ngOnChanges();
|
||||
}));
|
||||
|
||||
it('should emit an error when app name and/or task id are not provided', async(() => {
|
||||
|
||||
component.error.subscribe((error) => {
|
||||
expect(error).toEqual('App Name and Task Id are mandatory');
|
||||
});
|
||||
|
||||
component.appName = '';
|
||||
component.taskId = '';
|
||||
component.ngOnChanges();
|
||||
|
||||
component.appName = 'app';
|
||||
component.ngOnChanges();
|
||||
|
||||
component.appName = '';
|
||||
component.taskId = 'taskId';
|
||||
component.ngOnChanges();
|
||||
}));
|
||||
|
||||
it('should call the loadTaskDetailsById when both app name and task id are provided', async(() => {
|
||||
spyOn(component, 'loadTaskDetailsById');
|
||||
component.appName = 'appName';
|
||||
component.taskId = 'taskId';
|
||||
component.ngOnChanges();
|
||||
fixture.detectChanges();
|
||||
expect(component.loadTaskDetailsById).toHaveBeenCalledWith(component.appName, component.taskId);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@@ -57,9 +57,9 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
||||
@Output()
|
||||
unclaim: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
/** Emitted when the task has not been found. */
|
||||
/** Emitted when the given task has errors. */
|
||||
@Output()
|
||||
taskError: EventEmitter<any> = new EventEmitter<any>();
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
taskDetails: TaskDetailsCloudModel = new TaskDetailsCloudModel();
|
||||
properties: CardViewItem[];
|
||||
@@ -99,6 +99,8 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
||||
this.taskDetails = new TaskDetailsCloudModel();
|
||||
if (this.appName && this.taskId) {
|
||||
this.loadTaskDetailsById(this.appName, this.taskId);
|
||||
} else {
|
||||
this.error.emit('App Name and Task Id are mandatory');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +114,7 @@ export class TaskHeaderCloudComponent implements OnInit, OnDestroy, OnChanges {
|
||||
this.refreshData();
|
||||
}
|
||||
},
|
||||
(err) => this.taskError.emit(err), () => {});
|
||||
(err) => this.error.emit(err));
|
||||
}
|
||||
|
||||
private initDefaultProperties() {
|
||||
|
Reference in New Issue
Block a user