From 78b636dafe039986f841b60d3ed979f6537c9fbc Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 24 Dec 2014 12:13:57 -0800 Subject: [PATCH] [Telemetry] Update plot specs Update plot specs to reflect refactoring out of formatter for telemetry values, WTD-599. --- platform/features/plot/src/SubPlot.js | 3 + .../features/plot/test/PlotControllerSpec.js | 7 +- .../features/plot/test/SubPlotFactorySpec.js | 47 +++++++++++++ platform/features/plot/test/SubPlotSpec.js | 8 ++- .../plot/test/modes/PlotModeOptionsSpec.js | 13 ++-- .../plot/test/modes/PlotOverlayModeSpec.js | 66 ++++++++++++++----- .../plot/test/modes/PlotStackModeSpec.js | 61 +++++++++++++---- platform/features/plot/test/suite.json | 1 + .../scrolling/test/DomainColumnSpec.js | 7 +- .../scrolling/test/RangeColumnSpec.js | 7 +- 10 files changed, 184 insertions(+), 36 deletions(-) create mode 100644 platform/features/plot/test/SubPlotFactorySpec.js diff --git a/platform/features/plot/src/SubPlot.js b/platform/features/plot/src/SubPlot.js index c99ebcc187..18ea559d40 100644 --- a/platform/features/plot/src/SubPlot.js +++ b/platform/features/plot/src/SubPlot.js @@ -20,6 +20,9 @@ define( * which will be plotted in this sub-plot * @param {PlotPanZoomStack} panZoomStack the stack of pan-zoom * 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) { // We are used from a template often, so maintain diff --git a/platform/features/plot/test/PlotControllerSpec.js b/platform/features/plot/test/PlotControllerSpec.js index 15edec51be..c5c7d45005 100644 --- a/platform/features/plot/test/PlotControllerSpec.js +++ b/platform/features/plot/test/PlotControllerSpec.js @@ -10,6 +10,7 @@ define( describe("The plot controller", function () { var mockScope, + mockFormatter, mockTelemetry, // mock telemetry controller mockData, mockDomainObject, @@ -22,6 +23,10 @@ define( "$scope", [ "$watch", "$on" ] ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); mockTelemetry = jasmine.createSpyObj( "telemetry", [ "getResponse", "getMetadata" ] @@ -41,7 +46,7 @@ define( mockData.getDomainValue.andCallFake(echo); mockData.getRangeValue.andCallFake(echo); - controller = new PlotController(mockScope); + controller = new PlotController(mockScope, mockFormatter); }); it("listens for telemetry updates", function () { diff --git a/platform/features/plot/test/SubPlotFactorySpec.js b/platform/features/plot/test/SubPlotFactorySpec.js new file mode 100644 index 0000000000..2e96c424c1 --- /dev/null +++ b/platform/features/plot/test/SubPlotFactorySpec.js @@ -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]); + }); + }); + } +); \ No newline at end of file diff --git a/platform/features/plot/test/SubPlotSpec.js b/platform/features/plot/test/SubPlotSpec.js index 5f5393f433..0cd81681c0 100644 --- a/platform/features/plot/test/SubPlotSpec.js +++ b/platform/features/plot/test/SubPlotSpec.js @@ -11,6 +11,7 @@ define( describe("A sub-plot", function () { var mockDomainObject, mockPanZoomStack, + mockFormatter, mockElement, testDomainObjects, testOrigin, @@ -35,6 +36,10 @@ define( "getDimensions" ] ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); mockElement = jasmine.createSpyObj( "element", [ "getBoundingClientRect" ] @@ -55,7 +60,8 @@ define( subplot = new SubPlot( testDomainObjects, - mockPanZoomStack + mockPanZoomStack, + mockFormatter ); }); diff --git a/platform/features/plot/test/modes/PlotModeOptionsSpec.js b/platform/features/plot/test/modes/PlotModeOptionsSpec.js index 99c9f3b0b3..39f04ccf5c 100644 --- a/platform/features/plot/test/modes/PlotModeOptionsSpec.js +++ b/platform/features/plot/test/modes/PlotModeOptionsSpec.js @@ -9,18 +9,23 @@ define( "use strict"; describe("Plot mode options", function () { - var mockDomainObject; + var mockDomainObject, + mockSubPlotFactory; beforeEach(function () { mockDomainObject = jasmine.createSpyObj( "domainObject", [ "getId", "getModel", "getCapability" ] ); + mockSubPlotFactory = jasmine.createSpyObj( + "subPlotFactory", + [ "createSubPlot" ] + ); }); it("offers only one option when one object is present", function () { expect( - new PlotModeOptions([mockDomainObject]) + new PlotModeOptions([mockDomainObject], mockSubPlotFactory) .getModeOptions().length ).toEqual(1); }); @@ -33,7 +38,7 @@ define( mockDomainObject ]; expect( - new PlotModeOptions(objects) + new PlotModeOptions(objects, mockSubPlotFactory) .getModeOptions().length ).toEqual(2); }); @@ -44,7 +49,7 @@ define( mockDomainObject, mockDomainObject, mockDomainObject - ]), + ], mockSubPlotFactory), initialHandler = plotModeOptions.getModeHandler(); // Change the mode diff --git a/platform/features/plot/test/modes/PlotOverlayModeSpec.js b/platform/features/plot/test/modes/PlotOverlayModeSpec.js index adf87a78e3..30a29ab1e3 100644 --- a/platform/features/plot/test/modes/PlotOverlayModeSpec.js +++ b/platform/features/plot/test/modes/PlotOverlayModeSpec.js @@ -10,8 +10,11 @@ define( describe("Overlaid plot mode", function () { var mockDomainObject, + mockSubPlotFactory, + mockSubPlot, mockPrepared, testBuffers, + testDrawingObjects, mode; function mockElement(x, y, w, h) { @@ -22,10 +25,24 @@ define( }; } - function doZoom(subplot, i) { - subplot.startMarquee({ target: mockElement() }); - subplot.hover({ target: mockElement() }); - subplot.endMarquee({ target: mockElement() }); + 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; } beforeEach(function () { @@ -33,12 +50,18 @@ define( "domainObject", [ "getId", "getModel", "getCapability" ] ); + mockSubPlotFactory = jasmine.createSpyObj( + "subPlotFactory", + [ "createSubPlot" ] + ); // Prepared telemetry data mockPrepared = jasmine.createSpyObj( "prepared", [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] ); + mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot); + // Act as if we have three buffers full of data testBuffers = [["a"], ["b"], ["c"]]; mockPrepared.getBuffers.andReturn(testBuffers); @@ -46,11 +69,14 @@ define( mockPrepared.getOrigin.andReturn([10, 10]); mockPrepared.getDimensions.andReturn([500, 500]); + // Clear out drawing objects + testDrawingObjects = []; + mode = new PlotOverlayMode([ mockDomainObject, mockDomainObject, mockDomainObject - ]); + ], mockSubPlotFactory); }); it("creates one sub-plot for all domain objects", function () { @@ -68,14 +94,15 @@ define( mode.plotTelemetry(mockPrepared); - // Should all each have one line - mode.getSubPlots().forEach(function (subplot, i) { + // Should have one sub-plot with three lines + testDrawingObjects.forEach(function (testDrawingObject, i) { // Either empty list or undefined is fine; // just want to make sure there are no lines. - expect(subplot.getDrawingObject().lines.length) + expect(testDrawingObject.lines.length) .toEqual(3); - // Make sure all buffers were drawn, in order. - subplot.getDrawingObject().lines.forEach(function (line, j) { + // Make sure the right buffer was drawn to the + // right subplot. + testDrawingObject.lines.forEach(function (line, j) { expect(line.buffer).toEqual(testBuffers[j]); }); }); @@ -86,7 +113,10 @@ define( expect(mode.isZoomed()).toBeFalsy(); // 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 expect(mode.isZoomed()).toBeTruthy(); @@ -94,8 +124,10 @@ define( it("supports unzooming", function () { // 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 expect(mode.isZoomed()).toBeTruthy(); @@ -108,12 +140,16 @@ define( it("supports stepping back through zoom states", function () { // 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 - mode.getSubPlots().forEach(function (subplot, i) { + mockSubPlotFactory.createSubPlot.calls.forEach(function (c) { // Should still be zoomed at start of each iteration expect(mode.isZoomed()).toBeTruthy(); + // Step back one of the zoom changes. mode.stepBackPanZoom(); }); diff --git a/platform/features/plot/test/modes/PlotStackModeSpec.js b/platform/features/plot/test/modes/PlotStackModeSpec.js index c0b81bde8c..c44cd8c8a3 100644 --- a/platform/features/plot/test/modes/PlotStackModeSpec.js +++ b/platform/features/plot/test/modes/PlotStackModeSpec.js @@ -10,8 +10,11 @@ define( describe("Stacked plot mode", function () { var mockDomainObject, + mockSubPlotFactory, + mockSubPlot, mockPrepared, testBuffers, + testDrawingObjects, mode; function mockElement(x, y, w, h) { @@ -22,10 +25,24 @@ define( }; } - function doZoom(subplot, i) { - subplot.startMarquee({ target: mockElement() }); - subplot.hover({ target: mockElement() }); - subplot.endMarquee({ target: mockElement() }); + 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; } beforeEach(function () { @@ -33,12 +50,18 @@ define( "domainObject", [ "getId", "getModel", "getCapability" ] ); + mockSubPlotFactory = jasmine.createSpyObj( + "subPlotFactory", + [ "createSubPlot" ] + ); // Prepared telemetry data mockPrepared = jasmine.createSpyObj( "prepared", [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] ); + mockSubPlotFactory.createSubPlot.andCallFake(createMockSubPlot); + // Act as if we have three buffers full of data testBuffers = [["a"], ["b"], ["c"]]; mockPrepared.getBuffers.andReturn(testBuffers); @@ -46,11 +69,14 @@ define( mockPrepared.getOrigin.andReturn([10, 10]); mockPrepared.getDimensions.andReturn([500, 500]); + // Objects that will be drawn to in sub-plots + testDrawingObjects = []; + mode = new PlotStackMode([ mockDomainObject, mockDomainObject, mockDomainObject - ]); + ], mockSubPlotFactory); }); it("creates one sub-plot per domain object", function () { @@ -69,14 +95,14 @@ define( mode.plotTelemetry(mockPrepared); // Should all each have one line - mode.getSubPlots().forEach(function (subplot, i) { + testDrawingObjects.forEach(function (testDrawingObject, i) { // Either empty list or undefined is fine; // just want to make sure there are no lines. - expect(subplot.getDrawingObject().lines.length) + expect(testDrawingObject.lines.length) .toEqual(1); // Make sure the right buffer was drawn to the // right subplot. - expect(subplot.getDrawingObject().lines[0].buffer) + expect(testDrawingObject.lines[0].buffer) .toEqual(testBuffers[i]); }); }); @@ -86,7 +112,10 @@ define( expect(mode.isZoomed()).toBeFalsy(); // 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 expect(mode.isZoomed()).toBeTruthy(); @@ -94,8 +123,10 @@ define( it("supports unzooming", function () { // 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 expect(mode.isZoomed()).toBeTruthy(); @@ -108,12 +139,16 @@ define( it("supports stepping back through zoom states", function () { // 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 - mode.getSubPlots().forEach(function (subplot, i) { + mockSubPlotFactory.createSubPlot.calls.forEach(function (c) { // Should still be zoomed at start of each iteration expect(mode.isZoomed()).toBeTruthy(); + // Step back mode.stepBackPanZoom(); }); diff --git a/platform/features/plot/test/suite.json b/platform/features/plot/test/suite.json index 077965efa6..7528ce7869 100644 --- a/platform/features/plot/test/suite.json +++ b/platform/features/plot/test/suite.json @@ -3,6 +3,7 @@ "MCTChart", "PlotController", "SubPlot", + "SubPlotFactory", "elements/PlotAxis", "elements/PlotPalette", "elements/PlotPanZoomStack", diff --git a/platform/features/scrolling/test/DomainColumnSpec.js b/platform/features/scrolling/test/DomainColumnSpec.js index 9fe38779e1..a7ee1b6589 100644 --- a/platform/features/scrolling/test/DomainColumnSpec.js +++ b/platform/features/scrolling/test/DomainColumnSpec.js @@ -11,6 +11,7 @@ define( describe("A domain column", function () { var mockDataSet, testMetadata, + mockFormatter, column; beforeEach(function () { @@ -18,11 +19,15 @@ define( "data", [ "getDomainValue" ] ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); testMetadata = { key: "testKey", name: "Test Name" }; - column = new DomainColumn(testMetadata); + column = new DomainColumn(testMetadata, mockFormatter); }); it("reports a column header from domain metadata", function () { diff --git a/platform/features/scrolling/test/RangeColumnSpec.js b/platform/features/scrolling/test/RangeColumnSpec.js index efb262420a..a3fe4832e4 100644 --- a/platform/features/scrolling/test/RangeColumnSpec.js +++ b/platform/features/scrolling/test/RangeColumnSpec.js @@ -11,6 +11,7 @@ define( describe("A range column", function () { var mockDataSet, testMetadata, + mockFormatter, column; beforeEach(function () { @@ -18,11 +19,15 @@ define( "data", [ "getRangeValue" ] ); + mockFormatter = jasmine.createSpyObj( + "formatter", + [ "formatDomainValue", "formatRangeValue" ] + ); testMetadata = { key: "testKey", name: "Test Name" }; - column = new RangeColumn(testMetadata); + column = new RangeColumn(testMetadata, mockFormatter); }); it("reports a column header from range metadata", function () {