expect(notificationService.save).not.toHaveBeenCalled();
}));
+ it('should be able to use preventDefault with 400 errors', fakeAsync(() => {
+ httpError(
+ { task: { name: 'someName', metadata: { component: 'someComponent' } } },
+ { status: 400 },
+ (resp) => resp.preventDefault()
+ );
+ tick(10);
+ expect(notificationService.save).not.toHaveBeenCalled();
+ }));
+
it('should prevent the default behaviour by status code', fakeAsync(() => {
httpError(undefined, { status: 500 }, (resp) => resp.ignoreStatusCode(500));
tick(10);
return next.handle(request).pipe(
catchError((resp) => {
if (resp instanceof HttpErrorResponse) {
- let showNotification = true;
+ let timeoutId: number;
switch (resp.status) {
case 400:
const finishedTask = new FinishedTask();
finishedTask.success = false;
finishedTask.exception = resp.error;
- this.notificationService.notifyTask(finishedTask);
- showNotification = false;
+ timeoutId = this.notificationService.notifyTask(finishedTask);
break;
case 401:
this.authStorageService.remove();
this.router.navigate(['/login']);
- showNotification = false;
break;
case 403:
this.router.navigate(['/403']);
break;
+ default:
+ timeoutId = this.prepareNotification(resp);
}
- const timeoutId = showNotification ? this.prepareNotification(resp) : undefined;
-
/**
* Decorated preventDefault method (in case error previously had
* preventDefault method defined). If called, it will prevent a
expect(notification.message).toBe(undefined);
}));
+ it('should be able to stop notifyTask from notifying', fakeAsync(() => {
+ const task = _.assign(new FinishedTask(), {
+ success: true
+ });
+ const timeoutId = service.notifyTask(task, true);
+ service.cancel(timeoutId);
+ tick(100);
+ expect(service['dataSource'].getValue().length).toBe(0);
+ }));
+
it('should show a error task notification', fakeAsync(() => {
const task = _.assign(
new FinishedTask('rbd/create', {
}"></i>`;
}
- notifyTask(finishedTask: FinishedTask, success: boolean = true) {
+ notifyTask(finishedTask: FinishedTask, success: boolean = true): number {
let notification: CdNotificationConfig;
if (finishedTask.success && success) {
notification = new CdNotificationConfig(
this.taskMessageService.getErrorMessage(finishedTask)
);
}
- this.show(notification);
+ return this.show(notification);
}
/**