From e11ec48ed3552ee200d98714bcccc05da0301e05 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 11 Apr 2018 13:35:54 -0700 Subject: [PATCH] Break tests out into individual cases --- tests/jsunit/metrics_test.js | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/tests/jsunit/metrics_test.js b/tests/jsunit/metrics_test.js index c16ca90ad..30cd11af3 100644 --- a/tests/jsunit/metrics_test.js +++ b/tests/jsunit/metrics_test.js @@ -40,7 +40,7 @@ function makeMockWs(scale, x, y, width, height) { y: y } }, - scale: 1 + scale: scale }; } @@ -49,17 +49,19 @@ var test_GetContentDimensionsExact_empty = function() { var ws = makeMockWs(1, 0, 0, 0, 0) var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); assertDimensionsMatch(defaultZoom, 0, 0, 0, 0); +} - // zoom in. - ws.scale = 2; +var test_GetContentDimensionsExact_emptyZoomIn = function() { + var ws = makeMockWs(2, 0, 0, 0, 0) var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); assertDimensionsMatch(zoomIn, 0, 0, 0, 0); +} - // zoom out. - ws.scale = .5; +var test_GetContentDimensionsExact_emptyZoomOut = function() { + var ws = makeMockWs(.5, 0, 0, 0, 0) var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); assertDimensionsMatch(zoomOut, 0, 0, 0, 0); -}; +} // Non-empty workspace, with top-left corner at ws origin. var test_GetContentDimensionsExact_nonEmptyAtOrigin = function() { @@ -67,19 +69,21 @@ var test_GetContentDimensionsExact_nonEmptyAtOrigin = function() { var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // Pixel and ws units are the same at default zoom. assertDimensionsMatch(defaultZoom, 0, 0, 100, 100); +} - // zoom in. - ws.scale = 2; +var test_GetContentDimensionsExact_nonEmptyAtOriginZoomIn = function() { + var ws = makeMockWs(2, 0, 0, 100, 100) var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 2 pixels at this zoom level. assertDimensionsMatch(zoomIn, 0, 0, 200, 200); +} - // zoom out. - ws.scale = .5; +var test_GetContentDimensionsExact_nonEmptyAtOriginZoomOut = function() { + var ws = makeMockWs(.5, 0, 0, 100, 100) var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 0.5 pixels at this zoom level. assertDimensionsMatch(zoomOut, 0, 0, 50, 50); -}; +} // Non-empty workspace, with top-left corner in positive ws coordinates. var test_GetContentDimensionsExact_nonEmptyPositiveOrigin = function() { @@ -87,21 +91,22 @@ var test_GetContentDimensionsExact_nonEmptyPositiveOrigin = function() { var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // Pixel and ws units are the same at default zoom. assertDimensionsMatch(defaultZoom, 10, 10, 100, 100); +} - // Changing zoom will change both width/height and origin location in pixels. - - // zoom in. - ws.scale = 2; +// Changing zoom will change both width/height and origin location in pixels. +var test_GetContentDimensionsExact_nonEmptyPositiveOriginZoomIn = function() { + var ws = makeMockWs(2, 10, 10, 100, 100) var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 2 pixels at this zoom level. assertDimensionsMatch(zoomIn, 20, 20, 200, 200); +} - // zoom out. - ws.scale = .5; +var test_GetContentDimensionsExact_nonEmptyPositiveOriginZoomOut = function() { + var ws = makeMockWs(.5, 10, 10, 100, 100) var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 0.5 pixels at this zoom level. assertDimensionsMatch(zoomOut, 5, 5, 50, 50); -}; +} // Non-empty workspace, with top-left corner in negative ws coordinates. var test_GetContentDimensionsExact_nonEmptyNegativeOrigin = function() { @@ -109,19 +114,19 @@ var test_GetContentDimensionsExact_nonEmptyNegativeOrigin = function() { var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // Pixel and ws units are the same at default zoom. assertDimensionsMatch(defaultZoom, -10, -10, 100, 100); +} - // Changing zoom will change both width/height and origin location in pixels. - - // zoom in. - ws.scale = 2; +// Changing zoom will change both width/height and origin location in pixels. +var test_GetContentDimensionsExact_nonEmptyNegativeOriginZoomIn = function() { + var ws = makeMockWs(2, -10, -10, 100, 100) var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 2 pixels at this zoom level. assertDimensionsMatch(zoomIn, -20, -20, 200, 200); +} - // zoom out. - ws.scale = .5; +var test_GetContentDimensionsExact_nonEmptyNegativeOriginZoomOut = function() { + var ws = makeMockWs(.5, -10, -10, 100, 100) var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); // 1 ws unit = 0.5 pixels at this zoom level. assertDimensionsMatch(zoomOut, -5, -5, 50, 50); -}; - +}