Fixing test failures

This commit is contained in:
Ian Gilman 2022-12-02 15:52:53 -08:00
parent 9c42062efb
commit 77030096e4
4 changed files with 98 additions and 92 deletions

View File

@ -21,6 +21,7 @@
// ----------
var createViewer = function(options) {
options = options || {};
// eslint-disable-next-line new-cap
viewer = OpenSeadragon(OpenSeadragon.extend({
id: 'example',
prefixUrl: '/build/openseadragon/images/',
@ -45,7 +46,7 @@
});
viewer.addHandler('open', function handler(event) {
viewer.viewport.setRotation(30, true);
viewer.viewport.setRotation(30, null, true);
Util.spyOnce(viewer.drawer.context, 'rotate', function() {
assert.ok(true, 'drawing with new rotation');
done();

View File

@ -9,6 +9,7 @@
testLog.reset();
// eslint-disable-next-line new-cap
viewer = OpenSeadragon( {
id: 'eventsexample',
prefixUrl: '/build/openseadragon/images/',
@ -194,13 +195,13 @@
var simulateEnter = function (x, y) {
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mouseenter', simEvent );
};
var simulateLeave = function (x, y) {
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
simEvent.relatedTarget = document.body;
$canvas.simulate( 'mouseleave', simEvent );
};
@ -215,28 +216,28 @@
var simulateDown = function (x, y) {
simEvent.button = 0;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mousedown', simEvent );
};
var simulateUp = function (x, y) {
simEvent.button = 0;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mouseup', simEvent );
};
var simulateNonPrimaryDown = function (x, y, button) {
simEvent.button = button;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mousedown', simEvent );
};
var simulateNonPrimaryUp = function (x, y, button) {
simEvent.button = button;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mouseup', simEvent );
};
@ -680,7 +681,7 @@
// start-end-end (multi-touch start event)
reset();
touches = TouchUtil.start( [0,0], [20,20] );
touches = TouchUtil.start( [0, 0], [20, 20] );
assessTouchExpectations({
description: 'start-end-end (multi-touch start event) [capture]: ',
captureCount: 2,
@ -790,7 +791,7 @@
"Zoom should not be prevented");
Util.assertRectangleEquals(
assert,
new OpenSeadragon.Rect(-249.5, -0.25, 500, 0.5),
new OpenSeadragon.Rect(-384.5, -0.25, 500, 0.5),
bounds,
epsilon,
'Pan should not be prevented');
@ -813,13 +814,13 @@
var simulateEnter = function (x, y) {
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mouseenter', simEvent );
};
var simulateLeave = function (x, y) {
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
simEvent.relatedTarget = document.body;
$canvas.simulate( 'mouseleave', simEvent );
};
@ -827,14 +828,14 @@
var simulateDown = function (x, y) {
simEvent.button = 0;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mousedown', simEvent );
};
var simulateUp = function (x, y) {
simEvent.button = 0;
simEvent.clientX = offset.left + x;
simEvent.clientY = offset.top + y;
simEvent.clientY = offset.top + y;
$canvas.simulate( 'mouseup', simEvent );
};
@ -912,50 +913,6 @@
dragEndsExpected = 1,
releasesExpected = 1;
var onOpen = function ( ) {
viewer.removeHandler( 'open', onOpen );
viewer.addHandler( 'canvas-drag', onEventSourceDrag );
viewer.addHandler( 'canvas-drag-end', onEventSourceDragEnd );
viewer.addHandler( 'canvas-release', onEventSourceRelease );
viewer.addHandler( 'canvas-click', onEventSourceClick );
mouseTracker = new OpenSeadragon.MouseTracker( {
element: $canvas[0],
userData: userData,
clickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickTimeThreshold,
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold,
dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold,
focusHandler: onMouseTrackerFocus,
blurHandler: onMouseTrackerBlur,
enterHandler: onMouseTrackerEnter,
pressHandler: onMouseTrackerPress,
moveHandler: onMouseTrackerMove,
dragHandler: onMouseTrackerDrag,
dragEndHandler: onMouseTrackerDragEnd,
releaseHandler: onMouseTrackerRelease,
clickHandler: onMouseTrackerClick,
leaveHandler: onMouseTrackerLeave
} );
var event = {
clientX:1,
clientY:1
};
$canvas.simulate( 'focus', event );
Util.simulateViewerClickWithDrag( {
viewer: viewer,
widthFactor: 0.25,
heightFactor: 0.25,
dragCount: dragCount,
dragDx: 1,
dragDy: 1
} );
$canvas.simulate( 'blur', event );
};
var checkOriginalEventReceivedViewer = function ( event ) {
eventsHandledViewer++;
//TODO Provide a better check for the original event...simulate doesn't currently extend the object
@ -1055,6 +1012,50 @@
done();
};
var onOpen = function ( ) {
viewer.removeHandler( 'open', onOpen );
viewer.addHandler( 'canvas-drag', onEventSourceDrag );
viewer.addHandler( 'canvas-drag-end', onEventSourceDragEnd );
viewer.addHandler( 'canvas-release', onEventSourceRelease );
viewer.addHandler( 'canvas-click', onEventSourceClick );
mouseTracker = new OpenSeadragon.MouseTracker( {
element: $canvas[0],
userData: userData,
clickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickTimeThreshold,
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold,
dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold,
focusHandler: onMouseTrackerFocus,
blurHandler: onMouseTrackerBlur,
enterHandler: onMouseTrackerEnter,
pressHandler: onMouseTrackerPress,
moveHandler: onMouseTrackerMove,
dragHandler: onMouseTrackerDrag,
dragEndHandler: onMouseTrackerDragEnd,
releaseHandler: onMouseTrackerRelease,
clickHandler: onMouseTrackerClick,
leaveHandler: onMouseTrackerLeave
} );
var event = {
clientX: 1,
clientY: 1
};
$canvas.simulate( 'focus', event );
Util.simulateViewerClickWithDrag( {
viewer: viewer,
widthFactor: 0.25,
heightFactor: 0.25,
dragCount: dragCount,
dragDx: 1,
dragDy: 1
} );
$canvas.simulate( 'blur', event );
};
viewer.addHandler( 'open', onOpen );
viewer.open( '/test/data/testpattern.dzi' );
} );

View File

@ -1,3 +1,4 @@
/* eslint-disable camelcase */
/* global QUnit, $, Util, testLog */
(function () {
@ -10,6 +11,7 @@
testLog.reset();
// eslint-disable-next-line new-cap
viewer = OpenSeadragon({
id: 'unitsexample',
prefixUrl: '/build/openseadragon/images/',
@ -210,13 +212,13 @@
checkPoint(assert, ' after zoom and pan');
//Restore rotation
viewer.viewport.setRotation(0, true);
viewer.viewport.setRotation(0, null, true);
done();
});
viewer.viewport.zoomTo(0.8).panTo(new OpenSeadragon.Point(0.1, 0.2));
});
viewer.viewport.setRotation(45, true);
viewer.viewport.setRotation(45, null, true);
viewer.open([{
tileSource: "/test/data/testpattern.dzi"
}, {

View File

@ -1,4 +1,5 @@
/* global QUnit, $, Util, testLog, console */
/* eslint-disable new-cap */
/* global QUnit, $, Util, testLog */
(function () {
var viewer;
@ -58,7 +59,8 @@
// values for zoom levels, and reopen the viewer for each iteration.
var reopenViewerHelper = function(assert, config) {
var done = assert.async();
var expected, level, actual, i = 0;
var expected, level, actual;
var i = 0;
var openHandler = function(event) {
var viewport = viewer.viewport;
expected = config.processExpected(level, expected);
@ -245,7 +247,7 @@
function openHandler() {
viewer.removeHandler('open', openHandler);
var viewport = viewer.viewport;
viewport.setRotation(-675, true);
viewport.setRotation(-675, null, true);
Util.assertRectangleEquals(
assert,
viewport.getHomeBoundsNoRotate(),
@ -267,7 +269,7 @@
function openHandler() {
viewer.removeHandler('open', openHandler);
var viewport = viewer.viewport;
viewport.setRotation(-675, true);
viewport.setRotation(-675, null, true);
Util.assertRectangleEquals(
assert,
viewport.getHomeBounds(),
@ -516,7 +518,7 @@
var bounds = viewport.getBounds();
Util.assertRectangleEquals(
assert,
new OpenSeadragon.Rect(-0.5, 1, 2, 2),
new OpenSeadragon.Rect(0, 1, 2, 2),
bounds,
EPSILON,
"Viewport.applyConstraints should move viewport to the center, not to a side.");
@ -531,14 +533,14 @@
var openHandler = function() {
viewer.removeHandler('open', openHandler);
var viewport = viewer.viewport;
viewport.setRotation(45, true);
viewport.setRotation(45, null, true);
viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true);
viewport.applyConstraints(true);
var bounds = viewport.getBounds();
Util.assertRectangleEquals(
assert,
new OpenSeadragon.Rect(1.2071067811865466, 0.20710678118654746, Math.sqrt(2), Math.sqrt(2), 45),
bounds,
new OpenSeadragon.Rect(1, 0, Math.sqrt(2), Math.sqrt(2), 45),
EPSILON,
"Viewport.applyConstraints with rotation should move viewport.");
@ -555,15 +557,15 @@
var viewport = viewer.viewport;
viewport.setFlip(true);
viewport.setRotation(45, true);
viewport.setRotation(45, null, true);
viewport.fitBounds(new OpenSeadragon.Rect(1, 1, 1, 1), true);
viewport.applyConstraints(true);
var bounds = viewport.getBounds();
Util.assertRectangleEquals(
assert,
new OpenSeadragon.Rect(1.2071067811865466, 0.20710678118654746, Math.sqrt(2), Math.sqrt(2), 45),
bounds,
new OpenSeadragon.Rect(1, 0, Math.sqrt(2), Math.sqrt(2), 45),
EPSILON,
"Viewport.applyConstraints flipped and with rotation should move viewport.");
@ -657,7 +659,7 @@
var openHandler = function(event) {
viewer.removeHandler('open', openHandler);
var viewport = viewer.viewport;
viewport.setRotation(45, true);
viewport.setRotation(45, null, true);
for(var i = 0; i < testRectsFitBounds.length; i++){
var rect = testRectsFitBounds[i];
@ -1064,20 +1066,20 @@
var viewport = viewer.viewport;
assert.propEqual(viewport.getRotation, 0, "Original rotation should be 0 degrees");
viewport.setRotation(90, true);
viewport.setRotation(90, null, true);
assert.propEqual(viewport.getRotation, 90, "Rotation should be 90 degrees");
viewport.setRotation(-75, true);
viewport.setRotation(-75, null, true);
assert.propEqual(viewport.getRotation, -75, "Rotation should be -75 degrees");
viewport.setRotation(0, true);
viewport.setRotation(0, null, true);
assert.strictEqual(viewport.getRotation(true), 0, 'viewport has default current rotation');
assert.strictEqual(viewport.getRotation(false), 0, 'viewport has default target rotation');
viewport.setRotation(400);
viewport.setRotation(33);
assert.strictEqual(viewport.getRotation(true), 0, 'current rotation is not changed');
assert.strictEqual(viewport.getRotation(false), 400, 'target rotation is set correctly');
assert.strictEqual(viewport.getRotation(false), 33, 'target rotation is set correctly');
viewport.setRotation(200, true);
viewport.setRotation(200, null, true);
assert.strictEqual(viewport.getRotation(true), 200, 'current rotation is set correctly');
assert.strictEqual(viewport.getRotation(false), 200, 'target rotation is set correctly');
@ -1097,9 +1099,9 @@
viewport.setFlip(true);
assert.propEqual(viewport.getRotation, 0, "Original flipped rotation should be 0 degrees");
viewport.setRotation(90, true);
viewport.setRotation(90, null, true);
assert.propEqual(viewport.getRotation, 90, "Flipped rotation should be 90 degrees");
viewport.setRotation(-75, true);
viewport.setRotation(-75, null, true);
assert.propEqual(viewport.getRotation, -75, "Flipped rotation should be -75 degrees");
done();
@ -1116,9 +1118,9 @@
var viewport = viewer.viewport;
for(var i = 0; i < testPoints.length; i++){
var new_size = testPoints[i].times(viewer.source.dimensions.x);
viewport.resize(new_size);
assert.propEqual(viewport.getContainerSize(), new_size, "Viewport resized successfully.");
var newSize = testPoints[i].times(viewer.source.dimensions.x);
viewport.resize(newSize);
assert.propEqual(viewport.getContainerSize(), newSize, "Viewport resized successfully.");
}
done();
};
@ -1272,12 +1274,12 @@
loopingTestHelper(assert, {
testArray: testPoints,
getOrig: function(el, viewport) {
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
return el.times(window_boundary);
var windowBoundary = Math.min(window.innerWidth, window.innerHeight);
return el.times(windowBoundary);
},
getExpected: function(orig, viewport) {
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
var posPoint = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(posPoint).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
},
method: 'windowToViewportCoordinates'
});
@ -1290,8 +1292,8 @@
return el.times(viewer.source.dimensions.x);
},
getExpected: function(orig, viewport) {
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
return orig.plus(pos_point).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
var posPoint = OpenSeadragon.getElementOffset(viewer.element);
return orig.plus(posPoint).minus(VIEWER_PADDING.times(viewport.getContainerSize().x * ZOOM_FACTOR));
},
method: 'imageToWindowCoordinates'
});
@ -1301,12 +1303,12 @@
loopingTestHelper(assert, {
testArray: testPoints,
getOrig: function(el, viewport) {
var window_boundary = Math.min(window.innerWidth, window.innerHeight);
return el.times(window_boundary);
var windowBoundary = Math.min(window.innerWidth, window.innerHeight);
return el.times(windowBoundary);
},
getExpected: function(orig, viewport) {
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(pos_point).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
var posPoint = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(posPoint).divide(viewport.getContainerSize().x * ZOOM_FACTOR).plus(VIEWER_PADDING);
},
method: 'windowToViewportCoordinates'
});
@ -1319,8 +1321,8 @@
return el.times(viewer.source.dimensions.x);
},
getExpected: function(orig, viewport) {
var pos_point = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(pos_point);
var posPoint = OpenSeadragon.getElementOffset(viewer.element);
return orig.minus(VIEWER_PADDING).times(viewport.getContainerSize().x * ZOOM_FACTOR).plus(posPoint);
},
method: 'viewportToWindowCoordinates'
});