Skip to content

Commit

Permalink
FIO-8769 added check for the simpleConditional properties state (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaKurban authored Aug 16, 2024
1 parent c5e4245 commit 6c3ff4d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/utils/__tests__/formUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
findComponents,
getComponent,
flattenComponents,
getComponentActualValue
getComponentActualValue,
hasCondition
} from "../formUtil";
import { fastCloneDeep } from 'utils/fastCloneDeep';

Expand Down Expand Up @@ -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);
})
})

5 changes: 3 additions & 2 deletions src/utils/formUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
isPlainObject,
isArray,
isEqual,
trim
trim,
isBoolean
} from "lodash";
import { compare, applyPatch } from 'fast-json-patch';
import {
Expand Down Expand Up @@ -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))
))
);
}
Expand Down

0 comments on commit 6c3ff4d

Please sign in to comment.