[ACS-9344] change permissions error message for opening records management library (#4414)

* [ACS-9344] Changed error messages

* [ACS-9344] Unit tests

* [ACS-9344] Fixed unit test
This commit is contained in:
AleksanderSklorz
2025-02-27 08:05:44 +01:00
committed by GitHub
parent f1c4dcf45d
commit 0696ce82ba
6 changed files with 297 additions and 10 deletions

View File

@@ -16,7 +16,7 @@
</div>
<div class="aca-page-layout-error">
<aca-generic-error />
<aca-generic-error [text]="errorTranslationKey" />
</div>
<div class="aca-page-layout-content">
@@ -47,7 +47,7 @@
(name-click)="handleNodeClick($event)"
(selectedItemsCountChanged)="onSelectedItemsCountChanged($event)"
(filterSelection)="onFilterSelected($event)"
(error)="onError()"
(error)="onError($event)"
>
<data-columns>
<ng-container *ngFor="let column of columns; trackBy: trackByColumnId">

View File

@@ -29,7 +29,7 @@ import { DocumentListService, FilterSearch, UploadService } from '@alfresco/adf-
import { NodeActionsService } from '../../services/node-actions.service';
import { FilesComponent } from './files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { AppExtensionService, ContentApiService, DocumentBasePageService, initialState } from '@alfresco/aca-shared';
import { AppExtensionService, ContentApiService, DocumentBasePageService, GenericErrorComponent, initialState } from '@alfresco/aca-shared';
import { of, Subject, throwError } from 'rxjs';
import { By } from '@angular/platform-browser';
import { NodeEntry, NodePaging, Node, PathElement } from '@alfresco/js-api';
@@ -38,6 +38,8 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { testHeader } from '../../testing/document-base-page-utils';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { getCurrentFolder } from '@alfresco/aca-shared/store';
import { UnitTestingUtils } from '@alfresco/adf-core';
import { HttpErrorResponse } from '@angular/common/http';
describe('FilesComponent', () => {
let node;
@@ -57,6 +59,7 @@ describe('FilesComponent', () => {
let spyContent = null;
let loadFolderByNodeIdSpy: jasmine.Spy;
let unitTestingUtils: UnitTestingUtils;
function verifyEmptyFilterTemplate() {
const template = fixture.debugElement.query(By.css('.empty-search__block')).nativeElement as HTMLElement;
@@ -108,6 +111,7 @@ describe('FilesComponent', () => {
extensions = TestBed.inject(AppExtensionService);
store = TestBed.inject(MockStore);
spyContent = spyOn(contentApi, 'getNode');
unitTestingUtils = new UnitTestingUtils(fixture.debugElement);
});
beforeEach(() => {
@@ -122,7 +126,7 @@ describe('FilesComponent', () => {
});
it('should be a valid current page', fakeAsync(() => {
spyContent.and.returnValue(throwError(null));
spyContent.and.returnValue(throwError(() => new HttpErrorResponse({ status: 404 })));
component.ngOnInit();
fixture.detectChanges();
@@ -521,5 +525,177 @@ describe('FilesComponent', () => {
});
});
describe('Generic error', () => {
const getGenericErrorText = () => unitTestingUtils.getByDirective(GenericErrorComponent).componentInstance.text;
beforeEach(() => {
router.url = '/libraries';
});
describe('error returned by getNode on contentApi', () => {
it('should have set text to library no permission error if user does not have permission and actual url is libraries', () => {
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 403
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NO_PERMISSIONS');
});
it('should have set text to library not found error if library does not exist and actual url is libraries', () => {
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 404
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NOT_FOUND');
});
it('should have set text to generic library loading error if there is different problem with loading of library and actual url is libraries', () => {
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 500
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_LOADING_ERROR');
});
it('should have set text to generic error if user does not have permission and actual url is not libraries', () => {
router.url = '/personal-files';
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 403
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
it('should have set text to generic error if library does not exist and actual url is not libraries', () => {
router.url = '/personal-files';
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 404
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
it('should have set text to generic error if there is different problem with loading of node and actual url is not libraries', () => {
router.url = '/personal-files';
spyContent.and.returnValue(
throwError(
() =>
new HttpErrorResponse({
status: 500
})
)
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
});
describe('error emitted by error event', () => {
beforeEach(() => {
fixture.detectChanges();
});
it('should have set text to library no permission error if user does not have permission issue and actual url is libraries', () => {
component.documentList.error.emit(
new HttpErrorResponse({
status: 403
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NO_PERMISSIONS');
});
it('should have set text to library not found error if library does not exist issue and actual url is libraries', () => {
component.documentList.error.emit(
new HttpErrorResponse({
status: 404
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NOT_FOUND');
});
it('should have set text to generic library loading error if there is different problem with loading of library and actual url is libraries', () => {
component.documentList.error.emit(
new HttpErrorResponse({
status: 500
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_LOADING_ERROR');
});
it('should have set text to generic error if user does not have permission issue and actual url is not libraries', () => {
router.url = '/personal-files';
component.documentList.error.emit(
new HttpErrorResponse({
status: 403
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
it('should have set text to generic error if library does not exist issue and actual url is not libraries', () => {
router.url = '/personal-files';
component.documentList.error.emit(
new HttpErrorResponse({
status: 404
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
it('should have set text to generic error if there is different problem with loading of node and actual url is not libraries', () => {
router.url = '/personal-files';
component.documentList.error.emit(
new HttpErrorResponse({
status: 500
})
);
fixture.detectChanges();
expect(getGenericErrorText()).toBe('APP.MESSAGES.ERRORS.MISSING_CONTENT');
});
});
});
testHeader(FilesComponent);
});

View File

@@ -60,6 +60,7 @@ import { DocumentListDirective } from '../../directives/document-list.directive'
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { SearchAiInputContainerComponent } from '../knowledge-retrieval/search-ai/search-ai-input-container/search-ai-input-container.component';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { HttpErrorResponse } from '@angular/common/http';
@Component({
standalone: true,
@@ -95,11 +96,16 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
selectedNode: NodeEntry;
queryParams = null;
showLoader$ = this.store.select(showLoaderSelector);
private nodePath: PathElement[];
columns: DocumentListPresetRef[] = [];
isFilterHeaderActive = false;
private nodePath: PathElement[];
private _errorTranslationKey = 'APP.MESSAGES.ERRORS.MISSING_CONTENT';
get errorTranslationKey(): string {
return this._errorTranslationKey;
}
constructor(private contentApi: ContentApiService, private nodeActionsService: NodeActionsService, private route: ActivatedRoute) {
super();
}
@@ -132,7 +138,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
});
}
},
() => (this.isValidPath = false)
(error: HttpErrorResponse) => this.onError(error)
);
});
@@ -394,7 +400,19 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
void this.router.navigate([], { relativeTo: this.route, queryParams: objectFromMap });
}
onError() {
onError(error: HttpErrorResponse) {
this.isValidPath = false;
if (this.router.url.includes('libraries')) {
switch (error.status) {
case 403:
this._errorTranslationKey = 'APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NO_PERMISSIONS';
break;
case 404:
this._errorTranslationKey = 'APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_NOT_FOUND';
break;
default:
this._errorTranslationKey = 'APP.BROWSE.LIBRARIES.ERRORS.LIBRARY_LOADING_ERROR';
}
}
}
}