mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[AAE-4697] Restrict content node selector breadcrumb when destination folder path is wrong (#6738)
* [AAE-4697] Restrict content node selector breadcrumb when destination folder path is wrong * * Added unit tests * * Used try/catch block * * Moved if logic from try black to a method
This commit is contained in:
parent
ab6354d39a
commit
cd0587dcfd
@ -57,7 +57,9 @@ import {
|
||||
mockAllFileSourceWithStaticPathType,
|
||||
formVariables,
|
||||
processVariables,
|
||||
mockAllFileSourceWithRenamedFolderVariablePathType
|
||||
mockAllFileSourceWithRenamedFolderVariablePathType,
|
||||
allSourceParamsWithWrongRelativePath,
|
||||
allSourceParamsWithRelativePath
|
||||
} from '../../../mocks/attach-file-cloud-widget.mock';
|
||||
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
@ -225,6 +227,46 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
});
|
||||
|
||||
it('should be able to fetch nodeId based on given alias if the relative path is wrong', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(new Promise((reject) => reject(undefined)));
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId').and.returnValue(mockNodeId);
|
||||
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParamsWithWrongRelativePath);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
clickOnAttachFileWidget('attach-file-alfresco');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-shared-';
|
||||
const opt = { relativePath: '/wrongRelativePath' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
});
|
||||
|
||||
it('should be able to fetch relativePath nodeId if the given relative path is correct', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId');
|
||||
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParamsWithRelativePath);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
clickOnAttachFileWidget('attach-file-alfresco');
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-shared-';
|
||||
const opt = { relativePath: '/myfiles' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).not.toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
});
|
||||
|
||||
it('should be able to use mapped string variable value if the destinationFolderPath set to string type variable', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeIdBasedOnStringVariableValue);
|
||||
|
||||
@ -244,7 +286,7 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should be able to use default location if mapped string variable value is undefined/empty', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId').and.returnValue(mockNodeId);
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithStringTypeEmptyValue);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@ -254,9 +296,8 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-my-';
|
||||
const opt = { relativePath: '' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
});
|
||||
|
||||
@ -275,7 +316,7 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
});
|
||||
|
||||
it('should be able to use default location if the mapped folder variable value is undefined/empty', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId').and.returnValue(mockNodeId);
|
||||
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithFolderTypeEmptyValue);
|
||||
fixture.detectChanges();
|
||||
@ -285,9 +326,8 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-my-';
|
||||
const opt = { relativePath: '' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toBe('mock-node-id');
|
||||
});
|
||||
|
||||
@ -384,7 +424,7 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
|
||||
describe('FilesSource', () => {
|
||||
it('Should be able to fetch nodeId of default user alias (-my-) if fileSource set only to Alfresco Content', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId').and.returnValue(mockNodeId);
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, false);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@ -393,15 +433,14 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-my-';
|
||||
const opt = { relativePath: '' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('mock-node-id', 'single', false, true);
|
||||
});
|
||||
|
||||
it('Should be able to fetch nodeId of default user alias (-my-) if fileSource set to multiple upload for Alfresco Content', async () => {
|
||||
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
|
||||
const fetchAliasNodeIdSpy = spyOn(contentCloudNodeSelectorService, 'fetchAliasNodeId').and.returnValue(mockNodeId);
|
||||
|
||||
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, true);
|
||||
fixture.detectChanges();
|
||||
@ -411,9 +450,8 @@ describe('AttachFileCloudWidgetComponent', () => {
|
||||
await fixture.whenStable();
|
||||
|
||||
const alias = '-my-';
|
||||
const opt = { relativePath: '' };
|
||||
|
||||
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
|
||||
expect(fetchAliasNodeIdSpy).toHaveBeenCalledWith(alias);
|
||||
expect(widget.rootNodeId).toEqual('mock-node-id');
|
||||
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('mock-node-id', 'multiple', false, true);
|
||||
});
|
||||
|
@ -151,13 +151,29 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
|
||||
}
|
||||
|
||||
if (!rootNodeId) {
|
||||
const nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, { relativePath: destinationFolderPath.path });
|
||||
try {
|
||||
const nodeId = await this.getNodeIdBasedOnPath(destinationFolderPath);
|
||||
rootNodeId = nodeId ? nodeId : destinationFolderPath.alias;
|
||||
} catch (error) {
|
||||
this.logService.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return rootNodeId;
|
||||
}
|
||||
|
||||
private async getNodeIdBasedOnPath(destinationFolderPath: DestinationFolderPathModel) {
|
||||
let nodeId: string;
|
||||
if (destinationFolderPath.path) {
|
||||
nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, { relativePath: destinationFolderPath.path });
|
||||
}
|
||||
if (!nodeId) {
|
||||
nodeId = await this.contentNodeSelectorService.fetchAliasNodeId(destinationFolderPath.alias);
|
||||
}
|
||||
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath: string): DestinationFolderPathModel {
|
||||
let alias: string; let path: string;
|
||||
if (destinationFolderPath) {
|
||||
|
@ -68,6 +68,28 @@ export const menuTestSourceParam = {
|
||||
}
|
||||
};
|
||||
|
||||
export const allSourceParamsWithWrongRelativePath = {
|
||||
fileSource: {
|
||||
name: 'all file sources',
|
||||
serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID,
|
||||
destinationFolderPath: {
|
||||
value: '-shared-/wrongRelativePath',
|
||||
type: DestinationFolderPathType.STATIC_TYPE
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const allSourceParamsWithRelativePath = {
|
||||
fileSource: {
|
||||
name: 'all file sources',
|
||||
serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID,
|
||||
destinationFolderPath: {
|
||||
value: '-shared-/myfiles',
|
||||
type: DestinationFolderPathType.STATIC_TYPE
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const allSourceParams = {
|
||||
fileSource: {
|
||||
name: 'all file sources',
|
||||
|
@ -54,11 +54,17 @@ export class ContentCloudNodeSelectorService {
|
||||
}
|
||||
|
||||
async fetchNodeIdFromRelativePath(alias: string, opts: { relativePath: string }): Promise<string> {
|
||||
const nodeEntry: any = await this.apiService.getInstance().node
|
||||
const relativePathNodeEntry: any = await this.apiService.getInstance().node
|
||||
.getNode(alias, opts)
|
||||
.catch((err) => this.handleError(err));
|
||||
return relativePathNodeEntry?.entry?.id;
|
||||
}
|
||||
|
||||
return nodeEntry?.entry?.id;
|
||||
async fetchAliasNodeId(alias: string): Promise<string> {
|
||||
const aliasNodeEntry: any = await this.apiService.getInstance().node
|
||||
.getNode(alias)
|
||||
.catch((err) => this.handleError(err));
|
||||
return aliasNodeEntry?.entry?.id;
|
||||
}
|
||||
|
||||
private openContentNodeDialog(data: ContentNodeSelectorComponentData, currentPanelClass: string, chosenWidth: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user