From d500bc67d7f26ff7a60b1c0f71930db07cd83357 Mon Sep 17 00:00:00 2001 From: Aayush Rohila <112551534+arohilaGL@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:50:31 +0530 Subject: [PATCH] [ACS-5831] Added Generic Error to Library Dialog. (#9005) * [ACS-5831] Added Generic Error to Library Dialogue. * format fix * format fix * [ci:force] --- .../dialogs/library/library.dialog.spec.ts | 23 +++++++++++++++++++ .../src/lib/dialogs/library/library.dialog.ts | 8 +++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts b/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts index 9f53574f140..f61e772019c 100644 --- a/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts +++ b/lib/content-services/src/lib/dialogs/library/library.dialog.spec.ts @@ -25,12 +25,14 @@ import { of, throwError } from 'rxjs'; import { delay } from 'rxjs/operators'; import { SiteEntry } from '@alfresco/js-api'; import { SitesService } from '../../common/services/sites.service'; +import { NotificationService } from '@alfresco/adf-core'; describe('LibraryDialogComponent', () => { let fixture: ComponentFixture; let component: LibraryDialogComponent; let sitesService: SitesService; let findSitesSpy; + let notificationService: NotificationService; const findSitesResponse = { list: { entries: [] } }; const dialogRef = { close: jasmine.createSpy('close') @@ -51,6 +53,7 @@ describe('LibraryDialogComponent', () => { component = fixture.componentInstance; sitesService = TestBed.inject(SitesService); findSitesSpy = spyOn(component['queriesApi'], 'findSites'); + notificationService = TestBed.inject(NotificationService); }); afterEach(() => { @@ -205,6 +208,26 @@ describe('LibraryDialogComponent', () => { }); })); + it('should handle default errors and show generic error in snackbar', fakeAsync(() => { + findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse)); + const error = {}; + spyOn(sitesService, 'createSite').and.callFake(() => throwError(error)); + spyOn(sitesService, 'getSite').and.callFake(() => throwError('error')); + spyOn(notificationService, 'showError').and.callThrough(); + + fixture.detectChanges(); + component.form.controls.title.setValue('test'); + tick(500); + flush(); + fixture.detectChanges(); + + component.submit(); + fixture.detectChanges(); + flush(); + + expect(notificationService.showError).toHaveBeenCalledWith('CORE.MESSAGES.ERRORS.GENERIC'); + })); + it('should not translate library title if value is not a valid id', fakeAsync(() => { findSitesSpy.and.returnValue(Promise.resolve(findSitesResponse)); spyOn(sitesService, 'getSite').and.callFake(() => throwError('error')); diff --git a/lib/content-services/src/lib/dialogs/library/library.dialog.ts b/lib/content-services/src/lib/dialogs/library/library.dialog.ts index 80c22260ccd..2e2d98bbf7f 100644 --- a/lib/content-services/src/lib/dialogs/library/library.dialog.ts +++ b/lib/content-services/src/lib/dialogs/library/library.dialog.ts @@ -33,7 +33,7 @@ import { } from '@angular/forms'; import { MatDialogRef } from '@angular/material/dialog'; import { QueriesApi, SiteBodyCreate, SiteEntry, SitePaging } from '@alfresco/js-api'; -import { AlfrescoApiService } from '@alfresco/adf-core'; +import { AlfrescoApiService, NotificationService } from '@alfresco/adf-core'; import { debounceTime, finalize, mergeMap, takeUntil } from 'rxjs/operators'; import { SitesService } from '../../common/services/sites.service'; @@ -84,7 +84,8 @@ export class LibraryDialogComponent implements OnInit, OnDestroy { private alfrescoApiService: AlfrescoApiService, private sitesService: SitesService, private formBuilder: UntypedFormBuilder, - private dialog: MatDialogRef + private dialog: MatDialogRef, + private notificationService: NotificationService ) { } @@ -198,6 +199,8 @@ export class LibraryDialogComponent implements OnInit, OnDestroy { } private handleError(error: any): any { + let errorMessage = 'CORE.MESSAGES.ERRORS.GENERIC'; + try { const { error: { statusCode } @@ -209,6 +212,7 @@ export class LibraryDialogComponent implements OnInit, OnDestroy { }); } } catch { + this.notificationService.showError(errorMessage); } return error;