From 796ac5a01e09d2c9557b742988b539f70f1dcd8c Mon Sep 17 00:00:00 2001 From: Hanna Kurban Date: Fri, 16 Aug 2024 11:15:12 +0300 Subject: [PATCH] FIO-8769 added check for the simpleConditional properties state --- src/utils/__tests__/formUtil.test.ts | 21 ++++++++++++++++++++- src/utils/formUtil.ts | 5 +++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/formUtil.test.ts b/src/utils/__tests__/formUtil.test.ts index 3493a3e1..96a189fb 100644 --- a/src/utils/__tests__/formUtil.test.ts +++ b/src/utils/__tests__/formUtil.test.ts @@ -20,7 +20,8 @@ import { findComponents, getComponent, flattenComponents, - getComponentActualValue + getComponentActualValue, + hasCondition } from "../formUtil"; import { fastCloneDeep } from 'utils/fastCloneDeep'; @@ -1795,4 +1796,22 @@ describe('getComponentActualValue', () => { expect(value).to.equal('yes'); }); }); + +describe('hasCondition', () => { + it('Should return false if conditions is saved in invalid state', () => { + const component = { + label: 'Text Field', + hidden: true, + key: 'textField', + conditional: { + conjunction: 'all' + }, + type: 'textfield', + input: true + } + + const result = hasCondition(component as Component); + expect(result).to.equal(false); + }) +}) \ No newline at end of file diff --git a/src/utils/formUtil.ts b/src/utils/formUtil.ts index 9568b146..531c438b 100644 --- a/src/utils/formUtil.ts +++ b/src/utils/formUtil.ts @@ -14,7 +14,8 @@ import { isPlainObject, isArray, isEqual, - trim + trim, + isBoolean } from "lodash"; import { compare, applyPatch } from 'fast-json-patch'; import { @@ -745,7 +746,7 @@ export function hasCondition(component: Component) { (component.conditional && ( (component.conditional as LegacyConditional).when || (component.conditional as JSONConditional).json || - (component.conditional as SimpleConditional).conjunction + ((component.conditional as SimpleConditional).conjunction && isBoolean((component.conditional as SimpleConditional).show) && !isEmpty((component.conditional as SimpleConditional).conditions)) )) ); }