Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for forms dependencies #38

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ dist/
bin/
obj/
App_Data/
.vs/
.vs/
.vscode/
coverage/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"jestrunner.jestCommand": "npm run test --",
"jest.rootPath": "src/@optimizely/forms-sdk",
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ export class FormDependConditions {
checkConditions = (formSubmissions: FormSubmission[]): boolean => {
if (!isNull(formSubmissions)) {
const conditionProps = (this._element.properties as unknown) as ConditionProperties;

if (isNull(conditionProps?.conditions)) {
return false;
}

let conditionArr = conditionProps.conditions.map(condition => {
const fieldValue = formSubmissions.filter(s => equals(s.elementKey, condition.field))[0]?.value as string
if (!isNull(fieldValue)) {
Expand All @@ -33,7 +31,6 @@ export class FormDependConditions {
}
return false
});

for (let i = 0; i < conditionArr.length; i++) {
const result = conditionArr[i]
if (conditionProps.conditionCombination === ConditionCombinationType.Any && result) {
Expand All @@ -43,11 +40,10 @@ export class FormDependConditions {
return false
}
}

// when reach here, there are two cases
// 1 : Not all conditions are statisfied and ConditionCombination === ConditionCombinations.All
// 2 : None condition is statisfied and ConditionCombination === ConditionCombinations.Any
return !(conditionProps.conditionCombination === ConditionCombinationType.Any);
// When reach here, there are two cases
// 1 : All conditions are statisfied and ConditionCombination === ConditionCombinations.All
// 2 : No condition is statisfied and ConditionCombination === ConditionCombinations.Any
return conditionProps.conditionCombination === ConditionCombinationType.All;
}
return false
}
Expand Down
Loading