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.
|
|
|
|
*****************************************************************************/
|
2015-01-29 20:34:58 +00:00
|
|
|
/*global define,Promise,describe,it,expect,xit,beforeEach,waitsFor,jasmine*/
|
2014-12-02 00:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/PlotController"],
|
|
|
|
function (PlotController) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
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,
|
|
|
|
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;
|
|
|
|
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2014-12-02 00:44:16 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockScope = jasmine.createSpyObj(
|
|
|
|
"$scope",
|
|
|
|
[ "$watch", "$on" ]
|
|
|
|
);
|
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-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",
|
|
|
|
"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);
|
|
|
|
mockHandle.getTelemetryObjects.andReturn([mockDomainObject]);
|
|
|
|
mockHandle.getMetadata.andReturn([{}]);
|
|
|
|
mockHandle.getDomainValue.andReturn(123);
|
|
|
|
mockHandle.getRangeValue.andReturn(42);
|
2014-12-02 02:13:03 +00:00
|
|
|
|
2015-04-17 23:42:15 +00:00
|
|
|
controller = new PlotController(mockScope, mockFormatter, mockHandler);
|
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
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
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
|
|
|
|
|
|
|
// Make an object available
|
|
|
|
mockScope.$watch.mostRecentCall.args[1](mockDomainObject);
|
|
|
|
|
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 () {
|
|
|
|
expect(controller.update).not.toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("allows changing pan-zoom state", function () {
|
|
|
|
expect(controller.isZoomed).not.toThrow();
|
|
|
|
expect(controller.stepBackPanZoom).not.toThrow();
|
|
|
|
expect(controller.unzoom).not.toThrow();
|
|
|
|
});
|
2015-02-03 00:17:17 +00:00
|
|
|
|
|
|
|
it("indicates if a request is pending", function () {
|
|
|
|
// Placeholder; need to support requesting telemetry
|
|
|
|
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
|
|
|
|
mockScope.$on.mostRecentCall.args[1]();
|
|
|
|
// Should have unsubscribed
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(mockHandle.unsubscribe).toHaveBeenCalled();
|
2015-02-06 01:34:37 +00:00
|
|
|
});
|
2014-12-02 00:44:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|