[Telemetry] Update plot specs

Update plot specs to reflect refactoring out of formatter
for telemetry values, WTD-599.
This commit is contained in:
Victor Woeltjen
2014-12-24 12:13:57 -08:00
parent f63038a83f
commit 78b636dafe
10 changed files with 184 additions and 36 deletions

View File

@ -20,6 +20,9 @@ define(
* which will be plotted in this sub-plot * which will be plotted in this sub-plot
* @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom * @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom
* states which is applicable to this sub-plot * states which is applicable to this sub-plot
* @param {TelemetryFormatter} telemetryFormatter the telemetry
* formatting service; used to convert domain/range values
* from telemetry data sets to a human-readable form.
*/ */
function SubPlot(telemetryObjects, panZoomStack, telemetryFormatter) { function SubPlot(telemetryObjects, panZoomStack, telemetryFormatter) {
// We are used from a template often, so maintain // We are used from a template often, so maintain

View File

@ -10,6 +10,7 @@ define(
describe("The plot controller", function () { describe("The plot controller", function () {
var mockScope, var mockScope,
mockFormatter,
mockTelemetry, // mock telemetry controller mockTelemetry, // mock telemetry controller
mockData, mockData,
mockDomainObject, mockDomainObject,
@ -22,6 +23,10 @@ define(
"$scope", "$scope",
[ "$watch", "$on" ] [ "$watch", "$on" ]
); );
mockFormatter = jasmine.createSpyObj(
"formatter",
[ "formatDomainValue", "formatRangeValue" ]
);
mockTelemetry = jasmine.createSpyObj( mockTelemetry = jasmine.createSpyObj(
"telemetry", "telemetry",
[ "getResponse", "getMetadata" ] [ "getResponse", "getMetadata" ]
@ -41,7 +46,7 @@ define(
mockData.getDomainValue.andCallFake(echo); mockData.getDomainValue.andCallFake(echo);
mockData.getRangeValue.andCallFake(echo); mockData.getRangeValue.andCallFake(echo);
controller = new PlotController(mockScope); controller = new PlotController(mockScope, mockFormatter);
}); });
it("listens for telemetry updates", function () { it("listens for telemetry updates", function () {

View File

@ -0,0 +1,47 @@
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
/**
* MergeModelsSpec. Created by vwoeltje on 11/6/14.
*/
define(
["../src/SubPlotFactory"],
function (SubPlotFactory) {
"use strict";
describe("The sub-plot factory", function () {
var mockDomainObject,
mockPanZoomStack,
mockFormatter,
factory;
beforeEach(function () {
mockDomainObject = jasmine.createSpyObj(
"domainObject",
[ "getId", "getModel", "getCapability" ]
);
mockPanZoomStack = jasmine.createSpyObj(
"panZoomStack",
[ "getPanZoom" ]
);
mockFormatter = jasmine.createSpyObj(
"formatter",
[ "formatDomainValue", "formatRangeValue" ]
);
mockPanZoomStack.getPanZoom.andReturn({
origin: [ 0, 0 ],
dimensions: [ 100, 100 ]
});
factory = new SubPlotFactory(mockFormatter);
});
it("creates sub-plots", function () {
expect(factory.createSubPlot(
[mockDomainObject],
mockPanZoomStack
).getTelemetryObjects()).toEqual([mockDomainObject]);
});
});
}
);

View File

@ -11,6 +11,7 @@ define(
describe("A sub-plot", function () { describe("A sub-plot", function () {
var mockDomainObject, var mockDomainObject,
mockPanZoomStack, mockPanZoomStack,
mockFormatter,
mockElement, mockElement,
testDomainObjects, testDomainObjects,
testOrigin, testOrigin,
@ -35,6 +36,10 @@ define(
"getDimensions" "getDimensions"
] ]
); );
mockFormatter = jasmine.createSpyObj(
"formatter",
[ "formatDomainValue", "formatRangeValue" ]
);
mockElement = jasmine.createSpyObj( mockElement = jasmine.createSpyObj(
"element", "element",
[ "getBoundingClientRect" ] [ "getBoundingClientRect" ]
@ -55,7 +60,8 @@ define(
subplot = new SubPlot( subplot = new SubPlot(
testDomainObjects, testDomainObjects,
mockPanZoomStack mockPanZoomStack,
mockFormatter
); );
}); });

View File

@ -9,18 +9,23 @@ define(
"use strict"; "use strict";
describe("Plot mode options", function () { describe("Plot mode options", function () {
var mockDomainObject; var mockDomainObject,
mockSubPlotFactory;
beforeEach(function () { beforeEach(function () {
mockDomainObject = jasmine.createSpyObj( mockDomainObject = jasmine.createSpyObj(
"domainObject", "domainObject",
[ "getId", "getModel", "getCapability" ] [ "getId", "getModel", "getCapability" ]
); );
mockSubPlotFactory = jasmine.createSpyObj(
"subPlotFactory",
[ "createSubPlot" ]
);
}); });
it("offers only one option when one object is present", function () { it("offers only one option when one object is present", function () {
expect( expect(
new PlotModeOptions([mockDomainObject]) new PlotModeOptions([mockDomainObject], mockSubPlotFactory)
.getModeOptions().length .getModeOptions().length
).toEqual(1); ).toEqual(1);
}); });
@ -33,7 +38,7 @@ define(
mockDomainObject mockDomainObject
]; ];
expect( expect(
new PlotModeOptions(objects) new PlotModeOptions(objects, mockSubPlotFactory)
.getModeOptions().length .getModeOptions().length
).toEqual(2); ).toEqual(2);
}); });
@ -44,7 +49,7 @@ define(
mockDomainObject, mockDomainObject,
mockDomainObject, mockDomainObject,
mockDomainObject mockDomainObject
]), ], mockSubPlotFactory),
initialHandler = plotModeOptions.getModeHandler(); initialHandler = plotModeOptions.getModeHandler();
// Change the mode // Change the mode

View File

@ -10,8 +10,11 @@ define(
describe("Overlaid plot mode", function () { describe("Overlaid plot mode", function () {
var mockDomainObject, var mockDomainObject,
mockSubPlotFactory,
mockSubPlot,
mockPrepared, mockPrepared,
testBuffers, testBuffers,
testDrawingObjects,
mode; mode;
function mockElement(x, y, w, h) { function mockElement(x, y, w, h) {
@ -22,10 +25,24 @@ define(
}; };
} }
function doZoom(subplot, i) { function createMockSubPlot() {
subplot.startMarquee({ target: mockElement() }); var mockSubPlot = jasmine.createSpyObj(
subplot.hover({ target: mockElement() }); "subPlot",
subplot.endMarquee({ target: mockElement() }); [
"setDomainOffset",
"hover",
"startMarquee",
"endMarquee",
"getDrawingObject",
"update"
]
),
testDrawingObject = {};
// Track drawing objects in order of creation
testDrawingObjects.push(testDrawingObject);
mockSubPlot.getDrawingObject.andReturn(testDrawingObject);
return mockSubPlot;
} }
beforeEach(function () { beforeEach(function () {
@ -33,12 +50,18 @@ define(
"domainObject", "domainObject",
[ "getId", "getModel", "getCapability" ] [ "getId", "getModel", "getCapability" ]
); );
mockSubPlotFactory = jasmine.createSpyObj(
"subPlotFactory",
[ "createSubPlot" ]
);
// Prepared telemetry data // Prepared telemetry data
mockPrepared = jasmine.createSpyObj( mockPrepared = jasmine.createSpyObj(
"prepared", "prepared",
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ]
); );
mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot);
// Act as if we have three buffers full of data // Act as if we have three buffers full of data
testBuffers = [["a"], ["b"], ["c"]]; testBuffers = [["a"], ["b"], ["c"]];
mockPrepared.getBuffers.andReturn(testBuffers); mockPrepared.getBuffers.andReturn(testBuffers);
@ -46,11 +69,14 @@ define(
mockPrepared.getOrigin.andReturn([10, 10]); mockPrepared.getOrigin.andReturn([10, 10]);
mockPrepared.getDimensions.andReturn([500, 500]); mockPrepared.getDimensions.andReturn([500, 500]);
// Clear out drawing objects
testDrawingObjects = [];
mode = new PlotOverlayMode([ mode = new PlotOverlayMode([
mockDomainObject, mockDomainObject,
mockDomainObject, mockDomainObject,
mockDomainObject mockDomainObject
]); ], mockSubPlotFactory);
}); });
it("creates one sub-plot for all domain objects", function () { it("creates one sub-plot for all domain objects", function () {
@ -68,14 +94,15 @@ define(
mode.plotTelemetry(mockPrepared); mode.plotTelemetry(mockPrepared);
// Should all each have one line // Should have one sub-plot with three lines
mode.getSubPlots().forEach(function (subplot, i) { testDrawingObjects.forEach(function (testDrawingObject, i) {
// Either empty list or undefined is fine; // Either empty list or undefined is fine;
// just want to make sure there are no lines. // just want to make sure there are no lines.
expect(subplot.getDrawingObject().lines.length) expect(testDrawingObject.lines.length)
.toEqual(3); .toEqual(3);
// Make sure all buffers were drawn, in order. // Make sure the right buffer was drawn to the
subplot.getDrawingObject().lines.forEach(function (line, j) { // right subplot.
testDrawingObject.lines.forEach(function (line, j) {
expect(line.buffer).toEqual(testBuffers[j]); expect(line.buffer).toEqual(testBuffers[j]);
}); });
}); });
@ -86,7 +113,10 @@ define(
expect(mode.isZoomed()).toBeFalsy(); expect(mode.isZoomed()).toBeFalsy();
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Should start out unzoomed // Should start out unzoomed
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
@ -94,8 +124,10 @@ define(
it("supports unzooming", function () { it("supports unzooming", function () {
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Verify that we are indeed zoomed now // Verify that we are indeed zoomed now
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
@ -108,12 +140,16 @@ define(
it("supports stepping back through zoom states", function () { it("supports stepping back through zoom states", function () {
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Step back the same number of zoom changes // Step back the same number of zoom changes
mode.getSubPlots().forEach(function (subplot, i) { mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Should still be zoomed at start of each iteration // Should still be zoomed at start of each iteration
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
// Step back one of the zoom changes.
mode.stepBackPanZoom(); mode.stepBackPanZoom();
}); });

View File

@ -10,8 +10,11 @@ define(
describe("Stacked plot mode", function () { describe("Stacked plot mode", function () {
var mockDomainObject, var mockDomainObject,
mockSubPlotFactory,
mockSubPlot,
mockPrepared, mockPrepared,
testBuffers, testBuffers,
testDrawingObjects,
mode; mode;
function mockElement(x, y, w, h) { function mockElement(x, y, w, h) {
@ -22,10 +25,24 @@ define(
}; };
} }
function doZoom(subplot, i) { function createMockSubPlot() {
subplot.startMarquee({ target: mockElement() }); var mockSubPlot = jasmine.createSpyObj(
subplot.hover({ target: mockElement() }); "subPlot",
subplot.endMarquee({ target: mockElement() }); [
"setDomainOffset",
"hover",
"startMarquee",
"endMarquee",
"getDrawingObject",
"update"
]
),
testDrawingObject = {};
// Track drawing objects in order of creation
testDrawingObjects.push(testDrawingObject);
mockSubPlot.getDrawingObject.andReturn(testDrawingObject);
return mockSubPlot;
} }
beforeEach(function () { beforeEach(function () {
@ -33,12 +50,18 @@ define(
"domainObject", "domainObject",
[ "getId", "getModel", "getCapability" ] [ "getId", "getModel", "getCapability" ]
); );
mockSubPlotFactory = jasmine.createSpyObj(
"subPlotFactory",
[ "createSubPlot" ]
);
// Prepared telemetry data // Prepared telemetry data
mockPrepared = jasmine.createSpyObj( mockPrepared = jasmine.createSpyObj(
"prepared", "prepared",
[ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ]
); );
mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot);
// Act as if we have three buffers full of data // Act as if we have three buffers full of data
testBuffers = [["a"], ["b"], ["c"]]; testBuffers = [["a"], ["b"], ["c"]];
mockPrepared.getBuffers.andReturn(testBuffers); mockPrepared.getBuffers.andReturn(testBuffers);
@ -46,11 +69,14 @@ define(
mockPrepared.getOrigin.andReturn([10, 10]); mockPrepared.getOrigin.andReturn([10, 10]);
mockPrepared.getDimensions.andReturn([500, 500]); mockPrepared.getDimensions.andReturn([500, 500]);
// Objects that will be drawn to in sub-plots
testDrawingObjects = [];
mode = new PlotStackMode([ mode = new PlotStackMode([
mockDomainObject, mockDomainObject,
mockDomainObject, mockDomainObject,
mockDomainObject mockDomainObject
]); ], mockSubPlotFactory);
}); });
it("creates one sub-plot per domain object", function () { it("creates one sub-plot per domain object", function () {
@ -69,14 +95,14 @@ define(
mode.plotTelemetry(mockPrepared); mode.plotTelemetry(mockPrepared);
// Should all each have one line // Should all each have one line
mode.getSubPlots().forEach(function (subplot, i) { testDrawingObjects.forEach(function (testDrawingObject, i) {
// Either empty list or undefined is fine; // Either empty list or undefined is fine;
// just want to make sure there are no lines. // just want to make sure there are no lines.
expect(subplot.getDrawingObject().lines.length) expect(testDrawingObject.lines.length)
.toEqual(1); .toEqual(1);
// Make sure the right buffer was drawn to the // Make sure the right buffer was drawn to the
// right subplot. // right subplot.
expect(subplot.getDrawingObject().lines[0].buffer) expect(testDrawingObject.lines[0].buffer)
.toEqual(testBuffers[i]); .toEqual(testBuffers[i]);
}); });
}); });
@ -86,7 +112,10 @@ define(
expect(mode.isZoomed()).toBeFalsy(); expect(mode.isZoomed()).toBeFalsy();
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Should start out unzoomed // Should start out unzoomed
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
@ -94,8 +123,10 @@ define(
it("supports unzooming", function () { it("supports unzooming", function () {
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Verify that we are indeed zoomed now // Verify that we are indeed zoomed now
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
@ -108,12 +139,16 @@ define(
it("supports stepping back through zoom states", function () { it("supports stepping back through zoom states", function () {
// Trigger some zoom changes // Trigger some zoom changes
mode.getSubPlots().forEach(doZoom); mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Second argument to the factory was pan-zoom stack
c.args[1].pushPanZoom([1, 2], [3, 4]);
});
// Step back the same number of zoom changes // Step back the same number of zoom changes
mode.getSubPlots().forEach(function (subplot, i) { mockSubPlotFactory.createSubPlot.calls.forEach(function (c) {
// Should still be zoomed at start of each iteration // Should still be zoomed at start of each iteration
expect(mode.isZoomed()).toBeTruthy(); expect(mode.isZoomed()).toBeTruthy();
// Step back
mode.stepBackPanZoom(); mode.stepBackPanZoom();
}); });

View File

@ -3,6 +3,7 @@
"MCTChart", "MCTChart",
"PlotController", "PlotController",
"SubPlot", "SubPlot",
"SubPlotFactory",
"elements/PlotAxis", "elements/PlotAxis",
"elements/PlotPalette", "elements/PlotPalette",
"elements/PlotPanZoomStack", "elements/PlotPanZoomStack",

View File

@ -11,6 +11,7 @@ define(
describe("A domain column", function () { describe("A domain column", function () {
var mockDataSet, var mockDataSet,
testMetadata, testMetadata,
mockFormatter,
column; column;
beforeEach(function () { beforeEach(function () {
@ -18,11 +19,15 @@ define(
"data", "data",
[ "getDomainValue" ] [ "getDomainValue" ]
); );
mockFormatter = jasmine.createSpyObj(
"formatter",
[ "formatDomainValue", "formatRangeValue" ]
);
testMetadata = { testMetadata = {
key: "testKey", key: "testKey",
name: "Test Name" name: "Test Name"
}; };
column = new DomainColumn(testMetadata); column = new DomainColumn(testMetadata, mockFormatter);
}); });
it("reports a column header from domain metadata", function () { it("reports a column header from domain metadata", function () {

View File

@ -11,6 +11,7 @@ define(
describe("A range column", function () { describe("A range column", function () {
var mockDataSet, var mockDataSet,
testMetadata, testMetadata,
mockFormatter,
column; column;
beforeEach(function () { beforeEach(function () {
@ -18,11 +19,15 @@ define(
"data", "data",
[ "getRangeValue" ] [ "getRangeValue" ]
); );
mockFormatter = jasmine.createSpyObj(
"formatter",
[ "formatDomainValue", "formatRangeValue" ]
);
testMetadata = { testMetadata = {
key: "testKey", key: "testKey",
name: "Test Name" name: "Test Name"
}; };
column = new RangeColumn(testMetadata); column = new RangeColumn(testMetadata, mockFormatter);
}); });
it("reports a column header from range metadata", function () { it("reports a column header from range metadata", function () {