From aa8fa9168a67165dfb7ff4472e6557c0ff39b473 Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Thu, 4 Jan 2018 09:37:18 -0800 Subject: [PATCH] add isDefined condition in condition Evaluator which fixes Issue 1860 Add appropriate tests Fix for isUndefined not working as well --- .../summaryWidget/src/ConditionEvaluator.js | 18 ++++++++++++++++-- .../test/ConditionEvaluatorSpec.js | 4 ++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/plugins/summaryWidget/src/ConditionEvaluator.js b/src/plugins/summaryWidget/src/ConditionEvaluator.js index 2bf8e90643..a38a66180c 100644 --- a/src/plugins/summaryWidget/src/ConditionEvaluator.js +++ b/src/plugins/summaryWidget/src/ConditionEvaluator.js @@ -206,6 +206,17 @@ define([], function () { getDescription: function () { return ' is undefined'; } + }, + isDefined: { + operation: function (input) { + return typeof input[0] !== 'undefined'; + }, + text: 'is defined', + appliesTo: ['string', 'number'], + inputCount: 0, + getDescription: function () { + return ' is defined'; + } } }; } @@ -304,9 +315,12 @@ define([], function () { op = this.operations[operation] && this.operations[operation].operation; input = telemetryValue && telemetryValue.concat(values); validator = op && this.inputValidators[this.operations[operation].appliesTo[0]]; - if (op && input && validator) { - return validator(input) && op(input); + if (this.operations[operation].appliesTo.length === 2) { + return (this.validateNumberInput(input) || this.validateStringInput(input)) && op(input); + } else { + return validator(input) && op(input); + } } else { throw new Error('Malformed condition'); } diff --git a/src/plugins/summaryWidget/test/ConditionEvaluatorSpec.js b/src/plugins/summaryWidget/test/ConditionEvaluatorSpec.js index d6dcedd391..0380ef2bb0 100644 --- a/src/plugins/summaryWidget/test/ConditionEvaluatorSpec.js +++ b/src/plugins/summaryWidget/test/ConditionEvaluatorSpec.js @@ -325,6 +325,10 @@ define(['../src/ConditionEvaluator'], function (ConditionEvaluator) { testOperation = testEvaluator.operations.isUndefined.operation; expect(testOperation([1])).toEqual(false); expect(testOperation([])).toEqual(true); + //isDefined + testOperation = testEvaluator.operations.isDefined.operation; + expect(testOperation([1])).toEqual(true); + expect(testOperation([])).toEqual(false); }); it('can produce a description for all supported operations', function () {