mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Improved form search for visibility service
This commit is contained in:
committed by
Mario Romano
parent
9d30db9017
commit
a915c0ad6a
@@ -363,10 +363,11 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(formValue).toBe('field_with_condition_value');
|
expect(formValue).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined if the field value is not in the form', () => {
|
it('should return empty string if the field value is not in the form', () => {
|
||||||
let formValue = service.searchForm(stubFormWithFields, 'FIELD_MYSTERY');
|
let formValue = service.searchForm(stubFormWithFields, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBeUndefined();
|
expect(formValue).not.toBeUndefined();
|
||||||
|
expect(formValue).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should search in the form if element value is not in form values', () => {
|
it('should search in the form if element value is not in form values', () => {
|
||||||
@@ -376,10 +377,11 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(value).toBe('field_with_condition_value');
|
expect(value).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined if the element is not present anywhere', () => {
|
it('should return empty string if the element is not present anywhere', () => {
|
||||||
let formValue = service.getFormValue(fakeFormWithField, 'FIELD_MYSTERY');
|
let formValue = service.getFormValue(fakeFormWithField, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBeUndefined();
|
expect(formValue).not.toBeUndefined();
|
||||||
|
expect(formValue).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the right field when it is a value', () => {
|
it('should retrieve the value for the right field when it is a value', () => {
|
||||||
@@ -443,10 +445,11 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(leftValue).toBe('value_2');
|
expect(leftValue).toBe('value_2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined for a value that is not on variable or form', () => {
|
it('should return empty string for a value that is not on variable or form', () => {
|
||||||
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).toBeUndefined();
|
expect(leftValue).not.toBeUndefined();
|
||||||
|
expect(leftValue).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate the visibility for the field with single visibility condition between two field values', () => {
|
it('should evaluate the visibility for the field with single visibility condition between two field values', () => {
|
||||||
@@ -467,11 +470,12 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined for a value that is not on variable or form', () => {
|
it('should return empty string for a value that is not on variable or form', () => {
|
||||||
visibilityObjTest.rightFormFieldId = 'NO_FIELD_FORM';
|
visibilityObjTest.rightFormFieldId = 'NO_FIELD_FORM';
|
||||||
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).toBeUndefined();
|
expect(rightValue).not.toBeUndefined();
|
||||||
|
expect(rightValue).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate the visibility for the field with single visibility condition between form values', () => {
|
it('should evaluate the visibility for the field with single visibility condition between form values', () => {
|
||||||
|
|||||||
@@ -119,18 +119,19 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
searchForm(form: FormModel, name: string) {
|
searchForm(form: FormModel, name: string) {
|
||||||
let res;
|
let fieldValue = '';
|
||||||
form.json.fields.forEach(columns => {
|
form.json.fields.forEach(columns => {
|
||||||
for (let i in columns.fields) {
|
for (let i in columns.fields) {
|
||||||
if (columns.fields.hasOwnProperty(i)) {
|
if (columns.fields.hasOwnProperty(i)) {
|
||||||
res = columns.fields[i].find(field => field.id === name);
|
let field = columns.fields[i].find(field => field.id === name);
|
||||||
if (res) {
|
if (field) {
|
||||||
return res.value;
|
fieldValue = field.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
return res ? res.value : res;
|
);
|
||||||
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user