From c9a4ab45705e3798a83b16db9713082de33de095 Mon Sep 17 00:00:00 2001 From: siva kumar Date: Thu, 18 Feb 2021 16:23:13 +0530 Subject: [PATCH] [AAE-4452] FE - [ADF] Fetch destination folder path from mapped variables (#6665) * [AAE-4452] FE - [ADF] Fetch destination folder path from variables * * Added unit test on the attach-file-cloud widget * Created a mock object. * Created destination and path type model objects * * Moved destination path logic from form-field-model to upload-cloud widget component * * Added unit test to the recent changes * Improved unit tests * * FIxed comments * Added one more unit test --- ...attach-file-cloud-widget.component.spec.ts | 628 +++++++----------- .../attach-file-cloud-widget.component.ts | 42 +- .../attach-file/upload-cloud.widget.ts | 38 ++ .../mocks/attach-file-cloud-widget.mock.ts | 344 ++++++++++ .../models/form-cloud-representation.model.ts | 11 + 5 files changed, 655 insertions(+), 408 deletions(-) create mode 100644 lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts 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 79c65b3d5d..2637fb6a6f 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 @@ -32,12 +32,38 @@ import { AlfrescoApiService, UploadWidgetContentLinkModel } from '@alfresco/adf-core'; +import { + allSourceParams, + contentSourceParam, + fakeMinimalNode, + mockNodeId, + fakeLocalPngResponse, + onlyLocalParams, + allSourceWithRootParams, + allSourceWithWrongAliasParams, + allSourceWithNoAliasParams, + allSourceWithoutDestinationFolderPath, + allSourceWithoutValueProperty, + fakeNodeWithProperties, + menuTestSourceParam, + expectedValues, + fakeLocalPngAnswer, + allSourceWithStringTypeEmptyValue, + allSourceWithFolderTypeEmptyValue, + mockNodeIdBasedOnStringVariableValue, + mockAllFileSourceWithStringVariablePathType, + mockAllFileSourceWithFolderVariablePathType, + mockContentFileSource, + mockAllFileSourceWithStaticPathType, + formVariables, + processVariables, + mockAllFileSourceWithRenamedFolderVariablePathType +} from '../../../mocks/attach-file-cloud-widget.mock'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ContentModule, ContentNodeSelectorPanelService } from '@alfresco/adf-content-services'; import { By } from '@angular/platform-browser'; import { of } from 'rxjs'; -import { Node } from '@alfresco/js-api'; import { FormCloudModule } from '../../../form-cloud.module'; import { TranslateModule } from '@ngx-translate/core'; @@ -56,165 +82,24 @@ describe('AttachFileCloudWidgetComponent', () => { let contentModelFormFileHandlerSpy: jasmine.Spy; let updateFormSpy: jasmine.Spy; let contentClickedSpy: jasmine.Spy; + let openUploadFileDialogSpy: jasmine.Spy; - const fakePngAnswer = { - id: 1155, - nodeId: 1155, - name: 'a_png_file.png', - created: '2017-07-25T17:17:37.099Z', - createdBy: { - id: 1001, - firstName: 'Admin', - lastName: 'admin', - email: 'admin' - }, - relatedContent: false, - contentAvailable: true, - link: false, - mimeType: 'image/png', - simpleType: 'image', - previewStatus: 'queued', - thumbnailStatus: 'queued', - properties: { - 'pfx:property_one': 'testValue', - 'pfx:property_two': true - } - }; + function createUploadWidgetField(form: FormModel, fieldId: string, value?: any, params?: any, multiple?: boolean, name?: string, readOnly?: boolean) { + widget.field = new FormFieldModel(form, { + type: FormFieldTypes.UPLOAD, + value: value, + id: fieldId, + readOnly: readOnly, + name: name, + tooltip: 'attach file widget', + params: { ...params, multiple: multiple } + }); + } - const onlyLocalParams = { - fileSource: { - serviceId: 'local-file' - } - }; - - const contentSourceParam = { - fileSource: { - name: 'mock-alf-content', - serviceId: 'alfresco-content' - } - }; - - const menuTestSourceParam = { - fileSource: { - name: 'mock-alf-content', - serviceId: 'alfresco-content' - }, - menuOptions: { - show: true, - download: true, - retrieveMetadata: true, - remove: true - } - }; - - const allSourceParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - destinationFolderPath: { - name: 'staticValue', - value: '-root-/myfiles', - type: 'value' - } - } - }; - - const allSourceWithRootParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - destinationFolderPath: { - name: 'staticValue', - value: '-root-', - type: 'value' - } - } - }; - - const allSourceWithWrongAliasParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - destinationFolderPath: { - name: 'staticValue', - value: '-wrongAlias-', - type: 'value' - } - } - }; - - const allSourceWithNoAliasParams = { - fileSource: { - name: 'all file sources', - serviceId: 'all-file-sources', - 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-' - } - }; - - const fakeMinimalNode: Node = { - id: 'fake', - name: 'fake-name', - content: { - mimeType: 'application/pdf' - } - }; - - const fakeNodeWithProperties: Node = { - id: 'fake-properties', - name: 'fake-properties-name', - content: { - mimeType: 'application/pdf' - }, - properties: { - 'pfx:property_one': 'testValue', - 'pfx:property_two': true - } - }; - - const expectedValues = { pfx_property_one: 'testValue', pfx_property_two: true }; - - const mockNodeId = new Promise(function (resolve) { - resolve('mock-node-id'); - }); - - const fakeLocalPngAnswer = { - id: 1155, - nodeId: 1155, - name: 'a_png_file.png', - created: '2017-07-25T17:17:37.099Z', - createdBy: { - id: 1001, - firstName: 'Admin', - lastName: 'admin', - email: 'admin' - }, - relatedContent: false, - contentAvailable: true, - link: false, - mimeType: 'image/png', - simpleType: 'image', - previewStatus: 'queued', - thumbnailStatus: 'queued' - }; + function clickOnAttachFileWidget(id: string) { + const attachButton: HTMLButtonElement = element.querySelector(`#${id}`); + attachButton.click(); + } setupTestBed({ imports: [ @@ -241,6 +126,7 @@ describe('AttachFileCloudWidgetComponent', () => { formService = TestBed.inject(FormService); alfrescoApiService = TestBed.inject(AlfrescoApiService); contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService); + openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode])); })); afterEach(() => { @@ -248,53 +134,28 @@ describe('AttachFileCloudWidgetComponent', () => { }); it('should show up as simple upload when is configured for only local files', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'simple-upload-button'; - widget.field.params = allSourceParams; + createUploadWidgetField(new FormModel(), 'simple-upload-button', [], allSourceParams); fixture.detectChanges(); + fixture.whenStable().then(() => { - expect( - element.querySelector('#simple-upload-button') - ).not.toBeNull(); + expect(element.querySelector('#simple-upload-button')).not.toBeNull(); }); })); it('should show up as content upload when is configured with content', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = contentSourceParam; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam); fixture.detectChanges(); + fixture.whenStable().then(() => { - expect( - element.querySelector('.adf-attach-widget__menu-upload') - ).not.toBeNull(); + expect(element.querySelector('.adf-attach-widget__menu-upload')).not.toBeNull(); }); })); - it('should be able to attach files coming from content selector', async () => { - spyOn( - contentCloudNodeSelectorService, - 'openUploadFileDialog' - ).and.returnValue(of([fakeMinimalNode])); - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = contentSourceParam; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); await fixture.whenStable(); fixture.detectChanges(); const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); @@ -306,23 +167,10 @@ describe('AttachFileCloudWidgetComponent', () => { it('should be able to attach files coming from all files source', async () => { spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); - spyOn( - contentCloudNodeSelectorService, - 'openUploadFileDialog' - ).and.returnValue(of([fakeMinimalNode])); - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceParams; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParams); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); + clickOnAttachFileWidget('attach-file-alfresco'); await fixture.whenStable(); fixture.detectChanges(); const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); @@ -333,26 +181,16 @@ describe('AttachFileCloudWidgetComponent', () => { }); it('should display file list when field has value', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [fakePngAnswer] - }); - widget.field.id = 'attach-file-attach'; - widget.field.params = onlyLocalParams; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [fakeLocalPngResponse], onlyLocalParams); fixture.detectChanges(); + fixture.whenStable().then(() => { expect(element.querySelector('#file-1155-icon')).not.toBeNull(); }); })); it('should be able to set label property for Attach File widget', () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - readOnly: true, - id: 'attach-file', - name: 'Label', - params: onlyLocalParams - }); + createUploadWidgetField(new FormModel(), 'attach-file', [], onlyLocalParams, false, 'Label', true); fixture.detectChanges(); fixture.whenStable().then(() => { expect(element.querySelector('label').innerText).toEqual('Label'); @@ -367,119 +205,136 @@ describe('AttachFileCloudWidgetComponent', () => { }); describe('destinationFolderPath', () => { - let openUploadFileDialogSpy: jasmine.Spy; - - beforeEach(async(() => { - openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode])); - })); it('should be able to fetch nodeId if destinationFolderPath is defined', async () => { const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceParams; + + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParams); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); const alias = '-root-'; const opt = { relativePath: '/myfiles' }; + expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/myfiles'); 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); + + const form = new FormModel({ formVariables, processVariables}); + createUploadWidgetField(form, 'attach-file-alfresco', [], mockAllFileSourceWithStringVariablePathType); + fixture.detectChanges(); + await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); + await fixture.whenStable(); + + const alias = '-root-'; + const opt = { relativePath: '/pathBasedOnStringvariablevalue' }; + + expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); + expect(widget.rootNodeId).toEqual('mock-string-value-node-id'); + }); + + 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); + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithStringTypeEmptyValue); + fixture.detectChanges(); + await fixture.whenStable(); + + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); + await fixture.whenStable(); + + const alias = '-my-'; + const opt = { relativePath: '' }; + + expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); + expect(widget.rootNodeId).toEqual('mock-node-id'); + }); + + it('should be able to use mapped folder variable value if destinationFolderPath set to folder type variable', async () => { + const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath'); + const form = new FormModel({ formVariables, processVariables}); + createUploadWidgetField(form, 'attach-file-alfresco', [], mockAllFileSourceWithFolderVariablePathType); + fixture.detectChanges(); + await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); + await fixture.whenStable(); + + expect(fetchNodeIdFromRelativePathSpy).not.toHaveBeenCalled(); + expect(widget.rootNodeId).toBe('mock-folder-id'); + }); + + 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); + + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithFolderTypeEmptyValue); + fixture.detectChanges(); + await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); + fixture.detectChanges(); + await fixture.whenStable(); + + const alias = '-my-'; + const opt = { relativePath: '' }; + + expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); + expect(widget.rootNodeId).toBe('mock-node-id'); + }); + it('Should be able to set given alias as rootNodeId if the nodeId of the alias is not fetched from the api', async () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithRootParams; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithRootParams); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(widget.rootNodeId).toEqual('-root-'); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-root-', 'single', true, true); }); it('Should set default user alias (-my-) as rootNodeId if destinationFolderPath contains wrong alias and single upload for Alfresco Content + Locale', async () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithWrongAliasParams; - widget.field.params.multiple = false; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithWrongAliasParams, false); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(widget.rootNodeId).toEqual('-my-'); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', true, true); }); it('Should set default user alias (-my-) as rootNodeId if destinationFolderPath contains wrong alias and multiple upload for Alfresco Content + Locale', async () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithWrongAliasParams; - widget.field.params.multiple = true; + + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithWrongAliasParams, true); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(widget.rootNodeId).toEqual('-my-'); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'multiple', true, true); }); it('Should set default user alias (-my-) as rootNodeId if destinationFolderPath does not have alias for Alfresco Content + Locale', async () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = allSourceWithNoAliasParams; - widget.field.params.multiple = true; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithNoAliasParams, true); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(widget.rootNodeId).toEqual('-my-'); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'multiple', true, true); @@ -487,17 +342,10 @@ describe('AttachFileCloudWidgetComponent', () => { 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 - }); + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithoutDestinationFolderPath); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - attachButton.click(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); await fixture.whenStable(); @@ -507,17 +355,10 @@ describe('AttachFileCloudWidgetComponent', () => { 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 - }); + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithoutValueProperty); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - attachButton.click(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); await fixture.whenStable(); @@ -533,6 +374,7 @@ describe('AttachFileCloudWidgetComponent', () => { } ] }); + expect(widget.replaceAppNameAliasWithValue('/myfiles/-appname-/folder')).toBe('/myfiles/fakeapp/folder'); }); @@ -543,21 +385,12 @@ 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); - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = contentSourceParam; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, false); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); const alias = '-my-'; const opt = { relativePath: '' }; @@ -569,22 +402,13 @@ describe('AttachFileCloudWidgetComponent', () => { 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); - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = contentSourceParam; - widget.field.params.multiple = true; + + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, true); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); const alias = '-my-'; const opt = { relativePath: '' }; @@ -595,34 +419,19 @@ describe('AttachFileCloudWidgetComponent', () => { }); it('Should be able to set default user alias (-my-) as rootNodeId if the nodeId of the alias is not fetched from the api', async () => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - value: [] - }); - widget.field.id = 'attach-file-alfresco'; - widget.field.params = contentSourceParam; - widget.field.params.multiple = false; + createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, false); fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(widget.rootNodeId).toEqual('-my-'); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', false, true); }); it('should display tooltip when tooltip is set', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - id: 'attach-file-attach', - type: FormFieldTypes.UPLOAD, - value: [], - tooltip: 'attach file widget' - }); + createUploadWidgetField(new FormModel(), 'attach-file-attach', [], onlyLocalParams); fixture.detectChanges(); const attachElement: any = element.querySelector('#attach-file-attach'); @@ -636,13 +445,7 @@ describe('AttachFileCloudWidgetComponent', () => { describe('when is readonly', () => { it('should show empty list message when there are no file', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - readOnly: true, - value: [] - }); - widget.field.id = 'empty-test'; - widget.field.params = onlyLocalParams; + createUploadWidgetField(new FormModel(), 'empty-test', [], onlyLocalParams, null, null, true); fixture.detectChanges(); fixture.whenStable().then(() => { expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull(); @@ -650,13 +453,7 @@ describe('AttachFileCloudWidgetComponent', () => { })); it('should not show empty list message when there are files', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - readOnly: true, - value: [fakePngAnswer] - }); - widget.field.id = 'fill-test'; - widget.field.params = onlyLocalParams; + createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true); fixture.detectChanges(); fixture.whenStable().then(() => { expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull(); @@ -664,14 +461,7 @@ describe('AttachFileCloudWidgetComponent', () => { })); it('should not show remove button when there are files attached', async(() => { - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - readOnly: true, - value: [fakePngAnswer] - }); - widget.field.id = 'fill-test'; - widget.field.params = onlyLocalParams; - + createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true); fixture.detectChanges(); const menuButton: HTMLButtonElement = ( fixture.debugElement.query(By.css('#file-1155-option-menu')) @@ -679,6 +469,7 @@ describe('AttachFileCloudWidgetComponent', () => { ); menuButton.click(); fixture.detectChanges(); + expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull(); })); }); @@ -687,10 +478,7 @@ describe('AttachFileCloudWidgetComponent', () => { beforeEach(async () => { apiServiceSpy = spyOn(alfrescoApiService.getInstance().node, 'getNode').and.returnValue(new Promise(resolve => resolve({entry: fakeNodeWithProperties}))); spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(new Promise(resolve => resolve('fake-properties'))); - spyOn( - contentCloudNodeSelectorService, - 'openUploadFileDialog' - ).and.returnValue(of([fakeNodeWithProperties])); + openUploadFileDialogSpy.and.returnValue(of([fakeNodeWithProperties])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -699,11 +487,7 @@ describe('AttachFileCloudWidgetComponent', () => { widget.field.params = menuTestSourceParam; fixture.detectChanges(); await fixture.whenStable(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - - expect(attachButton).not.toBeNull(); - - attachButton.click(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); await fixture.whenStable(); }); @@ -860,11 +644,7 @@ describe('AttachFileCloudWidgetComponent', () => { contentModelFormFileHandlerSpy = spyOn(widget, 'contentModelFormFileHandler').and.callThrough(); updateFormSpy = spyOn(formService.updateFormValuesRequested, 'next'); contentClickedSpy = spyOn(formService.formContentClicked, 'next'); - - spyOn( - contentCloudNodeSelectorService, - 'openUploadFileDialog' - ).and.returnValue(of([fakeNodeWithProperties])); + openUploadFileDialogSpy.and.returnValue(of([fakeNodeWithProperties])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -941,11 +721,9 @@ describe('AttachFileCloudWidgetComponent', () => { }); it('should have been called on attach file when value was empty', async () => { - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - expect(attachButton).not.toBeNull(); - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(contentModelFormFileHandlerSpy).toHaveBeenCalledWith(fakeNodeWithProperties); expect(updateFormSpy).toHaveBeenCalledWith(expectedValues); @@ -959,11 +737,9 @@ describe('AttachFileCloudWidgetComponent', () => { await fixture.whenStable(); fixture.detectChanges(); - const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - expect(attachButton).not.toBeNull(); - attachButton.click(); - await fixture.whenStable(); + clickOnAttachFileWidget('attach-file-alfresco'); fixture.detectChanges(); + await fixture.whenStable(); expect(contentModelFormFileHandlerSpy).not.toHaveBeenCalled(); }); @@ -1019,4 +795,70 @@ describe('AttachFileCloudWidgetComponent', () => { expect(contentClickedSpy).toHaveBeenCalledWith(new UploadWidgetContentLinkModel(null, widget.field.id)); }); }); + + describe('Upload widget with destination folder path params', () => { + let form: FormModel; + beforeEach(() => { + form = new FormModel({ + formVariables, + processVariables + }); + }); + + it('it should get a destination folder path value from a string variable', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithStringVariablePathType); + fixture.detectChanges(); + + expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('string'); + expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/pathBasedOnStringvariablevalue'); + }); + + it('it should get a destination folder path value from a folder variable', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithFolderVariablePathType); + fixture.detectChanges(); + + expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('folder'); + expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('mock-folder-id'); + }); + + it('it should get a destination folder path value from a folder variable', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithFolderVariablePathType); + fixture.detectChanges(); + + expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('folder'); + expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('mock-folder-id'); + }); + + it('it should set destination folder path value to undefined if mapped variable deleted/renamed', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithRenamedFolderVariablePathType); + fixture.detectChanges(); + + expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('folder'); + expect(widget.field.params.fileSource.destinationFolderPath.value).toBeUndefined(); + }); + + it('it should not have destination folder path property if the file source set to content source', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockContentFileSource); + fixture.detectChanges(); + + expect(widget.field.params.fileSource['destinationFolderPath']).toBeUndefined(); + }); + + it('it should not call getProcessVariableValue if the file source set to content source', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockContentFileSource); + fixture.detectChanges(); + const getProcessVariableValueSpy = spyOn(widget.field.form, 'getProcessVariableValue'); + + expect(getProcessVariableValueSpy).not.toHaveBeenCalled(); + }); + + it('it should not call getProcessVariableValue if the destination folder path type set to static type', () => { + createUploadWidgetField(form, 'attach-file-attach', [], mockAllFileSourceWithStaticPathType); + fixture.detectChanges(); + const getProcessVariableValueSpy = spyOn(widget.field.form, 'getProcessVariableValue'); + + expect(widget.field.params.fileSource.destinationFolderPath.type).toBe('value'); + expect(getProcessVariableValueSpy).not.toHaveBeenCalled(); + }); + }); }); 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 69bd0b0f2f..1020c53a15 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 @@ -33,7 +33,7 @@ import { Node, RelatedContentRepresentation } from '@alfresco/js-api'; import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { UploadCloudWidgetComponent } from './upload-cloud.widget'; -import { DestinationFolderPathModel } from '../../../models/form-cloud-representation.model'; +import { DestinationFolderPathModel, DestinationFolderPathType } from '../../../models/form-cloud-representation.model'; import { ContentNodeSelectorPanelService } from '@alfresco/adf-content-services'; @Component({ @@ -90,12 +90,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i } } - isAlfrescoAndLocal(): boolean { - return ( - this.field.params && - this.field.params.fileSource && - this.field.params.fileSource.serviceId === 'all-file-sources' - ); + isPathStaticType(): boolean { + return this.field.params?.fileSource?.destinationFolderPath?.type === DestinationFolderPathType.STATIC_TYPE; } isUploadButtonVisible(): boolean { @@ -124,14 +120,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() && 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 }); - this.rootNodeId = nodeId ? nodeId : destinationFolderPath.alias; - + const nodeId = await this.getDestinationFolderNodeId(); + this.rootNodeId = nodeId ? nodeId : AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER; this.contentNodeSelectorPanelService.customModels = this.field.params.customModels; this.contentNodeSelectorService @@ -146,6 +136,28 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i }); } + private async getDestinationFolderNodeId(): Promise { + let rootNodeId: string; + let destinationFolderPath = { alias: AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER, path: '' }; + if (this.isAlfrescoAndLocal() && this.hasDestinationFolder()) { + if (this.isPathVariableType(DestinationFolderPathType.STRING_TYPE) || this.isPathStaticType()) { + destinationFolderPath = this.getAliasAndRelativePathFromDestinationFolderPath(this.field.params.fileSource.destinationFolderPath.value); + destinationFolderPath.path = this.replaceAppNameAliasWithValue(destinationFolderPath.path); + } + + if (this.isPathVariableType(DestinationFolderPathType.FOLDER_TYPE)) { + rootNodeId = this.field.params.fileSource.destinationFolderPath.value; + } + } + + if (!rootNodeId) { + const nodeId = await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(destinationFolderPath.alias, { relativePath: destinationFolderPath.path }); + rootNodeId = nodeId ? nodeId : destinationFolderPath.alias; + } + + return rootNodeId; + } + getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath: string): DestinationFolderPathModel { let alias: string; let path: string; if (destinationFolderPath) { diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts index 7d91ca4fce..69c4212680 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts @@ -23,6 +23,7 @@ import { Observable, from } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; import { WidgetComponent, LogService, FormService, ThumbnailService, ContentLinkModel, NotificationService } from '@alfresco/adf-core'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; +import { FileSourceTypes, DestinationFolderPathType } from '../../../models/form-cloud-representation.model'; @Component({ selector: 'upload-cloud-widget', @@ -68,6 +69,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni this.fixIncompatibilityFromPreviousAndNewForm([]); } this.getMultipleFileParam(); + this.setDestinationFolderPathFromMappedVariable(); } removeFile(file: any) { @@ -160,4 +162,40 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni fileClicked(file: ContentLinkModel): void { this.formService.formContentClicked.next(file); } + + isAlfrescoAndLocal(): boolean { + return this.field?.params?.fileSource?.serviceId === FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID; + } + + isPathVariableType(type: string): boolean { + return this.field?.params?.fileSource?.destinationFolderPath?.type === type; + } + + setDestinationFolderPathFromMappedVariable() { + if (this.isAlfrescoAndLocal()) { + this.prepareUploadWidgetDestinationFolderPathFromStringVariable(); + this.prepareUploadWidgetDestinationFolderPathFromFolderVariable(); + } + } + + private prepareUploadWidgetDestinationFolderPathFromStringVariable() { + if (this.isPathVariableType(DestinationFolderPathType.STRING_TYPE)) { + this.setUploadWidgetDestinationFolderPath(this.getDestinationFolderPathValue()); + } + } + + private prepareUploadWidgetDestinationFolderPathFromFolderVariable() { + if (this.isPathVariableType(DestinationFolderPathType.FOLDER_TYPE)) { + const folder = this.getDestinationFolderPathValue(); + this.setUploadWidgetDestinationFolderPath(folder?.length ? folder[0].id : undefined); + } + } + + private setUploadWidgetDestinationFolderPath(path: string) { + this.field.params.fileSource.destinationFolderPath['value'] = path ? path : undefined; + } + + private getDestinationFolderPathValue(): any { + return this.field.form.getProcessVariableValue(this.field.params.fileSource?.destinationFolderPath?.name); + } } diff --git a/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts new file mode 100644 index 0000000000..c3ff624765 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/mocks/attach-file-cloud-widget.mock.ts @@ -0,0 +1,344 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Node } from '@alfresco/js-api'; +import { FileSourceTypes, DestinationFolderPathType } from '../models/form-cloud-representation.model'; + +export const fakeLocalPngResponse = { + id: 1155, + nodeId: 1155, + name: 'a_png_file.png', + created: '2017-07-25T17:17:37.099Z', + createdBy: { + id: 1001, + firstName: 'Admin', + lastName: 'admin', + email: 'admin' + }, + relatedContent: false, + contentAvailable: true, + link: false, + mimeType: 'image/png', + simpleType: 'image', + previewStatus: 'queued', + thumbnailStatus: 'queued', + properties: { + 'pfx:property_one': 'testValue', + 'pfx:property_two': true + } +}; + +export const onlyLocalParams = { + fileSource: { + serviceId: 'local-file' + } +}; + +export const contentSourceParam = { + fileSource: { + name: 'mock-alf-content', + serviceId: FileSourceTypes.ALFRESCO_CONTENT_SOURCES_SERVICE_ID + } +}; + +export const menuTestSourceParam = { + fileSource: { + name: 'mock-alf-content', + serviceId: FileSourceTypes.ALFRESCO_CONTENT_SOURCES_SERVICE_ID + }, + menuOptions: { + show: true, + download: true, + retrieveMetadata: true, + remove: true + } +}; + +export const allSourceParams = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + value: '-root-/myfiles', + type: DestinationFolderPathType.STATIC_TYPE + } + } +}; + +export const allSourceWithStringTypeEmptyValue = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + value: null, + name: 'stringVariableName', + type: DestinationFolderPathType.STRING_TYPE + } + } +}; + +export const allSourceWithFolderTypeEmptyValue = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + value: null, + name: 'folderVariableName', + type: DestinationFolderPathType.FOLDER_TYPE + } + } +}; + +export const allSourceWithRootParams = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + value: '-root-', + type: DestinationFolderPathType.STATIC_TYPE + } + } +}; + +export const allSourceWithWrongAliasParams = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + name: 'staticValue', + value: '-wrongAlias-', + type: DestinationFolderPathType.STATIC_TYPE + } + } +}; + +export const allSourceWithNoAliasParams = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: { + name: 'staticValue', + value: '/noalias/createdFolder', + type: DestinationFolderPathType.STATIC_TYPE + } + } +}; + +export const allSourceWithoutDestinationFolderPath = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID + } +}; + +export const allSourceWithoutValueProperty = { + fileSource: { + name: 'all file sources', + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + destinationFolderPath: '-mockAlias-' + } +}; + +export const fakeMinimalNode: Node = { + id: 'fake', + name: 'fake-name', + content: { + mimeType: 'application/pdf' + } +}; + +export const fakeNodeWithProperties: Node = { + id: 'fake-properties', + name: 'fake-properties-name', + content: { + mimeType: 'application/pdf' + }, + properties: { + 'pfx:property_one': 'testValue', + 'pfx:property_two': true + } +}; + +export const expectedValues = { + pfx_property_one: 'testValue', + pfx_property_two: true +}; + +export const mockNodeId = new Promise(function(resolve) { + resolve('mock-node-id'); +}); + +export const mockNodeIdBasedOnStringVariableValue = new Promise(function(resolve) { + resolve('mock-string-value-node-id'); +}); + +export const mockNodeIdBasedOnFolderVariableValue = new Promise(function(resolve) { + resolve('mock-folder-value-node-id'); +}); + +export const fakeLocalPngAnswer = { + id: 1155, + nodeId: 1155, + name: 'a_png_file.png', + created: '2017-07-25T17:17:37.099Z', + createdBy: { + id: 1001, + firstName: 'Admin', + lastName: 'admin', + email: 'admin' + }, + relatedContent: false, + contentAvailable: true, + link: false, + mimeType: 'image/png', + simpleType: 'image', + previewStatus: 'queued', + thumbnailStatus: 'queued' +}; + +export const mockContentFileSource = { + label: 'File Source', + fileSource: { + serviceId: FileSourceTypes.ALFRESCO_CONTENT_SOURCES_SERVICE_ID, + name: 'Alfresco Content' + }, + key: 'fileSource', + editable: true +}; + +export const mockAllFileSourceWithStaticPathType = { + label: 'File Source', + fileSource: { + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + name: 'Alfresco Content and Local', + destinationFolderPath: { + type: DestinationFolderPathType.STATIC_TYPE, + value: '-myfiles-' + } + }, + key: 'fileSource', + editable: true +}; + +export const mockAllFileSourceWithStringVariablePathType = { + label: 'File Source', + fileSource: { + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + name: 'Alfresco Content and Local', + destinationFolderPath: { + type: DestinationFolderPathType.STRING_TYPE, + name: 'name1', + id: 'var1', + value: '' + } + }, + key: 'fileSource', + editable: true +}; + +export const mockAllFileSourceWithFolderVariablePathType = { + label: 'File Source', + fileSource: { + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + name: 'Alfresco Content and Local', + destinationFolderPath: { + type: DestinationFolderPathType.FOLDER_TYPE, + name: 'name2', + id: 'var2', + value: '' + } + }, + key: 'fileSource', + editable: true +}; + +export const mockAllFileSourceWithRenamedFolderVariablePathType = { + label: 'File Source', + fileSource: { + serviceId: FileSourceTypes.ALL_FILE_SOURCES_SERVICE_ID, + name: 'Alfresco Content and Local', + destinationFolderPath: { + type: DestinationFolderPathType.FOLDER_TYPE, + name: 'name3', + id: 'var2', + value: '' + } + }, + key: 'fileSource', + editable: true +}; + +export const formVariables = [ + { + 'id': 'bfca9766-7bc1-45cc-8ecf-cdad551e36e2', + 'name': 'name1', + 'type': 'string', + 'value': 'hello' + }, + { + 'id': '3ed9f28a-dbae-463f-b991-47ef06658bb6', + 'name': 'name2', + 'type': 'folder' + }, + { + 'id': 'booleanVar', + 'name': 'bool', + 'type': 'boolean', + 'value': 'true' + } +]; + +export const processVariables = [ + { + 'serviceName': 'mock-variable-mapping-rb', + 'serviceFullName': 'mock-variable-mapping-rb', + 'serviceVersion': '', + 'appName': 'mock-variable-mapping', + 'appVersion': '', + 'serviceType': null, + 'id': 3, + 'type': 'string', + 'name': 'variables.name1', + 'createTime': 1566989626284, + 'lastUpdatedTime': 1566989626284, + 'executionId': null, + 'value': '-root-/pathBasedOnStringvariablevalue', + 'markedAsDeleted': false, + 'processInstanceId': '1be4785f-c982-11e9-bdd8-96d6903e4e44', + 'taskId': '1beab9f6-c982-11e9-bdd8-96d6903e4e44', + 'taskVariable': true + }, + { + 'serviceName': 'mock-variable-mapping-rb', + 'serviceFullName': 'mock-variable-mapping-rb', + 'serviceVersion': '', + 'appName': 'mock-variable-mapping', + 'appVersion': '', + 'serviceType': null, + 'id': 1, + 'type': 'folder', + 'name': 'variables.name2', + 'createTime': 1566989626283, + 'lastUpdatedTime': 1566989626283, + 'executionId': null, + 'value': [{ id: 'mock-folder-id'}], + 'markedAsDeleted': false, + 'processInstanceId': '1be4785f-c982-11e9-bdd8-96d6903e4e44', + 'taskId': '1beab9f6-c982-11e9-bdd8-96d6903e4e44', + 'taskVariable': true + } +]; diff --git a/lib/process-services-cloud/src/lib/form/models/form-cloud-representation.model.ts b/lib/process-services-cloud/src/lib/form/models/form-cloud-representation.model.ts index 365050622e..e37d085d94 100644 --- a/lib/process-services-cloud/src/lib/form/models/form-cloud-representation.model.ts +++ b/lib/process-services-cloud/src/lib/form/models/form-cloud-representation.model.ts @@ -54,3 +54,14 @@ export interface DestinationFolderPathModel { alias: string; path: string; } + +export enum FileSourceTypes { + ALL_FILE_SOURCES_SERVICE_ID = 'all-file-sources', + ALFRESCO_CONTENT_SOURCES_SERVICE_ID = 'alfresco-content' +} + +export enum DestinationFolderPathType { + STATIC_TYPE = 'value', + STRING_TYPE = 'string', + FOLDER_TYPE = 'folder' +}