[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
This commit is contained in:
siva kumar 2021-02-18 16:23:13 +05:30 committed by GitHub
parent 8d37819bc3
commit c9a4ab4570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 655 additions and 408 deletions

View File

@ -32,12 +32,38 @@ import {
AlfrescoApiService, AlfrescoApiService,
UploadWidgetContentLinkModel UploadWidgetContentLinkModel
} from '@alfresco/adf-core'; } 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 { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ContentModule, ContentNodeSelectorPanelService } from '@alfresco/adf-content-services'; import { ContentModule, ContentNodeSelectorPanelService } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { Node } from '@alfresco/js-api';
import { FormCloudModule } from '../../../form-cloud.module'; import { FormCloudModule } from '../../../form-cloud.module';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
@ -56,165 +82,24 @@ describe('AttachFileCloudWidgetComponent', () => {
let contentModelFormFileHandlerSpy: jasmine.Spy; let contentModelFormFileHandlerSpy: jasmine.Spy;
let updateFormSpy: jasmine.Spy; let updateFormSpy: jasmine.Spy;
let contentClickedSpy: jasmine.Spy; let contentClickedSpy: jasmine.Spy;
let openUploadFileDialogSpy: jasmine.Spy;
const fakePngAnswer = { function createUploadWidgetField(form: FormModel, fieldId: string, value?: any, params?: any, multiple?: boolean, name?: string, readOnly?: boolean) {
id: 1155, widget.field = new FormFieldModel(form, {
nodeId: 1155, type: FormFieldTypes.UPLOAD,
name: 'a_png_file.png', value: value,
created: '2017-07-25T17:17:37.099Z', id: fieldId,
createdBy: { readOnly: readOnly,
id: 1001, name: name,
firstName: 'Admin', tooltip: 'attach file widget',
lastName: 'admin', params: <FormFieldMetadata> { ...params, multiple: multiple }
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
}
};
const onlyLocalParams = { function clickOnAttachFileWidget(id: string) {
fileSource: { const attachButton: HTMLButtonElement = element.querySelector(`#${id}`);
serviceId: 'local-file' attachButton.click();
} }
};
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 = <Node> {
id: 'fake',
name: 'fake-name',
content: {
mimeType: 'application/pdf'
}
};
const fakeNodeWithProperties: Node = <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'
};
setupTestBed({ setupTestBed({
imports: [ imports: [
@ -241,6 +126,7 @@ describe('AttachFileCloudWidgetComponent', () => {
formService = TestBed.inject(FormService); formService = TestBed.inject(FormService);
alfrescoApiService = TestBed.inject(AlfrescoApiService); alfrescoApiService = TestBed.inject(AlfrescoApiService);
contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService); contentNodeSelectorPanelService = TestBed.inject(ContentNodeSelectorPanelService);
openUploadFileDialogSpy = spyOn(contentCloudNodeSelectorService, 'openUploadFileDialog').and.returnValue(of([fakeMinimalNode]));
})); }));
afterEach(() => { afterEach(() => {
@ -248,53 +134,28 @@ describe('AttachFileCloudWidgetComponent', () => {
}); });
it('should show up as simple upload when is configured for only local files', async(() => { it('should show up as simple upload when is configured for only local files', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'simple-upload-button', [], allSourceParams);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'simple-upload-button';
widget.field.params = <FormFieldMetadata> allSourceParams;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect( expect(element.querySelector('#simple-upload-button')).not.toBeNull();
element.querySelector('#simple-upload-button')
).not.toBeNull();
}); });
})); }));
it('should show up as content upload when is configured with content', async(() => { it('should show up as content upload when is configured with content', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> contentSourceParam;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect( expect(element.querySelector('.adf-attach-widget__menu-upload')).not.toBeNull();
element.querySelector('.adf-attach-widget__menu-upload')
).not.toBeNull();
}); });
})); }));
it('should be able to attach files coming from content selector', async () => { it('should be able to attach files coming from content selector', async () => {
spyOn( createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam);
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 = <FormFieldMetadata> contentSourceParam;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
fixture.detectChanges();
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable(); await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); 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 () => { it('should be able to attach files coming from all files source', async () => {
spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
spyOn( createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParams);
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 = <FormFieldMetadata> allSourceParams;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable(); await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); 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(() => { it('should display file list when field has value', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [fakeLocalPngResponse], onlyLocalParams);
type: FormFieldTypes.UPLOAD,
value: [fakePngAnswer]
});
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(element.querySelector('#file-1155-icon')).not.toBeNull(); expect(element.querySelector('#file-1155-icon')).not.toBeNull();
}); });
})); }));
it('should be able to set label property for Attach File widget', () => { it('should be able to set label property for Attach File widget', () => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file', [], onlyLocalParams, false, 'Label', true);
type: FormFieldTypes.UPLOAD,
readOnly: true,
id: 'attach-file',
name: 'Label',
params: onlyLocalParams
});
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(element.querySelector('label').innerText).toEqual('Label'); expect(element.querySelector('label').innerText).toEqual('Label');
@ -367,119 +205,136 @@ describe('AttachFileCloudWidgetComponent', () => {
}); });
describe('destinationFolderPath', () => { 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 () => { it('should be able to fetch nodeId if destinationFolderPath is defined', async () => {
const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD, createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceParams);
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> allSourceParams;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco');
expect(attachButton).not.toBeNull(); clickOnAttachFileWidget('attach-file-alfresco');
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
const alias = '-root-'; const alias = '-root-';
const opt = { relativePath: '/myfiles' }; const opt = { relativePath: '/myfiles' };
expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt);
expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/myfiles'); expect(widget.field.params.fileSource.destinationFolderPath.value).toBe('-root-/myfiles');
expect(widget.rootNodeId).toEqual('mock-node-id'); 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 () => { 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(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithRootParams);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> allSourceWithRootParams;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(widget.rootNodeId).toEqual('-root-'); expect(widget.rootNodeId).toEqual('-root-');
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-root-', 'single', true, true); 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 () => { 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(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithWrongAliasParams, false);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> allSourceWithWrongAliasParams;
widget.field.params.multiple = false;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(widget.rootNodeId).toEqual('-my-'); expect(widget.rootNodeId).toEqual('-my-');
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', true, true); 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 () => { 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, createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithWrongAliasParams, true);
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> allSourceWithWrongAliasParams;
widget.field.params.multiple = true;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(widget.rootNodeId).toEqual('-my-'); expect(widget.rootNodeId).toEqual('-my-');
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'multiple', true, true); 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 () => { 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(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithNoAliasParams, true);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> allSourceWithNoAliasParams;
widget.field.params.multiple = true;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(widget.rootNodeId).toEqual('-my-'); expect(widget.rootNodeId).toEqual('-my-');
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'multiple', true, true); 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 () => { it('Should set default user alias (-my-) as rootNodeId if destinationFolderPath is not defined', async () => {
const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough(); const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough();
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithoutDestinationFolderPath);
type: FormFieldTypes.UPLOAD,
value: [],
id: 'attach-file-alfresco',
params: <any> allSourceWithoutDestinationFolderPath
});
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
attachButton.click();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); 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 () => { it('Should set default user alias (-my-) as rootNodeId if value property missing from destinationFolderPath', async () => {
const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough(); const getAliasAndPathSpy = spyOn(widget, 'getAliasAndRelativePathFromDestinationFolderPath').and.callThrough();
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], allSourceWithoutValueProperty);
type: FormFieldTypes.UPLOAD,
value: [],
id: 'attach-file-alfresco',
params: <any> allSourceWithoutValueProperty
});
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
attachButton.click();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
@ -533,6 +374,7 @@ describe('AttachFileCloudWidgetComponent', () => {
} }
] ]
}); });
expect(widget.replaceAppNameAliasWithValue('/myfiles/-appname-/folder')).toBe('/myfiles/fakeapp/folder'); expect(widget.replaceAppNameAliasWithValue('/myfiles/-appname-/folder')).toBe('/myfiles/fakeapp/folder');
}); });
@ -543,21 +385,12 @@ describe('AttachFileCloudWidgetComponent', () => {
describe('FilesSource', () => { describe('FilesSource', () => {
it('Should be able to fetch nodeId of default user alias (-my-) if fileSource set only to Alfresco Content', async () => { 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 fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, false);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> contentSourceParam;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
const alias = '-my-'; const alias = '-my-';
const opt = { relativePath: '' }; 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 () => { 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 fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId);
widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD, createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, true);
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> contentSourceParam;
widget.field.params.multiple = true;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
const alias = '-my-'; const alias = '-my-';
const opt = { relativePath: '' }; 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 () => { 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(), { createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam, false);
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-alfresco';
widget.field.params = <FormFieldMetadata> contentSourceParam;
widget.field.params.multiple = false;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(widget.rootNodeId).toEqual('-my-'); expect(widget.rootNodeId).toEqual('-my-');
expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', false, true); expect(openUploadFileDialogSpy).toHaveBeenCalledWith('-my-', 'single', false, true);
}); });
it('should display tooltip when tooltip is set', async(() => { it('should display tooltip when tooltip is set', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'attach-file-attach', [], onlyLocalParams);
id: 'attach-file-attach',
type: FormFieldTypes.UPLOAD,
value: [],
tooltip: 'attach file widget'
});
fixture.detectChanges(); fixture.detectChanges();
const attachElement: any = element.querySelector('#attach-file-attach'); const attachElement: any = element.querySelector('#attach-file-attach');
@ -636,13 +445,7 @@ describe('AttachFileCloudWidgetComponent', () => {
describe('when is readonly', () => { describe('when is readonly', () => {
it('should show empty list message when there are no file', async(() => { it('should show empty list message when there are no file', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'empty-test', [], onlyLocalParams, null, null, true);
type: FormFieldTypes.UPLOAD,
readOnly: true,
value: []
});
widget.field.id = 'empty-test';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(element.querySelector('#adf-attach-empty-list-empty-test')).not.toBeNull(); 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(() => { it('should not show empty list message when there are files', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true);
type: FormFieldTypes.UPLOAD,
readOnly: true,
value: [fakePngAnswer]
});
widget.field.id = 'fill-test';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges(); fixture.detectChanges();
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(element.querySelector('#adf-attach-empty-list-fill-test')).toBeNull(); 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(() => { it('should not show remove button when there are files attached', async(() => {
widget.field = new FormFieldModel(new FormModel(), { createUploadWidgetField(new FormModel(), 'fill-test', [fakeLocalPngResponse], onlyLocalParams, null, null, true);
type: FormFieldTypes.UPLOAD,
readOnly: true,
value: [fakePngAnswer]
});
widget.field.id = 'fill-test';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
fixture.detectChanges(); fixture.detectChanges();
const menuButton: HTMLButtonElement = <HTMLButtonElement> ( const menuButton: HTMLButtonElement = <HTMLButtonElement> (
fixture.debugElement.query(By.css('#file-1155-option-menu')) fixture.debugElement.query(By.css('#file-1155-option-menu'))
@ -679,6 +469,7 @@ describe('AttachFileCloudWidgetComponent', () => {
); );
menuButton.click(); menuButton.click();
fixture.detectChanges(); fixture.detectChanges();
expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull(); expect(fixture.debugElement.query(By.css('#file-1155-remove'))).toBeNull();
})); }));
}); });
@ -687,10 +478,7 @@ describe('AttachFileCloudWidgetComponent', () => {
beforeEach(async () => { beforeEach(async () => {
apiServiceSpy = spyOn(alfrescoApiService.getInstance().node, 'getNode').and.returnValue(new Promise(resolve => resolve({entry: fakeNodeWithProperties}))); 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, 'fetchNodeIdFromRelativePath').and.returnValue(new Promise(resolve => resolve('fake-properties')));
spyOn( openUploadFileDialogSpy.and.returnValue(of([fakeNodeWithProperties]));
contentCloudNodeSelectorService,
'openUploadFileDialog'
).and.returnValue(of([fakeNodeWithProperties]));
widget.field = new FormFieldModel(new FormModel(), { widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD, type: FormFieldTypes.UPLOAD,
value: [] value: []
@ -699,11 +487,7 @@ describe('AttachFileCloudWidgetComponent', () => {
widget.field.params = <FormFieldMetadata> menuTestSourceParam; widget.field.params = <FormFieldMetadata> menuTestSourceParam;
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
}); });
@ -860,11 +644,7 @@ describe('AttachFileCloudWidgetComponent', () => {
contentModelFormFileHandlerSpy = spyOn(widget, 'contentModelFormFileHandler').and.callThrough(); contentModelFormFileHandlerSpy = spyOn(widget, 'contentModelFormFileHandler').and.callThrough();
updateFormSpy = spyOn(formService.updateFormValuesRequested, 'next'); updateFormSpy = spyOn(formService.updateFormValuesRequested, 'next');
contentClickedSpy = spyOn(formService.formContentClicked, 'next'); contentClickedSpy = spyOn(formService.formContentClicked, 'next');
openUploadFileDialogSpy.and.returnValue(of([fakeNodeWithProperties]));
spyOn(
contentCloudNodeSelectorService,
'openUploadFileDialog'
).and.returnValue(of([fakeNodeWithProperties]));
widget.field = new FormFieldModel(new FormModel(), { widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD, type: FormFieldTypes.UPLOAD,
value: [] value: []
@ -941,11 +721,9 @@ describe('AttachFileCloudWidgetComponent', () => {
}); });
it('should have been called on attach file when value was empty', async () => { it('should have been called on attach file when value was empty', async () => {
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(contentModelFormFileHandlerSpy).toHaveBeenCalledWith(fakeNodeWithProperties); expect(contentModelFormFileHandlerSpy).toHaveBeenCalledWith(fakeNodeWithProperties);
expect(updateFormSpy).toHaveBeenCalledWith(expectedValues); expect(updateFormSpy).toHaveBeenCalledWith(expectedValues);
@ -959,11 +737,9 @@ describe('AttachFileCloudWidgetComponent', () => {
await fixture.whenStable(); await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); clickOnAttachFileWidget('attach-file-alfresco');
expect(attachButton).not.toBeNull();
attachButton.click();
await fixture.whenStable();
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable();
expect(contentModelFormFileHandlerSpy).not.toHaveBeenCalled(); expect(contentModelFormFileHandlerSpy).not.toHaveBeenCalled();
}); });
@ -1019,4 +795,70 @@ describe('AttachFileCloudWidgetComponent', () => {
expect(contentClickedSpy).toHaveBeenCalledWith(new UploadWidgetContentLinkModel(null, widget.field.id)); 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();
});
});
}); });

View File

@ -33,7 +33,7 @@ import { Node, RelatedContentRepresentation } from '@alfresco/js-api';
import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service'; import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service';
import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service';
import { UploadCloudWidgetComponent } from './upload-cloud.widget'; 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'; import { ContentNodeSelectorPanelService } from '@alfresco/adf-content-services';
@Component({ @Component({
@ -90,12 +90,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
} }
} }
isAlfrescoAndLocal(): boolean { isPathStaticType(): boolean {
return ( return this.field.params?.fileSource?.destinationFolderPath?.type === DestinationFolderPathType.STATIC_TYPE;
this.field.params &&
this.field.params.fileSource &&
this.field.params.fileSource.serviceId === 'all-file-sources'
);
} }
isUploadButtonVisible(): boolean { isUploadButtonVisible(): boolean {
@ -124,14 +120,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
async openSelectDialog() { async openSelectDialog() {
const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; const selectedMode = this.field.params.multiple ? 'multiple' : 'single';
let destinationFolderPath = <DestinationFolderPathModel> { alias: AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER, path: '' }; const nodeId = await this.getDestinationFolderNodeId();
if (this.isAlfrescoAndLocal() && this.hasDestinationFolder()) { this.rootNodeId = nodeId ? nodeId : AttachFileCloudWidgetComponent.ALIAS_USER_FOLDER;
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;
this.contentNodeSelectorPanelService.customModels = this.field.params.customModels; this.contentNodeSelectorPanelService.customModels = this.field.params.customModels;
this.contentNodeSelectorService this.contentNodeSelectorService
@ -146,6 +136,28 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
}); });
} }
private async getDestinationFolderNodeId(): Promise<string> {
let rootNodeId: string;
let destinationFolderPath = <DestinationFolderPathModel> { 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 { getAliasAndRelativePathFromDestinationFolderPath(destinationFolderPath: string): DestinationFolderPathModel {
let alias: string; let path: string; let alias: string; let path: string;
if (destinationFolderPath) { if (destinationFolderPath) {

View File

@ -23,6 +23,7 @@ import { Observable, from } from 'rxjs';
import { mergeMap } from 'rxjs/operators'; import { mergeMap } from 'rxjs/operators';
import { WidgetComponent, LogService, FormService, ThumbnailService, ContentLinkModel, NotificationService } from '@alfresco/adf-core'; import { WidgetComponent, LogService, FormService, ThumbnailService, ContentLinkModel, NotificationService } from '@alfresco/adf-core';
import { ProcessCloudContentService } from '../../../services/process-cloud-content.service'; import { ProcessCloudContentService } from '../../../services/process-cloud-content.service';
import { FileSourceTypes, DestinationFolderPathType } from '../../../models/form-cloud-representation.model';
@Component({ @Component({
selector: 'upload-cloud-widget', selector: 'upload-cloud-widget',
@ -68,6 +69,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
this.fixIncompatibilityFromPreviousAndNewForm([]); this.fixIncompatibilityFromPreviousAndNewForm([]);
} }
this.getMultipleFileParam(); this.getMultipleFileParam();
this.setDestinationFolderPathFromMappedVariable();
} }
removeFile(file: any) { removeFile(file: any) {
@ -160,4 +162,40 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
fileClicked(file: ContentLinkModel): void { fileClicked(file: ContentLinkModel): void {
this.formService.formContentClicked.next(file); 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);
}
} }

View File

@ -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 = <Node> {
id: 'fake',
name: 'fake-name',
content: {
mimeType: 'application/pdf'
}
};
export const fakeNodeWithProperties: Node = <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
}
];

View File

@ -54,3 +54,14 @@ export interface DestinationFolderPathModel {
alias: string; alias: string;
path: 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'
}