diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts index eca5c360b5..60b8a91726 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.spec.ts @@ -44,6 +44,7 @@ describe('StartFormComponent', () => { let getDefinitionsSpy: jasmine.Spy; let getStartFormDefinitionSpy: jasmine.Spy; let startProcessSpy: jasmine.Spy; + let applyAlfrescoNodeSpy: jasmine.Spy; setupTestBed({ imports: [ @@ -62,7 +63,7 @@ describe('StartFormComponent', () => { getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of(testMultipleProcessDefs)); startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(of(newProcess)); getStartFormDefinitionSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(of(taskFormMock)); - spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of({ id: 1234 })); + applyAlfrescoNodeSpy = spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of({ id: 1234 })); }); afterEach(() => { @@ -191,6 +192,35 @@ describe('StartFormComponent', () => { fixture.whenStable().then(() => { expect(component.values.file[0].id).toBe(1234); + expect(applyAlfrescoNodeSpy).toHaveBeenCalled(); + }); + })); + + it('if values in input is a collection of nodes should be linked in the process service', async(() => { + + component.values = {}; + component.values['file'] = [ + { + isFile: true, + name: 'example-file-1' + }, + { + isFile: true, + name: 'example-fil-2' + }, + { + isFile: true, + name: 'example-file-3' + } + ]; + + component.moveNodeFromCStoPS(); + + fixture.whenStable().then(() => { + expect(component.values.file.length).toBe(3); + expect(component.values.file[0].id).toBe(1234); + expect(component.values.file[1].id).toBe(1234); + expect(applyAlfrescoNodeSpy).toHaveBeenCalledTimes(3); }); })); }); diff --git a/lib/process-services/src/lib/process-list/components/start-process.component.ts b/lib/process-services/src/lib/process-list/components/start-process.component.ts index 60581f10d2..3c4e2868fc 100644 --- a/lib/process-services/src/lib/process-list/components/start-process.component.ts +++ b/lib/process-services/src/lib/process-list/components/start-process.component.ts @@ -28,10 +28,11 @@ import { ProcessDefinitionRepresentation } from './../models/process-definition. import { ProcessInstance } from './../models/process-instance.model'; import { ProcessService } from './../services/process.service'; import { FormControl, Validators, AbstractControl } from '@angular/forms'; -import { Observable, Subject } from 'rxjs'; +import { Observable, Subject, forkJoin } from 'rxjs'; import { map, takeUntil } from 'rxjs/operators'; import { MatAutocompleteTrigger } from '@angular/material'; import { StartFormComponent } from '../../form'; +import { MinimalNode, RelatedContentRepresentation } from '@alfresco/js-api'; @Component({ selector: 'adf-start-process', @@ -213,13 +214,10 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr for (const key in this.values) { if (this.values.hasOwnProperty(key)) { - const currentValue = this.values[key]; - - if (currentValue.isFile) { - this.activitiContentService.applyAlfrescoNode(currentValue, null, accountIdentifier).subscribe((res) => { - this.values[key] = [res]; - }); - } + const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]]; + const contents = currentValue.filter((value: any) => value && value.isFile) + .map((content: MinimalNode) => this.activitiContentService.applyAlfrescoNode(content, null, accountIdentifier)); + forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => this.values[key] = [...res] ); } } }