openseadragon/test/modules/drawer.js

128 lines
4.0 KiB
JavaScript
Raw Normal View History

2017-12-07 04:20:39 +03:00
/* global QUnit, $, Util, testLog */
2014-11-19 03:28:08 +03:00
(function() {
var viewer;
2017-12-07 04:20:39 +03:00
QUnit.module('Drawer', {
beforeEach: function () {
$('<div id="example"></div>').appendTo("#qunit-fixture");
2014-11-19 03:28:08 +03:00
testLog.reset();
},
2017-12-07 04:20:39 +03:00
afterEach: function () {
2024-01-10 20:13:00 +03:00
if (viewer){
viewer.destroy();
}
2014-11-19 03:28:08 +03:00
viewer = null;
}
});
2014-11-21 01:25:17 +03:00
// ----------
var createViewer = function(options) {
options = options || {};
2022-12-03 02:52:53 +03:00
// eslint-disable-next-line new-cap
2014-11-21 01:25:17 +03:00
viewer = OpenSeadragon(OpenSeadragon.extend({
id: 'example',
prefixUrl: '/build/openseadragon/images/',
springStiffness: 100 // Faster animation = faster tests
}, options));
};
2014-11-19 03:28:08 +03:00
// ----------
2017-12-07 04:20:39 +03:00
QUnit.test('basics', function(assert) {
var done = assert.async();
2014-11-21 01:25:17 +03:00
createViewer();
2017-12-07 04:20:39 +03:00
assert.ok(viewer.drawer, 'Drawer exists');
assert.equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas');
done();
2014-11-19 03:28:08 +03:00
});
2014-11-21 01:25:17 +03:00
// ----------
2017-12-07 04:20:39 +03:00
QUnit.test('rotation', function(assert) {
var done = assert.async();
2014-11-21 01:25:17 +03:00
createViewer({
tileSources: '/test/data/testpattern.dzi',
drawer: 'canvas', // this test only makes sense for certain drawers
2014-11-21 01:25:17 +03:00
});
viewer.addHandler('open', function handler(event) {
viewer.viewport.setRotation(30, true);
2014-11-21 01:25:17 +03:00
Util.spyOnce(viewer.drawer.context, 'rotate', function() {
2017-12-07 04:20:39 +03:00
assert.ok(true, 'drawing with new rotation');
done();
2014-11-21 01:25:17 +03:00
});
});
});
// ----------
2017-12-07 04:20:39 +03:00
QUnit.test('debug', function(assert) {
var done = assert.async();
2014-11-21 01:25:17 +03:00
createViewer({
tileSources: '/test/data/testpattern.dzi',
debugMode: true
});
Util.spyOnce(viewer.drawer, '_drawDebugInfo', function() {
assert.ok(true, '_drawDebugInfo is called');
2017-12-07 04:20:39 +03:00
done();
2014-11-21 01:25:17 +03:00
});
});
2014-11-19 03:28:08 +03:00
2015-04-23 03:12:38 +03:00
// ----------
2017-12-07 04:20:39 +03:00
QUnit.test('sketchCanvas', function(assert) {
var done = assert.async();
2015-04-23 03:12:38 +03:00
createViewer({
tileSources: '/test/data/testpattern.dzi',
drawer: 'canvas' // test only makes sense for this drawer
2015-04-23 03:12:38 +03:00
});
var drawer = viewer.drawer;
viewer.addHandler('tile-drawn', function noOpacityHandler() {
viewer.removeHandler('tile-drawn', noOpacityHandler);
2017-12-07 04:20:39 +03:00
assert.equal(drawer.sketchCanvas, null,
2015-04-23 03:12:38 +03:00
'The sketch canvas should be null if no decimal opacity is used.');
2017-12-07 04:20:39 +03:00
assert.equal(drawer.sketchContext, null,
2015-04-23 03:12:38 +03:00
'The sketch context should be null if no decimal opacity is used.');
testOpacityDecimal();
});
function testOpacityDecimal() {
var tiledImage;
viewer.addTiledImage({
tileSource: '/test/data/testpattern.dzi',
opacity: 0.5,
success: function(event) {
tiledImage = event.item;
}
});
viewer.addHandler('tile-drawn', function opacityDecimalHandler(event) {
if (tiledImage !== event.tiledImage) {
return;
}
viewer.removeHandler('tile-drawn', opacityDecimalHandler);
2017-12-07 04:20:39 +03:00
assert.notEqual(drawer.sketchCanvas, null,
2015-04-23 03:12:38 +03:00
'The sketch canvas should not be null once a decimal opacity has been used.');
2017-12-07 04:20:39 +03:00
assert.notEqual(drawer.sketchContext, null,
2015-04-23 03:12:38 +03:00
'The sketch context should not be null once a decimal opacity has been used.');
2017-12-07 04:20:39 +03:00
done();
2015-04-23 03:12:38 +03:00
});
}
});
2014-11-21 01:25:17 +03:00
// ----------
2017-12-07 04:20:39 +03:00
QUnit.test('deprecations', function(assert) {
var done = assert.async();
2015-04-23 03:12:38 +03:00
createViewer({
tileSources: '/test/data/testpattern.dzi'
});
viewer.world.addHandler('add-item', function() {
2023-06-08 22:10:55 +03:00
// no current deprecated methods
assert.expect(0);
2017-12-07 04:20:39 +03:00
done();
2015-04-23 03:12:38 +03:00
});
2014-11-19 03:28:08 +03:00
});
})();