{"ScriptPreparationCode":null,"TestCases":[{"Name":"copy object","Code":"var x = {\r\n a: \u0022foo\u0022,\r\n b: \u0022bar\u0022,\r\n c: \u0022baz\u0022\r\n};\r\n\r\nvar deps = [\u0022a\u0022, \u0022b\u0022, \u0022c\u0022];\r\n\r\nconst extractDependencyValues = (dependencies, allFieldValues, fieldId) =\u003E {\r\n let result = {};\r\n if (!dependencies) return {};\r\n dependencies\r\n .filter(dependencyFieldId =\u003E allFieldValues[dependencyFieldId])\r\n .forEach(fieldId =\u003E {\r\n // @ts-ignore\r\n result[fieldId] = allFieldValues[fieldId];\r\n });\r\n return result;\r\n}\r\n\r\nextractDependencyValues(deps, x, \u0022foo\u0022);","IsDeferred":false},{"Name":"evaluate condition","Code":"function evaluateSingleValue(conditionValue, dependencyValue, operator) {\r\n let result;\r\n switch (operator) {\r\n case \u0022EQUALS\u0022:\r\n result = dependencyValue === conditionValue;\r\n break;\r\n case \u0022NOT_EQUALS\u0022:\r\n result = dependencyValue !== conditionValue;\r\n break;\r\n default:\r\n result = false;\r\n }\r\n return result;\r\n}\r\n\r\nfunction isConditionMatched(dependencyName, condition, dependencyValues) {\r\n const operator = condition.operator;\r\n let dependencyValue = dependencyValues \u0026\u0026 dependencyValues[dependencyName];\r\n // if (dependencyValue instanceof Array \u0026\u0026 dependencyValue.length === 0) {\r\n // dependencyValue = undefined;\r\n // }\r\n\r\n return evaluateSingleValue(condition.value, dependencyValue, operator);\r\n}\r\n\r\nfunction evaluateConditions(valuesWithConditions, dependencyValues) {\r\n let result = undefined;\r\n for (let i = 0; i \u003C valuesWithConditions.length; i\u002B\u002B) {\r\n const valueWithConditions = valuesWithConditions[i];\r\n const found = Object.getOwnPropertyNames(\r\n valueWithConditions.conditionsMap\r\n ).every(key =\u003E {\r\n return valueWithConditions.conditionsMap[key].some((condition) =\u003E\r\n isConditionMatched(key, condition, dependencyValues)\r\n );\r\n });\r\n if (found) {\r\n result = valueWithConditions.value;\r\n break;\r\n }\r\n }\r\n return result;\r\n}\r\n\r\nvar valueWithConditions = [\r\n {\r\n \u0022value\u0022: false,\r\n \u0022conditionsMap\u0022: {\r\n \u0022a\u0022: [\r\n {\r\n \u0022value\u0022: \u0022foo\u0022,\r\n \u0022operator\u0022: \u0022EQUALS\u0022\r\n }\r\n ],\r\n \u0022b\u0022: [\r\n {\r\n \u0022value\u0022: \u0022bar\u0022,\r\n \u0022operator\u0022: \u0022EQUALS\u0022\r\n }\r\n ]\r\n }\r\n }\r\n];\r\nevaluateConditions(valueWithConditions, {a: \u0022foo\u0022, b: \u0022bar\u0022});","IsDeferred":false}]}