diff --git a/test/demo/collections/main.js b/test/demo/collections/main.js index d1f9c652..a9f02b8c 100644 --- a/test/demo/collections/main.js +++ b/test/demo/collections/main.js @@ -6,7 +6,7 @@ init: function() { var self = this; - var testInitialOpen = false; + var testInitialOpen = true; var testOverlays = false; var testMargins = false; var testNavigator = false; @@ -16,8 +16,8 @@ // debugMode: true, zoomPerScroll: 1.02, showNavigator: testNavigator, - sequenceMode: true, - showReferenceStrip: true, + // sequenceMode: true, + // showReferenceStrip: true, // referenceStripScroll: 'vertical', navPrevNextWrap: false, preserveViewport: false, diff --git a/test/helpers/test.js b/test/helpers/test.js index 68010ef4..389c4763 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -50,6 +50,7 @@ .simulate( OpenSeadragon.MouseTracker.haveMouseEnter ? 'mouseleave' : 'mouseout', event ); }, + // ---------- initializeTestDOM: function () { $( "#qunit-fixture" ) .append( '
' ) @@ -57,14 +58,17 @@ .append( '
' ); }, + // ---------- equalsWithVariance: function ( value1, value2, variance ) { return Math.abs( value1 - value2 ) <= variance; }, + // ---------- assessNumericValue: function ( value1, value2, variance, message ) { ok( Util.equalsWithVariance( value1, value2, variance ), message + " Expected:" + value1 + " Found: " + value2 + " Variance: " + variance ); }, + // ---------- timeWatcher: function ( time ) { time = time || 2000; var finished = false; @@ -85,8 +89,21 @@ } } }; - } + }, + // ---------- + spyOnce: function(obj, functionName, callback) { + var original = obj[functionName]; + obj[functionName] = function() { + obj[functionName] = original; + var result = callback.apply(this, arguments); + if (result === undefined) { + result = original.apply(this, arguments); + } + + return result; + }; + } }; /* diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 694c6f3d..64028637 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -8,12 +8,6 @@ var example = $('
').appendTo("#qunit-fixture"); testLog.reset(); - - viewer = OpenSeadragon({ - id: 'example', - prefixUrl: '/build/openseadragon/images/', - springStiffness: 100 // Faster animation = faster tests - }); }, teardown: function () { if (viewer && viewer.close) { @@ -24,8 +18,44 @@ } }); + // ---------- + var createViewer = function(options) { + options = options || {}; + viewer = OpenSeadragon(OpenSeadragon.extend({ + id: 'example', + prefixUrl: '/build/openseadragon/images/', + springStiffness: 100 // Faster animation = faster tests + }, options)); + }; + + // ---------- + var testDeprecation = function(obj0, member0, obj1, member1) { + var called = false; + var errored = false; + + if (obj1 && member1) { + Util.spyOnce(obj1, member1, function() { + called = true; + return false; + }); + } else { + called = true; + } + + Util.spyOnce(OpenSeadragon.console, 'error', function(message) { + if (/deprecated/.test(message)) { + errored = true; + } + }); + + obj0[member0](); + equal(called, true, 'called through for ' + member0); + equal(errored, true, 'errored for ' + member0); + }; + // ---------- asyncTest('basics', function() { + createViewer(); ok(viewer.drawer, 'Drawer exists'); equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); equal(viewer.drawer.getOpacity(), 1, 'starts with full opacity'); @@ -36,6 +66,10 @@ // ---------- asyncTest('tile-drawing event', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi' + }); + viewer.addHandler('tile-drawing', function handler(event) { viewer.removeHandler('tile-drawing', handler); equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); @@ -44,8 +78,48 @@ ok(event.rendered, 'tile-drawing event includes a rendered'); start(); }); + }); - viewer.open('/test/data/testpattern.dzi'); + // ---------- + asyncTest('rotation', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi' + }); + + viewer.addHandler('open', function handler(event) { + viewer.viewport.setRotation(30); + Util.spyOnce(viewer.drawer.context, 'rotate', function() { + ok(true, 'drawing with new rotation'); + start(); + }); + }); + }); + + // ---------- + asyncTest('debug', function() { + createViewer({ + tileSources: '/test/data/testpattern.dzi', + debugMode: true + }); + + Util.spyOnce(viewer.drawer, 'drawDebugInfo', function() { + ok(true, 'drawDebugInfo is called'); + start(); + }); + }); + + // ---------- + asyncTest('deprecations', function() { + createViewer(); + testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + testDeprecation(viewer.drawer, 'needsUpdate'); + testDeprecation(viewer.drawer, 'numTilesLoaded'); + testDeprecation(viewer.drawer, 'reset'); + testDeprecation(viewer.drawer, 'update'); + start(); }); })();