diff --git a/test/helpers/test.js b/test/helpers/test.js index 1c4b4a9f..8e7685d8 100644 --- a/test/helpers/test.js +++ b/test/helpers/test.js @@ -119,13 +119,12 @@ if (result === undefined) { result = original.apply(this, arguments); } - return result; }; }, // ---------- - testDeprecation: function(obj0, member0, obj1, member1, assert) { + testDeprecation: function(assert, obj0, member0, obj1, member1) { var called = false; var errored = false; diff --git a/test/modules/drawer.js b/test/modules/drawer.js index 4016ebfd..ba53ba2d 100644 --- a/test/modules/drawer.js +++ b/test/modules/drawer.js @@ -1,15 +1,15 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, Util, testLog */ (function() { var viewer; - module('Drawer', { - setup: function () { - var example = $('
').appendTo("#qunit-fixture"); + QUnit.module('Drawer', { + beforeEach: function () { + $('').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -29,15 +29,17 @@ }; // ---------- - asyncTest('basics', function() { + QUnit.test('basics', function(assert) { + var done = assert.async(); createViewer(); - ok(viewer.drawer, 'Drawer exists'); - equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); - start(); + assert.ok(viewer.drawer, 'Drawer exists'); + assert.equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); + done(); }); // ---------- - asyncTest('rotation', function() { + QUnit.test('rotation', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi' }); @@ -45,27 +47,29 @@ viewer.addHandler('open', function handler(event) { viewer.viewport.setRotation(30); Util.spyOnce(viewer.drawer.context, 'rotate', function() { - ok(true, 'drawing with new rotation'); - start(); + assert.ok(true, 'drawing with new rotation'); + done(); }); }); }); // ---------- - asyncTest('debug', function() { + QUnit.test('debug', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi', debugMode: true }); Util.spyOnce(viewer.drawer, 'drawDebugInfo', function() { - ok(true, 'drawDebugInfo is called'); - start(); + assert.ok(true, 'drawDebugInfo is called'); + done(); }); }); // ---------- - asyncTest('sketchCanvas', function() { + QUnit.test('sketchCanvas', function(assert) { + var done = assert.async(); createViewer({ tileSources: '/test/data/testpattern.dzi' }); @@ -73,9 +77,9 @@ viewer.addHandler('tile-drawn', function noOpacityHandler() { viewer.removeHandler('tile-drawn', noOpacityHandler); - equal(drawer.sketchCanvas, null, + assert.equal(drawer.sketchCanvas, null, 'The sketch canvas should be null if no decimal opacity is used.'); - equal(drawer.sketchContext, null, + assert.equal(drawer.sketchContext, null, 'The sketch context should be null if no decimal opacity is used.'); testOpacityDecimal(); }); @@ -95,32 +99,34 @@ return; } viewer.removeHandler('tile-drawn', opacityDecimalHandler); - notEqual(drawer.sketchCanvas, null, + assert.notEqual(drawer.sketchCanvas, null, 'The sketch canvas should not be null once a decimal opacity has been used.'); - notEqual(drawer.sketchContext, null, + assert.notEqual(drawer.sketchContext, null, 'The sketch context should not be null once a decimal opacity has been used.'); - start(); + done(); }); } }); // ---------- - asyncTest('deprecations', function() { + QUnit.test('deprecations', function(assert) { + var done = assert.async(); + createViewer({ tileSources: '/test/data/testpattern.dzi' }); viewer.world.addHandler('add-item', function() { - Util.testDeprecation(viewer.drawer, 'addOverlay', viewer, 'addOverlay'); - Util.testDeprecation(viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); - Util.testDeprecation(viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); - Util.testDeprecation(viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); - Util.testDeprecation(viewer.drawer, 'needsUpdate', viewer.world, 'needsDraw'); - Util.testDeprecation(viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); - Util.testDeprecation(viewer.drawer, 'reset', viewer.world, 'resetItems'); - Util.testDeprecation(viewer.drawer, 'update', viewer.world, 'draw'); - Util.testDeprecation(viewer.drawer, 'setOpacity', viewer.world.getItemAt(0), 'setOpacity'); - Util.testDeprecation(viewer.drawer, 'getOpacity', viewer.world.getItemAt(0), 'getOpacity'); - start(); + Util.testDeprecation(assert, viewer.drawer, 'addOverlay', viewer, 'addOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'updateOverlay', viewer, 'updateOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'removeOverlay', viewer, 'removeOverlay'); + Util.testDeprecation(assert, viewer.drawer, 'clearOverlays', viewer, 'clearOverlays'); + Util.testDeprecation(assert, viewer.drawer, 'needsUpdate', viewer.world, 'needsDraw'); + Util.testDeprecation(assert, viewer.drawer, 'numTilesLoaded', viewer.tileCache, 'numTilesLoaded'); + Util.testDeprecation(assert, viewer.drawer, 'reset', viewer.world, 'resetItems'); + Util.testDeprecation(assert, viewer.drawer, 'update', viewer.world, 'draw'); + Util.testDeprecation(assert, viewer.drawer, 'setOpacity', viewer.world.getItemAt(0), 'setOpacity'); + Util.testDeprecation(assert, viewer.drawer, 'getOpacity', viewer.world.getItemAt(0), 'getOpacity'); + done(); }); }); diff --git a/test/modules/dzitilesource.js b/test/modules/dzitilesource.js index 25b0c265..8c6360c9 100644 --- a/test/modules/dzitilesource.js +++ b/test/modules/dzitilesource.js @@ -1,42 +1,48 @@ - -/*global module:true, test:true, equal:true, OpenSeadragon:true*/ +/* global QUnit, testLog */ (function() { - module('DziTileSource', { - setup: function() { + QUnit.module('DziTileSource', { + beforeEach: function() { testLog.reset(); } }); - function testImplicitTilesUrl(dziUrl, expected, msg) { + function testImplicitTilesUrl(assert, dziUrl, expected, msg) { var source = new OpenSeadragon.DziTileSource(); var options = source.configure({ Image: {Size: {Width:0, Height: 0}} }, dziUrl); - equal(options.tilesUrl, expected, msg); + assert.equal(options.tilesUrl, expected, msg); } - test('test implicit tilesUrl guessed from dzi url', function() { + QUnit.test('test implicit tilesUrl guessed from dzi url', function(assert) { testImplicitTilesUrl( + assert, '/path/my.dzi', '/path/my_files/', 'dzi extension should be stripped'); testImplicitTilesUrl( + assert, '/path/my', '/path/my_files/', 'no extension should still produce _files path'); testImplicitTilesUrl( + assert, '/my/', '/my_files/', 'no extension with trailing slash should preserve slash'); testImplicitTilesUrl( + assert, 'my.xml', 'my_files/', 'relative link should stay the same'); testImplicitTilesUrl( + assert, '/p/foo.dzi?a=1&b=2', '/p/foo_files/', 'querystring in dzi url should be ignored after slashes'); testImplicitTilesUrl( + assert, '/iiipsrv?DeepZoom=/path/my.dzi', '/iiipsrv?DeepZoom=/path/my_files/', 'querystring in dzi url should not be ignored before slashes'); testImplicitTilesUrl( + assert, '/fcg-bin/iipsrv.fcgi?Deepzoom=123test.tif.dzi', '/fcg-bin/iipsrv.fcgi?Deepzoom=123test.tif_files/', 'filename in querystring does not have to contain slash'); }); diff --git a/test/modules/formats.js b/test/modules/formats.js index 5a50eda8..e883d53c 100644 --- a/test/modules/formats.js +++ b/test/modules/formats.js @@ -21,7 +21,7 @@ }; var testOpen = function(tileSource, assert) { - var timeWatcher = Util.timeWatcher(7000, assert); + var timeWatcher = Util.timeWatcher(assert, 7000); viewer = OpenSeadragon({ id: 'example', diff --git a/test/modules/imageloader.js b/test/modules/imageloader.js index 1750ea73..1e201b10 100644 --- a/test/modules/imageloader.js +++ b/test/modules/imageloader.js @@ -1,4 +1,4 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer, @@ -8,13 +8,13 @@ springStiffness: 100 // Faster animation = faster tests }; - module('ImageLoader', { - setup: function () { - var example = $('').appendTo("#qunit-fixture"); + QUnit.module('ImageLoader', { + beforeEach: function () { + $('').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -25,19 +25,19 @@ // ---------- - test('Default timeout', function() { + QUnit.test('Default timeout', function(assert) { var actual, expected = OpenSeadragon.DEFAULT_SETTINGS.timeout, message, options = OpenSeadragon.extend(true, baseOptions, { imageLoaderLimit: 1 - }), + }), viewer = OpenSeadragon(options), imageLoader = viewer.imageLoader; message = 'ImageLoader timeout should be set to the default value of ' + expected + ' when none is specified'; actual = imageLoader.timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); // Manually seize the ImageLoader imageLoader.jobsInProgress = imageLoader.jobLimit; @@ -51,12 +51,12 @@ message = 'ImageJob should inherit the ImageLoader timeout value'; actual = imageLoader.jobQueue.shift().timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); }); // ---------- - - test('Configure timeout', function() { + + QUnit.test('Configure timeout', function(assert) { var actual, expected = 123456, message, @@ -69,7 +69,7 @@ message = 'ImageLoader timeout should be configurable'; actual = imageLoader.timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); imageLoader.jobsInProgress = imageLoader.jobLimit; imageLoader.addJob({ @@ -82,7 +82,7 @@ message = 'ImageJob should inherit the ImageLoader timeout value'; actual = imageLoader.jobQueue.shift().timeout; - equal(actual, expected, message); + assert.equal(actual, expected, message); }); })(); diff --git a/test/modules/rectangle.js b/test/modules/rectangle.js index 402e58c4..18ae8b3b 100644 --- a/test/modules/rectangle.js +++ b/test/modules/rectangle.js @@ -1,152 +1,152 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, Util */ (function() { - module('Rectangle', {}); + QUnit.module('Rectangle', {}); var precision = 0.000000001; - test('Constructor', function() { + QUnit.test('Constructor', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 5); - strictEqual(rect.x, 1, 'rect.x should be 1'); - strictEqual(rect.y, 2, 'rect.y should be 2'); - strictEqual(rect.width, 3, 'rect.width should be 3'); - strictEqual(rect.height, 4, 'rect.height should be 4'); - strictEqual(rect.degrees, 5, 'rect.degrees should be 5'); + assert.strictEqual(rect.x, 1, 'rect.x should be 1'); + assert.strictEqual(rect.y, 2, 'rect.y should be 2'); + assert.strictEqual(rect.width, 3, 'rect.width should be 3'); + assert.strictEqual(rect.height, 4, 'rect.height should be 4'); + assert.strictEqual(rect.degrees, 5, 'rect.degrees should be 5'); rect = new OpenSeadragon.Rect(); - strictEqual(rect.x, 0, 'rect.x should be 0'); - strictEqual(rect.y, 0, 'rect.y should be 0'); - strictEqual(rect.width, 0, 'rect.width should be 0'); - strictEqual(rect.height, 0, 'rect.height should be 0'); - strictEqual(rect.degrees, 0, 'rect.degrees should be 0'); + assert.strictEqual(rect.x, 0, 'rect.x should be 0'); + assert.strictEqual(rect.y, 0, 'rect.y should be 0'); + assert.strictEqual(rect.width, 0, 'rect.width should be 0'); + assert.strictEqual(rect.height, 0, 'rect.height should be 0'); + assert.strictEqual(rect.degrees, 0, 'rect.degrees should be 0'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, -405); - Util.assessNumericValue(Math.sqrt(2) / 2, rect.x, precision, + Util.assessNumericValue(assert, Math.sqrt(2) / 2, rect.x, precision, 'rect.x should be sqrt(2)/2'); - Util.assessNumericValue(-Math.sqrt(2) / 2, rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2) / 2, rect.y, precision, 'rect.y should be -sqrt(2)/2'); - Util.assessNumericValue(2, rect.width, precision, + Util.assessNumericValue(assert, 2, rect.width, precision, 'rect.width should be 2'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 2, 135); - Util.assessNumericValue(-Math.sqrt(2), rect.x, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.x, precision, 'rect.x should be -sqrt(2)'); - Util.assessNumericValue(-Math.sqrt(2), rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(2, rect.width, precision, + Util.assessNumericValue(assert, 2, rect.width, precision, 'rect.width should be 2'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); rect = new OpenSeadragon.Rect(0, 0, 1, 1, 585); - Util.assessNumericValue(0, rect.x, precision, + Util.assessNumericValue(assert, 0, rect.x, precision, 'rect.x should be 0'); - Util.assessNumericValue(-Math.sqrt(2), rect.y, precision, + Util.assessNumericValue(assert, -Math.sqrt(2), rect.y, precision, 'rect.y should be -sqrt(2)'); - Util.assessNumericValue(1, rect.width, precision, + Util.assessNumericValue(assert, 1, rect.width, precision, 'rect.width should be 1'); - Util.assessNumericValue(1, rect.height, precision, + Util.assessNumericValue(assert, 1, rect.height, precision, 'rect.height should be 1'); - strictEqual(45, rect.degrees, 'rect.degrees should be 45'); + assert.strictEqual(45, rect.degrees, 'rect.degrees should be 45'); }); - test('getTopLeft', function() { + QUnit.test('getTopLeft', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 5); var expected = new OpenSeadragon.Point(1, 2); - ok(expected.equals(rect.getTopLeft()), "Incorrect top left point."); + assert.ok(expected.equals(rect.getTopLeft()), "Incorrect top left point."); }); - test('getTopRight', function() { + QUnit.test('getTopRight', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 3); var expected = new OpenSeadragon.Point(1, 0); - ok(expected.equals(rect.getTopRight()), "Incorrect top right point."); + assert.ok(expected.equals(rect.getTopRight()), "Incorrect top right point."); rect.degrees = 45; expected = new OpenSeadragon.Point(1 / Math.sqrt(2), 1 / Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getTopRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getTopRight(), precision, "Incorrect top right point with rotation."); }); - test('getBottomLeft', function() { + QUnit.test('getBottomLeft', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 3, 1); var expected = new OpenSeadragon.Point(0, 1); - ok(expected.equals(rect.getBottomLeft()), "Incorrect bottom left point."); + assert.ok(expected.equals(rect.getBottomLeft()), "Incorrect bottom left point."); rect.degrees = 45; expected = new OpenSeadragon.Point(-1 / Math.sqrt(2), 1 / Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getBottomLeft(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomLeft(), precision, "Incorrect bottom left point with rotation."); }); - test('getBottomRight', function() { + QUnit.test('getBottomRight', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1); var expected = new OpenSeadragon.Point(1, 1); - ok(expected.equals(rect.getBottomRight()), "Incorrect bottom right point."); + assert.ok(expected.equals(rect.getBottomRight()), "Incorrect bottom right point."); rect.degrees = 45; expected = new OpenSeadragon.Point(0, Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 45 rotation."); rect.degrees = 90; expected = new OpenSeadragon.Point(-1, 1); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 90 rotation."); rect.degrees = 135; expected = new OpenSeadragon.Point(-Math.sqrt(2), 0); - Util.assertPointsEquals(expected, rect.getBottomRight(), precision, + Util.assertPointsEquals(assert, expected, rect.getBottomRight(), precision, "Incorrect bottom right point with 135 rotation."); }); - test('getCenter', function() { + QUnit.test('getCenter', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1); var expected = new OpenSeadragon.Point(0.5, 0.5); - ok(expected.equals(rect.getCenter()), "Incorrect center point."); + assert.ok(expected.equals(rect.getCenter()), "Incorrect center point."); rect.degrees = 45; expected = new OpenSeadragon.Point(0, 0.5 * Math.sqrt(2)); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 45 rotation."); rect.degrees = 90; expected = new OpenSeadragon.Point(-0.5, 0.5); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 90 rotation."); rect.degrees = 135; expected = new OpenSeadragon.Point(-0.5 * Math.sqrt(2), 0); - Util.assertPointsEquals(expected, rect.getCenter(), precision, + Util.assertPointsEquals(assert, expected, rect.getCenter(), precision, "Incorrect bottom right point with 135 rotation."); }); - test('times', function() { + QUnit.test('times', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 45); var expected = new OpenSeadragon.Rect(2, 4, 6, 8, 45); var actual = rect.times(2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect x2 rectangles."); }); - test('translate', function() { + QUnit.test('translate', function(assert) { var rect = new OpenSeadragon.Rect(1, 2, 3, 4, 45); var expected = new OpenSeadragon.Rect(2, 4, 3, 4, 45); var actual = rect.translate(new OpenSeadragon.Point(1, 2)); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect translation."); }); - test('union', function() { + QUnit.test('union', function(assert) { var rect1 = new OpenSeadragon.Rect(2, 2, 2, 3); var rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); var expected = new OpenSeadragon.Rect(0, 1, 4, 4); var actual = rect1.union(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect union with horizontal rectangles."); rect1 = new OpenSeadragon.Rect(0, -Math.sqrt(2), 2, 2, 45); @@ -157,30 +157,30 @@ 3 + Math.sqrt(2), 2 + Math.sqrt(2)); actual = rect1.union(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect union with non horizontal rectangles."); }); - test('intersection', function() { + QUnit.test('intersection', function(assert) { var rect1 = new OpenSeadragon.Rect(2, 2, 2, 3); var rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); var expected = null; var actual = rect1.intersection(rect2); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect2 + " should not intersect " + rect1); actual = rect2.intersection(rect1); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect1 + " should not intersect " + rect2); rect1 = new OpenSeadragon.Rect(0, 0, 2, 1); rect2 = new OpenSeadragon.Rect(1, 0, 2, 2); expected = new OpenSeadragon.Rect(1, 0, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); @@ -188,11 +188,11 @@ rect2 = new OpenSeadragon.Rect(1, 1, 1, 1); expected = new OpenSeadragon.Rect(1, 1, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); @@ -201,26 +201,26 @@ rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); expected = null; actual = rect1.intersection(rect2); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect2 + " should not intersect " + rect1); actual = rect2.intersection(rect1); - equal(expected, actual, + assert.equal(expected, actual, "Rectangle " + rect1 + " should not intersect " + rect2); rect1 = new OpenSeadragon.Rect(2, 0, 2, 3, 45); rect2 = new OpenSeadragon.Rect(0, 1, 1, 1); expected = new OpenSeadragon.Rect(0, 1, 1, 1); actual = rect1.intersection(rect2); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect2 + " with " + rect1 + " should be " + expected); actual = rect2.intersection(rect1); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Intersection of " + rect1 + " with " + rect2 + " should be " + expected); }); - test('rotate', function() { + QUnit.test('rotate', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 2, 1); var expected = new OpenSeadragon.Rect( @@ -230,73 +230,73 @@ 1, 45); var actual = rect.rotate(-675); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of -675deg around center."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 33); actual = rect.rotate(33, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 33deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 101); actual = rect.rotate(101, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 187deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 187); actual = rect.rotate(187, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 187deg around topLeft."); expected = new OpenSeadragon.Rect(0, 0, 2, 1, 300); actual = rect.rotate(300, rect.getTopLeft()); - Util.assertRectangleEquals(expected, actual, precision, + Util.assertRectangleEquals(assert, expected, actual, precision, "Incorrect rectangle after rotation of 300deg around topLeft."); }); - test('getBoundingBox', function() { + QUnit.test('getBoundingBox', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 2, 3); var bb = rect.getBoundingBox(); - ok(rect.equals(bb), "Bounding box of horizontal rectangle should be " + + assert.ok(rect.equals(bb), "Bounding box of horizontal rectangle should be " + "identical to rectangle."); rect.degrees = 90; var expected = new OpenSeadragon.Rect(-3, 0, 3, 2); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 90deg."); rect.degrees = 180; - var expected = new OpenSeadragon.Rect(-2, -3, 2, 3); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + expected = new OpenSeadragon.Rect(-2, -3, 2, 3); + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 180deg."); rect.degrees = 270; - var expected = new OpenSeadragon.Rect(0, -2, 3, 2); - Util.assertRectangleEquals(expected, rect.getBoundingBox(), precision, + expected = new OpenSeadragon.Rect(0, -2, 3, 2); + Util.assertRectangleEquals(assert, expected, rect.getBoundingBox(), precision, "Bounding box of rect rotated 270deg."); }); - test('containsPoint', function() { + QUnit.test('containsPoint', function(assert) { var rect = new OpenSeadragon.Rect(0, 0, 1, 1, 45); - ok(rect.containsPoint(new OpenSeadragon.Point(0, 0)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0, 0)), 'Point 0,0 should be inside ' + rect); - ok(rect.containsPoint(rect.getTopRight()), + assert.ok(rect.containsPoint(rect.getTopRight()), 'Top right vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getBottomRight()), + assert.ok(rect.containsPoint(rect.getBottomRight()), 'Bottom right vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getBottomLeft()), + assert.ok(rect.containsPoint(rect.getBottomLeft()), 'Bottom left vertex should be inside ' + rect); - ok(rect.containsPoint(rect.getCenter()), + assert.ok(rect.containsPoint(rect.getCenter()), 'Center should be inside ' + rect); - notOk(rect.containsPoint(new OpenSeadragon.Point(1, 0)), + assert.notOk(rect.containsPoint(new OpenSeadragon.Point(1, 0)), 'Point 1,0 should not be inside ' + rect); - ok(rect.containsPoint(new OpenSeadragon.Point(0.5, 0.5)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0.5, 0.5)), 'Point 0.5,0.5 should be inside ' + rect); - ok(rect.containsPoint(new OpenSeadragon.Point(0.4, 0.5)), + assert.ok(rect.containsPoint(new OpenSeadragon.Point(0.4, 0.5)), 'Point 0.4,0.5 should be inside ' + rect); - notOk(rect.containsPoint(new OpenSeadragon.Point(0.6, 0.5)), + assert.notOk(rect.containsPoint(new OpenSeadragon.Point(0.6, 0.5)), 'Point 0.6,0.5 should not be inside ' + rect); }); diff --git a/test/modules/referencestrip.js b/test/modules/referencestrip.js index 45130070..857c16fb 100644 --- a/test/modules/referencestrip.js +++ b/test/modules/referencestrip.js @@ -1,15 +1,15 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer; - module('ReferenceStrip', { - setup: function () { - var example = $('').appendTo("#qunit-fixture"); + QUnit.module('ReferenceStrip', { + beforeEach: function () { + $('').appendTo("#qunit-fixture"); testLog.reset(); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -29,7 +29,8 @@ }; // ---------- - asyncTest('basics', function() { + QUnit.test('basics', function(assert) { + var done = assert.async(); createViewer({ sequenceMode: true, showReferenceStrip: true, @@ -39,8 +40,8 @@ ] }); - ok(viewer.referenceStrip, 'referenceStrip exists'); - start(); + assert.ok(viewer.referenceStrip, 'referenceStrip exists'); + done(); }); })(); diff --git a/test/modules/spring.js b/test/modules/spring.js index b627f832..c71839f8 100644 --- a/test/modules/spring.js +++ b/test/modules/spring.js @@ -1,12 +1,12 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual, console */ +/* global QUnit, Util, console */ (function () { var originalNow; var now; - module("spring", { - setup: function () { + QUnit.module("spring", { + beforeEach: function () { now = 0; originalNow = OpenSeadragon.now; @@ -14,39 +14,41 @@ return now; }; }, - teardown: function () { + afterEach: function () { OpenSeadragon.now = originalNow; } }); - asyncTest('regular spring', function() { + QUnit.test('regular spring', function(assert) { + var done = assert.async(); var spring = new OpenSeadragon.Spring({ initial: 5, animationTime: 1, springStiffness: 0.000001 }); - equal(spring.current.value, 5, 'initial current value'); - equal(spring.target.value, 5, 'initial target value'); + assert.equal(spring.current.value, 5, 'initial current value'); + assert.equal(spring.target.value, 5, 'initial target value'); spring.springTo(6); - equal(spring.current.value, 5, 'current value after springTo'); - equal(spring.target.value, 6, 'target value after springTo'); + assert.equal(spring.current.value, 5, 'current value after springTo'); + assert.equal(spring.target.value, 6, 'target value after springTo'); now = 500; spring.update(); - Util.assessNumericValue(5.5, spring.current.value, 0.00001, 'current value after first update'); - equal(spring.target.value, 6, 'target value after first update'); + Util.assessNumericValue(assert, 5.5, spring.current.value, 0.00001, 'current value after first update'); + assert.equal(spring.target.value, 6, 'target value after first update'); now = 1000; spring.update(); - equal(spring.current.value, 6, 'current value after second update'); - equal(spring.target.value, 6, 'target value after second update'); + assert.equal(spring.current.value, 6, 'current value after second update'); + assert.equal(spring.target.value, 6, 'target value after second update'); - start(); + done(); }); - asyncTest('exponential spring', function() { + QUnit.test('exponential spring', function(assert) { + var done = assert.async(); var spring = new OpenSeadragon.Spring({ exponential: true, initial: 1, @@ -54,24 +56,24 @@ springStiffness: 0.000001 }); - equal(spring.current.value, 1, 'initial current value'); - equal(spring.target.value, 1, 'initial target value'); + assert.equal(spring.current.value, 1, 'initial current value'); + assert.equal(spring.target.value, 1, 'initial target value'); spring.springTo(2); - equal(spring.current.value, 1, 'current value after springTo'); - equal(spring.target.value, 2, 'target value after springTo'); + assert.equal(spring.current.value, 1, 'current value after springTo'); + assert.equal(spring.target.value, 2, 'target value after springTo'); now = 500; spring.update(); - Util.assessNumericValue(1.41421, spring.current.value, 0.00001, 'current value after first update'); - equal(spring.target.value, 2, 'target value after first update'); + Util.assessNumericValue(assert, 1.41421, spring.current.value, 0.00001, 'current value after first update'); + assert.equal(spring.target.value, 2, 'target value after first update'); now = 1000; spring.update(); - equal(spring.current.value, 2, 'current value after second update'); - equal(spring.target.value, 2, 'target value after second update'); + assert.equal(spring.current.value, 2, 'current value after second update'); + assert.equal(spring.target.value, 2, 'target value after second update'); - start(); + done(); }); })(); diff --git a/test/modules/tilecache.js b/test/modules/tilecache.js index ba89b73a..65fbf431 100644 --- a/test/modules/tilecache.js +++ b/test/modules/tilecache.js @@ -1,18 +1,20 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, testLog */ (function() { // ---------- - module('TileCache', { - setup: function () { + QUnit.module('TileCache', { + beforeEach: function () { testLog.reset(); }, - teardown: function () { + afterEach: function () { } }); // ---------- - asyncTest('basics', function() { + // TODO: this used to be async + QUnit.test('basics', function(assert) { + var done = assert.async(); var fakeViewer = { raiseEvent: function() {} }; @@ -38,35 +40,36 @@ }; var cache = new OpenSeadragon.TileCache(); - equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); cache.cacheTile({ tile: fakeTile0, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 1, 'tile count after cache'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after cache'); cache.cacheTile({ tile: fakeTile1, tiledImage: fakeTiledImage1 }); - equal(cache.numTilesLoaded(), 2, 'tile count after second cache'); + assert.equal(cache.numTilesLoaded(), 2, 'tile count after second cache'); cache.clearTilesFor(fakeTiledImage0); - equal(cache.numTilesLoaded(), 1, 'tile count after first clear'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after first clear'); cache.clearTilesFor(fakeTiledImage1); - equal(cache.numTilesLoaded(), 0, 'tile count after second clear'); + assert.equal(cache.numTilesLoaded(), 0, 'tile count after second clear'); - start(); + done(); }); // ---------- - asyncTest('maxImageCacheCount', function() { + QUnit.test('maxImageCacheCount', function(assert) { + var done = assert.async(); var fakeViewer = { raiseEvent: function() {} }; @@ -99,30 +102,30 @@ maxImageCacheCount: 1 }); - equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); + assert.equal(cache.numTilesLoaded(), 0, 'no tiles to begin with'); cache.cacheTile({ tile: fakeTile0, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 1, 'tile count after add'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after add'); cache.cacheTile({ tile: fakeTile1, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 1, 'tile count after add of second image'); + assert.equal(cache.numTilesLoaded(), 1, 'tile count after add of second image'); cache.cacheTile({ tile: fakeTile2, tiledImage: fakeTiledImage0 }); - equal(cache.numTilesLoaded(), 2, 'tile count after additional same image'); + assert.equal(cache.numTilesLoaded(), 2, 'tile count after additional same image'); - start(); + done(); }); })(); diff --git a/test/modules/tiledimage.js b/test/modules/tiledimage.js index b2206341..0fce1dc7 100644 --- a/test/modules/tiledimage.js +++ b/test/modules/tiledimage.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, propEqual */ +/* global QUnit, $, Util, testLog */ (function() { var viewer; - module('TiledImage', { - setup: function() { - var example = $('').appendTo("#qunit-fixture"); + QUnit.module('TiledImage', { + beforeEach: function() { + $('').appendTo("#qunit-fixture"); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function() { + afterEach: function() { if (viewer && viewer.close) { viewer.close(); } @@ -25,39 +25,40 @@ }); // ---------- - var checkBounds = function(image, expected, message) { + var checkBounds = function(assert, image, expected, message) { var bounds = image.getBounds(); - equal(bounds.x, expected.x, message + ' x'); - equal(bounds.y, expected.y, message + ' y'); - equal(bounds.width, expected.width, message + ' width'); - equal(bounds.height, expected.height, message + ' height'); + assert.equal(bounds.x, expected.x, message + ' x'); + assert.equal(bounds.y, expected.y, message + ' y'); + assert.equal(bounds.width, expected.width, message + ' width'); + assert.equal(bounds.height, expected.height, message + ' height'); }; // ---------- - asyncTest('metrics', function() { + QUnit.test('metrics', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { var image = viewer.world.getItemAt(0); var contentSize = image.getContentSize(); - equal(contentSize.x, 500, 'contentSize.x'); - equal(contentSize.y, 2000, 'contentSize.y'); + assert.equal(contentSize.x, 500, 'contentSize.x'); + assert.equal(contentSize.y, 2000, 'contentSize.y'); - checkBounds(image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); + checkBounds(assert, image, new OpenSeadragon.Rect(5, 6, 10, 40), 'initial bounds'); var scale = image.getContentSize().x / image.getBounds().width; var viewportPoint = new OpenSeadragon.Point(10, 11); var imagePoint = viewportPoint.minus(image.getBounds().getTopLeft()).times(scale); - propEqual(image.viewportToImageCoordinates(viewportPoint), imagePoint, 'viewportToImageCoordinates'); - propEqual(image.imageToViewportCoordinates(imagePoint), viewportPoint, 'imageToViewportCoordinates'); + assert.propEqual(image.viewportToImageCoordinates(viewportPoint), imagePoint, 'viewportToImageCoordinates'); + assert.propEqual(image.imageToViewportCoordinates(imagePoint), viewportPoint, 'imageToViewportCoordinates'); var viewportRect = new OpenSeadragon.Rect(viewportPoint.x, viewportPoint.y, 6, 7); var imageRect = new OpenSeadragon.Rect(imagePoint.x, imagePoint.y, viewportRect.width * scale, viewportRect.height * scale); - propEqual(image.viewportToImageRectangle(viewportRect), imageRect, 'viewportToImageRectangle'); - propEqual(image.imageToViewportRectangle(imageRect), viewportRect, 'imageToViewportRectangle'); + assert.propEqual(image.viewportToImageRectangle(viewportRect), imageRect, 'viewportToImageRectangle'); + assert.propEqual(image.imageToViewportRectangle(imageRect), viewportRect, 'imageToViewportRectangle'); image.addHandler('bounds-change', function boundsChangeHandler(event) { image.removeHandler('bounds-change', boundsChangeHandler); @@ -65,16 +66,16 @@ }); image.setPosition(new OpenSeadragon.Point(7, 8)); - checkBounds(image, new OpenSeadragon.Rect(7, 8, 10, 40), 'bounds after position'); + checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 10, 40), 'bounds after position'); image.setWidth(5); - checkBounds(image, new OpenSeadragon.Rect(7, 8, 5, 20), 'bounds after width'); + checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 5, 20), 'bounds after width'); image.setHeight(4); - checkBounds(image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width'); + checkBounds(assert, image, new OpenSeadragon.Rect(7, 8, 1, 4), 'bounds after width'); - equal(handlerCount, 1, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 1, 'correct number of handlers called'); + done(); }); viewer.open({ @@ -86,25 +87,26 @@ }); // ---------- - asyncTest('animation', function() { + QUnit.test('animation', function(assert) { + var done = assert.async(); viewer.addHandler("open", function() { var image = viewer.world.getItemAt(0); - propEqual(image.getBounds(), new OpenSeadragon.Rect(0, 0, 1, 1), 'target bounds on open'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds on open'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(0, 0, 1, 1), 'target bounds on open'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds on open'); image.setPosition(new OpenSeadragon.Point(1, 2)); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 1, 1), 'target bounds after position'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after position'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 1, 1), 'target bounds after position'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after position'); image.setWidth(3); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after width'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after width'); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after width'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(0, 0, 1, 1), 'current bounds after width'); viewer.addHandler('animation-finish', function animationHandler() { viewer.removeHandler('animation-finish', animationHandler); - propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after animation'); - propEqual(image.getBounds(true), new OpenSeadragon.Rect(1, 2, 3, 3), 'current bounds after animation'); - start(); + assert.propEqual(image.getBounds(), new OpenSeadragon.Rect(1, 2, 3, 3), 'target bounds after animation'); + assert.propEqual(image.getBounds(true), new OpenSeadragon.Rect(1, 2, 3, 3), 'current bounds after animation'); + done(); }); }); @@ -112,55 +114,56 @@ }); // ---------- - asyncTest('update', function() { + QUnit.test('update', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { var image = viewer.world.getItemAt(0); - equal(image.needsDraw(), true, 'needs draw after open'); + assert.equal(image.needsDraw(), true, 'needs draw after open'); viewer.addHandler('update-level', function updateLevelHandler(event) { viewer.removeHandler('update-level', updateLevelHandler); handlerCount++; - equal(event.eventSource, viewer, 'sender of update-level event was viewer'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - ok('havedrawn' in event, 'update-level event includes havedrawn'); - ok('level' in event, 'update-level event includes level'); - ok('opacity' in event, 'update-level event includes opacity'); - ok('visibility' in event, 'update-level event includes visibility'); - ok('topleft' in event, 'update-level event includes topleft'); - ok('bottomright' in event, 'update-level event includes bottomright'); - ok('currenttime' in event, 'update-level event includes currenttime'); - ok('best' in event, 'update-level event includes best'); + assert.equal(event.eventSource, viewer, 'sender of update-level event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok('havedrawn' in event, 'update-level event includes havedrawn'); + assert.ok('level' in event, 'update-level event includes level'); + assert.ok('opacity' in event, 'update-level event includes opacity'); + assert.ok('visibility' in event, 'update-level event includes visibility'); + assert.ok('topleft' in event, 'update-level event includes topleft'); + assert.ok('bottomright' in event, 'update-level event includes bottomright'); + assert.ok('currenttime' in event, 'update-level event includes currenttime'); + assert.ok('best' in event, 'update-level event includes best'); }); viewer.addHandler('update-tile', function updateTileHandler(event) { viewer.removeHandler('update-tile', updateTileHandler); handlerCount++; - equal(event.eventSource, viewer, 'sender of update-tile event was viewer'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - ok(event.tile, 'update-tile event includes tile'); + assert.equal(event.eventSource, viewer, 'sender of update-tile event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'update-tile event includes tile'); }); viewer.addHandler('tile-drawing', function tileDrawingHandler(event) { viewer.removeHandler('tile-drawing', tileDrawingHandler); handlerCount++; - equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - ok(event.tile, 'tile-drawing event includes a tile'); - ok(event.context, 'tile-drawing event includes a context'); - ok(event.rendered, 'tile-drawing event includes a rendered'); + assert.equal(event.eventSource, viewer, 'sender of tile-drawing event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'tile-drawing event includes a tile'); + assert.ok(event.context, 'tile-drawing event includes a context'); + assert.ok(event.rendered, 'tile-drawing event includes a rendered'); }); viewer.addHandler('tile-drawn', function tileDrawnHandler(event) { viewer.removeHandler('tile-drawn', tileDrawnHandler); handlerCount++; - equal(event.eventSource, viewer, 'sender of tile-drawn event was viewer'); - equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); - ok(event.tile, 'tile-drawn event includes tile'); + assert.equal(event.eventSource, viewer, 'sender of tile-drawn event was viewer'); + assert.equal(event.tiledImage, image, 'tiledImage of update-level event is correct'); + assert.ok(event.tile, 'tile-drawn event includes tile'); - equal(handlerCount, 4, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 4, 'correct number of handlers called'); + done(); }); image.draw(); @@ -170,49 +173,51 @@ }); // ---------- - asyncTest('reset', function() { + QUnit.test('reset', function(assert) { + var done = assert.async(); viewer.addHandler('tile-drawn', function updateHandler() { viewer.removeHandler('tile-drawn', updateHandler); - ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); + assert.ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); viewer.world.getItemAt(0).reset(); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); viewer.addHandler('tile-drawn', function updateHandler2() { viewer.removeHandler('tile-drawn', updateHandler2); - ok(viewer.tileCache.numTilesLoaded() > 0, 'more tiles load'); + assert.ok(viewer.tileCache.numTilesLoaded() > 0, 'more tiles load'); viewer.world.getItemAt(0).destroy(); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after destroy'); - start(); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after destroy'); + done(); }); }); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('clip', function() { + QUnit.test('clip', function(assert) { + var done = assert.async(); var clip = new OpenSeadragon.Rect(100, 100, 800, 800); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); - propEqual(image.getClip(), clip, 'image has correct clip'); + assert.propEqual(image.getClip(), clip, 'image has correct clip'); image.setClip(null); - equal(image.getClip(), null, 'clip is cleared'); + assert.equal(image.getClip(), null, 'clip is cleared'); image.setClip(clip); - propEqual(image.getClip(), clip, 'clip is set correctly'); + assert.propEqual(image.getClip(), clip, 'clip is set correctly'); Util.spyOnce(viewer.drawer, 'setClip', function(rect) { var homeBounds = viewer.viewport.getHomeBounds(); var canvasClip = viewer.drawer .viewportToDrawerRectangle(homeBounds); var precision = 0.00000001; - Util.assertRectangleEquals(rect, canvasClip, precision, + Util.assertRectangleEquals(assert, rect, canvasClip, precision, 'clipping should be ' + canvasClip); - start(); + done(); }); }); @@ -223,15 +228,16 @@ }); // ---------- - asyncTest('clip-change event', function() { - expect(0); + QUnit.test('clip-change event', function(assert) { + var done = assert.async(); + assert.expect(0); var clip = new OpenSeadragon.Rect(100, 100, 800, 800); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); image.addOnceHandler('clip-change', function() { image.addOnceHandler('clip-change', function() { - start(); + done(); }); image.setClip(clip); }); @@ -244,23 +250,24 @@ }); // ---------- - asyncTest('getClipBounds', function() { + QUnit.test('getClipBounds', function(assert) { + var done = assert.async(); var clip = new OpenSeadragon.Rect(100, 200, 800, 500); viewer.addHandler('open', function() { var image = viewer.world.getItemAt(0); var bounds = image.getClippedBounds(); var expectedBounds = new OpenSeadragon.Rect(1.2, 1.4, 1.6, 1); - propEqual(bounds, expectedBounds, + assert.propEqual(bounds, expectedBounds, 'getClipBounds should take clipping into account.'); image = viewer.world.getItemAt(1); bounds = image.getClippedBounds(); expectedBounds = new OpenSeadragon.Rect(1, 2, 2, 2); - propEqual(bounds, expectedBounds, + assert.propEqual(bounds, expectedBounds, 'getClipBounds should work when no clipping set.'); - start(); + done(); }); viewer.open([{ @@ -278,15 +285,15 @@ }); // ---------- - asyncTest('opacity', function() { - + QUnit.test('opacity', function(assert) { + var done = assert.async(); function testDefaultOpacity() { viewer.removeHandler('open', testDefaultOpacity); var image = viewer.world.getItemAt(0); - strictEqual(image.getOpacity(), 0.5, 'image has default opacity'); + assert.strictEqual(image.getOpacity(), 0.5, 'image has default opacity'); image.setOpacity(1); - strictEqual(image.getOpacity(), 1, 'opacity is set correctly'); + assert.strictEqual(image.getOpacity(), 1, 'opacity is set correctly'); viewer.addHandler('open', testTileSourceOpacity); viewer.open({ @@ -298,12 +305,12 @@ function testTileSourceOpacity() { viewer.removeHandler('open', testTileSourceOpacity); var image = viewer.world.getItemAt(0); - strictEqual(image.getOpacity(), 0.25, 'image has correct opacity'); + assert.strictEqual(image.getOpacity(), 0.25, 'image has correct opacity'); image.setOpacity(0); - strictEqual(image.getOpacity(), 0, 'opacity is set correctly'); + assert.strictEqual(image.getOpacity(), 0, 'opacity is set correctly'); - start(); + done(); } viewer.addHandler('open', testDefaultOpacity); @@ -315,20 +322,20 @@ }); // ---------- - asyncTest('rotation', function() { - + QUnit.test('rotation', function(assert) { + var done = assert.async(); function testDefaultRotation() { var image = viewer.world.getItemAt(0); - strictEqual(image.getRotation(true), 0, 'image has default current rotation'); - strictEqual(image.getRotation(false), 0, 'image has default target rotation'); + assert.strictEqual(image.getRotation(true), 0, 'image has default current rotation'); + assert.strictEqual(image.getRotation(false), 0, 'image has default target rotation'); image.setRotation(400); - strictEqual(image.getRotation(true), 0, 'current rotation is not changed'); - strictEqual(image.getRotation(false), 400, 'target rotation is set correctly'); + assert.strictEqual(image.getRotation(true), 0, 'current rotation is not changed'); + assert.strictEqual(image.getRotation(false), 400, 'target rotation is set correctly'); image.setRotation(200, true); - strictEqual(image.getRotation(true), 200, 'current rotation is set correctly'); - strictEqual(image.getRotation(false), 200, 'target rotation is set correctly'); + assert.strictEqual(image.getRotation(true), 200, 'current rotation is set correctly'); + assert.strictEqual(image.getRotation(false), 200, 'target rotation is set correctly'); viewer.addOnceHandler('open', testTileSourceRotation); viewer.open({ @@ -339,9 +346,9 @@ function testTileSourceRotation() { var image = viewer.world.getItemAt(0); - strictEqual(image.getRotation(true), -60, 'image has correct current rotation'); - strictEqual(image.getRotation(false), -60, 'image has correct target rotation'); - start(); + assert.strictEqual(image.getRotation(true), -60, 'image has correct current rotation'); + assert.strictEqual(image.getRotation(false), -60, 'image has correct target rotation'); + done(); } viewer.addOnceHandler('open', testDefaultRotation); @@ -350,10 +357,10 @@ }); }); - asyncTest('fitBounds', function() { - + QUnit.test('fitBounds', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -386,7 +393,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(0, 1.75, 1, 0.25); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([ @@ -397,10 +404,10 @@ }); // ---------- - asyncTest('fitBounds in constructor', function() { - + QUnit.test('fitBounds in constructor', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -421,7 +428,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(0, 1.75, 1, 0.25); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([{ @@ -443,10 +450,10 @@ }); // ---------- - asyncTest('fitBounds with clipping', function() { - + QUnit.test('fitBounds with clipping', function(assert) { + var done = assert.async(); function assertRectEquals(actual, expected, message) { - ok(actual.equals(expected), message + ' should be ' + + assert.ok(actual.equals(expected), message + ' should be ' + expected.toString() + ', found ' + actual.toString()); } @@ -467,7 +474,7 @@ actualBounds = wideImage.getBounds(true); expectedBounds = new OpenSeadragon.Rect(1, 1, 16, 4); assertRectEquals(actualBounds, expectedBounds, 'Wide image bounds'); - start(); + done(); }); viewer.open([{ @@ -488,27 +495,28 @@ }); // ---------- - asyncTest('fullyLoaded', function() { + QUnit.test('fullyLoaded', function(assert) { + var done = assert.async(); viewer.addHandler('open', function openHandler() { viewer.removeHandler('open', openHandler); var image = viewer.world.getItemAt(0); - equal(image.getFullyLoaded(), false, 'not fully loaded at first'); + assert.equal(image.getFullyLoaded(), false, 'not fully loaded at first'); var count = 0; var fullyLoadedChangeHandler = function(event) { if (count === 0) { - equal(event.fullyLoaded, true, 'event includes true fullyLoaded property'); - equal(image.getFullyLoaded(), true, 'image is fully loaded after event'); + assert.equal(event.fullyLoaded, true, 'event includes true fullyLoaded property'); + assert.equal(image.getFullyLoaded(), true, 'image is fully loaded after event'); viewer.viewport.zoomBy(5, null, true); } else if (count === 1) { - equal(event.fullyLoaded, false, 'event includes false fullyLoaded property'); - equal(image.getFullyLoaded(), false, 'image is not fully loaded after zoom'); + assert.equal(event.fullyLoaded, false, 'event includes false fullyLoaded property'); + assert.equal(image.getFullyLoaded(), false, 'image is not fully loaded after zoom'); } else { image.removeHandler('fully-loaded-change', fullyLoadedChangeHandler); - equal(image.getFullyLoaded(), true, 'image is once again fully loaded'); - start(); + assert.equal(image.getFullyLoaded(), true, 'image is once again fully loaded'); + done(); } count++; @@ -529,7 +537,7 @@ }; } - test('_getCornerTiles without wrapping', function() { + QUnit.test('_getCornerTiles without wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: false, wrapVertical: false, @@ -548,10 +556,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -561,7 +569,7 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 6) - ) + ); // Floating point errors should be handled assertCornerTiles( @@ -569,17 +577,17 @@ new OpenSeadragon.Point(1 + 1e-14, 10 / 15 + 1e-14), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0.3, 0.5), new OpenSeadragon.Point(0.5, 0.6), new OpenSeadragon.Point(2, 5), new OpenSeadragon.Point(3, 6) - ) + ); }); - test('_getCornerTiles with horizontal wrapping', function() { + QUnit.test('_getCornerTiles with horizontal wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: true, wrapVertical: false, @@ -598,10 +606,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -611,24 +619,24 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(8, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(-1, 0), new OpenSeadragon.Point(0.5, 10 / 15 + 1e-14), new OpenSeadragon.Point(-8, 0), new OpenSeadragon.Point(3, 6) - ) + ); assertCornerTiles( new OpenSeadragon.Point(1.3, 0.5), new OpenSeadragon.Point(1.5, 0.6), new OpenSeadragon.Point(10, 5), new OpenSeadragon.Point(11, 6) - ) + ); }); - test('_getCornerTiles with vertical wrapping', function() { + QUnit.test('_getCornerTiles with vertical wrapping', function(assert) { var tiledImageMock = { wrapHorizontal: false, wrapVertical: true, @@ -647,10 +655,10 @@ function assertCornerTiles(topLeftBound, bottomRightBound, expectedTopLeft, expectedBottomRight) { var cornerTiles = _getCornerTiles(11, topLeftBound, bottomRightBound); - ok(cornerTiles.topLeft.equals(expectedTopLeft), + assert.ok(cornerTiles.topLeft.equals(expectedTopLeft), 'Top left tile should be ' + expectedTopLeft.toString() + ' found ' + cornerTiles.topLeft.toString()); - ok(cornerTiles.bottomRight.equals(expectedBottomRight), + assert.ok(cornerTiles.bottomRight.equals(expectedBottomRight), 'Bottom right tile should be ' + expectedBottomRight.toString() + ' found ' + cornerTiles.bottomRight.toString()); } @@ -660,21 +668,21 @@ new OpenSeadragon.Point(1, 10 / 15), new OpenSeadragon.Point(0, 0), new OpenSeadragon.Point(7, 7) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0, -10 / 15 / 2), new OpenSeadragon.Point(0.5, 0.5), new OpenSeadragon.Point(0, -4), new OpenSeadragon.Point(3, 5) - ) + ); assertCornerTiles( new OpenSeadragon.Point(0, 10 / 15 + 0.1), new OpenSeadragon.Point(0.3, 10 / 15 + 0.3), new OpenSeadragon.Point(0, 7), new OpenSeadragon.Point(2, 9) - ) + ); }); })(); diff --git a/test/modules/tilesource.js b/test/modules/tilesource.js index bac637c8..10262d6f 100644 --- a/test/modules/tilesource.js +++ b/test/modules/tilesource.js @@ -1,33 +1,33 @@ -/* global module, ok, equal, start, test, testLog, Util */ +/* global QUnit, testLog, Util */ (function() { - module('TileSource', { - setup: function() { + QUnit.module('TileSource', { + beforeEach: function() { testLog.reset(); } }); - test("should set sane tile size defaults", function() { + QUnit.test("should set sane tile size defaults", function(assert) { var source = new OpenSeadragon.TileSource(); - equal(source.getTileWidth(), 0, "getTileWidth() should return 0 if not provided a size"); - equal(source.getTileHeight(), 0, "getTileHeight() should return 0 if not provided a size"); + assert.equal(source.getTileWidth(), 0, "getTileWidth() should return 0 if not provided a size"); + assert.equal(source.getTileHeight(), 0, "getTileHeight() should return 0 if not provided a size"); }); - test("providing tileSize", function(){ + QUnit.test("providing tileSize", function(assert){ var tileSize = 256, source = new OpenSeadragon.TileSource({ tileSize: tileSize }); - equal(source.tileSize, undefined, "tileSize should not be set on the tileSource"); - equal(source.getTileWidth(), tileSize, "getTileWidth() should equal tileSize"); - equal(source.getTileHeight(), tileSize, "getTileHeight() should equal tileSize"); + assert.equal(source.tileSize, undefined, "tileSize should not be set on the tileSource"); + assert.equal(source.getTileWidth(), tileSize, "getTileWidth() should equal tileSize"); + assert.equal(source.getTileHeight(), tileSize, "getTileHeight() should equal tileSize"); }); - test("providing tileWidth and tileHeight", function(){ + QUnit.test("providing tileWidth and tileHeight", function(assert){ var tileWidth = 256, tileHeight = 512, source = new OpenSeadragon.TileSource({ @@ -35,20 +35,20 @@ tileHeight: tileHeight }); - equal(source._tileWidth, tileWidth, "tileWidth option should set _tileWidth"); - equal(source._tileHeight, tileHeight, "tileHeight option should set _tileHeight"); - equal(source.tileWidth, undefined, "tileWidth should be renamed _tileWidth"); - equal(source.tileHeight, undefined, "tileHeight should be renamed _tileHeight"); - equal(source.getTileWidth(), tileWidth, "getTileWidth() should equal tileWidth"); - equal(source.getTileHeight(), tileHeight, "getTileHeight() should equal tileHeight"); + assert.equal(source._tileWidth, tileWidth, "tileWidth option should set _tileWidth"); + assert.equal(source._tileHeight, tileHeight, "tileHeight option should set _tileHeight"); + assert.equal(source.tileWidth, undefined, "tileWidth should be renamed _tileWidth"); + assert.equal(source.tileHeight, undefined, "tileHeight should be renamed _tileHeight"); + assert.equal(source.getTileWidth(), tileWidth, "getTileWidth() should equal tileWidth"); + assert.equal(source.getTileHeight(), tileHeight, "getTileHeight() should equal tileHeight"); }); - test('getTileSize() deprecation', function() { + QUnit.test('getTileSize() deprecation', function(assert) { var source = new OpenSeadragon.TileSource(); - Util.testDeprecation(source, 'getTileSize'); + Util.testDeprecation(assert, source, 'getTileSize'); }); - test('getTileAtPoint', function() { + QUnit.test('getTileAtPoint', function(assert) { var tileSource = new OpenSeadragon.TileSource({ width: 1500, height: 1000, @@ -57,11 +57,11 @@ tileOverlap: 1, }); - equal(tileSource.maxLevel, 11, "The max level should be 11."); + assert.equal(tileSource.maxLevel, 11, "The max level should be 11."); function assertTileAtPoint(level, position, expected) { var actual = tileSource.getTileAtPoint(level, position); - ok(actual.equals(expected), "The tile at level " + level + + assert.ok(actual.equals(expected), "The tile at level " + level + ", position " + position.toString() + " should be tile " + expected.toString() + " got " + actual.toString()); diff --git a/test/modules/tilesourcecollection.js b/test/modules/tilesourcecollection.js index a9bbf79e..8a4aa617 100644 --- a/test/modules/tilesourcecollection.js +++ b/test/modules/tilesourcecollection.js @@ -1,20 +1,19 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, Util, testLog */ (function() { - var viewer; - - module('TileSourceCollection', { - setup: function () { + QUnit.module('TileSourceCollection', { + beforeEach: function () { testLog.reset(); }, - teardown: function () { + afterEach: function () { } }); // ---------- - asyncTest('deprecation', function() { - Util.testDeprecation(OpenSeadragon, 'TileSourceCollection'); - start(); + QUnit.test('deprecation', function(assert) { + var done = assert.async(); + Util.testDeprecation(assert, OpenSeadragon, 'TileSourceCollection'); + done(); }); })(); diff --git a/test/modules/world.js b/test/modules/world.js index 0c5aebf7..d524a131 100644 --- a/test/modules/world.js +++ b/test/modules/world.js @@ -1,11 +1,11 @@ -/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */ +/* global QUnit, $, testLog */ (function() { var viewer; - module('World', { - setup: function () { - var example = $('').appendTo("#qunit-fixture"); + QUnit.module('World', { + beforeEach: function () { + $('').appendTo("#qunit-fixture"); testLog.reset(); @@ -15,7 +15,7 @@ springStiffness: 100 // Faster animation = faster tests }); }, - teardown: function () { + afterEach: function () { if (viewer && viewer.close) { viewer.close(); } @@ -25,54 +25,56 @@ }); // ---------- - var checkBounds = function(expected, message) { + var checkBounds = function(assert, expected, message) { var bounds = viewer.world.getHomeBounds(); - ok(bounds.equals(expected), message + ' ' + bounds.toString()); + assert.ok(bounds.equals(expected), message + ' ' + bounds.toString()); }; // ---------- - asyncTest('adding a tiled image', function() { - ok(viewer.world, 'World exists'); + QUnit.test('adding a tiled image', function(assert) { + var done = assert.async(); + assert.ok(viewer.world, 'World exists'); viewer.world.addHandler('add-item', function(event) { - ok(event, 'add-item handler received event data'); - equal(event.eventSource, viewer.world, 'sender of add-item event was world'); - ok(event.item, 'add-item event includes item'); - equal(viewer.world.getItemCount(), 1, 'there is now 1 item'); - equal(event.item, viewer.world.getItemAt(0), 'item is accessible via getItemAt'); - equal(viewer.world.getIndexOfItem(event.item), 0, 'item index is 0'); - start(); + assert.ok(event, 'add-item handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of add-item event was world'); + assert.ok(event.item, 'add-item event includes item'); + assert.equal(viewer.world.getItemCount(), 1, 'there is now 1 item'); + assert.equal(event.item, viewer.world.getItemAt(0), 'item is accessible via getItemAt'); + assert.equal(viewer.world.getIndexOfItem(event.item), 0, 'item index is 0'); + done(); }); - equal(viewer.world.getItemCount(), 0, 'no items to start with'); + assert.equal(viewer.world.getItemCount(), 0, 'no items to start with'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('metrics', function() { + QUnit.test('metrics', function(assert) { + var done = assert.async(); viewer.addHandler('open', function(event) { - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 4), 'bounds after open'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 4), 'bounds after open'); var expectedContentFactor = viewer.world.getItemAt(1).getContentSize().x / 2; - equal(viewer.world.getContentFactor(), expectedContentFactor, 'content factor has changed'); + assert.equal(viewer.world.getContentFactor(), expectedContentFactor, 'content factor has changed'); viewer.world.addHandler('metrics-change', function metricsChangeHandler(event) { viewer.world.removeHandler('metrics-change', metricsChangeHandler); - ok(event, 'metrics-change handler received event data'); - equal(event.eventSource, viewer.world, 'sender of metrics-change event was world'); - checkBounds(new OpenSeadragon.Rect(0, 0, 7, 12), 'bounds after position'); + assert.ok(event, 'metrics-change handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of metrics-change event was world'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 7, 12), 'bounds after position'); viewer.world.getItemAt(0).setWidth(20); - checkBounds(new OpenSeadragon.Rect(0, 0, 20, 20), 'bounds after size'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 20, 20), 'bounds after size'); - start(); + done(); }); viewer.world.getItemAt(1).setPosition(new OpenSeadragon.Point(5, 10)); }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 1), 'default bounds'); - equal(viewer.world.getContentFactor(), 1, 'default content factor'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 1), 'default bounds'); + assert.equal(viewer.world.getContentFactor(), 1, 'default content factor'); viewer.open([ { @@ -86,23 +88,24 @@ }); // ---------- - asyncTest('remove/reorder tiled images', function() { + QUnit.test('remove/reorder tiled images', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { - equal(viewer.world.getItemCount(), 3, 'there are now 3 items'); + assert.equal(viewer.world.getItemCount(), 3, 'there are now 3 items'); var item0 = viewer.world.getItemAt(0); var item1 = viewer.world.getItemAt(1); viewer.world.addHandler('item-index-change', function(event) { handlerCount++; - ok(event, 'item-index-change handler received event data'); - equal(event.eventSource, viewer.world, 'sender of item-index-change event was world'); - equal(event.item, item0, 'item-index-change event includes correct item'); - equal(event.newIndex, 1, 'item-index-change event includes correct newIndex'); - equal(event.previousIndex, 0, 'item-index-change event includes correct previousIndex'); - equal(viewer.world.getItemAt(0), item1, 'item1 is now at index 0'); - equal(viewer.world.getItemAt(1), item0, 'item0 is now at index 1'); + assert.ok(event, 'item-index-change handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of item-index-change event was world'); + assert.equal(event.item, item0, 'item-index-change event includes correct item'); + assert.equal(event.newIndex, 1, 'item-index-change event includes correct newIndex'); + assert.equal(event.previousIndex, 0, 'item-index-change event includes correct previousIndex'); + assert.equal(viewer.world.getItemAt(0), item1, 'item1 is now at index 0'); + assert.equal(viewer.world.getItemAt(1), item0, 'item0 is now at index 1'); }); viewer.world.setItemIndex(item0, 1); @@ -110,11 +113,11 @@ viewer.world.addHandler('remove-item', function removeHandler(event) { viewer.world.removeHandler('remove-item', removeHandler); handlerCount++; - ok(event, 'remove-item handler received event data'); - equal(event.eventSource, viewer.world, 'sender of remove-item event was world'); - equal(event.item, item1, 'remove-item event includes correct item'); - equal(viewer.world.getItemCount(), 2, 'after removal, only two items remain'); - equal(viewer.world.getItemAt(0), item0, 'item0 is now at index 0'); + assert.ok(event, 'remove-item handler received event data'); + assert.equal(event.eventSource, viewer.world, 'sender of remove-item event was world'); + assert.equal(event.item, item1, 'remove-item event includes correct item'); + assert.equal(viewer.world.getItemCount(), 2, 'after removal, only two items remain'); + assert.equal(viewer.world.getItemAt(0), item0, 'item0 is now at index 0'); }); viewer.world.removeItem(item1); @@ -124,17 +127,17 @@ removeCount++; if (removeCount === 2) { handlerCount++; - equal(viewer.world.getItemCount(), 0, 'after removeAll, no items remain'); + assert.equal(viewer.world.getItemCount(), 0, 'after removeAll, no items remain'); } }); viewer.world.removeAll(); - equal(handlerCount, 3, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 3, 'correct number of handlers called'); + done(); }); - equal(viewer.world.getItemCount(), 0, 'no items to start with'); + assert.equal(viewer.world.getItemCount(), 0, 'no items to start with'); viewer.open([ '/test/data/testpattern.dzi', @@ -144,11 +147,12 @@ }); // ---------- - asyncTest('draw', function() { + QUnit.test('draw', function(assert) { + var done = assert.async(); var handlerCount = 0; viewer.addHandler('open', function(event) { - equal(viewer.world.needsDraw(), true, 'needs draw after open'); + assert.equal(viewer.world.needsDraw(), true, 'needs draw after open'); viewer.addHandler('update-level', function updateHandler() { viewer.removeHandler('update-level', updateHandler); @@ -157,34 +161,36 @@ viewer.world.draw(); - equal(handlerCount, 1, 'correct number of handlers called'); - start(); + assert.equal(handlerCount, 1, 'correct number of handlers called'); + done(); }); - equal(viewer.world.needsDraw(), false, 'needs no draw at first'); + assert.equal(viewer.world.needsDraw(), false, 'needs no draw at first'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('resetItems', function() { + QUnit.test('resetItems', function(assert) { + var done = assert.async(); viewer.addHandler('tile-drawn', function updateHandler() { viewer.removeHandler('tile-drawn', updateHandler); - ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); + assert.ok(viewer.tileCache.numTilesLoaded() > 0, 'we have tiles after tile-drawn'); viewer.world.resetItems(); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); - start(); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles after reset'); + done(); }); - equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); + assert.equal(viewer.tileCache.numTilesLoaded(), 0, 'no tiles at start'); viewer.open('/test/data/testpattern.dzi'); }); // ---------- - asyncTest('arrange', function() { + QUnit.test('arrange', function(assert) { + var done = assert.async(); viewer.addHandler('open', function(event) { - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 1), 'all stacked'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 1), 'all stacked'); viewer.world.arrange({ layout: 'horizontal', @@ -193,7 +199,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 1), 'one horizontal row'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 1), 'one horizontal row'); viewer.world.arrange({ layout: 'horizontal', @@ -202,7 +208,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 2.5, 2.5), 'grid'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 2.5, 2.5), 'grid'); viewer.world.arrange({ layout: 'vertical', @@ -211,7 +217,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 4), 'one vertical column'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 4), 'one vertical column'); viewer.world.arrange({ layout: 'horizontal', @@ -221,7 +227,7 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 4, 1), 'three horizontal columns (one horizontal row)'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 4, 1), 'three horizontal columns (one horizontal row)'); viewer.world.arrange({ layout: 'vertical', @@ -231,9 +237,9 @@ tileMargin: 0.5 }); - checkBounds(new OpenSeadragon.Rect(0, 0, 1, 4), 'three vertical rows (one vertical column)'); + checkBounds(assert, new OpenSeadragon.Rect(0, 0, 1, 4), 'three vertical rows (one vertical column)'); - start(); + done(); }); viewer.open([ diff --git a/test/test.html b/test/test.html index 98f8ffff..a165ffd6 100644 --- a/test/test.html +++ b/test/test.html @@ -32,7 +32,7 @@ - + -