Merge branch 'condition-ui' of https://github.com/nasa/openmct into condition-ui

This commit is contained in:
Joshi 2020-01-28 12:36:57 -08:00
commit de03cfbe64
6 changed files with 31 additions and 37 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: 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

@ -2,7 +2,7 @@
<div v-if="condition"
id="conditionArea"
class="c-cs-ui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent && (isCurrent.key === conditionIdentifier.key) }]"
:class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
>
<div class="title-bar">
<span class="condition-name">
@ -28,7 +28,7 @@ export default {
type: Object,
required: true
},
isCurrent: {
currentConditionIdentifier: {
type: Object,
required: true
}

View File

@ -35,7 +35,7 @@
>
<div v-if="isEditing">
<ConditionEdit :condition-identifier="conditionIdentifier"
:is-current="currentConditionIdentifier"
:current-condition-identifier="currentConditionIdentifier"
@update-current-condition="updateCurrentCondition"
@remove-condition="removeCondition"
@condition-result-updated="handleConditionResult"
@ -43,7 +43,7 @@
</div>
<div v-else>
<Condition :condition-identifier="conditionIdentifier"
:is-current="currentConditionIdentifier"
:current-condition-identifier="currentConditionIdentifier"
/>
</div>
</div>
@ -88,6 +88,8 @@ export default {
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) {
this.addCondition(null, true);
} else {
this.updateCurrentCondition(this.conditionCollection[0]);
}
},
methods: {
@ -98,7 +100,6 @@ export default {
},
updateCurrentConditionId() {
let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1];
for (let i=0, ii = this.conditionCollection.length-1; i< ii; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) {

View File

@ -1,7 +1,7 @@
<template>
<div v-if="condition"
class="c-cs-editui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent && (isCurrent.key === conditionIdentifier.key) }]"
:class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
>
<div class="title-bar">
<span
@ -147,7 +147,7 @@ export default {
type: Object,
required: true
},
isCurrent: {
currentConditionIdentifier: {
type: Object,
required: true
}
@ -160,8 +160,8 @@ export default {
telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS,
selectedMetaDataKey: null,
selectedTelemetryKey: null,
selectedOperationKey: null,
selectedTelemetryKey: '',
selectedOperationKey: '',
selectedOutputKey: null,
stringOutputField: false,
comparisonValueField: false,
@ -239,7 +239,7 @@ export default {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.telemetryMetadata[0].key;
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = this.telemetryObject.identifier;
});
} else {

View File

@ -77,7 +77,9 @@ export default class TelemetryCriterion extends EventEmitter {
let params = [];
let result = false;
params.push(data[this.metaDataKey]);
params.push(this.input);
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({