mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Merged latest change from develop
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||||
import { WidgetVisibilityService } from './widget-visibility.service';
|
import { WidgetVisibilityService } from './widget-visibility.service';
|
||||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
@@ -206,9 +205,14 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(res).toBeFalsy();
|
expect(res).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should be able to retrieve the value of a process variable', (done) => {
|
|
||||||
|
it('should be able to retrieve the value of a process variable', (done) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
let varValue = service.getValueFromVariable(formTest, 'TEST_VAR_1', res);
|
||||||
|
expect(varValue).not.toBeUndefined();
|
||||||
|
expect(varValue).toBe('test_value_1');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -217,12 +221,6 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
let varValue = service.getValueFromVariable(formTest, 'TEST_VAR_1');
|
|
||||||
|
|
||||||
expect(varValue).not.toBe(null);
|
|
||||||
expect(varValue).toBe('test_value_1');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve the value of a form variable', () => {
|
it('should be able to retrieve the value of a form variable', () => {
|
||||||
@@ -231,15 +229,18 @@ describe('WidgetVisibilityService', () => {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
value: 'form_value_test' }
|
value: 'form_value_test' }
|
||||||
]});
|
]});
|
||||||
let varValue = service.getValueFromVariable(fakeForm, 'FORM_VARIABLE_TEST');
|
let varValue = service.getValueFromVariable(fakeForm, 'FORM_VARIABLE_TEST', null);
|
||||||
|
|
||||||
expect(varValue).not.toBe(null);
|
expect(varValue).not.toBeUndefined();
|
||||||
expect(varValue).toBe('form_value_test');
|
expect(varValue).toBe('form_value_test');
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should return null if the variable does not exist', (done) => {
|
|
||||||
|
it('should return undefined if the variable does not exist', (done) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
|
let varValue = service.getValueFromVariable(formTest, 'TEST_MYSTERY_VAR', res);
|
||||||
|
expect(varValue).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -249,25 +250,24 @@ describe('WidgetVisibilityService', () => {
|
|||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
|
|
||||||
let varValue = service.getValueFromVariable(formTest, 'TEST_MYSTERY_VAR');
|
|
||||||
|
|
||||||
expect(varValue).toBe(null);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
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 stubFormWithFields = new FormModel(fakeFormJson);
|
let stubFormWithFields = new FormModel(fakeFormJson);
|
||||||
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_WITH_CONDITION');
|
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_WITH_CONDITION');
|
||||||
|
|
||||||
expect(formValue).not.toBe(null);
|
expect(formValue).not.toBeNull();
|
||||||
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 undefined if the field value is not in the form', () => {
|
||||||
let stubFormWithFields = new FormModel(fakeFormJson);
|
let stubFormWithFields = new FormModel(fakeFormJson);
|
||||||
|
|
||||||
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_MYSTERY');
|
let formValue = service.getFormValueByName(stubFormWithFields, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBe(null);
|
expect(formValue).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should take the value from form values if it is present', () => {
|
it('should take the value from form values if it is present', () => {
|
||||||
@@ -275,7 +275,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let formValue = service.getValueOField(formTest, 'test_1');
|
let formValue = service.getValueOField(formTest, 'test_1');
|
||||||
|
|
||||||
expect(formValue).not.toBe(null);
|
expect(formValue).not.toBeNull();
|
||||||
expect(formValue).toBe('value_1');
|
expect(formValue).toBe('value_1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -285,17 +285,17 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let value = service.getValueOField(fakeFormWithField, 'FIELD_WITH_CONDITION');
|
let value = service.getValueOField(fakeFormWithField, 'FIELD_WITH_CONDITION');
|
||||||
|
|
||||||
expect(value).not.toBe(null);
|
expect(value).not.toBeNull();
|
||||||
expect(value).toBe('field_with_condition_value');
|
expect(value).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if the element is not present anywhere', () => {
|
it('should return undefined if the element is not present anywhere', () => {
|
||||||
let fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
fakeFormWithField.values = formValues;
|
fakeFormWithField.values = formValues;
|
||||||
|
|
||||||
let formValue = service.getValueOField(fakeFormWithField, 'FIELD_MYSTERY');
|
let formValue = service.getValueOField(fakeFormWithField, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).toBe(null);
|
expect(formValue).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
@@ -307,9 +307,16 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(rightValue).toBe('100');
|
expect(rightValue).toBe('100');
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('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) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
||||||
|
|
||||||
|
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(rightValue).not.toBeNull();
|
||||||
|
expect(rightValue).toBe('test_value_2');
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -318,13 +325,6 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
|
||||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
|
||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
|
||||||
expect(rightValue).toBe('test_value_2');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
@@ -334,7 +334,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
expect(rightValue).not.toBeNull();
|
||||||
expect(rightValue).toBe('RIGHT_FORM_FIELD_VALUE');
|
expect(rightValue).toBe('RIGHT_FORM_FIELD_VALUE');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -345,12 +345,12 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
let rightValue = service.getRightValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
expect(rightValue).not.toBeNull();
|
||||||
expect(formTest.values).toEqual(formValues);
|
expect(formTest.values).toEqual(formValues);
|
||||||
expect(rightValue).toBe('value_2');
|
expect(rightValue).toBe('value_2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null for a value that is not on variable or form', () => {
|
it('should return undefined for a value that is not on variable or form', () => {
|
||||||
let fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
fakeFormWithField.values = formValues;
|
fakeFormWithField.values = formValues;
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
@@ -358,13 +358,20 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
let rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(rightValue).toBe(null);
|
expect(rightValue).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should retrieve the value for the left field when it is a process variable', (variableUpdated) => {
|
it('should retrieve the value for the left field when it is a process variable', (done) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
variableUpdated();
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
visibilityObjTest.leftRestResponseId = 'TEST_VAR_2';
|
||||||
|
|
||||||
|
let rightValue = service.getLeftValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
|
expect(rightValue).not.toBeNull();
|
||||||
|
expect(rightValue).toBe('test_value_2');
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
@@ -372,13 +379,6 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
|
||||||
visibilityObjTest.leftRestResponseId = 'TEST_VAR_2';
|
|
||||||
|
|
||||||
let rightValue = service.getLeftValue(formTest, visibilityObjTest);
|
|
||||||
|
|
||||||
expect(rightValue).not.toBe(null);
|
|
||||||
expect(rightValue).toBe('test_value_2');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
@@ -392,7 +392,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let leftValue = service.getLeftValue(fakeForm, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeForm, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBeNull();
|
||||||
expect(leftValue).toBe('form_value_test');
|
expect(leftValue).toBe('form_value_test');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBeNull();
|
||||||
expect(leftValue).toBe('field_with_condition_value');
|
expect(leftValue).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -414,17 +414,17 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
let leftValue = service.getLeftValue(formTest, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).not.toBe(null);
|
expect(leftValue).not.toBeNull();
|
||||||
expect(leftValue).toBe('value_2');
|
expect(leftValue).toBe('value_2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null for a value that is not on variable or form', () => {
|
it('should return undefined for a value that is not on variable or form', () => {
|
||||||
let fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
|
||||||
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
let leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(leftValue).toBe(null);
|
expect(leftValue).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
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', () => {
|
||||||
@@ -463,17 +463,9 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should evaluate the visibility for the field between form value and process var', (varReady) => {
|
it('should evaluate the visibility for the field between form value and process var', (done) => {
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
(res: TaskProcessVariableModel[]) => {
|
(res: TaskProcessVariableModel[]) => {
|
||||||
varReady();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
'status': 200,
|
|
||||||
contentType: 'application/json',
|
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
|
||||||
});
|
|
||||||
let fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||||
@@ -483,12 +475,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
done();
|
||||||
|
|
||||||
xit('should evaluate visibility with multiple conditions', (ready) => {
|
|
||||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
|
||||||
(res: TaskProcessVariableModel[]) => {
|
|
||||||
ready();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
@@ -496,6 +483,12 @@ describe('WidgetVisibilityService', () => {
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should evaluate visibility with multiple conditions', (done) => {
|
||||||
|
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||||
|
(res: TaskProcessVariableModel[]) => {
|
||||||
let fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
let visibilityObjTest = new WidgetVisibilityModel();
|
let visibilityObjTest = new WidgetVisibilityModel();
|
||||||
let chainedVisibilityObj = new WidgetVisibilityModel();
|
let chainedVisibilityObj = new WidgetVisibilityModel();
|
||||||
@@ -510,6 +503,14 @@ describe('WidgetVisibilityService', () => {
|
|||||||
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
let isVisible = service.evaluateVisibilityForField(fakeFormWithField, visibilityObjTest);
|
||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
'status': 200,
|
||||||
|
contentType: 'application/json',
|
||||||
|
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return true when the visibility condition is not valid', () => {
|
it('should return true when the visibility condition is not valid', () => {
|
||||||
@@ -550,4 +551,3 @@ describe('WidgetVisibilityService', () => {
|
|||||||
expect(fakeFormField.isVisible).toBeFalsy();
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
|
|||||||
Reference in New Issue
Block a user