diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts index 244b05121e..ca145df371 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.spec.ts @@ -17,7 +17,7 @@ import { SimpleChange, DebugElement } from '@angular/core'; import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; -import { setupTestBed } from '@alfresco/adf-core'; +import { FormModel, setupTestBed } from '@alfresco/adf-core'; import { of, throwError } from 'rxjs'; import { StartProcessCloudService } from '../services/start-process-cloud.service'; import { FormCloudService } from '../../../form/services/form-cloud.service'; @@ -35,7 +35,8 @@ import { fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid, fakeProcessInstance, fakeNoNameProcessDefinitions, fakeSingleProcessDefinition, - fakeSingleProcessDefinitionWithoutForm + fakeSingleProcessDefinitionWithoutForm, + fakeFormModelJson } from '../mock/start-process.component.mock'; import { By } from '@angular/platform-browser'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; @@ -674,13 +675,16 @@ describe('StartProcessCloudComponent', () => { expect(startButton).not.toBeNull(); }); - it('should call service with the correct parameters when button is clicked', async () => { + it('should call service with the correct parameters when button is clicked and variables are defined and formCloud is undefined', async () => { component.ngOnChanges({ appName: firstChange }); component.processForm.controls['processInstanceName'].setValue('My Process 1'); component.appName = 'test app name'; + component.variables = { correlationKey: 'AIyRfpxbBX' }; + component.formCloud = null; const payload: ProcessPayloadCloud = new ProcessPayloadCloud({ name: component.processInstanceName.value, - ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey + ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey, + variables: Object.assign(component.variables, component.formCloud) }); fixture.detectChanges(); @@ -698,6 +702,79 @@ describe('StartProcessCloudComponent', () => { }); + it('should call service with the correct parameters when variables and formCloud are both undefined', async () => { + component.ngOnChanges({ appName: firstChange }); + component.processForm.controls['processInstanceName'].setValue('My Process 1'); + component.appName = 'test app name'; + component.variables = undefined; + component.formCloud = undefined; + const payload: ProcessPayloadCloud = new ProcessPayloadCloud({ + name: component.processInstanceName.value, + ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey, + variables: {} + }); + + fixture.detectChanges(); + await fixture.whenStable(); + const startButton = fixture.debugElement.query(By.css('#button-start')); + expect(startButton).not.toBeNull(); + + startButton.triggerEventHandler('click', null); + expect(startProcessSpy).toHaveBeenCalledWith(component.appName, payload); + }); + + it('should call service with the correct parameters when variables and formCloud are both defined', async () => { + component.ngOnChanges({ appName: firstChange }); + component.processForm.controls['processInstanceName'].setValue('My Process 1'); + component.appName = 'test app name'; + component.variables = { correlationKey: 'AIyRfpxbBX' }; + component.formCloud = new FormModel(JSON.stringify(fakeFormModelJson)); + component.formCloud.values = { dropdown: { id: '1', name: 'label 2' } }; + + const payload: ProcessPayloadCloud = new ProcessPayloadCloud({ + name: component.processInstanceName.value, + ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey, + variables: Object.assign(component.variables, component.formCloud.values) + }); + + fixture.detectChanges(); + await fixture.whenStable(); + const startButton = fixture.debugElement.query(By.css('#button-start')); + expect(startButton).not.toBeNull(); + + startButton.triggerEventHandler('click', null); + expect(startProcessSpy).toHaveBeenCalledWith(component.appName, payload); + }); + + it('should call service with the correct parameters when variables are undefined and formCloud is defined', fakeAsync(() => { + getDefinitionsSpy = getDefinitionsSpy.and.returnValue(of([fakeProcessDefinitions[0]])); + formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm)); + const change = new SimpleChange('myApp', 'myApp1', true); + component.ngOnInit(); + component.ngOnChanges({ appName: change }); + component.processForm.controls['processDefinition'].setValue('process'); + fixture.detectChanges(); + tick(3000); + component.processDefinitionName = fakeProcessDefinitions[0].name; + component.setProcessDefinitionOnForm(fakeProcessDefinitions[0].name); + fixture.detectChanges(); + tick(3000); + + const processForm = fixture.nativeElement.querySelector('adf-cloud-form'); + expect(component.hasForm()).toBeTruthy(); + expect(processForm).not.toBeNull(); + + const payload: ProcessPayloadCloud = new ProcessPayloadCloud({ + name: component.processInstanceName.value, + processDefinitionKey: fakeProcessDefinitions[0].key, + variables: Object.assign({}, component.formCloud.values) + }); + const startButton = fixture.debugElement.query(By.css('#button-start')); + expect(startButton).not.toBeNull(); + + startButton.triggerEventHandler('click', null); + expect(startProcessSpy).toHaveBeenCalledWith(component.appName, payload); + })); it('should output start event when process started successfully', () => { const emitSpy = spyOn(component.success, 'emit'); diff --git a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts index f29e7f3ec6..b21e88aa2f 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/components/start-process-cloud.component.ts @@ -252,7 +252,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy isProcessFormValid(): boolean { if (this.hasForm() && this.isFormCloudLoaded) { - return this.formCloud.isValid || this.isLoading; + return (this.formCloud ? !Object.keys(this.formCloud.values).length : false) || this.formCloud?.isValid || this.isLoading; } else { return this.processForm.valid || this.isLoading; } @@ -280,9 +280,17 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy startProcess() { this.isLoading = true; + let payloadVariables = {}; + if (this.variables) { + payloadVariables = this.variables; + } + if (this.hasForm()) { + payloadVariables = Object.assign(payloadVariables, this.formCloud.values); + } const createPayload: ProcessPayloadCloud = new ProcessPayloadCloud({ name: this.processInstanceName.value, - processDefinitionKey: this.processPayloadCloud.processDefinitionKey + processDefinitionKey: this.processPayloadCloud.processDefinitionKey, + variables: payloadVariables }); this.startProcessCloudService.startProcess(this.appName, createPayload) .subscribe( diff --git a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts index 4e2a0f84dd..65dae4bc23 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/mock/start-process.component.mock.ts @@ -15,12 +15,13 @@ * limitations under the License. */ +import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; import { ProcessInstanceCloud } from '../models/process-instance-cloud.model'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; -import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model'; export const fakeProcessInstance: ProcessInstanceCloud = { appName: 'simple-app', + appVersion: '1', id: 'd0b30377-dc5a-11e8-ae24-0a58646001fa', name: 'My Process Name', startDate: new Date('2018-10-30T15:45:24.136+0000'), @@ -244,3 +245,56 @@ export const fakeStartFormNotValid = { } } }; + +export const fakeFormModelJson = { + id: 'form-0d52227f-dfb8-4ed3-a492-cd26fd6062dd', + name: 'f', + description: '', + version: 0, + standAlone: true, + tabs: [], + fields: [{ + id: '60b007f6-f838-458c-b4d4-43c69f355ef9', + name: 'Label', + type: 'container', + ab: null, + numberOfColumns: 1, + fields: { + 1: [{ + id: 'dropdown', + name: 'Dropdown', + type: 'dropdown', + readOnly: false, + required: false, + colspan: 1, + rowspan: 1, + optionType: 'manual', + options: [ + { + id: '1', + name: 'Label 1' + }, + { + id: '2', + name: 'Label 2' + } + ], + authName: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + selectionType: 'single', + visibilityCondition: null, + params: { + existingColspan: 1, + maxColspan: 2 + }, + rule: null + }] + } + }], + outcomes: [], + metadata: {}, + variables: [] +}; diff --git a/lib/process-services-cloud/src/lib/process/start-process/models/process-instance-cloud.model.ts b/lib/process-services-cloud/src/lib/process/start-process/models/process-instance-cloud.model.ts index 4e451cf0a1..7f007b6b0e 100755 --- a/lib/process-services-cloud/src/lib/process/start-process/models/process-instance-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/process/start-process/models/process-instance-cloud.model.ts @@ -18,16 +18,23 @@ import { ProcessInstanceVariable } from '../../../models/process-instance-variable.model'; export interface ProcessInstanceCloud { appName?: string; - id?: string; - name?: string; - startDate?: Date; - initiator?: string; - status?: string; + appVersion?: string; businessKey?: string; + completedDate?: string; + id?: string; + initiator?: string; lastModified?: Date; + name?: string; parentId?: string; processDefinitionId?: string; processDefinitionKey?: string; processDefinitionName?: string; + processDefinitionVersion?: string; + serviceName?: string; + serviceFullName?: string; + serviceType?: string; + serviceVersion?: string; + startDate?: Date; + status?: string; variables?: ProcessInstanceVariable[]; }