[AAE-2198] Error thrown on start process with pre-selected multiple files on start form. (#5567)

* [AAE-2198] Error thrown on start process with pre-selected multiple files on start form.

* * Removed unwanted method
This commit is contained in:
siva kumar
2020-03-27 15:29:43 +05:30
committed by GitHub
parent 6806504a65
commit 779ea83b8e
2 changed files with 37 additions and 9 deletions

View File

@@ -44,6 +44,7 @@ describe('StartFormComponent', () => {
let getDefinitionsSpy: jasmine.Spy; let getDefinitionsSpy: jasmine.Spy;
let getStartFormDefinitionSpy: jasmine.Spy; let getStartFormDefinitionSpy: jasmine.Spy;
let startProcessSpy: jasmine.Spy; let startProcessSpy: jasmine.Spy;
let applyAlfrescoNodeSpy: jasmine.Spy;
setupTestBed({ setupTestBed({
imports: [ imports: [
@@ -62,7 +63,7 @@ describe('StartFormComponent', () => {
getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of(testMultipleProcessDefs)); getDefinitionsSpy = spyOn(processService, 'getProcessDefinitions').and.returnValue(of(testMultipleProcessDefs));
startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(of(newProcess)); startProcessSpy = spyOn(processService, 'startProcess').and.returnValue(of(newProcess));
getStartFormDefinitionSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(of(taskFormMock)); 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(() => { afterEach(() => {
@@ -191,6 +192,35 @@ describe('StartFormComponent', () => {
fixture.whenStable().then(() => { fixture.whenStable().then(() => {
expect(component.values.file[0].id).toBe(1234); 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);
}); });
})); }));
}); });

View File

@@ -28,10 +28,11 @@ import { ProcessDefinitionRepresentation } from './../models/process-definition.
import { ProcessInstance } from './../models/process-instance.model'; import { ProcessInstance } from './../models/process-instance.model';
import { ProcessService } from './../services/process.service'; import { ProcessService } from './../services/process.service';
import { FormControl, Validators, AbstractControl } from '@angular/forms'; 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 { map, takeUntil } from 'rxjs/operators';
import { MatAutocompleteTrigger } from '@angular/material'; import { MatAutocompleteTrigger } from '@angular/material';
import { StartFormComponent } from '../../form'; import { StartFormComponent } from '../../form';
import { MinimalNode, RelatedContentRepresentation } from '@alfresco/js-api';
@Component({ @Component({
selector: 'adf-start-process', selector: 'adf-start-process',
@@ -213,13 +214,10 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
for (const key in this.values) { for (const key in this.values) {
if (this.values.hasOwnProperty(key)) { if (this.values.hasOwnProperty(key)) {
const currentValue = this.values[key]; const currentValue = Array.isArray(this.values[key]) ? this.values[key] : [this.values[key]];
const contents = currentValue.filter((value: any) => value && value.isFile)
if (currentValue.isFile) { .map((content: MinimalNode) => this.activitiContentService.applyAlfrescoNode(content, null, accountIdentifier));
this.activitiContentService.applyAlfrescoNode(currentValue, null, accountIdentifier).subscribe((res) => { forkJoin(contents).subscribe((res: RelatedContentRepresentation[]) => this.values[key] = [...res] );
this.values[key] = [res];
});
}
} }
} }
} }