2014-12-12 17:44:05 +00:00
|
|
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../../src/modes/PlotStackMode"],
|
|
|
|
function (PlotStackMode) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
describe("Stacked plot mode", function () {
|
2014-12-12 20:56:26 +00:00
|
|
|
var mockDomainObject,
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory,
|
|
|
|
mockSubPlot,
|
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-12 20:56:26 +00:00
|
|
|
function mockElement(x, y, w, h) {
|
|
|
|
return {
|
|
|
|
getBoundingClientRect: function () {
|
|
|
|
return { left: x, top: y, width: w, height: h };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-01-29 20:34:58 +00:00
|
|
|
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers", "getLength" ]
|
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
|
|
|
|
testBuffers = [["a"], ["b"], ["c"]];
|
|
|
|
mockPrepared.getBuffers.andReturn(testBuffers);
|
|
|
|
mockPrepared.getDomainOffset.andReturn(1234);
|
|
|
|
mockPrepared.getOrigin.andReturn([10, 10]);
|
|
|
|
mockPrepared.getDimensions.andReturn([500, 500]);
|
2015-01-29 20:34:58 +00:00
|
|
|
mockPrepared.getLength.andReturn(3);
|
2014-12-12 20:56:26 +00:00
|
|
|
|
2014-12-24 20:13:57 +00:00
|
|
|
// Objects that will be drawn to in sub-plots
|
|
|
|
testDrawingObjects = [];
|
|
|
|
|
2014-12-12 20:56:26 +00:00
|
|
|
mode = new PlotStackMode([
|
|
|
|
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 per domain object", function () {
|
|
|
|
expect(mode.getSubPlots().length).toEqual(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Should all each have one line
|
2014-12-24 20:13:57 +00:00
|
|
|
testDrawingObjects.forEach(function (testDrawingObject, i) {
|
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(1);
|
|
|
|
// Make sure the right buffer was drawn to the
|
|
|
|
// right subplot.
|
2014-12-24 20:13:57 +00:00
|
|
|
expect(testDrawingObject.lines[0].buffer)
|
2014-12-12 20:56:26 +00:00
|
|
|
.toEqual(testBuffers[i]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
2014-12-24 20:13:57 +00:00
|
|
|
mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
|
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
|
2014-12-12 20:56:26 +00:00
|
|
|
mode.stepBackPanZoom();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Should no longer be zoomed
|
|
|
|
expect(mode.isZoomed()).toBeFalsy();
|
2014-12-12 17:49:44 +00:00
|
|
|
});
|
|
|
|
|
2014-12-12 17:44:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|