mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-22051] - Fix form field mapping when value is zero (#6517)
* [MNT-22051] - Fix form field mapping when value is zero * PR changes * add validation for null
This commit is contained in:
@@ -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();
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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({
|
||||
|
@@ -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)));
|
||||
|
Reference in New Issue
Block a user