From 72b3a75a854b368a905e18d0a3a1b1d25c0022bb Mon Sep 17 00:00:00 2001 From: Silviu Popa Date: Thu, 11 Jul 2019 19:07:27 +0300 Subject: [PATCH] [ADF-4710] - adapt visibility condition to the new schema (#4884) * [ADF-4710] - adapt new visibility condition schema * [ADF-4710] - fix unit tests * [ADF-4710] - support visibility for APS1 and APS2 --- .../widgets/core/form-field.model.ts | 3 +- .../form/models/widget-visibility.model.ts | 91 +- .../widget-visibility-cloud.service.spec.ts | 1029 +++++++++++++++++ .../widget-visibility.service.spec.ts | 25 +- .../services/widget-visibility.service.ts | 52 +- .../form/formDefinitionVisibility.mock.ts | 10 +- .../widget-visibility-cloud.service.mock.ts | 865 ++++++++++++++ .../form/widget-visibility.service.mock.ts | 4 - 8 files changed, 2014 insertions(+), 65 deletions(-) create mode 100644 lib/core/form/services/widget-visibility-cloud.service.spec.ts create mode 100644 lib/core/mock/form/widget-visibility-cloud.service.mock.ts diff --git a/lib/core/form/components/widgets/core/form-field.model.ts b/lib/core/form/components/widgets/core/form-field.model.ts index 3fb62282f5..91830b4d33 100644 --- a/lib/core/form/components/widgets/core/form-field.model.ts +++ b/lib/core/form/components/widgets/core/form-field.model.ts @@ -136,7 +136,6 @@ export class FormFieldModel extends FormWidgetModel { constructor(form: FormModel, json?: any) { super(form, json); - if (json) { this.fieldType = json.fieldType; this.id = json.id; @@ -163,7 +162,7 @@ export class FormFieldModel extends FormWidgetModel { this.params = json.params || {}; this.hyperlinkUrl = json.hyperlinkUrl; this.displayText = json.displayText; - this.visibilityCondition = json.visibilityCondition; + this.visibilityCondition = json.visibilityCondition ? new WidgetVisibilityModel(json.visibilityCondition) : undefined; this.enableFractions = json.enableFractions; this.currency = json.currency; this.dateDisplayFormat = json.dateDisplayFormat || this.getDefaultDateFormat(json); diff --git a/lib/core/form/models/widget-visibility.model.ts b/lib/core/form/models/widget-visibility.model.ts index 19df6bc630..626b52cc20 100644 --- a/lib/core/form/models/widget-visibility.model.ts +++ b/lib/core/form/models/widget-visibility.model.ts @@ -16,13 +16,90 @@ */ export class WidgetVisibilityModel { - leftFormFieldId: string; - leftRestResponseId: string; + rightRestResponseId?: string; + rightFormFieldId?: string; + leftRestResponseId?: string; + leftFormFieldId?: string; + operator: string; nextCondition: WidgetVisibilityModel; nextConditionOperator: string; - operator: string; - rightFormFieldId: string; - rightRestResponseId: string; - rightType: string; - rightValue: string; + + constructor(private json?: any) { + if (json) { + this.operator = json.operator; + this.nextCondition = new WidgetVisibilityModel(json.nextCondition); + this.nextConditionOperator = json.nextConditionOperator; + this.rightRestResponseId = json.rightRestResponseId; + this.rightFormFieldId = json.rightFormFieldId; + this.leftFormFieldId = json.leftFormFieldId; + this.leftRestResponseId = json.leftRestResponseId; + } else { + this.json = {}; + } + } + + set leftType(leftType: string) { + this.json.leftType = leftType; + } + + set rightType(rightType: string) { + this.json.rightType = rightType; + } + + set leftValue(leftValue: string) { + this.json.leftValue = leftValue; + } + + set rightValue(rightValue: string) { + this.json.rightValue = rightValue; + } + + get leftType() { + if (this.leftFormFieldId) { + return WidgetTypeEnum.field; + } else if (this.leftRestResponseId) { + return WidgetTypeEnum.variable; + } else if ( !!this.json.leftType) { + return this.json.leftType; + } + } + + get leftValue() { + if ( this.json.leftValue ) { + return this.json.leftValue; + } else if (this.leftFormFieldId) { + return this.leftFormFieldId; + } else { + return this.leftRestResponseId; + } + } + + get rightType() { + if ( !!this.json.rightType ) { + return this.json.rightType; + } else if (this.json.rightValue) { + return WidgetTypeEnum.value; + } else if (this.rightRestResponseId) { + return WidgetTypeEnum.variable; + } else if (this.rightFormFieldId) { + return WidgetTypeEnum.field; + } + } + + get rightValue() { + if (this.json.rightValue) { + return this.json.rightValue; + } else if (this.rightFormFieldId) { + return this.rightFormFieldId; + } else { + return this.rightRestResponseId; + } + } + +} + +export enum WidgetTypeEnum { + field = 'field', + variable = 'variable', + value = 'value' } diff --git a/lib/core/form/services/widget-visibility-cloud.service.spec.ts b/lib/core/form/services/widget-visibility-cloud.service.spec.ts new file mode 100644 index 0000000000..4a0fc674fd --- /dev/null +++ b/lib/core/form/services/widget-visibility-cloud.service.spec.ts @@ -0,0 +1,1029 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { TestBed } from '@angular/core/testing'; +import { + ContainerModel, + FormFieldModel, + FormFieldTypes, + FormModel, + TabModel +} from './../components/widgets/core/index'; +import { TaskProcessVariableModel } from './../models/task-process-variable.model'; +import { WidgetVisibilityModel, WidgetTypeEnum } from './../models/widget-visibility.model'; +import { WidgetVisibilityService } from './widget-visibility.service'; +import { setupTestBed } from '../../testing/setupTestBed'; +import { CoreModule } from '../../core.module'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { AlfrescoApiService } from '../../services/alfresco-api.service'; +import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock'; +import { + fakeFormJson, fakeTaskProcessVariableModels, + formTest, formValues, complexVisibilityJsonVisible, + complexVisibilityJsonNotVisible } from 'core/mock/form/widget-visibility-cloud.service.mock'; + +declare let jasmine: any; + +describe('WidgetVisibilityCloudService', () => { + + let service: WidgetVisibilityService; + let booleanResult: boolean; + const stubFormWithFields = new FormModel(fakeFormJson); + + setupTestBed({ + imports: [ + NoopAnimationsModule, + CoreModule.forRoot() + ], + providers: [ + { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock } + ] + }); + + beforeEach(() => { + service = TestBed.get(WidgetVisibilityService); + jasmine.Ajax.install(); + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + describe('should be able to evaluate logic operations', () => { + + it('using AND and return true', () => { + booleanResult = service.evaluateLogicalOperation('and', true, true); + expect(booleanResult).toBeTruthy(); + }); + + it('using AND and return false', () => { + booleanResult = service.evaluateLogicalOperation('and', true, false); + expect(booleanResult).toBeFalsy(); + }); + + it('using OR and return true', () => { + booleanResult = service.evaluateLogicalOperation('or', true, false); + expect(booleanResult).toBeTruthy(); + }); + + it('using OR and return false', () => { + booleanResult = service.evaluateLogicalOperation('or', false, false); + expect(booleanResult).toBeFalsy(); + }); + + it('using AND NOT and return true', () => { + booleanResult = service.evaluateLogicalOperation('and-not', true, false); + expect(booleanResult).toBeTruthy(); + }); + + it('using AND NOT and return false', () => { + booleanResult = service.evaluateLogicalOperation('and-not', false, false); + expect(booleanResult).toBeFalsy(); + }); + + it('using OR NOT and return true', () => { + booleanResult = service.evaluateLogicalOperation('or-not', true, true); + expect(booleanResult).toBeTruthy(); + }); + + it('using OR NOT and return false', () => { + booleanResult = service.evaluateLogicalOperation('or-not', false, true); + expect(booleanResult).toBeFalsy(); + }); + + it('should fail with invalid operation', () => { + booleanResult = service.evaluateLogicalOperation(undefined, false, true); + expect(booleanResult).toBeUndefined(); + }); + }); + + describe('should be able to evaluate next condition operations', () => { + + it('using == and return true', () => { + booleanResult = service.evaluateCondition('test', 'test', '=='); + expect(booleanResult).toBeTruthy(); + }); + + it('using < and return true', () => { + booleanResult = service.evaluateCondition(1, 2, '<'); + expect(booleanResult).toBeTruthy(); + }); + + it('using != and return true', () => { + booleanResult = service.evaluateCondition(true, false, '!='); + expect(booleanResult).toBeTruthy(); + }); + + it('using != and return false', () => { + booleanResult = service.evaluateCondition(true, true, '!='); + expect(booleanResult).toBeFalsy(); + }); + + it('using >= and return true', () => { + booleanResult = service.evaluateCondition(2, 2, '>='); + expect(booleanResult).toBeTruthy(); + }); + + it('using empty with null values and return true', () => { + booleanResult = service.evaluateCondition(null, null, 'empty'); + expect(booleanResult).toBeTruthy(); + }); + + it('using empty with empty strings values and return true', () => { + booleanResult = service.evaluateCondition('', '', 'empty'); + expect(booleanResult).toBeTruthy(); + }); + + it('using empty with empty string value and return false', () => { + booleanResult = service.evaluateCondition('fake_value', undefined, 'empty'); + expect(booleanResult).toBeFalsy(); + }); + + it('using > and return false', () => { + booleanResult = service.evaluateCondition(2, 3, '>'); + expect(booleanResult).toBeFalsy(); + }); + + it('using not empty with null values and return false', () => { + booleanResult = service.evaluateCondition(null, null, '!empty'); + expect(booleanResult).toBeFalsy(); + }); + + it('using OR NOT with empty strings and return false', () => { + booleanResult = service.evaluateCondition('', '', '!empty'); + expect(booleanResult).toBeFalsy(); + }); + + it('using <= and return false', () => { + booleanResult = service.evaluateCondition(2, 1, '<='); + expect(booleanResult).toBeFalsy(); + }); + + it('using <= and return true for different values', () => { + booleanResult = service.evaluateCondition(1, 2, '<='); + expect(booleanResult).toBeTruthy(); + }); + + it('using <= and return true for same values', () => { + booleanResult = service.evaluateCondition(2, 2, '<='); + expect(booleanResult).toBeTruthy(); + }); + + it('should return undefined for invalid operation', () => { + booleanResult = service.evaluateCondition(null, null, undefined); + expect(booleanResult).toBeUndefined(); + }); + }); + + describe('should retrieve the process variables', () => { + const fakeFormWithField = new FormModel(fakeFormJson); + let visibilityObjTest: WidgetVisibilityModel; + const chainedVisibilityObj = new WidgetVisibilityModel({}); + + beforeEach(() => { + visibilityObjTest = new WidgetVisibilityModel({}); + }); + + it('should return the process variables for task', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res) => { + expect(res).toBeDefined(); + expect(res.length).toEqual(3); + expect(res[0].id).toEqual('TEST_VAR_1'); + expect(res[0].type).toEqual('string'); + expect(res[0].value).toEqual('test_value_1'); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should be able to retrieve the value of a process variable', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + expect(res).toBeDefined(); + const varValue = service.getVariableValue(formTest, 'TEST_VAR_1', res); + expect(varValue).not.toBeUndefined(); + expect(varValue).toBe('test_value_1'); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should return undefined if the variable does not exist', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + const varValue = service.getVariableValue(formTest, 'TEST_MYSTERY_VAR', res); + expect(varValue).toBeUndefined(); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should retrieve the value for the right field when it is a process variable', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + visibilityObjTest.rightValue = 'test_value_2'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).not.toBeNull(); + expect(rightValue).toBe('test_value_2'); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should retrieve the value for the left field when it is a process variable', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + visibilityObjTest.leftValue = 'TEST_VAR_2'; + visibilityObjTest.leftType = WidgetTypeEnum.field; + const rightValue = service.getLeftValue(formTest, visibilityObjTest); + + expect(rightValue).not.toBeNull(); + expect(rightValue).toBe('test_value_2'); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should evaluate the visibility for the field between form value and process var', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + visibilityObjTest.leftType = 'LEFT_FORM_FIELD_ID'; + visibilityObjTest.operator = '!='; + visibilityObjTest.rightValue = 'TEST_VAR_2'; + const isVisible = service.isFieldVisible(fakeFormWithField, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should evaluate visibility with multiple conditions', (done) => { + service.getTaskProcessVariable('9999').subscribe( + (res: TaskProcessVariableModel[]) => { + visibilityObjTest.leftType = 'field'; + visibilityObjTest.leftValue = 'TEST_VAR_2'; + visibilityObjTest.operator = '!='; + visibilityObjTest.rightValue = 'TEST_VAR_2'; + visibilityObjTest.nextConditionOperator = 'and'; + chainedVisibilityObj.leftType = 'field'; + chainedVisibilityObj.leftValue = 'TEST_VAR_2'; + chainedVisibilityObj.operator = '!empty'; + visibilityObjTest.nextCondition = chainedVisibilityObj; + + const isVisible = service.isFieldVisible(fakeFormWithField, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + done(); + } + ); + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: fakeTaskProcessVariableModels + }); + }); + + it('should catch error on 403 response', (done) => { + service.getTaskProcessVariable('9999').subscribe(() => { + }, () => { + done(); + }); + + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 403 + }); + }); + }); + + describe('should return the value of the field', () => { + let visibilityObjTest: WidgetVisibilityModel; + const fakeFormWithField = new FormModel(fakeFormJson); + const jsonFieldFake = { + id: 'FAKE_FORM_FIELD_ID', + value: 'FAKE_FORM_FIELD_VALUE', + visibilityCondition: undefined + }; + const fakeForm = new FormModel({ + variables: [ + { + name: 'FORM_VARIABLE_TEST', + type: 'string', + value: 'form_value_test' + }] + }); + + beforeEach(() => { + visibilityObjTest = new WidgetVisibilityModel({}); + formTest.values = formValues; + jsonFieldFake.visibilityCondition = visibilityObjTest; + }); + + afterEach(() => { + service.cleanProcessVariable(); + }); + + it('should be able to retrieve a field value searching in the form', () => { + const formValue = service.searchValueInForm(stubFormWithFields, 'FIELD_WITH_CONDITION'); + + expect(formValue).not.toBeNull(); + expect(formValue).toBe('field_with_condition_value'); + }); + + it('should return empty string if the field value is not in the form', () => { + const formValue = service.searchValueInForm(stubFormWithFields, 'FIELD_MYSTERY'); + + expect(formValue).not.toBeUndefined(); + expect(formValue).toBe(''); + }); + + it('should search in the form if element value is not in form values', () => { + const value = service.getFormValue(fakeFormWithField, 'FIELD_WITH_CONDITION'); + + expect(value).not.toBeNull(); + expect(value).toBe('field_with_condition_value'); + }); + + it('should return empty string if the element is not present anywhere', () => { + const formValue = service.getFormValue(fakeFormWithField, 'FIELD_MYSTERY'); + + expect(formValue).not.toBeUndefined(); + expect(formValue).toBe(''); + }); + + it('should retrieve the value for the right field when it is a value', () => { + visibilityObjTest.rightValue = '100'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).toBe('100'); + }); + + it('should return formatted date when right value is a date', () => { + visibilityObjTest.rightValue = '9999-12-31'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).toBe('9999-12-31T00:00:00.000Z'); + }); + + it('should return the value when right value is not a date', () => { + visibilityObjTest.rightValue = '9999-99-99'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).toBe('9999-99-99'); + }); + + it('should retrieve the value for the right field when it is a form variable', () => { + visibilityObjTest.rightType = 'field'; + visibilityObjTest.rightValue = 'RIGHT_FORM_FIELD_ID'; + const rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest); + + expect(rightValue).not.toBeNull(); + expect(rightValue).toBe('RIGHT_FORM_FIELD_VALUE'); + }); + + it('should take the value from form values if it is present', () => { + const formValue = service.getFormValue(formTest, 'test_1'); + + expect(formValue).not.toBeNull(); + expect(formValue).toBe('value_1'); + }); + + it('should retrieve right value from form values if it is present', () => { + visibilityObjTest.rightType = WidgetTypeEnum.field; + visibilityObjTest.rightValue = 'test_2'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).not.toBeNull(); + expect(formTest.values).toEqual(formValues); + expect(rightValue).toBe('value_2'); + }); + + it('should retrieve the value for the left field when it is a form value', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'FIELD_WITH_CONDITION'; + const leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest); + + expect(leftValue).not.toBeNull(); + expect(leftValue).toBe('field_with_condition_value'); + }); + + it('should retrieve left value from form values if it is present', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'test_2'; + const leftValue = service.getLeftValue(formTest, visibilityObjTest); + + expect(leftValue).not.toBeNull(); + expect(leftValue).toBe('value_2'); + }); + + it('should return empty string for a value that is not on variable or form', () => { + const leftValue = service.getLeftValue(fakeFormWithField, visibilityObjTest); + expect(leftValue).toBe(''); + }); + + it('should evaluate the visibility for the field with single visibility condition between two field values', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'test_1'; + visibilityObjTest.operator = '=='; + visibilityObjTest.rightType = WidgetTypeEnum.field; + visibilityObjTest.rightValue = 'test_3'; + const isVisible = service.isFieldVisible(formTest, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + }); + + it('should evaluate true visibility for the field with single visibility condition between a field and a value', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'test_1'; + visibilityObjTest.operator = '=='; + visibilityObjTest.rightValue = 'value_1'; + const isVisible = service.isFieldVisible(formTest, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + }); + + xit('should return empty string for a value that is not on variable or form', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'NO_FIELD_FORM'; + const rightValue = service.getRightValue(fakeFormWithField, visibilityObjTest); + + expect(rightValue).not.toBeUndefined(); + expect(rightValue).toBe(''); + }); + + it('should evaluate the visibility for the field with single visibility condition between form values', () => { + visibilityObjTest.leftType = 'LEFT_FORM_FIELD_ID'; + visibilityObjTest.operator = '!='; + visibilityObjTest.rightType = 'RIGHT_FORM_FIELD_ID'; + const isVisible = service.isFieldVisible(fakeFormWithField, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + }); + + it('should refresh the visibility for a form field object', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + 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(); + }); + + it('should return true when the visibility condition is not valid', () => { + visibilityObjTest = new WidgetVisibilityModel(); + visibilityObjTest.leftType = ''; + visibilityObjTest.leftValue = ''; + visibilityObjTest.operator = '!='; + const isVisible = service.evaluateVisibility(formTest, visibilityObjTest); + + expect(isVisible).toBeTruthy(); + }); + + it('should return always true when field does not have a visibility condition', () => { + jsonFieldFake.visibilityCondition = null; + const fakeFormField: FormFieldModel = new FormFieldModel(fakeFormWithField, jsonFieldFake); + fakeFormField.isVisible = false; + service.refreshEntityVisibility(fakeFormField); + + expect(fakeFormField.isVisible).toBeTruthy(); + }); + + it('should be able to retrieve the value of a form variable', () => { + const varValue = service.getVariableValue(fakeForm, 'FORM_VARIABLE_TEST', null); + + expect(varValue).not.toBeUndefined(); + expect(varValue).toBe('form_value_test'); + }); + + it('should return undefined for not existing form variable', () => { + const varValue = service.getVariableValue(fakeForm, 'MYSTERY_FORM_VARIABLE', null); + + expect(varValue).toBeUndefined(); + }); + + it('should retrieve the value for the left field when it is a form variable', () => { + visibilityObjTest.leftType = WidgetTypeEnum.field; + visibilityObjTest.leftValue = 'FORM_VARIABLE_TEST'; + const leftValue = service.getLeftValue(fakeForm, visibilityObjTest); + + expect(leftValue).not.toBeNull(); + expect(leftValue).toBe('form_value_test'); + }); + + xit('should determine visibility for dropdown on label condition', () => { + const dropdownValue = service.getFieldValue(formTest.values, 'Dropdown'); + + expect(dropdownValue).not.toBeNull(); + expect(dropdownValue).toBeDefined(); + expect(dropdownValue).toBe('Dropdown'); + }); + + it('should be able to get the value for a standard field', () => { + const dropdownValue = service.getFieldValue(formTest.values, 'test_2'); + + expect(dropdownValue).not.toBeNull(); + expect(dropdownValue).toBeDefined(); + expect(dropdownValue).toBe('value_2'); + }); + + xit('should get the dropdown label value from a form', () => { + const dropdownValue = service.getFormValue(formTest, 'Dropdown'); + + expect(dropdownValue).not.toBeNull(); + expect(dropdownValue).toBeDefined(); + expect(dropdownValue).toBe('Dropdown'); + }); + + it('should get the dropdown id value from a form', () => { + const dropdownValue = service.getFormValue(formTest, 'dropdown'); + + expect(dropdownValue).not.toBeNull(); + expect(dropdownValue).toBeDefined(); + expect(dropdownValue).toBe('dropdown_id'); + }); + + it('should retrieve the value for the right field when it is a dropdown id', () => { + visibilityObjTest.rightType = 'field'; + visibilityObjTest.rightValue = 'dropdown'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).toBeDefined(); + expect(rightValue).toBe('dropdown_id'); + }); + + xit('should retrieve the value for the right field when it is a dropdown label', () => { + visibilityObjTest.rightType = 'field'; + visibilityObjTest.rightValue = 'Dropdown'; + const rightValue = service.getRightValue(formTest, visibilityObjTest); + + expect(rightValue).toBeDefined(); + expect(rightValue).toBe('Dropdown'); + }); + + xit('should be able to evaluate condition with a dropdown