mirror of
https://github.com/openseadragon/openseadragon.git
synced 2025-01-19 17:21:50 +03:00
Factor out looping and reopening viewer into a helper method, based on Ian's example.
This commit is contained in:
parent
e901248816
commit
aebfecb4e8
224
test/viewport.js
224
test/viewport.js
@ -52,20 +52,45 @@
|
|||||||
new OpenSeadragon.Rect(1, 1, 1, 1)
|
new OpenSeadragon.Rect(1, 1, 1, 1)
|
||||||
];
|
];
|
||||||
|
|
||||||
// ----------
|
// Test helper - a lot of these tests loop through a few possible
|
||||||
/*
|
// values for zoom levels, and reopen the viewer for each iteration.
|
||||||
asyncTest('template', function() {
|
var reopenViewerHelper = function(config) {
|
||||||
|
var expected, level, actual, i = 0;
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
viewer.removeHandler('open', openHandler);
|
viewer.removeHandler('open', openHandler);
|
||||||
var viewport = viewer.viewport;
|
var viewport = viewer.viewport;
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
expected = config.processExpected(level, expected);
|
||||||
|
actual = viewport[config.method]();
|
||||||
|
|
||||||
start();
|
propEqual(
|
||||||
|
actual,
|
||||||
|
expected,
|
||||||
|
"Test " + config.method + " with zoom level of " + level + ". Expected : " + expected + ", got " + actual
|
||||||
|
);
|
||||||
|
i++;
|
||||||
|
if(i < testZoomLevels.length){
|
||||||
|
level = expected = testZoomLevels[i];
|
||||||
|
var viewerConfig = {
|
||||||
|
id: VIEWER_ID,
|
||||||
|
prefixUrl: PREFIX_URL,
|
||||||
|
springStiffness: SPRING_STIFFNESS
|
||||||
|
};
|
||||||
|
|
||||||
|
viewerConfig[config.property] = level;
|
||||||
|
viewer = OpenSeadragon(viewerConfig);
|
||||||
|
viewer.addHandler('open', openHandler);
|
||||||
|
viewer.open(DZI_PATH);
|
||||||
|
} else {
|
||||||
|
start();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
viewer.addHandler('open', openHandler);
|
viewer.addHandler('open', openHandler);
|
||||||
|
level = expected = testZoomLevels[i];
|
||||||
|
viewer[config.property] = level;
|
||||||
viewer.open(DZI_PATH);
|
viewer.open(DZI_PATH);
|
||||||
});
|
};
|
||||||
*/
|
|
||||||
|
// Tests start here.
|
||||||
asyncTest('getContainerSize', function() {
|
asyncTest('getContainerSize', function() {
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
viewer.removeHandler('open', openHandler);
|
viewer.removeHandler('open', openHandler);
|
||||||
@ -119,159 +144,70 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('getMinZoom', function() {
|
asyncTest('getMinZoom', function() {
|
||||||
var expected, level, i = 0;
|
reopenViewerHelper({
|
||||||
var openHandler = function(event) {
|
property: 'minZoomLevel',
|
||||||
viewer.removeHandler('open', openHandler);
|
method: 'getMinZoom',
|
||||||
var viewport = viewer.viewport;
|
processExpected: function(level, expected){
|
||||||
|
if(level === 0) { // 0 means use the default
|
||||||
if(level === 0) { // 0 means use the default
|
expected = 0.9;
|
||||||
expected = 0.9;
|
} else if(level > 1) {
|
||||||
} else if(level > 1){
|
expected = 1; // min zoom won't go bigger than 1.
|
||||||
expected = 1; // min zoom won't go bigger than 1.
|
}
|
||||||
|
return expected;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
equal(
|
|
||||||
viewport.getMinZoom(),
|
|
||||||
expected,
|
|
||||||
"Test getMinZoom with zoom level of " + level
|
|
||||||
);
|
|
||||||
i++;
|
|
||||||
if(i < testZoomLevels.length){
|
|
||||||
level = expected = testZoomLevels[i];
|
|
||||||
viewer = OpenSeadragon({
|
|
||||||
id: VIEWER_ID,
|
|
||||||
prefixUrl: PREFIX_URL,
|
|
||||||
springStiffness: SPRING_STIFFNESS,
|
|
||||||
minZoomLevel: level
|
|
||||||
});
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
} else {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
level = expected = testZoomLevels[i];
|
|
||||||
viewer.minZoomLevel = level;
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('getMaxZoom', function() {
|
asyncTest('getMaxZoom', function() {
|
||||||
var expected, level, i = 0;
|
reopenViewerHelper({
|
||||||
var openHandler = function(event) {
|
property: 'maxZoomLevel',
|
||||||
viewer.removeHandler('open', openHandler);
|
method: 'getMaxZoom',
|
||||||
var viewport = viewer.viewport;
|
processExpected: function(level, expected) {
|
||||||
|
if(level === 0){ // 0 means use the default
|
||||||
if(level === 0){ // 0 means use the default
|
expected = 2.2;
|
||||||
expected = 2.2;
|
} else if(level < 1){
|
||||||
} else if(level < 1){
|
expected = 1; // max zoom won't go smaller than 1.
|
||||||
expected = 1; // max zoom won't go smaller than 1.
|
}
|
||||||
|
return expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
equal(
|
});
|
||||||
viewport.getMaxZoom(),
|
|
||||||
expected,
|
|
||||||
"Test getMaxZoom with zoom level of " + level
|
|
||||||
);
|
|
||||||
i++;
|
|
||||||
if(i < testZoomLevels.length){
|
|
||||||
level = expected = testZoomLevels[i];
|
|
||||||
viewer = OpenSeadragon({
|
|
||||||
id: VIEWER_ID,
|
|
||||||
prefixUrl: PREFIX_URL,
|
|
||||||
springStiffness: SPRING_STIFFNESS,
|
|
||||||
maxZoomLevel: level
|
|
||||||
});
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
} else {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
level = expected = testZoomLevels[i];
|
|
||||||
viewer.maxZoomLevel = level;
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('getHomeBounds', function() {
|
asyncTest('getHomeBounds', function() {
|
||||||
var expected, i = 0;
|
reopenViewerHelper({
|
||||||
var openHandler = function(event) {
|
property: 'defaultZoomLevel',
|
||||||
viewer.removeHandler('open', openHandler);
|
method: 'getHomeBounds',
|
||||||
var viewport = viewer.viewport;
|
processExpected: function(level, expected) {
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
// Have to special case this to avoid dividing by 0
|
||||||
viewport.update(); // need to call this even with immediately=true
|
if(level === 0){
|
||||||
|
expected = new OpenSeadragon.Rect(0, 0, 1, 1);
|
||||||
// Have to special case this to avoid dividing by 0
|
} else {
|
||||||
if(testZoomLevels[i] === 0){
|
var sideLength = 1.0 / viewer.defaultZoomLevel; // it's a square in this case
|
||||||
expected = new OpenSeadragon.Rect(0, 0, 1, 1);
|
var position = 0.5 - (sideLength / 2.0);
|
||||||
} else {
|
expected = new OpenSeadragon.Rect(position, position, sideLength, sideLength);
|
||||||
var sideLength = 1.0 / viewer.defaultZoomLevel; // it's a square in this case
|
}
|
||||||
var position = 0.5 - (sideLength / 2.0);
|
return expected;
|
||||||
expected = new OpenSeadragon.Rect(position, position, sideLength, sideLength);
|
|
||||||
}
|
}
|
||||||
propEqual(
|
});
|
||||||
viewport.getHomeBounds(),
|
|
||||||
expected,
|
|
||||||
"Test getHomeBounds with default zoom level of " + viewer.defaultZoomLevel
|
|
||||||
);
|
|
||||||
i++;
|
|
||||||
if(i < testZoomLevels.length){
|
|
||||||
viewer = OpenSeadragon({
|
|
||||||
id: VIEWER_ID,
|
|
||||||
prefixUrl: PREFIX_URL,
|
|
||||||
springStiffness: SPRING_STIFFNESS,
|
|
||||||
defaultZoomLevel: testZoomLevels[i]
|
|
||||||
});
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
} else {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.defaultZoomLevel = testZoomLevels[i];
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest('getHomeZoom', function() {
|
asyncTest('getHomeZoom', function() {
|
||||||
var expected, i = 0;
|
reopenViewerHelper({
|
||||||
var openHandler = function(event) {
|
property: 'defaultZoomLevel',
|
||||||
viewer.removeHandler('open', openHandler);
|
method: 'getHomeZoom',
|
||||||
var viewport = viewer.viewport;
|
processExpected: function(level, expected){
|
||||||
viewport.zoomTo(ZOOM_FACTOR, null, true);
|
// If the default zoom level is set to 0, then we expect the home zoom to be 1.
|
||||||
viewport.update(); // need to call this even with immediately=true
|
if(expected === 0){
|
||||||
|
expected = 1;
|
||||||
// If the default zoom level is set to 0, then we expect the home zoom to be 1.
|
}
|
||||||
if(expected === 0){
|
return expected;
|
||||||
expected = 1;
|
|
||||||
}
|
}
|
||||||
equal(
|
});
|
||||||
viewport.getHomeZoom(),
|
|
||||||
expected,
|
|
||||||
"Test getHomeZoom with default zoom level of " + expected
|
|
||||||
);
|
|
||||||
i++;
|
|
||||||
if(i < testZoomLevels.length){
|
|
||||||
expected = testZoomLevels[i];
|
|
||||||
viewer = OpenSeadragon({
|
|
||||||
id: VIEWER_ID,
|
|
||||||
prefixUrl: PREFIX_URL,
|
|
||||||
springStiffness: SPRING_STIFFNESS,
|
|
||||||
defaultZoomLevel: expected
|
|
||||||
});
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
} else {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
viewer.addHandler('open', openHandler);
|
|
||||||
expected = testZoomLevels[i];
|
|
||||||
viewer.defaultZoomLevel = expected;
|
|
||||||
viewer.open(DZI_PATH);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// I don't use the helper for this one because it sets a couple more
|
||||||
|
// properties that would need a lot of special casing.
|
||||||
asyncTest('getHomeZoomWithHomeFillsViewer', function() {
|
asyncTest('getHomeZoomWithHomeFillsViewer', function() {
|
||||||
var expected, level, i = 0;
|
var expected, level, i = 0;
|
||||||
var openHandler = function(event) {
|
var openHandler = function(event) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user