openseadragon/test/modules/viewerretrieval.js

102 lines
3.7 KiB
JavaScript
Raw Normal View History

2021-07-02 20:18:46 +03:00
/* global QUnit, $, testLog */
(function() {
var viewer1;
var viewer2;
QUnit.module('ViewerRetrieval', {
beforeEach: function () {
$('<div id="example1"></div><div id="example2"></div>')
.appendTo("#qunit-fixture");
testLog.reset();
viewer1 = OpenSeadragon({
id: 'example1',
prefixUrl: 'build/openseadragon/images/',
springStiffness: 100 // Faster animation = faster tests
});
viewer2 = OpenSeadragon({
id: 'example2',
prefixUrl: 'build/openseadragon/images/',
springStiffness: 100
});
},
afterEach: function () {
2024-01-18 01:07:25 +03:00
if (viewer1){
let errors = viewer1.drawer._numGlMaxTextureErrors;
if(errors > 0){
console.log('Number of times MAX_TEXTURE_IMAGE_UNITS had a bad value:', errors);
}
2021-07-02 20:18:46 +03:00
viewer1.destroy();
}
2024-01-18 01:07:25 +03:00
if (viewer2){
let errors = viewer2.drawer._numGlMaxTextureErrors;
if(errors > 0){
console.log('Number of times MAX_TEXTURE_IMAGE_UNITS had a bad value:', errors);
}
2021-07-02 20:18:46 +03:00
viewer2.destroy();
}
viewer1 = viewer2 = null;
}
});
QUnit.test('Get Viewers by Id', function(assert) {
var retrievedViewer1 = OpenSeadragon.getViewer('example1');
assert.ok(retrievedViewer1, 'Attached viewer retrieved');
assert.equal(retrievedViewer1, viewer1, 'Viewers are same instance');
var retrievedViewer2 = OpenSeadragon.getViewer('example2');
assert.ok(retrievedViewer2, 'Attached viewer retrieved');
assert.equal(retrievedViewer2, viewer2, 'Viewers are same instance');
// Internal state
assert.equal(OpenSeadragon._viewers.size, 2, 'Correct amount of viewers');
});
QUnit.test('Get Viewers by Element', function(assert) {
var retrievedViewer1 = OpenSeadragon.getViewer(
document.getElementById('example1'));
assert.ok(retrievedViewer1, 'Attached viewer retrieved');
assert.equal(retrievedViewer1, viewer1, 'Viewers are same instance');
var retrievedViewer2 = OpenSeadragon.getViewer(
document.getElementById('example2'));
assert.ok(retrievedViewer2, 'Attached viewer retrieved');
assert.equal(retrievedViewer2, viewer2, 'Viewers are same instance');
// Internal state
assert.equal(OpenSeadragon._viewers.size, 2, 'Correct amount of viewers');
});
QUnit.test('Undefined on Get Non-Existent Viewer by Id', function(assert) {
var notFoundViewer = OpenSeadragon.getViewer('no-viewer');
assert.equal(notFoundViewer, undefined, "Not found viewer is undefined");
});
QUnit.test('Undefined on Get Non-Existent Viewer by Element', function(assert) {
var element = document.createElement('div');
element.id = 'no-viewer';
document.body.appendChild(element);
var notFoundViewer = OpenSeadragon.getViewer(element);
assert.equal(notFoundViewer, undefined, "Not found viewer is undefined");
});
QUnit.test('Cleanup Viewers Registration', function(assert) {
viewer1.destroy();
viewer2.destroy();
viewer1 = viewer2 = null;
var retrievedViewer1 = OpenSeadragon.getViewer('example1');
var retrievedViewer2 = OpenSeadragon.getViewer('example2');
assert.equal(retrievedViewer1, undefined, 'Viewer was destroyed');
assert.equal(retrievedViewer2, undefined, 'Viewer was destroyed');
// Internal state
assert.equal(OpenSeadragon._viewers.size, 0, 'No viewers are registered');
});
})();