[ACA-4647] Fix for e2e (#8104)

* [ci:force] ACA-4647 Fix for e2e

* ACA-4647 added missing parameters to unit test

* ACA-4647 added unit test to cover changes in startProcess

* ACA-4647 changed property name to fix build error

* ACA-4647 changed json to object to avoid lint errors

* ACA-4647 added missing semicolon

Co-authored-by: tomek.hanaj <tomek.hanaj@hyland.com>
This commit is contained in:
AleksanderSklorz 2023-01-10 20:05:35 +01:00 committed by GitHub
parent fd6f881eab
commit 1791534ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 158 additions and 12 deletions

View File

@ -17,7 +17,7 @@
import { SimpleChange, DebugElement } from '@angular/core'; import { SimpleChange, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'; 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 { of, throwError } from 'rxjs';
import { StartProcessCloudService } from '../services/start-process-cloud.service'; import { StartProcessCloudService } from '../services/start-process-cloud.service';
import { FormCloudService } from '../../../form/services/form-cloud.service'; import { FormCloudService } from '../../../form/services/form-cloud.service';
@ -35,7 +35,8 @@ import {
fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid, fakeProcessDefinitions, fakeStartForm, fakeStartFormNotValid,
fakeProcessInstance, fakeNoNameProcessDefinitions, fakeProcessInstance, fakeNoNameProcessDefinitions,
fakeSingleProcessDefinition, fakeSingleProcessDefinition,
fakeSingleProcessDefinitionWithoutForm fakeSingleProcessDefinitionWithoutForm,
fakeFormModelJson
} from '../mock/start-process.component.mock'; } from '../mock/start-process.component.mock';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
@ -674,13 +675,16 @@ describe('StartProcessCloudComponent', () => {
expect(startButton).not.toBeNull(); 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.ngOnChanges({ appName: firstChange });
component.processForm.controls['processInstanceName'].setValue('My Process 1'); component.processForm.controls['processInstanceName'].setValue('My Process 1');
component.appName = 'test app name'; component.appName = 'test app name';
component.variables = { correlationKey: 'AIyRfpxbBX' };
component.formCloud = null;
const payload: ProcessPayloadCloud = new ProcessPayloadCloud({ const payload: ProcessPayloadCloud = new ProcessPayloadCloud({
name: component.processInstanceName.value, name: component.processInstanceName.value,
ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey ProcessDefinitionKey: component.processPayloadCloud.processDefinitionKey,
variables: Object.assign(component.variables, component.formCloud)
}); });
fixture.detectChanges(); 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', () => { it('should output start event when process started successfully', () => {
const emitSpy = spyOn(component.success, 'emit'); const emitSpy = spyOn(component.success, 'emit');

View File

@ -252,7 +252,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
isProcessFormValid(): boolean { isProcessFormValid(): boolean {
if (this.hasForm() && this.isFormCloudLoaded) { 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 { } else {
return this.processForm.valid || this.isLoading; return this.processForm.valid || this.isLoading;
} }
@ -280,9 +280,17 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
startProcess() { startProcess() {
this.isLoading = true; 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({ const createPayload: ProcessPayloadCloud = new ProcessPayloadCloud({
name: this.processInstanceName.value, name: this.processInstanceName.value,
processDefinitionKey: this.processPayloadCloud.processDefinitionKey processDefinitionKey: this.processPayloadCloud.processDefinitionKey,
variables: payloadVariables
}); });
this.startProcessCloudService.startProcess(this.appName, createPayload) this.startProcessCloudService.startProcess(this.appName, createPayload)
.subscribe( .subscribe(

View File

@ -15,12 +15,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model'; import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model'; import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
export const fakeProcessInstance: ProcessInstanceCloud = { export const fakeProcessInstance: ProcessInstanceCloud = {
appName: 'simple-app', appName: 'simple-app',
appVersion: '1',
id: 'd0b30377-dc5a-11e8-ae24-0a58646001fa', id: 'd0b30377-dc5a-11e8-ae24-0a58646001fa',
name: 'My Process Name', name: 'My Process Name',
startDate: new Date('2018-10-30T15:45:24.136+0000'), 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: []
};

View File

@ -18,16 +18,23 @@
import { ProcessInstanceVariable } from '../../../models/process-instance-variable.model'; import { ProcessInstanceVariable } from '../../../models/process-instance-variable.model';
export interface ProcessInstanceCloud { export interface ProcessInstanceCloud {
appName?: string; appName?: string;
id?: string; appVersion?: string;
name?: string;
startDate?: Date;
initiator?: string;
status?: string;
businessKey?: string; businessKey?: string;
completedDate?: string;
id?: string;
initiator?: string;
lastModified?: Date; lastModified?: Date;
name?: string;
parentId?: string; parentId?: string;
processDefinitionId?: string; processDefinitionId?: string;
processDefinitionKey?: string; processDefinitionKey?: string;
processDefinitionName?: string; processDefinitionName?: string;
processDefinitionVersion?: string;
serviceName?: string;
serviceFullName?: string;
serviceType?: string;
serviceVersion?: string;
startDate?: Date;
status?: string;
variables?: ProcessInstanceVariable[]; variables?: ProcessInstanceVariable[];
} }