diff --git a/platform/features/plot/test/PlotControllerSpec.js b/platform/features/plot/test/PlotControllerSpec.js index 0b96dcc176..15edec51be 100644 --- a/platform/features/plot/test/PlotControllerSpec.js +++ b/platform/features/plot/test/PlotControllerSpec.js @@ -12,7 +12,6 @@ define( var mockScope, mockTelemetry, // mock telemetry controller mockData, - mockElement, mockDomainObject, controller; @@ -31,10 +30,6 @@ define( "data", [ "getPointCount", "getDomainValue", "getRangeValue" ] ); - mockElement = jasmine.createSpyObj( - "element", - [ "getBoundingClientRect" ] - ); mockDomainObject = jasmine.createSpyObj( "domainObject", [ "getId", "getModel", "getCapability" ] @@ -45,12 +40,6 @@ define( mockData.getPointCount.andReturn(2); mockData.getDomainValue.andCallFake(echo); mockData.getRangeValue.andCallFake(echo); - mockElement.getBoundingClientRect.andReturn({ - left: 0, - top: 0, - width: 100, - height: 100 - }); controller = new PlotController(mockScope); }); diff --git a/platform/features/plot/test/modes/PlotOverlayModeSpec.js b/platform/features/plot/test/modes/PlotOverlayModeSpec.js index e0964693eb..adf87a78e3 100644 --- a/platform/features/plot/test/modes/PlotOverlayModeSpec.js +++ b/platform/features/plot/test/modes/PlotOverlayModeSpec.js @@ -9,16 +9,117 @@ define( "use strict"; describe("Overlaid plot mode", function () { - var testDrawingObject; + var mockDomainObject, + mockPrepared, + testBuffers, + mode; + function mockElement(x, y, w, h) { + return { + getBoundingClientRect: function () { + return { left: x, top: y, width: w, height: h }; + } + }; + } - it("draws all lines to one subplot", function () { + function doZoom(subplot, i) { + subplot.startMarquee({ target: mockElement() }); + subplot.hover({ target: mockElement() }); + subplot.endMarquee({ target: mockElement() }); + } - // Should have put some lines in the drawing scope, - // which the template should pass along to the renderer - //expect(testDrawingObject.lines).toBeDefined(); + beforeEach(function () { + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel", "getCapability" ] + ); + // Prepared telemetry data + mockPrepared = jasmine.createSpyObj( + "prepared", + [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] + ); + + // 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]); + + mode = new PlotOverlayMode([ + mockDomainObject, + mockDomainObject, + mockDomainObject + ]); }); + 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); + + // Should all each have one line + mode.getSubPlots().forEach(function (subplot, i) { + // Either empty list or undefined is fine; + // just want to make sure there are no lines. + expect(subplot.getDrawingObject().lines.length) + .toEqual(3); + // Make sure all buffers were drawn, in order. + subplot.getDrawingObject().lines.forEach(function (line, j) { + expect(line.buffer).toEqual(testBuffers[j]); + }); + }); + }); + + it("tracks zoomed state of subplots", function () { + // Should start out unzoomed + expect(mode.isZoomed()).toBeFalsy(); + + // Trigger some zoom changes + mode.getSubPlots().forEach(doZoom); + + // Should start out unzoomed + expect(mode.isZoomed()).toBeTruthy(); + }); + + it("supports unzooming", function () { + // Trigger some zoom changes + mode.getSubPlots().forEach(doZoom); + + // 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 + mode.getSubPlots().forEach(doZoom); + + // Step back the same number of zoom changes + mode.getSubPlots().forEach(function (subplot, i) { + // Should still be zoomed at start of each iteration + expect(mode.isZoomed()).toBeTruthy(); + mode.stepBackPanZoom(); + }); + + // Should no longer be zoomed + expect(mode.isZoomed()).toBeFalsy(); + }); }); } ); \ No newline at end of file diff --git a/platform/features/plot/test/modes/PlotStackModeSpec.js b/platform/features/plot/test/modes/PlotStackModeSpec.js index 1758f92714..c0b81bde8c 100644 --- a/platform/features/plot/test/modes/PlotStackModeSpec.js +++ b/platform/features/plot/test/modes/PlotStackModeSpec.js @@ -9,13 +9,116 @@ define( "use strict"; describe("Stacked plot mode", function () { - var testDrawingObject; + var mockDomainObject, + mockPrepared, + testBuffers, + mode; - it("draws all lines to one subplot", function () { + function mockElement(x, y, w, h) { + return { + getBoundingClientRect: function () { + return { left: x, top: y, width: w, height: h }; + } + }; + } - // Should have put some lines in the drawing scope, - // which the template should pass along to the renderer - //expect(testDrawingObject.lines).toBeDefined(); + function doZoom(subplot, i) { + subplot.startMarquee({ target: mockElement() }); + subplot.hover({ target: mockElement() }); + subplot.endMarquee({ target: mockElement() }); + } + + beforeEach(function () { + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel", "getCapability" ] + ); + // Prepared telemetry data + mockPrepared = jasmine.createSpyObj( + "prepared", + [ "getDomainOffset", "getOrigin", "getDimensions", "getBuffers" ] + ); + + // 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]); + + mode = new PlotStackMode([ + mockDomainObject, + mockDomainObject, + mockDomainObject + ]); + }); + + 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 + mode.getSubPlots().forEach(function (subplot, i) { + // Either empty list or undefined is fine; + // just want to make sure there are no lines. + expect(subplot.getDrawingObject().lines.length) + .toEqual(1); + // Make sure the right buffer was drawn to the + // right subplot. + expect(subplot.getDrawingObject().lines[0].buffer) + .toEqual(testBuffers[i]); + }); + }); + + it("tracks zoomed state of subplots", function () { + // Should start out unzoomed + expect(mode.isZoomed()).toBeFalsy(); + + // Trigger some zoom changes + mode.getSubPlots().forEach(doZoom); + + // Should start out unzoomed + expect(mode.isZoomed()).toBeTruthy(); + }); + + it("supports unzooming", function () { + // Trigger some zoom changes + mode.getSubPlots().forEach(doZoom); + + // 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 + mode.getSubPlots().forEach(doZoom); + + // Step back the same number of zoom changes + mode.getSubPlots().forEach(function (subplot, i) { + // Should still be zoomed at start of each iteration + expect(mode.isZoomed()).toBeTruthy(); + mode.stepBackPanZoom(); + }); + + // Should no longer be zoomed + expect(mode.isZoomed()).toBeFalsy(); }); });