add isDefined condition in condition Evaluator which fixes Issue 1860

Add appropriate tests
Fix for isUndefined not working as well
This commit is contained in:
Deep Tailor 2018-01-04 09:37:18 -08:00 committed by Victor Woeltjen
parent 3f1b7e0a87
commit aa8fa9168a
2 changed files with 20 additions and 2 deletions

View File

@ -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');
}

View File

@ -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 () {