From 7ea63fce8c160010ec831d88d54e0993b981cd20 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 12 Dec 2014 10:45:34 -0800 Subject: [PATCH] [Plot] Add specs for PlotPanZoomStackGroup Add specs to verify the behavior of PlotPanZoomStackGroup, which is responsible for synchronizing the domain axis between multiple sub-plots in a stacked plot view. WTD-625. --- .../src/elements/PlotPanZoomStackGroup.js | 2 +- .../elements/PlotPanZoomStackGroupSpec.js | 95 ++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/platform/features/plot/src/elements/PlotPanZoomStackGroup.js b/platform/features/plot/src/elements/PlotPanZoomStackGroup.js index b10ec2723a..385f54ee9a 100644 --- a/platform/features/plot/src/elements/PlotPanZoomStackGroup.js +++ b/platform/features/plot/src/elements/PlotPanZoomStackGroup.js @@ -38,7 +38,7 @@ define( function clearPanZoom() { stacks.forEach(function (stack) { - stack.popPanZoom(); + stack.clearPanZoom(); }); } diff --git a/platform/features/plot/test/elements/PlotPanZoomStackGroupSpec.js b/platform/features/plot/test/elements/PlotPanZoomStackGroupSpec.js index f28fcaa098..ff9b32e506 100644 --- a/platform/features/plot/test/elements/PlotPanZoomStackGroupSpec.js +++ b/platform/features/plot/test/elements/PlotPanZoomStackGroupSpec.js @@ -5,10 +5,103 @@ */ define( ["../../src/elements/PlotPanZoomStackGroup"], - function (PlotController) { + function (PlotPanZoomStackGroup) { "use strict"; + var COUNT = 8; + describe("A plot pan-zoom stack group", function () { + var stacks, + group; + + beforeEach(function () { + group = new PlotPanZoomStackGroup(COUNT); + stacks = []; + while (stacks.length < COUNT) { + stacks.push(group.getPanZoomStack(stacks.length)); + } + }); + + it("creates a number of separate stacks", function () { + expect(group.getPanZoomStack(0)).toBeDefined(); + expect(group.getPanZoomStack(COUNT - 1)).toBeDefined(); + expect(group.getPanZoomStack(COUNT)).toBeUndefined(); + }); + + it("synchronizes pan-zoom stack depth", function () { + expect(group.getDepth()).toEqual(1); + group.getPanZoomStack(1).pushPanZoom([ 10, 20 ], [ 30, 40 ]); + stacks.forEach(function (stack) { + expect(stack.getDepth()).toEqual(2); + }); + }); + + it("synchronizes domain but not range", function () { + // Set up different initial states + stacks.forEach(function (stack, i) { + stack.pushPanZoom([ i, i ], [ i, i ]); + }); + + // Push a new pan-zoom state onto one of the stacks + group.getPanZoomStack(1).pushPanZoom([ 99, 99 ], [ 42, 42 ]); + + // Should changed domain values for all stacks, but + // only changed range values for stack 1 + stacks.forEach(function (stack, i) { + expect(stack.getOrigin()) + .toEqual([99, i === 1 ? 99 : i]); + expect(stack.getDimensions()) + .toEqual([42, i === 1 ? 42 : i]); + }); + }); + + it("synchronizes base pan-zoom", function () { + group.setBasePanZoom([10, 9], [8, 7]); + stacks.forEach(function (stack) { + expect(stack.getOrigin()).toEqual([10, 9]); + expect(stack.getDimensions()).toEqual([8, 7]); + }); + }); + + it("clears pan-zoom on request", function () { + // Set up different initial states + stacks.forEach(function (stack, i) { + stack.pushPanZoom([ i, i ], [ i, i ]); + }); + + // Verify that we have a greater depth + expect(group.getDepth() > 1).toBeTruthy(); + + // Clear the pan-zoom state + group.clearPanZoom(); + + // Should be back down to our initial state + expect(group.getDepth()).toEqual(1); + stacks.forEach(function (stack) { + expect(stack.getDepth()).toEqual(1); + }); + }); + + it("pops pan-zoom on request", function () { + // Set up different initial states + stacks.forEach(function (stack, i) { + stack.pushPanZoom([ i, i ], [ i, i ]); + }); + + // Verify that we have a greater depth + expect(group.getDepth()).toEqual(COUNT + 1); + + // Clear the pan-zoom state + group.popPanZoom(); + + // Should be back down to our initial state + expect(group.getDepth()).toEqual(COUNT); + stacks.forEach(function (stack) { + expect(stack.getDepth()).toEqual(COUNT); + }); + }); + + }); } ); \ No newline at end of file