From 3d3f4dbee5a90ed8239b378adb056134df47b019 Mon Sep 17 00:00:00 2001 From: nein09 Date: Thu, 15 Jan 2015 12:36:01 -0800 Subject: [PATCH] More viewport unit tests - resize, get and set rotation, and the start of zoomBy and zoomTo. --- test/viewport.js | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/test/viewport.js b/test/viewport.js index 35402d87..cf6b020c 100644 --- a/test/viewport.js +++ b/test/viewport.js @@ -118,6 +118,7 @@ }; // Tests start here. + asyncTest('getContainerSize', function() { var openHandler = function(event) { viewer.removeHandler('open', openHandler); @@ -276,6 +277,84 @@ viewer.open(TALL_PATH); // use a different image for homeFillsViewer }); + asyncTest('zoomBy', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + var orig, expected, actual; + for (var i = 0; i < testZoomLevels.length; i++){ + viewport.zoomBy(testZoomLevels[i], null, true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed by the correct amount." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('zoomTo', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + var orig, expected, actual; + for (var i = 0; i < testZoomLevels.length; i++){ + viewport.zoomTo(testZoomLevels[i], null, true); + viewport.update(); // need to call this even with immediately=true + propEqual( + viewport.getZoom(), + testZoomLevels[i], + "Zoomed to the correct level." + ); + } + + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('rotation', function(){ + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees"); + viewport.setRotation(90); + propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees"); + viewport.setRotation(-75); + propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees"); + start(); + }; + + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + + asyncTest('resize', function() { + var openHandler = function(event) { + viewer.removeHandler('open', openHandler); + var viewport = viewer.viewport; + + for(var i = 0; i < testPoints.length; i++){ + var new_size = testPoints[i].times(viewer.source.dimensions.x); + viewport.resize(new_size); + viewport.update(); + propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully."); + } + start(); + }; + viewer.addHandler('open', openHandler); + viewer.open(DZI_PATH); + }); + asyncTest('deltaPixelsFromPoints', function() { loopingTestHelper({ testArray: testPoints,