From fdf61488115d010ccb5da8efaf93216f626e2696 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 9 Nov 2015 17:48:58 -0800 Subject: [PATCH] [Layout] Enforce minimum size on drop Addresses nasa/openmctweb#271, ensuring frames in a layout are not too tiny to use, even if the grid size is small. --- .../features/layout/src/LayoutController.js | 2 +- .../layout/test/LayoutControllerSpec.js | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js index 89364a1bb2..d7906dd0fa 100644 --- a/platform/features/layout/src/LayoutController.js +++ b/platform/features/layout/src/LayoutController.js @@ -113,7 +113,7 @@ define( Math.floor(position.x / self.gridSize[0]), Math.floor(position.y / self.gridSize[1]) ], - dimensions: DEFAULT_DIMENSIONS + dimensions: self.defaultDimensions() }; // Mark change as persistable if ($scope.commit) { diff --git a/platform/features/layout/test/LayoutControllerSpec.js b/platform/features/layout/test/LayoutControllerSpec.js index b0ab7a13fb..085f7766a2 100644 --- a/platform/features/layout/test/LayoutControllerSpec.js +++ b/platform/features/layout/test/LayoutControllerSpec.js @@ -192,6 +192,29 @@ define( expect(parseInt(styleB.width, 10)).toBeGreaterThan(63); expect(parseInt(styleB.width, 10)).toBeGreaterThan(31); }); + + it("ensures a minimum frame size on drop", function () { + var style; + + // Start with a very small frame size + testModel.layoutGrid = [ 1, 1 ]; + mockScope.$watch.calls[0].args[1](testModel.layoutGrid); + + // Notify that a drop occurred + testModel.composition.push('d'); + mockScope.$on.mostRecentCall.args[1]( + mockEvent, + 'd', + { x: 300, y: 100 } + ); + mockScope.$watch.calls[0].args[1](['d']); + + style = controller.getFrameStyle("d"); + + // Resulting size should still be reasonably large pixel-size + expect(parseInt(style.width, 10)).toBeGreaterThan(63); + expect(parseInt(style.height, 10)).toBeGreaterThan(31); + }); }); } );