From 3615ad412fbd01a989946f23ce121bd1aa3ce7d2 Mon Sep 17 00:00:00 2001
From: Nelson Campos <ncampos@criteriamarathon.com>
Date: Wed, 6 Jun 2018 17:03:40 +0100
Subject: [PATCH] Adds some more tests and tries to solve some code bugs.

A new variance parameter was added to assertPointsEquals function.

Variance value was set on loopingTestHelper function (1e-15).

The following tests were modified to execute tests on flipped viewport:
* 'panBy'
* 'panTo'
* 'zoomBy with ref point'
---
 test/modules/viewport.js | 59 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/test/modules/viewport.js b/test/modules/viewport.js
index abc1306f..2c03ced3 100644
--- a/test/modules/viewport.js
+++ b/test/modules/viewport.js
@@ -118,6 +118,7 @@
                         assert,
                         actual,
                         expected,
+                        1e-15,
                         "Correctly converted coordinates " + orig
                     );
                 } else {
@@ -136,8 +137,8 @@
         viewer.open(DZI_PATH);
     };
 
-    function assertPointsEquals(assert, actual, expected, message) {
-        Util.assertPointsEquals(assert, actual, expected, 1e-15, message);
+    function assertPointsEquals(assert, actual, expected, variance, message) {
+        Util.assertPointsEquals(assert, actual, expected, variance, message);
     }
 
 // Tests start here.
@@ -736,6 +737,19 @@
                 );
             }
 
+            viewport = viewer.viewport; // Get viewport original state
+            viewport.setFlip(true);
+
+            for (var i = 0; i < testPoints.length; i++){
+                var expected = viewport.getCenter().plus(testPoints[i]);
+                viewport.panBy(testPoints[i], true);
+                assert.propEqual(
+                    viewport.getCenter(),
+                    expected,
+                    "Panned flipped by the correct amount."
+                );
+            }
+
             done();
         };
         viewer.addHandler('open', openHandler);
@@ -757,6 +771,18 @@
                 );
             }
 
+            viewport = viewer.viewport; // Get viewport original state
+            viewport.setFlip(true);
+
+            for (var i = 0; i < testPoints.length; i++){
+                viewport.panTo(testPoints[i], true);
+                assert.propEqual(
+                    viewport.getCenter(),
+                    testPoints[i],
+                    "Panned flipped to the correct location."
+                );
+            }
+
             done();
         };
         viewer.addHandler('open', openHandler);
@@ -815,6 +841,34 @@
                 );
             }
 
+            viewport = viewer.viewport; // Get viewport original state
+            viewport.setFlip(true);
+
+            var expectedFlippedCenters = [
+                new OpenSeadragon.Point(12.121, 11.871),
+                new OpenSeadragon.Point(14.117, 13.867),
+                new OpenSeadragon.Point(14.367, 13.867),
+                new OpenSeadragon.Point(14.367, 13.867),
+                new OpenSeadragon.Point(14.742, 14.242),
+                new OpenSeadragon.Point(14.742, 14.242),
+            ];
+
+            for (var i = 0; i < testZoomLevels.length; i++) {
+                viewport.zoomBy(testZoomLevels[i], testPoints[i], true);
+                assert.propEqual(
+                    testZoomLevels[i],
+                    viewport.getZoom(),
+                    "Zoomed flipped by the correct amount."
+                );
+                assertPointsEquals(
+                    assert,
+                    expectedFlippedCenters[i],
+                    viewport.getCenter(),
+                    1e-6,
+                    "Panned flipped to the correct location."
+                );
+            }
+
             done();
         };
         viewer.addHandler('open', openHandler);
@@ -1179,4 +1233,5 @@
       viewer.addHandler('open', openHandler);
       viewer.open(DZI_PATH);
     });
+    
 })();