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-12 17:44:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../../src/modes/PlotOverlayMode"],
|
|
|
|
function (PlotOverlayMode) {
|
|
|
|
|
|
|
|
describe("Overlaid plot mode", function () {
|
2014-12-12 20:56:26 +00:00
|
|
|
var mockDomainObject,
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory,
|
2014-12-12 20:56:26 +00:00
|
|
|
mockPrepared,
|
|
|
|
testBuffers,
|
2014-12-24 20:13:57 +00:00
|
|
|
testDrawingObjects,
|
2014-12-12 20:56:26 +00:00
|
|
|
mode;
|
2014-12-12 17:49:44 +00:00
|
|
|
|
2014-12-24 20:13:57 +00:00
|
|
|
function createMockSubPlot() {
|
|
|
|
var mockSubPlot = jasmine.createSpyObj(
|
|
|
|
"subPlot",
|
|
|
|
[
|
|
|
|
"setDomainOffset",
|
|
|
|
"hover",
|
|
|
|
"startMarquee",
|
|
|
|
"endMarquee",
|
|
|
|
"getDrawingObject",
|
|
|
|
"update"
|
|
|
|
]
|
|
|
|
),
|
|
|
|
testDrawingObject = {};
|
|
|
|
|
|
|
|
// Track drawing objects in order of creation
|
|
|
|
testDrawingObjects.push(testDrawingObject);
|
|
|
|
mockSubPlot.getDrawingObject.andReturn(testDrawingObject);
|
|
|
|
return mockSubPlot;
|
2014-12-12 20:56:26 +00:00
|
|
|
}
|
2014-12-12 17:49:44 +00:00
|
|
|
|
2014-12-12 20:56:26 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
"domainObject",
|
|
|
|
[ "getId", "getModel", "getCapability" ]
|
|
|
|
);
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory = jasmine.createSpyObj(
|
|
|
|
"subPlotFactory",
|
|
|
|
[ "createSubPlot" ]
|
|
|
|
);
|
2014-12-12 20:56:26 +00:00
|
|
|
// Prepared telemetry data
|
|
|
|
mockPrepared = jasmine.createSpyObj(
|
|
|
|
"prepared",
|
2015-04-17 23:42:15 +00:00
|
|
|
[
|
|
|
|
"getDomainOffset",
|
|
|
|
"getOrigin",
|
|
|
|
"getDimensions",
|
|
|
|
"getLineBuffers"
|
|
|
|
]
|
2014-12-12 20:56:26 +00:00
|
|
|
);
|
|
|
|
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot);
|
|
|
|
|
2014-12-12 20:56:26 +00:00
|
|
|
// Act as if we have three buffers full of data
|
2015-04-17 23:42:15 +00:00
|
|
|
testBuffers = ['a', 'b', 'c'].map(function (id) {
|
|
|
|
var mockBuffer = jasmine.createSpyObj(
|
|
|
|
'buffer-' + id,
|
|
|
|
['getBuffer', 'getLength']
|
|
|
|
);
|
|
|
|
mockBuffer.getBuffer.andReturn([id]);
|
|
|
|
mockBuffer.getLength.andReturn(3);
|
|
|
|
return mockBuffer;
|
|
|
|
});
|
|
|
|
mockPrepared.getLineBuffers.andReturn(testBuffers);
|
2014-12-12 20:56:26 +00:00
|
|
|
mockPrepared.getDomainOffset.andReturn(1234);
|
|
|
|
mockPrepared.getOrigin.andReturn([10, 10]);
|
|
|
|
mockPrepared.getDimensions.andReturn([500, 500]);
|
|
|
|
|
2014-12-24 20:13:57 +00:00
|
|
|
// Clear out drawing objects
|
|
|
|
testDrawingObjects = [];
|
|
|
|
|
2014-12-12 20:56:26 +00:00
|
|
|
mode = new PlotOverlayMode([
|
|
|
|
mockDomainObject,
|
|
|
|
mockDomainObject,
|
|
|
|
mockDomainObject
|
2014-12-24 20:13:57 +00:00
|
|
|
], mockSubPlotFactory);
|
2014-12-12 20:56:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("creates one sub-plot for all domain objects", function () {
|
|
|
|
expect(mode.getSubPlots().length).toEqual(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("draws telemetry to subplots", function () {
|
|
|
|
// Verify precondition
|
|
|
|
mode.getSubPlots().forEach(function (subplot) {
|
|
|
|
// Either empty list or undefined is fine;
|
|
|
|
// just want to make sure there are no lines.
|
|
|
|
expect(subplot.getDrawingObject().lines || [])
|
|
|
|
.toEqual([]);
|
|
|
|
});
|
|
|
|
|
|
|
|
mode.plotTelemetry(mockPrepared);
|
|
|
|
|
2014-12-24 20:13:57 +00:00
|
|
|
// Should have one sub-plot with three lines
|
2016-03-04 20:56:14 +00:00
|
|
|
testDrawingObjects.forEach(function (testDrawingObject) {
|
2014-12-12 20:56:26 +00:00
|
|
|
// Either empty list or undefined is fine;
|
|
|
|
// just want to make sure there are no lines.
|
2014-12-24 20:13:57 +00:00
|
|
|
expect(testDrawingObject.lines.length)
|
2014-12-12 20:56:26 +00:00
|
|
|
.toEqual(3);
|
2014-12-24 20:13:57 +00:00
|
|
|
// Make sure the right buffer was drawn to the
|
|
|
|
// right subplot.
|
|
|
|
testDrawingObject.lines.forEach(function (line, j) {
|
2015-04-17 23:42:15 +00:00
|
|
|
expect(line.buffer).toEqual(testBuffers[j].getBuffer());
|
2014-12-12 20:56:26 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tracks zoomed state of subplots", function () {
|
|
|
|
// Should start out unzoomed
|
|
|
|
expect(mode.isZoomed()).toBeFalsy();
|
|
|
|
|
|
|
|
// Trigger some zoom changes
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
|
|
|
|
// Second argument to the factory was pan-zoom stack
|
|
|
|
c.args[1].pushPanZoom([1, 2], [3, 4]);
|
|
|
|
});
|
2014-12-12 20:56:26 +00:00
|
|
|
|
|
|
|
// Should start out unzoomed
|
|
|
|
expect(mode.isZoomed()).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("supports unzooming", function () {
|
|
|
|
// Trigger some zoom changes
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
|
|
|
|
// Second argument to the factory was pan-zoom stack
|
|
|
|
c.args[1].pushPanZoom([1, 2], [3, 4]);
|
|
|
|
});
|
2014-12-12 20:56:26 +00:00
|
|
|
// Verify that we are indeed zoomed now
|
|
|
|
expect(mode.isZoomed()).toBeTruthy();
|
|
|
|
|
|
|
|
// Unzoom
|
|
|
|
mode.unzoom();
|
|
|
|
|
|
|
|
// Should no longer be zoomed
|
|
|
|
expect(mode.isZoomed()).toBeFalsy();
|
2014-12-12 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2014-12-12 20:56:26 +00:00
|
|
|
it("supports stepping back through zoom states", function () {
|
|
|
|
// Trigger some zoom changes
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
|
|
|
|
// Second argument to the factory was pan-zoom stack
|
|
|
|
c.args[1].pushPanZoom([1, 2], [3, 4]);
|
|
|
|
});
|
2014-12-12 20:56:26 +00:00
|
|
|
|
|
|
|
// Step back the same number of zoom changes
|
2016-03-04 20:56:14 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.calls.forEach(function () {
|
2014-12-12 20:56:26 +00:00
|
|
|
// Should still be zoomed at start of each iteration
|
|
|
|
expect(mode.isZoomed()).toBeTruthy();
|
2014-12-24 20:13:57 +00:00
|
|
|
// Step back one of the zoom changes.
|
2014-12-12 20:56:26 +00:00
|
|
|
mode.stepBackPanZoom();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Should no longer be zoomed
|
|
|
|
expect(mode.isZoomed()).toBeFalsy();
|
|
|
|
});
|
2014-12-12 17:44:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|