fix broken tests

This commit is contained in:
David Tsay 2020-03-20 15:00:24 -07:00
parent aed5377ad2
commit d51dd8b7d0
3 changed files with 31 additions and 29 deletions

View File

@ -76,7 +76,7 @@ describe('ConditionManager', () => {
beforeEach(function () { beforeEach(function () {
mockAngularComponents(); mockAngularComponents();
mockListener = jasmine.createSpy('mockListener');
loader = {}; loader = {};
loader.promise = new Promise(function (resolve, reject) { loader.promise = new Promise(function (resolve, reject) {
loader.resolve = resolve; loader.resolve = resolve;
@ -84,7 +84,9 @@ describe('ConditionManager', () => {
}); });
mockComposition = jasmine.createSpyObj('compositionCollection', [ mockComposition = jasmine.createSpyObj('compositionCollection', [
'load' 'load',
'on',
'off'
]); ]);
mockComposition.load.and.callFake(() => { mockComposition.load.and.callFake(() => {
setTimeout(() => { setTimeout(() => {
@ -92,6 +94,8 @@ describe('ConditionManager', () => {
}); });
return loader.promise; return loader.promise;
}); });
mockComposition.on('add', mockListener);
mockComposition.on('remove', mockListener);
openmct.composition = jasmine.createSpyObj('compositionAPI', [ openmct.composition = jasmine.createSpyObj('compositionAPI', [
'get' 'get'
]); ]);
@ -108,15 +112,15 @@ describe('ConditionManager', () => {
openmct.objects.mutate.and.returnValue(function () {}); openmct.objects.mutate.and.returnValue(function () {});
conditionMgr = new ConditionManager(conditionSetDomainObject, openmct); conditionMgr = new ConditionManager(conditionSetDomainObject, openmct);
mockListener = jasmine.createSpy('mockListener');
conditionMgr.on('conditionSetResultUpdated', mockListener); conditionMgr.on('conditionSetResultUpdated', mockListener);
conditionMgr.on('broadcastTelemetry', mockListener);
}); });
it('creates a conditionCollection with a default condition', function () { it('creates a conditionCollection with a default condition', function () {
expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(1); expect(conditionMgr.conditionSetDomainObject.configuration.conditionCollection.length).toEqual(1);
let defaultConditionId = conditionMgr.conditionClassCollection[0].id; let defaultConditionId = conditionMgr.conditionClassCollection[0].id;
expect(defaultConditionId).toEqual(mockCondition.id); expect(defaultConditionId).toEqual(mockCondition.id);
}); });
}); });

View File

@ -28,11 +28,19 @@ let openmct = {},
mockListener, mockListener,
testConditionDefinition, testConditionDefinition,
testTelemetryObject, testTelemetryObject,
conditionObj; conditionObj,
conditionManager,
mockBroadcastTelemetry;
describe("The condition", function () { describe("The condition", function () {
beforeEach (() => { beforeEach (() => {
conditionManager = jasmine.createSpyObj('conditionManager',
['on']
);
mockBroadcastTelemetry = jasmine.createSpy('listener');
conditionManager.on('broadcastTelemetry', mockBroadcastTelemetry);
mockListener = jasmine.createSpy('listener'); mockListener = jasmine.createSpy('listener');
testTelemetryObject = { testTelemetryObject = {
identifier:{ namespace: "", key: "test-object"}, identifier:{ namespace: "", key: "test-object"},
@ -66,11 +74,14 @@ describe("The condition", function () {
testConditionDefinition = { testConditionDefinition = {
id: '123-456', id: '123-456',
configuration: { configuration: {
name: 'mock condition',
output: 'mock output',
trigger: TRIGGER.ANY, trigger: TRIGGER.ANY,
criteria: [ criteria: [
{ {
id: '1234-5678-9999-0000',
operation: 'equalTo', operation: 'equalTo',
input: false, input: ['0'],
metadata: 'value', metadata: 'value',
telemetry: testTelemetryObject.identifier telemetry: testTelemetryObject.identifier
} }
@ -80,14 +91,14 @@ describe("The condition", function () {
conditionObj = new Condition( conditionObj = new Condition(
testConditionDefinition, testConditionDefinition,
openmct openmct,
conditionManager
); );
conditionObj.on('conditionUpdated', mockListener); conditionObj.on('conditionUpdated', mockListener);
}); });
it("generates criteria with an id", function () { it("generates criteria with the correct properties", function () {
const testCriterion = testConditionDefinition.configuration.criteria[0]; const testCriterion = testConditionDefinition.configuration.criteria[0];
let criterion = conditionObj.generateCriterion(testCriterion); let criterion = conditionObj.generateCriterion(testCriterion);
expect(criterion.id).toBeDefined(); expect(criterion.id).toBeDefined();
@ -98,6 +109,7 @@ describe("The condition", function () {
}); });
it("initializes with an id", function () { it("initializes with an id", function () {
console.log(conditionObj);
expect(conditionObj.id).toBeDefined(); expect(conditionObj.id).toBeDefined();
}); });

View File

@ -78,7 +78,9 @@ describe("The telemetry criterion", function () {
testCriterionDefinition = { testCriterionDefinition = {
id: 'test-criterion-id', id: 'test-criterion-id',
telemetry: openmct.objects.makeKeyString(testTelemetryObject.identifier) telemetry: openmct.objects.makeKeyString(testTelemetryObject.identifier),
operation: 'lessThan',
metadata: 'sin'
}; };
mockListener = jasmine.createSpy('listener'); mockListener = jasmine.createSpy('listener');
@ -102,12 +104,7 @@ describe("The telemetry criterion", function () {
expect(mockListener2).toHaveBeenCalled(); expect(mockListener2).toHaveBeenCalled();
}); });
it("subscribes to telemetry providers", function () { it("updates and emits event on new data from telemetry providers", function () {
telemetryCriterion.subscribe();
expect(telemetryCriterion.subscription).toBeDefined();
});
it("emits update event on new data from telemetry providers", function () {
telemetryCriterion.initialize(testTelemetryObject); telemetryCriterion.initialize(testTelemetryObject);
spyOn(telemetryCriterion, 'emitEvent').and.callThrough(); spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
telemetryCriterion.handleSubscription({ telemetryCriterion.handleSubscription({
@ -115,16 +112,5 @@ describe("The telemetry criterion", function () {
utc: 'Hi' utc: 'Hi'
}); });
expect(telemetryCriterion.emitEvent).toHaveBeenCalled(); expect(telemetryCriterion.emitEvent).toHaveBeenCalled();
expect(mockListener).toHaveBeenCalled();
}); });
it("un-subscribes from telemetry providers", function () {
telemetryCriterion.subscribe();
expect(telemetryCriterion.subscription).toBeDefined();
telemetryCriterion.destroy();
expect(telemetryCriterion.subscription).toBeUndefined();
expect(telemetryCriterion.telemetryObjectIdAsString).toBeUndefined();
expect(telemetryCriterion.telemetryObject).toBeUndefined();
});
}); });