From 301df3dcb84b7bc568cf36b1dfd2e5987a7da6ce Mon Sep 17 00:00:00 2001 From: siva kumar Date: Fri, 5 Feb 2021 15:15:04 +0530 Subject: [PATCH] [AAE-4504] FE - [ADF] Fetch destination Folder Path from a static path (#6557) * [AAE4504] FE - [ADF] Fetch destination Folder Path from a static path * * Added condition to check destination folder path * * Added typescript way to check * Fix attach file from local e2e * * Added unit tests to the recent changes * * Fixed comments Co-authored-by: Cristina Jalba --- .../widgets/core/form-field-file-source.ts | 9 ++- ...attach-file-cloud-widget.component.spec.ts | 81 +++++++++++++++++-- .../attach-file-cloud-widget.component.ts | 8 +- .../content-node-selector-dialog.page.ts | 3 +- 4 files changed, 92 insertions(+), 9 deletions(-) diff --git a/lib/core/form/components/widgets/core/form-field-file-source.ts b/lib/core/form/components/widgets/core/form-field-file-source.ts index 83cf39bfea..f168e03453 100644 --- a/lib/core/form/components/widgets/core/form-field-file-source.ts +++ b/lib/core/form/components/widgets/core/form-field-file-source.ts @@ -19,10 +19,17 @@ import { FormFieldSelectedFolder } from './form-field-selected-folder'; +export interface DestinationFolderPath { + id?: string; + name?: string; + type: string; + value: string; +} + export interface FormFieldFileSource { metadataAllowed: boolean; name: string; selectedFolder: FormFieldSelectedFolder; serviceId: string; - destinationFolderPath: string; + destinationFolderPath: DestinationFolderPath; } diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index 43d967532f..79c65b3d5d 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -111,7 +111,11 @@ describe('AttachFileCloudWidgetComponent', () => { fileSource: { name: 'all file sources', serviceId: 'all-file-sources', - destinationFolderPath: '-root-/myfiles' + destinationFolderPath: { + name: 'staticValue', + value: '-root-/myfiles', + type: 'value' + } } }; @@ -119,7 +123,11 @@ describe('AttachFileCloudWidgetComponent', () => { fileSource: { name: 'all file sources', serviceId: 'all-file-sources', - destinationFolderPath: '-root-' + destinationFolderPath: { + name: 'staticValue', + value: '-root-', + type: 'value' + } } }; @@ -127,7 +135,11 @@ describe('AttachFileCloudWidgetComponent', () => { fileSource: { name: 'all file sources', serviceId: 'all-file-sources', - destinationFolderPath: '-wrongAlias-' + destinationFolderPath: { + name: 'staticValue', + value: '-wrongAlias-', + type: 'value' + } } }; @@ -135,7 +147,26 @@ describe('AttachFileCloudWidgetComponent', () => { fileSource: { name: 'all file sources', serviceId: 'all-file-sources', - destinationFolderPath: '/noalias/createdFolder' + destinationFolderPath: { + name: 'staticValue', + value: '/noalias/createdFolder', + type: 'value' + } + } + }; + + const allSourceWithoutDestinationFolderPath = { + fileSource: { + name: 'all file sources', + serviceId: 'all-file-sources' + } + }; + + const allSourceWithoutValueProperty = { + fileSource: { + name: 'all file sources', + serviceId: 'all-file-sources', + destinationFolderPath: '-mockAlias-' } }; @@ -363,7 +394,7 @@ describe('AttachFileCloudWidgetComponent', () => { const alias = '-root-'; const opt = { relativePath: '/myfiles' }; expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); - expect(widget.field.params.fileSource.destinationFolderPath).toBe('-root-/myfiles'); + expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/myfiles'); expect(widget.rootNodeId).toEqual('mock-node-id'); }); @@ -454,6 +485,46 @@ describe('AttachFileCloudWidgetComponent', () => { expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'multiple', true, true); }); + it('Should set default user alias (-my-) as rootNodeId if destinationFolderPath is not defined', async () => { + const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [], + id: 'attach-file-alfresco', + params: allSourceWithoutDestinationFolderPath + }); + fixture.detectChanges(); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + attachButton.click(); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(getAliasAndPathSpy).not.toHaveBeenCalled(); + expect(widget.rootNodeId).toEqual('-my-'); + }); + + it('Should set default user alias (-my-) as rootNodeId if value property missing from destinationFolderPath', async () => { + const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [], + id: 'attach-file-alfresco', + params: allSourceWithoutValueProperty + }); + fixture.detectChanges(); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + attachButton.click(); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(getAliasAndPathSpy).not.toHaveBeenCalled(); + expect(widget.rootNodeId).toEqual('-my-'); + }); + it('should return the application name in case -appname- placeholder is present', async() => { appConfigService.config = Object.assign(appConfigService.config, { 'alfresco-deployed-apps': [ diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index 55cc013502..69bd0b0f2f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -125,8 +125,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i async openSelectDialog() { const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; let destinationFolderPath = { alias: AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER, path: '' }; - if (this.isAlfrescoAndLocal()) { - destinationFolderPath = this.getAliasAndRelativePathFromDestinationFolderPath(this.field.params.fileSource.destinationFolderPath); + if (this.isAlfrescoAndLocal() && this.hasDestinationFolder()) { + destinationFolderPath = this.getAliasAndRelativePathFromDestinationFolderPath(this.field.params.fileSource.destinationFolderPath.value); destinationFolderPath.path = this.replaceAppNameAliasWithValue(destinationFolderPath.path); } const nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, { relativePath: destinationFolderPath.path }); @@ -218,6 +218,10 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i return alias && AttachFileCloudWidgetComponent.VALID_ALIAS.includes(alias); } + private hasDestinationFolder(): boolean { + return !!this.field?.params?.fileSource?.destinationFolderPath?.value; + } + ngOnDestroy() { this.contentNodeSelectorPanelService.customModels = []; } diff --git a/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts b/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts index c09ae9960d..50b5837739 100644 --- a/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts +++ b/lib/testing/src/lib/content-services/dialog/content-node-selector-dialog.page.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { by, element } from 'protractor'; +import { by, element, browser } from 'protractor'; import { DocumentListPage } from '../pages/document-list.page'; import { BrowserVisibility } from '../../core/utils/browser-visibility'; import { BrowserActions } from '../../core/utils/browser-actions'; @@ -149,6 +149,7 @@ export class ContentNodeSelectorDialogPage { const uploadButton = element(by.css('adf-upload-button input')); await BrowserVisibility.waitUntilElementIsPresent(uploadButton); + await browser.sleep(500); await uploadButton.sendKeys(fileLocation); await this.tabPage.clickTabByLabel(this.repositoryTabName);