From 6c3ff4d1a3fb35806f74a5b4a4ba18f93967d83e Mon Sep 17 00:00:00 2001 From: HannaKurban <96909212+HannaKurban@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:35:13 +0300 Subject: [PATCH] FIO-8769 added check for the simpleConditional properties state (#136) --- 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 b2524e6e..7947f7ac 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 { @@ -748,7 +749,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)) )) ); }