Fixes tests

This commit is contained in:
Joshi 2020-01-28 10:36:13 -08:00
parent f42ec7e2c5
commit b3488c54cd
3 changed files with 20 additions and 28 deletions

View File

@ -64,15 +64,17 @@ describe("The condition", function () {
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
testConditionDefinition = {
trigger: TRIGGER.ANY,
criteria: [
{
operation: 'equalTo',
input: false,
metaDataKey: 'value',
key: testTelemetryObject.identifier
}
]
definition: {
trigger: 'any',
criteria: [
{
operation: 'equalTo',
input: false,
metaDataKey: 'value',
key: testTelemetryObject.identifier
}
]
}
};
conditionObj = new Condition(
@ -85,7 +87,7 @@ describe("The condition", function () {
});
it("generates criteria with an id", function () {
const testCriterion = testConditionDefinition.criteria[0];
const testCriterion = testConditionDefinition.definition.criteria[0];
let criterion = conditionObj.generateCriterion(testCriterion);
expect(criterion.id).toBeDefined();
expect(criterion.operation).toEqual(testCriterion.operation);
@ -101,15 +103,15 @@ describe("The condition", function () {
it("initializes with criteria from the condition definition", function () {
expect(conditionObj.criteria.length).toEqual(1);
let criterion = conditionObj.criteria[0];
console.log(criterion);
expect(criterion instanceof TelemetryCriterion).toBeTrue();
expect(criterion.operator).toEqual(testConditionDefinition.operator);
expect(criterion.input).toEqual(testConditionDefinition.input);
expect(criterion.metaDataKey).toEqual(testConditionDefinition.metaDataKey);
expect(criterion.key).toEqual(testConditionDefinition.key);
expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator);
expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input);
expect(criterion.metaDataKey).toEqual(testConditionDefinition.definition.criteria[0].metaDataKey);
});
it("initializes with the trigger from the condition definition", function () {
expect(conditionObj.trigger).toEqual(testConditionDefinition.trigger);
expect(conditionObj.trigger).toEqual(testConditionDefinition.definition.trigger);
});
it("destroys all criteria for a condition", function () {

View File

@ -77,8 +77,9 @@ export default class TelemetryCriterion extends EventEmitter {
let params = [];
let result = false;
params.push(data[this.metaDataKey]);
params.push(this.input[0]);
console.log(params);
if (this.input instanceof Array && this.input.length) {
params.push(this.input[0]);
}
if (typeof comparator === 'function') {
result = comparator(params);
}

View File

@ -94,17 +94,6 @@ describe("The telemetry criterion", function () {
expect(telemetryCriterion.subscription).toBeDefined();
});
it("normalizes telemetry data", function () {
let result = telemetryCriterion.normalizeData({
key: 'some-key',
source: 'testSource',
testSource: 'Hello'
});
expect(result).toEqual({
'some-key': 'Hello'
})
});
it("emits update event on new data from telemetry providers", function () {
spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
telemetryCriterion.handleSubscription({