test drawers separately

This commit is contained in:
Tom 2024-01-10 17:46:17 -05:00
parent 834795b4b8
commit 8be2ca2dfb

View File

@ -2,6 +2,10 @@
(function() { (function() {
var viewer; var viewer;
const drawerTypes = ['webgl','canvas','html'];
drawerTypes.forEach(runDrawerTests);
function runDrawerTests(drawerType){
QUnit.module('Drawer', { QUnit.module('Drawer', {
beforeEach: function () { beforeEach: function () {
@ -24,27 +28,38 @@
viewer = OpenSeadragon(OpenSeadragon.extend({ viewer = OpenSeadragon(OpenSeadragon.extend({
id: 'example', id: 'example',
prefixUrl: '/build/openseadragon/images/', prefixUrl: '/build/openseadragon/images/',
springStiffness: 100 // Faster animation = faster tests springStiffness: 100, // Faster animation = faster tests
drawer: drawerType,
}, options)); }, options));
}; };
// ---------- // ----------
QUnit.test('basics', function(assert) { QUnit.test('basics-'+drawerType, function(assert) {
var done = assert.async(); var done = assert.async();
createViewer(); createViewer();
assert.ok(viewer.drawer, 'Drawer exists'); assert.ok(viewer.drawer, 'Drawer exists');
assert.equal(viewer.drawer.canRotate(), OpenSeadragon.supportsCanvas, 'we can rotate if we have canvas'); assert.equal(viewer.drawer.canRotate(), ['webgl','canvas'].includes(drawerType), 'we can rotate if we have canvas');
done(); done();
}); });
// ---------- // ----------
QUnit.test('rotation', function(assert) { QUnit.test('rotation-'+drawerType, function(assert) {
var done = assert.async(); var done = assert.async();
createViewer({ createViewer({
tileSources: '/test/data/testpattern.dzi', tileSources: '/test/data/testpattern.dzi'
drawer: 'canvas', // this test only makes sense for certain drawers
}); });
// this test only makes sense for canvas drawer because of how it is
// detected by watching for the canvas context rotate function
// TODO: add test for actual rotation of the drawn image in a way that
// applies to the webgl drawer as well as the canvas drawer.
if(viewer.drawer.getType() !== 'canvas'){
assert.expect(0);
done();
};
viewer.addHandler('open', function handler(event) { viewer.addHandler('open', function handler(event) {
viewer.viewport.setRotation(30, true); viewer.viewport.setRotation(30, true);
Util.spyOnce(viewer.drawer.context, 'rotate', function() { Util.spyOnce(viewer.drawer.context, 'rotate', function() {
@ -55,13 +70,18 @@
}); });
// ---------- // ----------
QUnit.test('debug', function(assert) { QUnit.test('debug-'+drawerType, function(assert) {
var done = assert.async(); var done = assert.async();
createViewer({ createViewer({
tileSources: '/test/data/testpattern.dzi', tileSources: '/test/data/testpattern.dzi',
debugMode: true debugMode: true
}); });
// only test this for canvas and webgl drawers
if( !['canvas','webgl'].includes(viewer.drawer.getType() )){
assert.expect(0);
done()
}
Util.spyOnce(viewer.drawer, '_drawDebugInfo', function() { Util.spyOnce(viewer.drawer, '_drawDebugInfo', function() {
assert.ok(true, '_drawDebugInfo is called'); assert.ok(true, '_drawDebugInfo is called');
done(); done();
@ -69,14 +89,20 @@
}); });
// ---------- // ----------
QUnit.test('sketchCanvas', function(assert) { QUnit.test('sketchCanvas-'+drawerType, function(assert) {
var done = assert.async(); var done = assert.async();
createViewer({ createViewer({
tileSources: '/test/data/testpattern.dzi', tileSources: '/test/data/testpattern.dzi',
drawer: 'canvas' // test only makes sense for this drawer
}); });
var drawer = viewer.drawer; var drawer = viewer.drawer;
// this test only makes sense for canvas drawer
if(viewer.drawer.getType() !== 'canvas'){
assert.expect(0);
done();
};
viewer.addHandler('tile-drawn', function noOpacityHandler() { viewer.addHandler('tile-drawn', function noOpacityHandler() {
viewer.removeHandler('tile-drawn', noOpacityHandler); viewer.removeHandler('tile-drawn', noOpacityHandler);
assert.equal(drawer.sketchCanvas, null, assert.equal(drawer.sketchCanvas, null,
@ -111,7 +137,7 @@
}); });
// ---------- // ----------
QUnit.test('deprecations', function(assert) { QUnit.test('deprecations-'+drawerType, function(assert) {
var done = assert.async(); var done = assert.async();
createViewer({ createViewer({
@ -124,4 +150,6 @@
}); });
}); });
}
})(); })();