mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4758] - reset form value when field is not visible (#4958)
* [ADF-4758] - reset form value when field is not visible * [ADF-4758] - fix unit test * [ADF-4758] - fix unit tests
This commit is contained in:
committed by
Eugenio Romano
parent
6ca04ee929
commit
5772c1482e
@@ -344,7 +344,7 @@ describe('WidgetVisibilityCloudService', () => {
|
|||||||
|
|
||||||
describe('should return the value of the field', () => {
|
describe('should return the value of the field', () => {
|
||||||
let visibilityObjTest: WidgetVisibilityModel;
|
let visibilityObjTest: WidgetVisibilityModel;
|
||||||
const fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
const jsonFieldFake = {
|
const jsonFieldFake = {
|
||||||
id: 'FAKE_FORM_FIELD_ID',
|
id: 'FAKE_FORM_FIELD_ID',
|
||||||
value: 'FAKE_FORM_FIELD_VALUE',
|
value: 'FAKE_FORM_FIELD_VALUE',
|
||||||
@@ -362,6 +362,7 @@ describe('WidgetVisibilityCloudService', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
visibilityObjTest = new WidgetVisibilityModel({});
|
visibilityObjTest = new WidgetVisibilityModel({});
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
|
fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
jsonFieldFake.visibilityCondition = visibilityObjTest;
|
jsonFieldFake.visibilityCondition = visibilityObjTest;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -509,6 +510,18 @@ describe('WidgetVisibilityCloudService', () => {
|
|||||||
expect(fakeFormField.isVisible).toBeFalsy();
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should reset value when the field is not visibile', () => {
|
||||||
|
visibilityObjTest.leftValue = 'test_1';
|
||||||
|
visibilityObjTest.operator = '==';
|
||||||
|
visibilityObjTest.rightType = WidgetTypeEnum.field;
|
||||||
|
visibilityObjTest.rightValue = 'test_3';
|
||||||
|
const fakeFormField: FormFieldModel = new FormFieldModel(formTest, jsonFieldFake);
|
||||||
|
|
||||||
|
service.refreshEntityVisibility(fakeFormField);
|
||||||
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
|
expect(fakeFormField.value).toEqual(null);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return true when the visibility condition is not valid', () => {
|
it('should return true when the visibility condition is not valid', () => {
|
||||||
visibilityObjTest = new WidgetVisibilityModel();
|
visibilityObjTest = new WidgetVisibilityModel();
|
||||||
visibilityObjTest.leftType = '';
|
visibilityObjTest.leftType = '';
|
||||||
@@ -979,6 +992,5 @@ describe('WidgetVisibilityCloudService', () => {
|
|||||||
|
|
||||||
expect(isVisible).toBeTruthy();
|
expect(isVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -190,12 +190,13 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('should retrieve the process variables', () => {
|
describe('should retrieve the process variables', () => {
|
||||||
const fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
let visibilityObjTest: WidgetVisibilityModel;
|
let visibilityObjTest: WidgetVisibilityModel;
|
||||||
const chainedVisibilityObj = new WidgetVisibilityModel({});
|
const chainedVisibilityObj = new WidgetVisibilityModel({});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
visibilityObjTest = new WidgetVisibilityModel({});
|
visibilityObjTest = new WidgetVisibilityModel({});
|
||||||
|
fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the process variables for task', (done) => {
|
it('should return the process variables for task', (done) => {
|
||||||
@@ -341,7 +342,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
describe('should return the value of the field', () => {
|
describe('should return the value of the field', () => {
|
||||||
let visibilityObjTest: WidgetVisibilityModel;
|
let visibilityObjTest: WidgetVisibilityModel;
|
||||||
const fakeFormWithField = new FormModel(fakeFormJson);
|
let fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
const jsonFieldFake = {
|
const jsonFieldFake = {
|
||||||
id: 'FAKE_FORM_FIELD_ID',
|
id: 'FAKE_FORM_FIELD_ID',
|
||||||
value: 'FAKE_FORM_FIELD_VALUE',
|
value: 'FAKE_FORM_FIELD_VALUE',
|
||||||
@@ -358,6 +359,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
visibilityObjTest = new WidgetVisibilityModel();
|
visibilityObjTest = new WidgetVisibilityModel();
|
||||||
|
fakeFormWithField = new FormModel(fakeFormJson);
|
||||||
formTest.values = formValues;
|
formTest.values = formValues;
|
||||||
jsonFieldFake.visibilityCondition = visibilityObjTest;
|
jsonFieldFake.visibilityCondition = visibilityObjTest;
|
||||||
});
|
});
|
||||||
@@ -659,7 +661,6 @@ describe('WidgetVisibilityService', () => {
|
|||||||
tab.visibilityCondition = visibilityObjTest;
|
tab.visibilityCondition = visibilityObjTest;
|
||||||
fakeFormWithField.tabs.push(tab);
|
fakeFormWithField.tabs.push(tab);
|
||||||
service.refreshVisibility(fakeFormWithField);
|
service.refreshVisibility(fakeFormWithField);
|
||||||
|
|
||||||
expect(fakeFormWithField.tabs[0].isVisible).toBeFalsy();
|
expect(fakeFormWithField.tabs[0].isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -909,6 +910,17 @@ describe('WidgetVisibilityService', () => {
|
|||||||
service.refreshEntityVisibility(contModel.field);
|
service.refreshEntityVisibility(contModel.field);
|
||||||
expect(contModel.isVisible).toBeFalsy();
|
expect(contModel.isVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should set null value when the field is not visibile', () => {
|
||||||
|
visibilityObjTest.leftFormFieldId = 'test_4';
|
||||||
|
visibilityObjTest.operator = '!=';
|
||||||
|
visibilityObjTest.rightFormFieldId = 'dropdown';
|
||||||
|
const fakeFormField: FormFieldModel = new FormFieldModel(formTest, jsonFieldFake);
|
||||||
|
|
||||||
|
service.refreshEntityVisibility(fakeFormField);
|
||||||
|
expect(fakeFormField.isVisible).toBeFalsy();
|
||||||
|
expect(fakeFormField.value).toEqual(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Visibility based on form variables', () => {
|
describe('Visibility based on form variables', () => {
|
||||||
|
@@ -48,6 +48,9 @@ export class WidgetVisibilityService {
|
|||||||
|
|
||||||
refreshEntityVisibility(element: FormFieldModel | TabModel) {
|
refreshEntityVisibility(element: FormFieldModel | TabModel) {
|
||||||
const visible = this.evaluateVisibility(element.form, element.visibilityCondition);
|
const visible = this.evaluateVisibility(element.form, element.visibilityCondition);
|
||||||
|
if (!visible && element instanceof FormFieldModel) {
|
||||||
|
element.value = null;
|
||||||
|
}
|
||||||
element.isVisible = visible;
|
element.isVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user