#1970: Update unit test to check for changed url behavior

This commit is contained in:
John Reagan 2022-12-02 10:29:52 -05:00
parent 601160e9fb
commit 8ef5270d7f

View file

@ -8,6 +8,10 @@
var viewer = null;
var OriginalAjax = OpenSeadragon.makeAjaxRequest;
var OriginalTile = OpenSeadragon.Tile;
// These variables allow tracking when the first request for data has finished
var firstUrlPromise = null;
var isFirstUrlPromiseResolved = false;
var firstUrlPromiseResolver = null;
/**
* Set up shared variables for test
@ -15,6 +19,12 @@
var configure = function(assert, url) {
ASSERT = assert;
DYNAMIC_URL = url;
firstUrlPromise = new Promise(resolve => {
firstUrlPromiseResolver = () => {
isFirstUrlPromiseResolved = true;
resolve();
};
});
};
QUnit.module('TileSourceDynamicUrl', {
@ -28,7 +38,7 @@
};
OpenSeadragon.extend( OpenSeadragon.DynamicUrlTestTileSource.prototype, OpenSeadragon.TileSource.prototype, {
supports: function( data, url ){
supports: function(_data, url){
return url.indexOf('dynamic') !== -1;
},
@ -79,8 +89,15 @@
//first AJAX firing is the image info getter, second is the first tile request: can exit
if (hasCompletedImageInfoRequest) {
// Assert dynamic url from tileSource is called
ASSERT.equal(url, DYNAMIC_URL, 'Called dynamic url correctly');
ASSERT.equal(url, DYNAMIC_URL, 'Called dynamic url correctly: ' + DYNAMIC_URL);
// If we've only queried for one url, resolve that promise to set up second query
// Otherwise close viewer
if (isFirstUrlPromiseResolved) {
viewer.close();
} else {
firstUrlPromiseResolver();
}
return null;
}
@ -151,34 +168,32 @@
viewer.addHandler('ready', readyHandler);
var openHandler = function(event) {
var openHandler = function(_event) {
viewer.removeHandler('open', openHandler);
ASSERT.ok(true, 'Open event was sent');
viewer.addHandler('close', closeHandler);
viewer.world.draw();
};
var closeHandler = function(event) {
var closeHandler = function(_event) {
viewer.removeHandler('close', closeHandler);
$('#example').empty();
ASSERT.ok(true, 'Close event was sent');
timeWatcher.done();
};
viewer.addHandler('open', openHandler);
return viewer;
};
// ----------
QUnit.test('TileSource.getTileUrl supports returning a function', function(assert) {
/**
* Expect 5 assertions to be called:
* 1. Open event was sent
* 2. DynamicUrlTileSource.getTileUrl called
* 3. Tile.getUrl called
* 4. Called dynamic url correctly
* 5. Close event was sent
*/
assert.expect(5);
configure(assert, 'dynamicUrl');
testUrlCall('dynamicUrl');
const viewer = testUrlCall('dynamicUrl');
firstUrlPromise.then(() => {
// after querying with first dynamic url, update the url and trigger new request
DYNAMIC_URL = 'dyanmicUrl2';
delete viewer.world.getItemAt(0).tilesMatrix[1][0][0];
})
});
})();