diff --git a/lib/core/form/components/widgets/core/form.model.spec.ts b/lib/core/form/components/widgets/core/form.model.spec.ts index 6a736e7012..ebcf328040 100644 --- a/lib/core/form/components/widgets/core/form.model.spec.ts +++ b/lib/core/form/components/widgets/core/form.model.spec.ts @@ -77,6 +77,14 @@ describe('FormModel', () => { expect(form.readOnly).toBeTruthy(); }); + it('should set form values when variable value is 0', () => { + const variables = { + pfx_property_one: 0 + }; + const form = new FormModel(fakeMetadataForm, variables, true); + expect(form.getFormFields()[0].fields[1][0].value).toEqual(0); + }); + it('should check tabs', () => { const form = new FormModel(); diff --git a/lib/core/form/components/widgets/core/form.model.ts b/lib/core/form/components/widgets/core/form.model.ts index e3a78a30c4..e73cb7568e 100644 --- a/lib/core/form/components/widgets/core/form.model.ts +++ b/lib/core/form/components/widgets/core/form.model.ts @@ -234,13 +234,17 @@ export class FormModel { for (const field of this.getFormFields()) { const variableId = `variables.${field.name}`; - if (formValues[variableId] || formValues[field.id]) { + if (this.isDefined(formValues[variableId]) || this.isDefined(formValues[field.id])) { field.json.value = formValues[variableId] || formValues[field.id]; field.value = field.parseValue(field.json); } } } + private isDefined(value: string): boolean { + return value !== undefined && value !== null; + } + /** * Returns a form variable that matches the identifier. * @param identifier The `name` or `id` value. diff --git a/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts b/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts index 48716d1bfb..3cf5f7b007 100644 --- a/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts @@ -23,7 +23,11 @@ export class TaskVariableCloud { constructor(obj) { this.id = obj.name || null; this.name = obj.name || null; - this.value = obj.value || null; + this.value = this.hasValue(obj) ? obj.value : null; this.type = obj.type || null; } + + hasValue(obj: TaskVariableCloud): boolean { + return typeof obj.value !== undefined && obj.value !== null; + } } diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index cef3a5865b..5bb0e67cb8 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -140,6 +140,51 @@ describe('Form Cloud service', () => { }); }); + it('should fetch result if the variable value is 0', (done) => { + oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ + 'list': { + 'entries': [ + { + 'entry': { + 'serviceName': 'fake-rb', + 'serviceFullName': 'fake-rb', + 'serviceVersion': '', + 'appName': 'fake', + 'appVersion': '', + 'serviceType': null, + 'id': 25, + 'type': 'string', + 'name': 'fakeProperty', + 'createTime': 1556112661342, + 'lastUpdatedTime': 1556112661342, + 'executionId': null, + 'value': 0, + 'markedAsDeleted': false, + 'processInstanceId': '18e16bc7-6694-11e9-9c1b-0a586460028a', + 'taskId': '18e192da-6694-11e9-9c1b-0a586460028a', + 'taskVariable': true + } + } + ], + 'pagination': { + 'skipCount': 0, + 'maxItems': 100, + 'count': 1, + 'hasMoreItems': false, + 'totalItems': 1 + } + } + })); + + service.getTaskVariables(appName, taskId).subscribe((result) => { + expect(result).toBeDefined(); + expect(result.length).toBe(1); + expect(result[0].name).toBe('fakeProperty'); + expect(result[0].value).toBe(0); + done(); + }); + }); + it('should fetch task form flattened', (done) => { spyOn(service, 'getTask').and.returnValue(of(responseBody.entry)); spyOn(service, 'getForm').and.returnValue(of({ 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 4d6592c009..39e71a48db 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 @@ -205,6 +205,28 @@ describe('StartProcessCloudComponent', () => { beforeEach(() => { component.name = 'My new process with form'; + component.values = [{ + 'id': '1', + 'type': 'string', + 'name': 'firstName', + 'value': 'FakeName', + get 'hasValue'() { + return this['value']; + }, + set 'hasValue'(value) { + this['value'] = value; + } + }, { + 'id': '1', 'type': 'string', + 'name': 'lastName', + 'value': 'FakeLastName', + get 'hasValue'() { + return this['value']; + }, + set 'hasValue'(value) { + this['value'] = value; + } + }]; }); it('should be able to start a process with a valid form', fakeAsync(() => { @@ -264,11 +286,6 @@ describe('StartProcessCloudComponent', () => { it('should be able to start a process with a prefilled valid form', fakeAsync(() => { component.processDefinitionName = 'processwithform'; getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName))); - component.values = [{'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, { - 'id': '1', 'type': 'string', - 'name': 'lastName', - 'value': 'FakeLastName' - }]; fixture.detectChanges(); formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartForm)); @@ -299,11 +316,6 @@ describe('StartProcessCloudComponent', () => { it('should NOT be able to start a process with a prefilled NOT valid form', fakeAsync(() => { component.processDefinitionName = 'processwithform'; getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName))); - component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, { - 'id': '1', 'type': 'string', - 'name': 'lastName', - 'value': 'FakeLastName' - }]; fixture.detectChanges(); formDefinitionSpy = spyOn(formCloudService, 'getForm').and.returnValue(of(fakeStartFormNotValid)); @@ -333,11 +345,6 @@ describe('StartProcessCloudComponent', () => { })); it('should create a process instance if the selection is valid', fakeAsync(() => { - component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, { - 'id': '1', 'type': 'string', - 'name': 'lastName', - 'value': 'FakeLastName' - }]; component.name = 'testFormWithProcess'; component.processDefinitionName = 'processwithoutform2'; getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName))); @@ -365,11 +372,6 @@ describe('StartProcessCloudComponent', () => { })); it('should have start button enabled when default values are set', fakeAsync(() => { - component.values = [{ 'id': '1', 'type': 'string', 'name': 'firstName', 'value': 'FakeName' }, { - 'id': '1', 'type': 'string', - 'name': 'lastName', - 'value': 'FakeLastName' - }]; component.name = 'testFormWithProcess'; component.processDefinitionName = 'processwithoutform2'; getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinition(component.processDefinitionName)));