From d5e7c0066b177fc6c4b469aa606b481f9ac493d5 Mon Sep 17 00:00:00 2001 From: dhrn <14145706+dhrn@users.noreply.github.com> Date: Thu, 5 Sep 2019 20:24:34 +0530 Subject: [PATCH] [ADF-4794] Not able to attach a second file to a form after one has already been attached (#5058) --- .../attach-file-widget.component.ts | 12 ++--- .../attach-file-widget.components.spec.ts | 46 +++++++++++++++++++ 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lib/process-services/content-widget/attach-file-widget.component.ts b/lib/process-services/content-widget/attach-file-widget.component.ts index da122fb2c4..2e9219ec6f 100644 --- a/lib/process-services/content-widget/attach-file-widget.component.ts +++ b/lib/process-services/content-widget/attach-file-widget.component.ts @@ -71,12 +71,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements } ngOnInit() { - if (this.field && - this.field.value && - this.field.value.length > 0) { - this.hasFile = true; - } - this.getMultipleFileParam(); + super.ngOnInit(); this.activitiContentService.getAlfrescoRepositories(null, true).subscribe((repoList) => { this.repositoryList = repoList; @@ -229,8 +224,9 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements this.logger.error(error); }, () => { - this.field.value = filesSaved; - this.field.json.value = filesSaved; + const previousFiles = this.field.value; + this.field.value = [ ...previousFiles, ...filesSaved ]; + this.field.json.value = [ ...previousFiles, ...filesSaved ]; this.hasFile = true; }); } diff --git a/lib/process-services/content-widget/attach-file-widget.components.spec.ts b/lib/process-services/content-widget/attach-file-widget.components.spec.ts index 9dafcf1a68..def0f79332 100644 --- a/lib/process-services/content-widget/attach-file-widget.components.spec.ts +++ b/lib/process-services/content-widget/attach-file-widget.components.spec.ts @@ -80,6 +80,20 @@ const fakeMinimalNode: Node = { } }; +const fakePngUpload = { + 'id': 1166, + 'name': 'fake-png.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' +}; + const fakePngAnswer = { 'id': 1155, 'name': 'a_png_file.png', @@ -194,6 +208,38 @@ describe('AttachFileWidgetComponent', () => { }); })); + it('should be able to upload more than one file from content node selector', async(() => { + const clickAttachFile = () => { + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-attach'); + expect(attachButton).not.toBeNull(); + attachButton.click(); + fixture.detectChanges(); + }; + spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); + spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValues(of(fakePngAnswer), of(fakePngUpload)); + spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(of([fakeMinimalNode])); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [] + }); + widget.field.id = 'attach-file-attach'; + widget.field.params = allSourceParams; + widget.field.params.multiple = true; + fixture.detectChanges(); + fixture.whenStable().then(() => { + clickAttachFile(); + fixture.debugElement.query(By.css('#attach-SHAREME')).nativeElement.click(); + fixture.detectChanges(); + clickAttachFile(); + fixture.debugElement.query(By.css('#attach-GOKUSHARE')).nativeElement.click(); + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(element.querySelector('#file-1155')).not.toBeNull(); + expect(element.querySelector('#file-1166')).not.toBeNull(); + }); + }); + })); + it('should be able to upload files when a defined folder is selected', async(() => { widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD,