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

View File

@ -21,9 +21,8 @@
*****************************************************************************/
import TelemetryCriterion from "./TelemetryCriterion";
import { createOpenMct } from "../../../testTools";
let openmct = createOpenMct(),
let openmct = {},
mockListener,
testTelemetryObject,
telemetryCriterion;
@ -31,7 +30,6 @@ let openmct = createOpenMct(),
describe("The telemetry criterion", function () {
beforeEach (() => {
mockListener = jasmine.createSpy('listener');
testTelemetryObject = {
identifier:{ namespace: "", key: "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(
testTelemetryObject,
testTelemetryObject.identifier,
openmct
);