From cf2413e0c9838ae403058d7fb278242f798e6ede Mon Sep 17 00:00:00 2001 From: Aiosa <34658867+Aiosa@users.noreply.github.com> Date: Sun, 10 Dec 2023 16:49:56 +0100 Subject: [PATCH] Fix test for the preload hack (and fix the parentheses to always call updateMulti). --- src/viewer.js | 8 ++++---- test/modules/events.js | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/viewer.js b/src/viewer.js index 5b5af50a..16e4f093 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -356,7 +356,7 @@ $.Viewer = function( options ) { //if we are not throttling if (_this.imageLoader.canAcceptNewJob()) { - //todo small hack, we could make this builtin speedup more sophisticated + //todo small hack, we could make this builtin speedup more sophisticated, breaks tests --> commented out const item = event.item; const origOpacity = item.opacity; const origMaxTiles = item.maxTilesPerFrame; @@ -367,10 +367,10 @@ $.Viewer = function( options ) { item._needsDraw = true; //we did not draw item.opacity = origOpacity; item.maxTilesPerFrame = origMaxTiles; + } - if (!_this._updateRequestId) { - _this._updateRequestId = scheduleUpdate( _this, updateMulti ); - } + if (!_this._updateRequestId) { + _this._updateRequestId = scheduleUpdate( _this, updateMulti ); } }); diff --git a/test/modules/events.js b/test/modules/events.js index cf5171a3..e0a0b291 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -1288,22 +1288,25 @@ QUnit.test( 'Viewer: tile-unloaded event.', function(assert) { var tiledImage; - var tile; + var tiles = []; var done = assert.async(); function tileLoaded( event ) { - viewer.removeHandler( 'tile-loaded', tileLoaded); tiledImage = event.tiledImage; - tile = event.tile; - setTimeout(function() { - tiledImage.reset(); - }, 0); + tiles.push(event.tile); + if (tiles.length === 1) { + setTimeout(function() { + tiledImage.reset(); + }, 0); + } } function tileUnloaded( event ) { + viewer.removeHandler( 'tile-loaded', tileLoaded); viewer.removeHandler( 'tile-unloaded', tileUnloaded ); - assert.equal( tile, event.tile, - "The unloaded tile should be the same than the loaded one." ); + + assert.equal( tiles.find(t => t === event.tile), event.tile, + "The unloaded tile should be one of the loaded tiles." ); assert.equal( tiledImage, event.tiledImage, "The tiledImage of the unloaded tile should be the same than the one of the loaded one." ); done();