From a2d22a4558cff97ce5bad0d3e4a4e74d82b5029e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 12 Dec 2014 10:08:58 -0800 Subject: [PATCH] [Plot] Restore coverage on PlotController Restore full test coverage on PlotController after refactoring for WTD-625, stacked plots. --- .../features/plot/test/PlotControllerSpec.js | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/platform/features/plot/test/PlotControllerSpec.js b/platform/features/plot/test/PlotControllerSpec.js index e323977492..0b96dcc176 100644 --- a/platform/features/plot/test/PlotControllerSpec.js +++ b/platform/features/plot/test/PlotControllerSpec.js @@ -13,6 +13,7 @@ define( mockTelemetry, // mock telemetry controller mockData, mockElement, + mockDomainObject, controller; function echo(i) { return i; } @@ -34,6 +35,10 @@ define( "element", [ "getBoundingClientRect" ] ); + mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getModel", "getCapability" ] + ); mockScope.telemetry = mockTelemetry; mockTelemetry.getResponse.andReturn([mockData]); @@ -76,8 +81,82 @@ define( // Just want to not have an exception }); + it("draws lines when data becomes available", function () { + // Verify precondition + controller.getSubPlots().forEach(function (subplot) { + expect(subplot.getDrawingObject().lines) + .not.toBeDefined(); + }); + + // Make sure there actually are subplots being verified + expect(controller.getSubPlots().length > 0) + .toBeTruthy(); + + // Broadcast data + mockScope.$on.mostRecentCall.args[1](); + + controller.getSubPlots().forEach(function (subplot) { + expect(subplot.getDrawingObject().lines) + .toBeDefined(); + }); + }); + it("changes modes depending on number of objects", function () { + var expectedWatch = "telemetry.getTelemetryObjects()", + watchFunction; + + // Find the watch for telemetry objects, which + // should change plot mode options + mockScope.$watch.calls.forEach(function (call) { + if (call.args[0] === expectedWatch) { + watchFunction = call.args[1]; + } + }); + + watchFunction([mockDomainObject]); + expect(controller.getModeOptions().length).toEqual(1); + + watchFunction([ + mockDomainObject, + mockDomainObject, + mockDomainObject + ]); + expect(controller.getModeOptions().length).toEqual(2); + }); + + // Interface tests follow; these will be delegated (mostly + // to PlotModeOptions, which is tested separately). + it("provides access to available plot mode options", function () { + expect(Array.isArray(controller.getModeOptions())) + .toBeTruthy(); + }); + + it("provides a current plot mode", function () { + expect(controller.getMode().name) + .toEqual(jasmine.any(String)); + }); + + it("allows plot mode to be changed", function () { + expect(function () { + controller.setMode(controller.getMode()); + }).not.toThrow(); + }); + + it("provides an array of sub-plots", function () { + expect(Array.isArray(controller.getSubPlots())) + .toBeTruthy(); + }); + + it("allows plots to be updated", function () { + expect(controller.update).not.toThrow(); + }); + + it("allows changing pan-zoom state", function () { + expect(controller.isZoomed).not.toThrow(); + expect(controller.stepBackPanZoom).not.toThrow(); + expect(controller.unzoom).not.toThrow(); + }); }); } ); \ No newline at end of file