Skip to content

Commit

Permalink
[ACS-5831] Added Generic Error to Library Dialog. (#9005)
Browse files Browse the repository at this point in the history
* [ACS-5831] Added Generic Error to Library Dialogue.

* format fix

* format fix

* [ci:force]
  • Loading branch information
arohilaGL authored Oct 18, 2023
1 parent 678df42 commit d500bc6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<LibraryDialogComponent>;
let component: LibraryDialogComponent;
let sitesService: SitesService;
let findSitesSpy;
let notificationService: NotificationService;
const findSitesResponse = { list: { entries: [] } };
const dialogRef = {
close: jasmine.createSpy('close')
Expand All @@ -51,6 +53,7 @@ describe('LibraryDialogComponent', () => {
component = fixture.componentInstance;
sitesService = TestBed.inject(SitesService);
findSitesSpy = spyOn(component['queriesApi'], 'findSites');
notificationService = TestBed.inject(NotificationService);
});

afterEach(() => {
Expand Down Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -84,7 +84,8 @@ export class LibraryDialogComponent implements OnInit, OnDestroy {
private alfrescoApiService: AlfrescoApiService,
private sitesService: SitesService,
private formBuilder: UntypedFormBuilder,
private dialog: MatDialogRef<LibraryDialogComponent>
private dialog: MatDialogRef<LibraryDialogComponent>,
private notificationService: NotificationService
) {
}

Expand Down Expand Up @@ -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 }
Expand All @@ -209,6 +212,7 @@ export class LibraryDialogComponent implements OnInit, OnDestroy {
});
}
} catch {
this.notificationService.showError(errorMessage);
}

return error;
Expand Down

0 comments on commit d500bc6

Please sign in to comment.