mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Added other tests
This commit is contained in:
parent
0fbaf7faf0
commit
57196ca50a
@ -571,12 +571,12 @@ describe('ActivitiForm', () => {
|
|||||||
expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form);
|
expect(formComponent.getFormDefinitionOutcomes).toHaveBeenCalledWith(form);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the visibility when the container raise the change event', (done) => {
|
it('should update the visibility when the container raise the change event', (valueChanged) => {
|
||||||
spyOn(formComponent, 'checkVisibility').and.callThrough();
|
spyOn(formComponent, 'checkVisibility').and.callThrough();
|
||||||
let widget = new ContainerWidget();
|
let widget = new ContainerWidget();
|
||||||
let fakeForm = new FormModel();
|
let fakeForm = new FormModel();
|
||||||
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
|
let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'});
|
||||||
widget.formValueChanged.subscribe(field => { console.log('called'); done(); });
|
widget.formValueChanged.subscribe(field => { valueChanged(); });
|
||||||
widget.fieldChanged(fakeField);
|
widget.fieldChanged(fakeField);
|
||||||
|
|
||||||
expect(formComponent.checkVisibility).toHaveBeenCalledWith(fakeField);
|
expect(formComponent.checkVisibility).toHaveBeenCalledWith(fakeField);
|
||||||
|
@ -21,14 +21,15 @@ import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfr
|
|||||||
import { HTTP_PROVIDERS } from '@angular/http';
|
import { HTTP_PROVIDERS } from '@angular/http';
|
||||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||||
import { FormModel, FormFieldModel, FormValues } from '../components/widgets/core/index';
|
import { FormModel, FormValues, FormFieldModel } from '../components/widgets/core/index';
|
||||||
|
|
||||||
declare let AlfrescoApi: any;
|
declare let AlfrescoApi: any;
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
describe('WidgetVisibilityService', () => {
|
describe('WidgetVisibilityService', () => {
|
||||||
let service;
|
let service;
|
||||||
|
let formTest = new FormModel({});
|
||||||
|
let formValues: FormValues = { 'test_1': 'value_1', 'test_2': 'value_2', 'test_3': 'value_1' };
|
||||||
let fakeTaskProcessVariableModels = [
|
let fakeTaskProcessVariableModels = [
|
||||||
{id: 'TEST_VAR_1', type: 'string', value: 'test_value_1'},
|
{id: 'TEST_VAR_1', type: 'string', value: 'test_value_1'},
|
||||||
{id: 'TEST_VAR_2', type: 'string', value: 'test_value_2'},
|
{id: 'TEST_VAR_2', type: 'string', value: 'test_value_2'},
|
||||||
@ -59,37 +60,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
name: 'FIELD_WITH_CONDITION',
|
name: 'FIELD_WITH_CONDITION',
|
||||||
type: 'text',
|
type: 'text',
|
||||||
value: 'field_with_condition_value',
|
value: 'field_with_condition_value',
|
||||||
visibilityCondition: {
|
visibilityCondition: null
|
||||||
leftFormFieldId: 'LEFT_FORM_FIELD',
|
|
||||||
leftRestResponseId: null,
|
|
||||||
'operator': '==',
|
|
||||||
rightValue: 'true',
|
|
||||||
rightType: null,
|
|
||||||
rightFormFieldId: '',
|
|
||||||
rightRestResponseId: '',
|
|
||||||
nextConditionOperator: 'and',
|
|
||||||
nextCondition: {
|
|
||||||
leftFormFieldId: 'numero_1',
|
|
||||||
leftRestResponseId: null,
|
|
||||||
operator: '!empty',
|
|
||||||
rightValue: null,
|
|
||||||
rightType: null,
|
|
||||||
rightFormFieldId: '',
|
|
||||||
rightRestResponseId: '',
|
|
||||||
nextConditionOperator: 'or',
|
|
||||||
nextCondition: {
|
|
||||||
leftFormFieldId: 'testo_1',
|
|
||||||
leftRestResponseId: null,
|
|
||||||
operator: '==',
|
|
||||||
rightValue: 'pippo',
|
|
||||||
rightType: null,
|
|
||||||
rightFormFieldId: '',
|
|
||||||
rightRestResponseId: '',
|
|
||||||
nextConditionOperator: '',
|
|
||||||
nextCondition: null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldType: 'FormFieldRepresentation',
|
fieldType: 'FormFieldRepresentation',
|
||||||
@ -112,41 +83,9 @@ describe('WidgetVisibilityService', () => {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
variables: [
|
|
||||||
{ name: 'FORM_VARIABLE_TEST',
|
|
||||||
type: 'string',
|
|
||||||
value: 'form_value_test' }
|
|
||||||
],
|
|
||||||
gridsterForm: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let formValues: FormValues = { 'test_1': 'value_1', 'test_2': 'value_2', 'test_3': 'value_1' };
|
|
||||||
|
|
||||||
let visibilityObjTest: WidgetVisibilityModel = {
|
|
||||||
leftFormFieldId : '',
|
|
||||||
leftRestResponseId : '',
|
|
||||||
nextCondition : null,
|
|
||||||
nextConditionOperator : '',
|
|
||||||
operator : '',
|
|
||||||
rightFormFieldId : '',
|
|
||||||
rightRestResponseId : '',
|
|
||||||
rightType : '',
|
|
||||||
rightValue : null
|
|
||||||
};
|
|
||||||
|
|
||||||
let chainedVisibilityObj: WidgetVisibilityModel = {
|
|
||||||
leftFormFieldId : '',
|
|
||||||
leftRestResponseId : '',
|
|
||||||
nextCondition : null,
|
|
||||||
nextConditionOperator : '',
|
|
||||||
operator : '',
|
|
||||||
rightFormFieldId : '',
|
|
||||||
rightRestResponseId : '',
|
|
||||||
rightType : '',
|
|
||||||
rightValue : null
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
return [
|
return [
|
||||||
HTTP_PROVIDERS,
|
HTTP_PROVIDERS,
|
||||||
@ -277,7 +216,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
|
|
||||||
let varValue = service.getValueFromVariable(formTest, 'TEST_VAR_1');
|
let varValue = service.getValueFromVariable(formTest, 'TEST_VAR_1');
|
||||||
|
|
||||||
@ -285,20 +224,13 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(varValue).toBe('test_value_1');
|
expect(varValue).toBe('test_value_1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve the value of a form variable', (done) => {
|
it('should be able to retrieve the value of a form variable', () => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
let fakeForm = new FormModel({variables: [
|
||||||
(res: TaskProcessVariableModel[]) => {
|
{ name: 'FORM_VARIABLE_TEST',
|
||||||
done();
|
type: 'string',
|
||||||
}
|
value: 'form_value_test' }
|
||||||
);
|
]});
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
let varValue = service.getValueFromVariable(fakeForm, 'FORM_VARIABLE_TEST');
|
||||||
'status': 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
|
||||||
});
|
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
|
|
||||||
let varValue = service.getValueFromVariable(formTest, 'FORM_VARIABLE_TEST');
|
|
||||||
|
|
||||||
expect(varValue).not.toBe(null);
|
expect(varValue).not.toBe(null);
|
||||||
expect(varValue).toBe('form_value_test');
|
expect(varValue).toBe('form_value_test');
|
||||||
@ -315,7 +247,6 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
|
|
||||||
let varValue = service.getValueFromVariable(formTest, 'TEST_MYSTERY_VAR');
|
let varValue = service.getValueFromVariable(formTest, 'TEST_MYSTERY_VAR');
|
||||||
|
|
||||||
@ -323,66 +254,56 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve a field value searching in the form', () => {
|
it('should be able to retrieve a field value searching in the form', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let stubFormWithFields = new FormModel(fakeFormJson);
|
||||||
|
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_WITH_CONDITION');
|
||||||
let formValue = service.getFormValueByName(formTest, 'FIELD_WITH_CONDITION');
|
|
||||||
|
|
||||||
expect(formValue).not.toBe(null);
|
expect(formValue).not.toBe(null);
|
||||||
expect(formValue).toBe('field_with_condition_value');
|
expect(formValue).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if the field value is not in the form', () => {
|
it('should return null if the field value is not in the form', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let stubFormWithFields = new FormModel(fakeFormJson);
|
||||||
|
|
||||||
let formValue = service.getFormValueByName(formTest, 'FIELD_MYSTERY');
|
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBe(null);
|
expect(formValue).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should take the value from form values if it is present', () => {
|
it('should take the value from form values if it is present', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
|
|
||||||
let formValue = service.getValueOField(formTest, 'test_1');
|
let formValue = service.getValueOField(formTest, 'test_1');
|
||||||
|
|
||||||
expect(formValue).not.toBe(null);
|
expect(formValue).not.toBe(null);
|
||||||
expect(formValue).toBe('value_1');
|
expect(formValue).toBe('value_1');
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = formValues;
|
fakeFormWithField.values = formValues;
|
||||||
|
|
||||||
let formValue = service.getValueOField(formTest, 'FIELD_WITH_CONDITION');
|
let value = service.getValueOField(fakeFormWithField, 'FIELD_WITH_CONDITION');
|
||||||
|
|
||||||
expect(formValue).not.toBe(null);
|
expect(value).not.toBe(null);
|
||||||
expect(formValue).toBe('field_with_condition_value');
|
expect(value).toBe('field_with_condition_value');
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if the element is not present anywhere', () => {
|
it('should return null if the element is not present anywhere', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = formValues;
|
fakeFormWithField.values = formValues;
|
||||||
|
|
||||||
let formValue = service.getValueOField(formTest, 'FIELD_MYSTERY');
|
let formValue = service.getValueOField(fakeFormWithField, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBe(null);
|
expect(formValue).toBe(null);
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.rightValue = '100';
|
visibilityObjTest.rightValue = '100';
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).toBe('100');
|
expect(rightValue).toBe('100');
|
||||||
|
|
||||||
visibilityObjTest.rightValue = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the right field when it is a process variable', (done) => {
|
it('should retrieve the value for the right field when it is a process variable', (done) => {
|
||||||
@ -396,48 +317,29 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
expect(rightValue).not.toBe(null);
|
||||||
expect(rightValue).toBe('test_value_2');
|
expect(rightValue).toBe('test_value_2');
|
||||||
|
|
||||||
visibilityObjTest.rightRestResponseId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the right field when it is a form variable', () => {
|
it('should retrieve the value for the right field when it is a form variable', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
visibilityObjTest.rightRestResponseId = 'FORM_VARIABLE_TEST';
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
expect(rightValue).not.toBe(null);
|
||||||
expect(rightValue).toBe('form_value_test');
|
expect(rightValue).toBe('RIGHT_FORM_FIELD_VALUE');
|
||||||
|
|
||||||
visibilityObjTest.rightRestResponseId = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should retrieve the value for the right field when it is a form value', () => {
|
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = {};
|
|
||||||
visibilityObjTest.rightRestResponseId = null;
|
|
||||||
visibilityObjTest.rightFormFieldId = 'FIELD_WITH_CONDITION';
|
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
|
||||||
expect({}).toEqual(formTest.values);
|
|
||||||
expect(rightValue).toBe('field_with_condition_value');
|
|
||||||
|
|
||||||
visibilityObjTest.rightFormFieldId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve right value from form values if it is present', () => {
|
it('should retrieve right value from form values if it is present', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
visibilityObjTest.rightRestResponseId = null;
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.rightFormFieldId = 'test_2';
|
visibilityObjTest.rightFormFieldId = 'test_2';
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
||||||
@ -445,28 +347,23 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(rightValue).not.toBe(null);
|
expect(rightValue).not.toBe(null);
|
||||||
expect(formTest.values).toEqual(formValues);
|
expect(formTest.values).toEqual(formValues);
|
||||||
expect(rightValue).toBe('value_2');
|
expect(rightValue).toBe('value_2');
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null for a value that is not on variable or form', () => {
|
it('should return null for a value that is not on variable or form', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = {};
|
fakeFormWithField.values = formValues;
|
||||||
visibilityObjTest.rightRestResponseId = null;
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.rightFormFieldId = null;
|
visibilityObjTest.rightFormFieldId = 'NO_FIELD_FORM';
|
||||||
visibilityObjTest.rightValue = null;
|
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).toBe(null);
|
expect(rightValue).toBe(null);
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the left field when it is a process variable', (done) => {
|
it('should retrieve the value for the left field when it is a process variable', (variableUpdated) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
done();
|
variableUpdated();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
@ -474,75 +371,64 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftRestResponseId = 'TEST_VAR_2';
|
visibilityObjTest.leftRestResponseId = 'TEST_VAR_2';
|
||||||
|
|
||||||
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
let rightValue = service.getLeftValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(rightValue).not.toBe(null);
|
||||||
expect(leftValue).toBe('test_value_2');
|
expect(rightValue).toBe('test_value_2');
|
||||||
|
|
||||||
visibilityObjTest.leftRestResponseId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the left field when it is a form variable', () => {
|
it('should retrieve the value for the left field when it is a form variable', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeForm = new FormModel({variables: [
|
||||||
|
{ name: 'FORM_VARIABLE_TEST',
|
||||||
|
type: 'string',
|
||||||
|
value: 'form_value_test' }
|
||||||
|
]});
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftRestResponseId = 'FORM_VARIABLE_TEST';
|
visibilityObjTest.leftRestResponseId = 'FORM_VARIABLE_TEST';
|
||||||
|
|
||||||
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeForm, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBe(null);
|
||||||
expect(leftValue).toBe('form_value_test');
|
expect(leftValue).toBe('form_value_test');
|
||||||
|
|
||||||
visibilityObjTest.leftRestResponseId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the value for the left field when it is a form value', () => {
|
it('should retrieve the value for the left field when it is a form value', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = {};
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftRestResponseId = null;
|
|
||||||
visibilityObjTest.leftFormFieldId = 'FIELD_WITH_CONDITION';
|
visibilityObjTest.leftFormFieldId = 'FIELD_WITH_CONDITION';
|
||||||
|
|
||||||
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBe(null);
|
||||||
expect({}).toEqual(formTest.values);
|
|
||||||
expect(leftValue).toBe('field_with_condition_value');
|
expect(leftValue).toBe('field_with_condition_value');
|
||||||
|
|
||||||
visibilityObjTest.leftFormFieldId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve left value from form values if it is present', () => {
|
it('should retrieve left value from form values if it is present', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
visibilityObjTest.leftRestResponseId = null;
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'test_2';
|
visibilityObjTest.leftFormFieldId = 'test_2';
|
||||||
|
|
||||||
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBe(null);
|
||||||
expect(formTest.values).toEqual(formValues);
|
|
||||||
expect(leftValue).toBe('value_2');
|
expect(leftValue).toBe('value_2');
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null for a value that is not on variable or form', () => {
|
it('should return null for a value that is not on variable or form', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = {};
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftRestResponseId = null;
|
|
||||||
visibilityObjTest.leftFormFieldId = null;
|
|
||||||
|
|
||||||
let rightValue = service.getLeftValue(formTest, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).toBe(null);
|
expect(leftValue).toBe(null);
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'test_1';
|
visibilityObjTest.leftFormFieldId = 'test_1';
|
||||||
visibilityObjTest.operator = '==';
|
visibilityObjTest.operator = '==';
|
||||||
visibilityObjTest.rightFormFieldId = 'test_3';
|
visibilityObjTest.rightFormFieldId = 'test_3';
|
||||||
@ -553,8 +439,8 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate true visibility for the field with single visibility condition between a field and a value', () => {
|
it('should evaluate true visibility for the field with single visibility condition between a field and a value', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'test_1';
|
visibilityObjTest.leftFormFieldId = 'test_1';
|
||||||
visibilityObjTest.operator = '==';
|
visibilityObjTest.operator = '==';
|
||||||
visibilityObjTest.rightValue = 'value_1';
|
visibilityObjTest.rightValue = 'value_1';
|
||||||
@ -564,35 +450,22 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate false visibility with single visibility condition between a field and a value', () => {
|
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
formTest.values = formValues;
|
|
||||||
visibilityObjTest.leftFormFieldId = 'test_1';
|
|
||||||
visibilityObjTest.operator = '!=';
|
|
||||||
visibilityObjTest.rightValue = 'value_1';
|
|
||||||
|
|
||||||
let isVisible = service.evaluateVisibilityForField(formTest, visibilityObjTest);
|
|
||||||
|
|
||||||
expect(isVisible).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
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', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '!=';
|
||||||
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
visibilityObjTest.rightFormFieldId = 'RIGHT_FORM_FIELD_ID';
|
||||||
|
|
||||||
let isVisible = service.evaluateVisibilityForField(formTest, visibilityObjTest);
|
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate the visibility for the field with single visibility condition between form value and process var', (done) => {
|
it('should evaluate the visibility for the field between form value and process var', (varReady) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
done();
|
varReady();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
@ -600,22 +473,21 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '!=';
|
||||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
||||||
|
|
||||||
let isVisible = service.evaluateVisibilityForField(formTest, visibilityObjTest);
|
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should evaluate visibility with multiple conditions', (done) => {
|
it('should evaluate visibility with multiple conditions', (ready) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
done();
|
ready();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
@ -623,7 +495,9 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
let chainedVisibilityObj = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '!=';
|
||||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
||||||
@ -632,40 +506,13 @@ describe('WidgetVisibilityService', () => {
|
|||||||
chainedVisibilityObj.operator = '!empty';
|
chainedVisibilityObj.operator = '!empty';
|
||||||
visibilityObjTest.nextCondition = chainedVisibilityObj;
|
visibilityObjTest.nextCondition = chainedVisibilityObj;
|
||||||
|
|
||||||
let isVisible = service.evaluateVisibilityForField(formTest, visibilityObjTest);
|
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
|
||||||
|
|
||||||
formTest.values = null;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true evaluating a proper condition for a field', (done) => {
|
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
|
||||||
(res: TaskProcessVariableModel[]) => {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
'status': 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
|
||||||
});
|
|
||||||
let formTest = new FormModel(fakeFormJson);
|
|
||||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
|
||||||
visibilityObjTest.operator = '!=';
|
|
||||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
|
||||||
visibilityObjTest.nextConditionOperator = 'and';
|
|
||||||
chainedVisibilityObj.leftRestResponseId = 'TEST_VAR_2';
|
|
||||||
chainedVisibilityObj.operator = '!empty';
|
|
||||||
visibilityObjTest.nextCondition = chainedVisibilityObj;
|
|
||||||
|
|
||||||
let isVisible = service.getVisiblityForField(formTest, visibilityObjTest);
|
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true when the visibility condition is not valid', () => {
|
it('should return true when the visibility condition is not valid', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = '';
|
visibilityObjTest.leftFormFieldId = '';
|
||||||
visibilityObjTest.leftRestResponseId = '';
|
visibilityObjTest.leftRestResponseId = '';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '!=';
|
||||||
@ -676,16 +523,29 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should refresh the visibility for a form field object', () => {
|
it('should refresh the visibility for a form field object', () => {
|
||||||
let formTest = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = formValues;
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
fakeFormWithField.values = formValues;
|
||||||
visibilityObjTest.leftFormFieldId = 'test_1';
|
visibilityObjTest.leftFormFieldId = 'test_1';
|
||||||
visibilityObjTest.operator = '!=';
|
visibilityObjTest.operator = '!=';
|
||||||
visibilityObjTest.rightFormFieldId = 'test_3';
|
visibilityObjTest.rightFormFieldId = 'test_3';
|
||||||
let jsonFieldFake = {id: 'FAKE_FORM_FIELD_ID', value: 'FAKE_FORM_FIELD_VALUE', visibilityCondition: visibilityObjTest};
|
let jsonFieldFake = {id: 'FAKE_FORM_FIELD_ID', value: 'FAKE_FORM_FIELD_VALUE', visibilityCondition: visibilityObjTest};
|
||||||
let fakeFormField: FormFieldModel = new FormFieldModel(formTest, jsonFieldFake);
|
let fakeFormField: FormFieldModel = new FormFieldModel(fakeFormWithField, jsonFieldFake);
|
||||||
|
|
||||||
service.refreshVisibilityForField(fakeFormField);
|
service.refreshVisibilityForField(fakeFormField);
|
||||||
|
|
||||||
expect(fakeFormField.isVisible).toBeFalsy();
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not change the isVisible if field does not have visibility condition', () => {
|
||||||
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
|
let jsonFieldFake = {id: 'FAKE_FORM_FIELD_ID',
|
||||||
|
value: 'FAKE_FORM_FIELD_VALUE',
|
||||||
|
visibilityCondition: null
|
||||||
|
};
|
||||||
|
let fakeFormField: FormFieldModel = new FormFieldModel(fakeFormWithField, jsonFieldFake);
|
||||||
|
fakeFormField.isVisible = false;
|
||||||
|
service.refreshVisibilityForField(fakeFormField);
|
||||||
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user