mirror of
https://github.com/nasa/openmct.git
synced 2025-05-31 14:40:48 +00:00
Merge pull request #379 from nasa/open1337
[Limits] Add test cases for limits
This commit is contained in:
commit
9b63a63efc
@ -423,6 +423,42 @@ define(
|
|||||||
// Style should have been updated
|
// Style should have been updated
|
||||||
expect(controller.selected().style).not.toEqual(oldStyle);
|
expect(controller.selected().style).not.toEqual(oldStyle);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("reflects limit status", function () {
|
||||||
|
var elements;
|
||||||
|
|
||||||
|
mockHandle.getDatum.andReturn({});
|
||||||
|
mockHandle.getTelemetryObjects().forEach(function (mockObject) {
|
||||||
|
var id = mockObject.getId(),
|
||||||
|
mockLimitCapability =
|
||||||
|
jasmine.createSpyObj('limit-' + id, ['evaluate']);
|
||||||
|
|
||||||
|
mockObject.getCapability.andCallFake(function (key) {
|
||||||
|
return (key === 'limit') && mockLimitCapability;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockLimitCapability.evaluate
|
||||||
|
.andReturn({ cssClass: 'alarm-' + id });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
mockScope.domainObject = mockDomainObject;
|
||||||
|
mockScope.model = testModel;
|
||||||
|
findWatch("domainObject")(mockDomainObject);
|
||||||
|
findWatch("model.modified")(1);
|
||||||
|
findWatch("model.composition")(mockScope.model.composition);
|
||||||
|
|
||||||
|
// Invoke the subscription callback
|
||||||
|
mockHandler.handle.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
// Get elements that controller is now exposing
|
||||||
|
elements = controller.getElements();
|
||||||
|
|
||||||
|
// Limit-based CSS classes should be available
|
||||||
|
expect(elements[0].cssClass).toEqual("alarm-a");
|
||||||
|
expect(elements[1].cssClass).toEqual("alarm-b");
|
||||||
|
expect(elements[2].cssClass).toEqual("alarm-c");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -285,6 +285,33 @@ define(
|
|||||||
fireWatch("axes[1].active.key", 'someNewKey');
|
fireWatch("axes[1].active.key", 'someNewKey');
|
||||||
expect(mockHandle.request.calls.length).toEqual(2);
|
expect(mockHandle.request.calls.length).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides classes for legends based on limit state", function () {
|
||||||
|
var mockTelemetryObjects = mockHandle.getTelemetryObjects();
|
||||||
|
|
||||||
|
mockHandle.getDatum.andReturn({});
|
||||||
|
mockTelemetryObjects.forEach(function (mockObject, i) {
|
||||||
|
var id = 'object-' + i,
|
||||||
|
mockLimitCapability =
|
||||||
|
jasmine.createSpyObj('limit-' + id, ['evaluate']);
|
||||||
|
|
||||||
|
mockObject.getId.andReturn(id);
|
||||||
|
mockObject.getCapability.andCallFake(function (key) {
|
||||||
|
return (key === 'limit') && mockLimitCapability;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockLimitCapability.evaluate
|
||||||
|
.andReturn({ cssClass: 'alarm-' + id });
|
||||||
|
});
|
||||||
|
|
||||||
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
||||||
|
mockHandler.handle.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
mockTelemetryObjects.forEach(function (mockTelemetryObject) {
|
||||||
|
expect(controller.getLegendClass(mockTelemetryObject))
|
||||||
|
.toEqual('alarm-' + mockTelemetryObject.getId());
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
103
platform/features/plot/test/elements/PlotLimitTrackerSpec.js
Normal file
103
platform/features/plot/test/elements/PlotLimitTrackerSpec.js
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||||
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
|
* Administration. All rights reserved.
|
||||||
|
*
|
||||||
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
* Open MCT Web includes source code licensed under additional open source
|
||||||
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||||
|
* this source code distribution or the Licensing information page available
|
||||||
|
* at runtime from the About dialog for additional information.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
["../../src/elements/PlotLimitTracker"],
|
||||||
|
function (PlotLimitTracker) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
describe("A plot's limit tracker", function () {
|
||||||
|
var mockHandle,
|
||||||
|
testRange,
|
||||||
|
mockTelemetryObjects,
|
||||||
|
testData,
|
||||||
|
mockLimitCapabilities,
|
||||||
|
tracker;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
testRange = "some-range";
|
||||||
|
testData = {};
|
||||||
|
mockHandle = jasmine.createSpyObj(
|
||||||
|
'handle',
|
||||||
|
['getTelemetryObjects', 'getDatum']
|
||||||
|
);
|
||||||
|
mockTelemetryObjects = ['a', 'b', 'c'].map(function (id, i) {
|
||||||
|
var mockTelemetryObject = jasmine.createSpyObj(
|
||||||
|
'object-' + id,
|
||||||
|
[ 'getId', 'getCapability', 'getModel' ]
|
||||||
|
),
|
||||||
|
mockLimitCapability = jasmine.createSpyObj(
|
||||||
|
'limit-' + id,
|
||||||
|
[ 'evaluate' ]
|
||||||
|
);
|
||||||
|
testData[id] = { id: id, value: i };
|
||||||
|
mockTelemetryObject.getId.andReturn(id);
|
||||||
|
mockTelemetryObject.getCapability.andCallFake(function (key) {
|
||||||
|
return key === 'limit' && mockLimitCapability;
|
||||||
|
});
|
||||||
|
mockLimitCapability.evaluate
|
||||||
|
.andReturn({ cssClass: 'alarm-' + id});
|
||||||
|
return mockTelemetryObject;
|
||||||
|
});
|
||||||
|
mockHandle.getTelemetryObjects.andReturn(mockTelemetryObjects);
|
||||||
|
mockHandle.getDatum.andCallFake(function (telemetryObject) {
|
||||||
|
return testData[telemetryObject.getId()];
|
||||||
|
});
|
||||||
|
|
||||||
|
tracker = new PlotLimitTracker(mockHandle, testRange);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("initially provides no limit state", function () {
|
||||||
|
mockTelemetryObjects.forEach(function (mockTelemetryObject) {
|
||||||
|
expect(tracker.getLegendClass(mockTelemetryObject))
|
||||||
|
.toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("when asked to update", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
tracker.update();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("evaluates limits using the limit capability", function () {
|
||||||
|
mockTelemetryObjects.forEach(function (mockTelemetryObject) {
|
||||||
|
var id = mockTelemetryObject.getId(),
|
||||||
|
mockLimit =
|
||||||
|
mockTelemetryObject.getCapability('limit');
|
||||||
|
expect(mockLimit.evaluate)
|
||||||
|
.toHaveBeenCalledWith(testData[id], testRange);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes legend classes returned by the limit capability", function () {
|
||||||
|
mockTelemetryObjects.forEach(function (mockTelemetryObject) {
|
||||||
|
var id = mockTelemetryObject.getId();
|
||||||
|
expect(tracker.getLegendClass(mockTelemetryObject))
|
||||||
|
.toEqual('alarm-' + id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
@ -6,6 +6,7 @@
|
|||||||
"SubPlot",
|
"SubPlot",
|
||||||
"SubPlotFactory",
|
"SubPlotFactory",
|
||||||
"elements/PlotAxis",
|
"elements/PlotAxis",
|
||||||
|
"elements/PlotLimitTracker",
|
||||||
"elements/PlotLine",
|
"elements/PlotLine",
|
||||||
"elements/PlotLineBuffer",
|
"elements/PlotLineBuffer",
|
||||||
"elements/PlotPalette",
|
"elements/PlotPalette",
|
||||||
|
@ -243,6 +243,26 @@ define(
|
|||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
expect(mockUnlisten).toHaveBeenCalled();
|
expect(mockUnlisten).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides telemetry as datum objects", function () {
|
||||||
|
var testDatum = { a: 1, b: 13, c: 42, d: -1977 };
|
||||||
|
|
||||||
|
function lookup(index, key) {
|
||||||
|
return testDatum[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
mockSeries.getDomainValue.andCallFake(lookup);
|
||||||
|
mockSeries.getRangeValue.andCallFake(lookup);
|
||||||
|
|
||||||
|
testMetadata.domains = [ { key: 'a' }, { key: 'b'} ];
|
||||||
|
testMetadata.ranges = [ { key: 'c' }, { key: 'd'} ];
|
||||||
|
|
||||||
|
mockTelemetry.subscribe.mostRecentCall.args[0](mockSeries);
|
||||||
|
mockTimeout.mostRecentCall.args[0]();
|
||||||
|
|
||||||
|
expect(subscription.getDatum(mockDomainObject))
|
||||||
|
.toEqual(testDatum);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user