Removes use of createOpenMCT and uses mock object for openmct instead.

This commit is contained in:
Joshi 2020-01-13 13:58:25 -08:00
parent 36055b7c04
commit 7cf6dc386f
2 changed files with 16 additions and 8 deletions

View File

@ -24,15 +24,15 @@ import * as EventEmitter from 'eventemitter3';
export default class TelemetryCriterion extends EventEmitter { export default class TelemetryCriterion extends EventEmitter {
constructor(telemetryDomainObject, openmct) { constructor(telemetryDomainObjectKey, openmct) {
super(); super();
this.telemetryObject = telemetryDomainObject;
this.openmct = openmct; this.openmct = openmct;
this.telemetryObject = this.openmct.objects.get(this.openmct.objects.makeKeyString(telemetryDomainObjectKey));
this.telemetryAPI = this.openmct.telemetry; this.telemetryAPI = this.openmct.telemetry;
this.subscription = null; this.subscription = null;
this.telemetryObjectIdAsString = null;
this.telemetryMetadata = null; this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null;
if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) { if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) {
this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier); this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier);
} }
@ -73,7 +73,9 @@ export default class TelemetryCriterion extends EventEmitter {
*/ */
unsubscribe() { unsubscribe() {
//unsubscribe from telemetry source //unsubscribe from telemetry source
if (typeof this.subscription === 'function') {
this.subscription(); this.subscription();
}
delete this.subscription; delete this.subscription;
this.emit('criterion::Remove', this.telemetryObjectIdAsString); this.emit('criterion::Remove', this.telemetryObjectIdAsString);
delete this.telemetryObjectIdAsString; delete this.telemetryObjectIdAsString;

View File

@ -21,9 +21,8 @@
*****************************************************************************/ *****************************************************************************/
import TelemetryCriterion from "./TelemetryCriterion"; import TelemetryCriterion from "./TelemetryCriterion";
import { createOpenMct } from "../../../testTools";
let openmct = createOpenMct(), let openmct = {},
mockListener, mockListener,
testTelemetryObject, testTelemetryObject,
telemetryCriterion; telemetryCriterion;
@ -31,7 +30,6 @@ let openmct = createOpenMct(),
describe("The telemetry criterion", function () { describe("The telemetry criterion", function () {
beforeEach (() => { beforeEach (() => {
mockListener = jasmine.createSpy('listener');
testTelemetryObject = { testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"}, identifier:{ namespace: "", key: "test-object"},
type: "test-object", type: "test-object",
@ -52,9 +50,17 @@ describe("The telemetry criterion", function () {
}] }]
} }
}; };
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString', ]);
openmct.objects.get.and.returnValue(testTelemetryObject);
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe"]);
openmct.telemetry.isTelemetryObject.and.returnValue(true);
openmct.telemetry.subscribe.and.returnValue(function () {});
mockListener = jasmine.createSpy('listener');
telemetryCriterion = new TelemetryCriterion( telemetryCriterion = new TelemetryCriterion(
testTelemetryObject, testTelemetryObject.identifier,
openmct openmct
); );