2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* 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.
|
|
|
|
*****************************************************************************/
|
2014-12-02 00:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/PlotController"],
|
|
|
|
function (PlotController) {
|
|
|
|
|
|
|
|
describe("The plot controller", function () {
|
|
|
|
var mockScope,
|
2014-12-24 20:13:57 +00:00
|
|
|
mockFormatter,
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandler,
|
2015-06-11 00:02:16 +00:00
|
|
|
mockThrottle,
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandle,
|
2014-12-12 18:08:58 +00:00
|
|
|
mockDomainObject,
|
2015-04-21 00:04:34 +00:00
|
|
|
mockSeries,
|
2014-12-02 00:44:16 +00:00
|
|
|
controller;
|
|
|
|
|
2015-08-13 19:12:15 +00:00
|
|
|
function bind(method, thisObj) {
|
|
|
|
return function () {
|
|
|
|
return method.apply(thisObj, arguments);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-09-17 00:00:56 +00:00
|
|
|
function fireEvent(name, args) {
|
|
|
|
mockScope.$on.calls.forEach(function (call) {
|
|
|
|
if (call.args[0] === name) {
|
|
|
|
call.args[1].apply(null, args || []);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-11 00:17:43 +00:00
|
|
|
function fireWatch(expr, value) {
|
|
|
|
mockScope.$watch.calls.forEach(function (call) {
|
|
|
|
if (call.args[0] === expr) {
|
|
|
|
call.args[1].apply(null, [value]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2014-12-02 00:44:16 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
2015-09-04 22:53:55 +00:00
|
|
|
[ "$watch", "$on", "$emit" ]
|
2014-12-02 00:44:16 +00:00
|
|
|
);
|
2014-12-24 20:13:57 +00:00
|
|
|
mockFormatter = jasmine.createSpyObj(
|
|
|
|
"formatter",
|
|
|
|
[ "formatDomainValue", "formatRangeValue" ]
|
|
|
|
);
|
2014-12-12 18:08:58 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[ "getId", "getModel", "getCapability" ]
|
|
|
|
);
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandler = jasmine.createSpyObj(
|
2015-01-29 20:34:58 +00:00
|
|
|
"telemetrySubscriber",
|
2015-04-17 23:42:15 +00:00
|
|
|
["handle"]
|
2015-01-29 20:34:58 +00:00
|
|
|
);
|
2015-06-11 00:02:16 +00:00
|
|
|
mockThrottle = jasmine.createSpy("throttle");
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandle = jasmine.createSpyObj(
|
2015-02-03 00:17:17 +00:00
|
|
|
"subscription",
|
|
|
|
[
|
|
|
|
"unsubscribe",
|
|
|
|
"getTelemetryObjects",
|
|
|
|
"getMetadata",
|
|
|
|
"getDomainValue",
|
2015-04-17 23:42:15 +00:00
|
|
|
"getRangeValue",
|
2015-06-23 20:43:00 +00:00
|
|
|
"getDatum",
|
2015-04-17 23:42:15 +00:00
|
|
|
"request"
|
2015-02-03 00:17:17 +00:00
|
|
|
]
|
|
|
|
);
|
2015-04-21 00:04:34 +00:00
|
|
|
mockSeries = jasmine.createSpyObj(
|
|
|
|
'series',
|
|
|
|
['getPointCount', 'getDomainValue', 'getRangeValue']
|
|
|
|
);
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandler.handle.andReturn(mockHandle);
|
2015-06-11 00:02:16 +00:00
|
|
|
mockThrottle.andCallFake(function (fn) { return fn; });
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandle.getTelemetryObjects.andReturn([mockDomainObject]);
|
|
|
|
mockHandle.getMetadata.andReturn([{}]);
|
|
|
|
mockHandle.getDomainValue.andReturn(123);
|
|
|
|
mockHandle.getRangeValue.andReturn(42);
|
2015-09-17 00:00:56 +00:00
|
|
|
mockScope.domainObject = mockDomainObject;
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2015-06-11 00:02:16 +00:00
|
|
|
controller = new PlotController(
|
|
|
|
mockScope,
|
|
|
|
mockFormatter,
|
|
|
|
mockHandler,
|
|
|
|
mockThrottle
|
|
|
|
);
|
2014-12-02 00:44:16 +00:00
|
|
|
});
|
|
|
|
|
2014-12-02 02:13:03 +00:00
|
|
|
it("provides plot colors", function () {
|
|
|
|
// PlotPalette will have its own tests
|
|
|
|
expect(controller.getColor(0))
|
|
|
|
.toEqual(jasmine.any(String));
|
|
|
|
|
|
|
|
// Colors should be unique
|
|
|
|
expect(controller.getColor(0))
|
|
|
|
.not.toEqual(controller.getColor(1));
|
|
|
|
});
|
|
|
|
|
2015-02-03 00:17:17 +00:00
|
|
|
it("subscribes to telemetry when a domain object appears in scope", function () {
|
|
|
|
// Make sure we're using the right watch here
|
|
|
|
expect(mockScope.$watch.mostRecentCall.args[0])
|
|
|
|
.toEqual("domainObject");
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
// Should have subscribed
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandler.handle).toHaveBeenCalledWith(
|
2015-02-03 00:17:17 +00:00
|
|
|
mockDomainObject,
|
|
|
|
jasmine.any(Function),
|
|
|
|
true // Lossless
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("draws lines when data becomes available", function () {
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
|
2014-12-12 18:08:58 +00:00
|
|
|
// Verify precondition
|
|
|
|
controller.getSubPlots().forEach(function (subplot) {
|
|
|
|
expect(subplot.getDrawingObject().lines)
|
|
|
|
.not.toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Make sure there actually are subplots being verified
|
2015-02-03 00:17:17 +00:00
|
|
|
expect(controller.getSubPlots().length > 0).toBeTruthy();
|
2014-12-12 18:08:58 +00:00
|
|
|
|
|
|
|
// Broadcast data
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandler.handle.mostRecentCall.args[1]();
|
2014-12-12 18:08:58 +00:00
|
|
|
|
|
|
|
controller.getSubPlots().forEach(function (subplot) {
|
|
|
|
expect(subplot.getDrawingObject().lines)
|
|
|
|
.toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-02-03 00:17:17 +00:00
|
|
|
it("unsubscribes when domain object changes", function () {
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
// Verify precondition - shouldn't unsubscribe yet
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandle.unsubscribe).not.toHaveBeenCalled();
|
2015-02-03 00:17:17 +00:00
|
|
|
// Remove the domain object
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](undefined);
|
|
|
|
// Should have unsubscribed
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandle.unsubscribe).toHaveBeenCalled();
|
2015-02-03 00:17:17 +00:00
|
|
|
});
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2014-12-02 00:44:16 +00:00
|
|
|
|
2015-02-03 00:17:17 +00:00
|
|
|
it("changes modes depending on number of objects", function () {
|
|
|
|
// Act like one object is available
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandle.getTelemetryObjects.andReturn([
|
2015-02-03 00:17:17 +00:00
|
|
|
mockDomainObject
|
|
|
|
]);
|
|
|
|
|
2015-10-27 22:52:11 +00:00
|
|
|
// Make an object available; invoke handler's callback
|
2015-02-03 00:17:17 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
2015-10-27 22:52:11 +00:00
|
|
|
mockHandler.handle.mostRecentCall.args[1]();
|
2014-12-12 18:08:58 +00:00
|
|
|
|
|
|
|
expect(controller.getModeOptions().length).toEqual(1);
|
|
|
|
|
2015-02-03 00:17:17 +00:00
|
|
|
// Act like one object is available
|
2015-04-17 23:42:15 +00:00
|
|
|
mockHandle.getTelemetryObjects.andReturn([
|
2014-12-12 18:08:58 +00:00
|
|
|
mockDomainObject,
|
|
|
|
mockDomainObject,
|
|
|
|
mockDomainObject
|
|
|
|
]);
|
2015-02-03 00:17:17 +00:00
|
|
|
|
2015-10-27 22:52:11 +00:00
|
|
|
// Make an object available; invoke handler's callback
|
2015-02-03 00:17:17 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
2015-10-27 22:52:11 +00:00
|
|
|
mockHandler.handle.mostRecentCall.args[1]();
|
2015-02-03 00:17:17 +00:00
|
|
|
|
2014-12-12 18:08:58 +00:00
|
|
|
expect(controller.getModeOptions().length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Interface tests follow; these will be delegated (mostly
|
|
|
|
// to PlotModeOptions, which is tested separately).
|
|
|
|
it("provides access to available plot mode options", function () {
|
|
|
|
expect(Array.isArray(controller.getModeOptions()))
|
|
|
|
.toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("provides a current plot mode", function () {
|
|
|
|
expect(controller.getMode().name)
|
|
|
|
.toEqual(jasmine.any(String));
|
|
|
|
});
|
|
|
|
|
2015-02-03 00:17:17 +00:00
|
|
|
it("allows plot mode to be changed", function () {
|
2014-12-12 18:08:58 +00:00
|
|
|
expect(function () {
|
|
|
|
controller.setMode(controller.getMode());
|
|
|
|
}).not.toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("provides an array of sub-plots", function () {
|
|
|
|
expect(Array.isArray(controller.getSubPlots()))
|
|
|
|
.toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows plots to be updated", function () {
|
2015-08-13 19:12:15 +00:00
|
|
|
expect(bind(controller.update, controller)).not.toThrow();
|
2014-12-12 18:08:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("allows changing pan-zoom state", function () {
|
2015-08-13 19:12:15 +00:00
|
|
|
expect(bind(controller.isZoomed, controller)).not.toThrow();
|
|
|
|
expect(bind(controller.stepBackPanZoom, controller)).not.toThrow();
|
|
|
|
expect(bind(controller.unzoom, controller)).not.toThrow();
|
2014-12-12 18:08:58 +00:00
|
|
|
});
|
2015-02-03 00:17:17 +00:00
|
|
|
|
|
|
|
it("indicates if a request is pending", function () {
|
2015-09-16 22:23:08 +00:00
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(controller.isRequestPending()).toBeTruthy();
|
|
|
|
mockHandle.request.mostRecentCall.args[1](
|
|
|
|
mockDomainObject,
|
|
|
|
mockSeries
|
|
|
|
);
|
2015-02-03 00:17:17 +00:00
|
|
|
expect(controller.isRequestPending()).toBeFalsy();
|
|
|
|
});
|
2015-02-06 01:34:37 +00:00
|
|
|
|
2015-04-21 00:04:34 +00:00
|
|
|
it("requests historical telemetry", function () {
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(mockHandle.request).toHaveBeenCalled();
|
|
|
|
mockHandle.request.mostRecentCall.args[1](
|
|
|
|
mockDomainObject,
|
|
|
|
mockSeries
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2015-02-06 01:34:37 +00:00
|
|
|
it("unsubscribes when destroyed", function () {
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
// Make sure $destroy is what's listened for
|
|
|
|
expect(mockScope.$on.mostRecentCall.args[0]).toEqual('$destroy');
|
|
|
|
// Also verify precondition
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandle.unsubscribe).not.toHaveBeenCalled();
|
2015-02-06 01:34:37 +00:00
|
|
|
// Destroy the scope
|
2015-09-17 00:00:56 +00:00
|
|
|
fireEvent("$destroy");
|
2015-02-06 01:34:37 +00:00
|
|
|
// Should have unsubscribed
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandle.unsubscribe).toHaveBeenCalled();
|
2015-02-06 01:34:37 +00:00
|
|
|
});
|
2015-09-17 00:00:56 +00:00
|
|
|
|
|
|
|
it("requeries when displayable bounds change", function () {
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(1);
|
|
|
|
fireEvent("telemetry:display:bounds", [
|
|
|
|
{},
|
|
|
|
{ start: 10, end: 100 }
|
|
|
|
]);
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(2);
|
|
|
|
});
|
2015-11-11 00:17:43 +00:00
|
|
|
|
|
|
|
it("requeries when user changes domain selection", function () {
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(1);
|
|
|
|
fireWatch("axes[0].active.key", 'someNewKey');
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("requeries when user changes range selection", function () {
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(1);
|
|
|
|
fireWatch("axes[1].active.key", 'someNewKey');
|
|
|
|
expect(mockHandle.request.calls.length).toEqual(2);
|
|
|
|
});
|
2015-12-30 18:04:04 +00:00
|
|
|
|
2015-12-30 18:15:05 +00:00
|
|
|
|
2015-12-30 18:04:04 +00:00
|
|
|
it("maintains externally-provided domain axis bounds after data is received", function () {
|
|
|
|
mockSeries.getPointCount.andReturn(3);
|
|
|
|
mockSeries.getRangeValue.andReturn(42);
|
|
|
|
mockSeries.getDomainValue.andCallFake(function (i) {
|
|
|
|
return 2500 + i * 2500;
|
|
|
|
});
|
|
|
|
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
fireEvent("telemetry:display:bounds", [
|
|
|
|
{},
|
2015-12-30 18:15:05 +00:00
|
|
|
{start: 0, end: 10000}
|
2015-12-30 18:04:04 +00:00
|
|
|
]);
|
|
|
|
mockHandle.request.mostRecentCall.args[1](
|
|
|
|
mockDomainObject,
|
|
|
|
mockSeries
|
|
|
|
);
|
|
|
|
|
|
|
|
// Pan-zoom state should reflect bounds set externally;
|
|
|
|
// domain axis should not have shrunk to fit data.
|
|
|
|
expect(
|
|
|
|
controller.getSubPlots()[0].panZoomStack.getOrigin()[0]
|
|
|
|
).toEqual(0);
|
|
|
|
expect(
|
|
|
|
controller.getSubPlots()[0].panZoomStack.getDimensions()[0]
|
|
|
|
).toEqual(10000);
|
|
|
|
});
|
2015-12-30 18:15:05 +00:00
|
|
|
|
2015-12-07 20:45:40 +00:00
|
|
|
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());
|
|
|
|
});
|
|
|
|
});
|
2014-12-02 00:44:16 +00:00
|
|
|
});
|
|
|
|
}
|
2015-06-11 00:02:16 +00:00
|
|
|
);
|