mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-29 08:36:10 +03:00
Converted layer tests to multi-image tests
This commit is contained in:
parent
33f0fa1e4b
commit
98111212cd
271
test/layers.js
271
test/layers.js
@ -1,16 +1,16 @@
|
|||||||
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog, expect */
|
||||||
|
|
||||||
( function() {
|
( function() {
|
||||||
var viewer;
|
var viewer;
|
||||||
|
|
||||||
module( 'Layers', {
|
module( 'Multi-Image', {
|
||||||
setup: function() {
|
setup: function() {
|
||||||
$( '<div id="layersexample"></div>' ).appendTo( "#qunit-fixture" );
|
$( '<div id="itemsexample"></div>' ).appendTo( "#qunit-fixture" );
|
||||||
|
|
||||||
testLog.reset();
|
testLog.reset();
|
||||||
|
|
||||||
viewer = OpenSeadragon( {
|
viewer = OpenSeadragon( {
|
||||||
id: 'layersexample',
|
id: 'itemsexample',
|
||||||
prefixUrl: '/build/openseadragon/images/',
|
prefixUrl: '/build/openseadragon/images/',
|
||||||
springStiffness: 100 // Faster animation = faster tests
|
springStiffness: 100 // Faster animation = faster tests
|
||||||
});
|
});
|
||||||
@ -21,16 +21,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
viewer = null;
|
viewer = null;
|
||||||
$( "#layersexample" ).remove();
|
$( "#itemsexample" ).remove();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// ----------
|
// ----------
|
||||||
asyncTest( 'Layers operations', function() {
|
asyncTest( 'Multi-image operations', function() {
|
||||||
expect( 23 );
|
expect( 21 );
|
||||||
viewer.addHandler( "open", function( ) {
|
viewer.addHandler( "open", function( ) {
|
||||||
equal( 1, viewer.getLayersCount( ),
|
equal( 1, viewer.world.getItemCount( ),
|
||||||
"One layer should be present after opening." );
|
"One item should be present after opening." );
|
||||||
var options = {
|
var options = {
|
||||||
tileSource: {
|
tileSource: {
|
||||||
type: 'legacy-image-pyramid',
|
type: 'legacy-image-pyramid',
|
||||||
@ -41,87 +41,76 @@
|
|||||||
} ]
|
} ]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
viewer.addLayer( options );
|
viewer.addTiledImage( options );
|
||||||
viewer.addHandler( "add-layer", function addFirstLayerHandler( event ) {
|
viewer.world.addHandler( "add-item", function addFirstItemHandler( event ) {
|
||||||
viewer.removeHandler( "add-layer", addFirstLayerHandler );
|
viewer.world.removeHandler( "add-item", addFirstItemHandler );
|
||||||
var layer1 = event.drawer;
|
var item1 = event.item;
|
||||||
equal( viewer.getLayersCount( ), 2,
|
equal( viewer.world.getItemCount( ), 2,
|
||||||
"2 layers should be present after adding a layer." );
|
"2 items should be present after adding a item." );
|
||||||
equal( options, event.options,
|
equal( viewer.world.getIndexOfItem( item1 ), 1,
|
||||||
"The options should be transmitted via the event." );
|
"The first added item should have a index of 1" );
|
||||||
equal( viewer.getLevelOfLayer( layer1 ), 1,
|
equal( viewer.world.getItemAt( 1 ), item1,
|
||||||
"The first added layer should have a level of 1" );
|
"The item at index 1 should be the first added item." );
|
||||||
equal( viewer.getLayerAtLevel( 1 ), layer1,
|
|
||||||
"The layer at level 1 should be the first added layer." );
|
|
||||||
|
|
||||||
viewer.addLayer( options );
|
viewer.addTiledImage( options );
|
||||||
viewer.addHandler( "add-layer", function addSecondLayerHandler( event ) {
|
viewer.world.addHandler( "add-item", function addSecondItemHandler( event ) {
|
||||||
viewer.removeHandler( "add-layer", addSecondLayerHandler );
|
viewer.world.removeHandler( "add-item", addSecondItemHandler );
|
||||||
var layer2 = event.drawer;
|
var item2 = event.item;
|
||||||
equal( viewer.getLayersCount( ), 3,
|
equal( viewer.world.getItemCount( ), 3,
|
||||||
"3 layers should be present after adding a second layer." );
|
"3 items should be present after adding a second item." );
|
||||||
equal( viewer.getLevelOfLayer( layer2 ), 2,
|
equal( viewer.world.getIndexOfItem( item2 ), 2,
|
||||||
"If not specified, a layer should be added with the highest level." );
|
"If not specified, a item should be added with the highest index." );
|
||||||
equal( viewer.getLayerAtLevel( 2 ), layer2,
|
equal( viewer.world.getItemAt( 2 ), item2,
|
||||||
"The layer at level 2 should be the second added layer." );
|
"The item at index 2 should be the second added item." );
|
||||||
|
|
||||||
viewer.addHandler( "layer-level-changed",
|
viewer.world.addHandler( "item-index-changed",
|
||||||
function layerLevelChangedHandler( event ) {
|
function itemIndexChangedHandler( event ) {
|
||||||
viewer.removeHandler( "layer-level-changed",
|
viewer.world.removeHandler( "item-index-changed",
|
||||||
layerLevelChangedHandler );
|
itemIndexChangedHandler );
|
||||||
equal( event.drawer, layer2,
|
equal( event.item, item2,
|
||||||
"The layer which changed level should be layer2" );
|
"The item which changed index should be item2" );
|
||||||
equal( event.previousLevel, 2, "Previous level should be 2." );
|
equal( event.previousIndex, 2, "Previous index should be 2." );
|
||||||
equal( event.newLevel, 1, "New level should be 1." );
|
equal( event.newIndex, 1, "New index should be 1." );
|
||||||
});
|
});
|
||||||
viewer.setLayerLevel( layer2, 1 );
|
viewer.world.setItemIndex( item2, 1 );
|
||||||
equal( viewer.getLevelOfLayer( layer2 ), 1,
|
equal( viewer.world.getIndexOfItem( item2 ), 1,
|
||||||
"Layer2 level should be 1 after setLayerLevel." );
|
"Item2 index should be 1 after setItemIndex." );
|
||||||
equal( viewer.getLevelOfLayer( layer1 ), 2,
|
equal( viewer.world.getIndexOfItem( item1 ), 2,
|
||||||
"Layer1 level should be 2 after setLayerLevel." );
|
"Item1 index should be 2 after setItemIndex." );
|
||||||
equal( viewer.getLayerAtLevel( 1 ), layer2,
|
equal( viewer.world.getItemAt( 1 ), item2,
|
||||||
"The layer at level 1 should be layer2." );
|
"The item at index 1 should be item2." );
|
||||||
equal( viewer.getLayerAtLevel( 2 ), layer1,
|
equal( viewer.world.getItemAt( 2 ), item1,
|
||||||
"The layer at level 2 should be layer1." );
|
"The item at index 2 should be item1." );
|
||||||
|
|
||||||
options.level = 2;
|
options.index = 2;
|
||||||
options.tileSource.levels[0].url = "data/CCyan.png";
|
options.tileSource.levels[0].url = "data/CCyan.png";
|
||||||
options.opacity = 0.5;
|
viewer.addTiledImage( options );
|
||||||
viewer.addLayer( options );
|
viewer.world.addHandler( "add-item", function addThirdItemHandler( event ) {
|
||||||
viewer.addHandler( "add-layer", function addThirdLayerHandler( event ) {
|
viewer.world.removeHandler( "add-item", addThirdItemHandler );
|
||||||
viewer.removeHandler( "add-layer", addThirdLayerHandler );
|
var item3 = event.item;
|
||||||
var layer3 = event.drawer;
|
equal( viewer.world.getItemCount( ), 4,
|
||||||
equal( viewer.getLayersCount( ), 4,
|
"4 items should be present after adding a third item." );
|
||||||
"4 layers should be present after adding a third layer." );
|
equal( viewer.world.getIndexOfItem( item3 ), 2,
|
||||||
equal( viewer.getLevelOfLayer( layer3 ), 2,
|
"Item 3 should be added with index 2." );
|
||||||
"Layer 3 should be added with level 2." );
|
equal( viewer.world.getIndexOfItem( item2 ), 1,
|
||||||
equal( viewer.getLevelOfLayer( layer2 ), 1,
|
"Item 2 should stay at index 1." );
|
||||||
"Layer 2 should stay at level 1." );
|
|
||||||
|
|
||||||
viewer.addHandler( "remove-layer", function removeLayerHandler( event ) {
|
viewer.world.addHandler( "remove-item", function removeItemHandler( event ) {
|
||||||
viewer.removeHandler( "remove-layer", removeLayerHandler );
|
viewer.world.removeHandler( "remove-item", removeItemHandler );
|
||||||
|
|
||||||
equal( layer2, event.drawer, "Removed layer should be layer2." );
|
equal( item2, event.item, "Removed item should be item2." );
|
||||||
|
|
||||||
equal( viewer.getLevelOfLayer( layer1 ), 2,
|
equal( viewer.world.getIndexOfItem( item1 ), 2,
|
||||||
"Layer 1 should be at level 2." );
|
"Item 1 should be at index 2." );
|
||||||
equal( viewer.getLevelOfLayer( layer2 ), -1,
|
equal( viewer.world.getIndexOfItem( item2 ), -1,
|
||||||
"Layer 2 should be at level -1." );
|
"Item 2 should be at index -1." );
|
||||||
equal( viewer.getLevelOfLayer( layer3 ), 1,
|
equal( viewer.world.getIndexOfItem( item3 ), 1,
|
||||||
"Layer 3 should be at level 1." );
|
"Item 3 should be at index 1." );
|
||||||
|
|
||||||
});
|
|
||||||
viewer.removeLayer( layer2 );
|
|
||||||
|
|
||||||
options.tileSource.levels[0].width = 500;
|
|
||||||
viewer.addHandler( "add-layer-failed", function addLayerFailed( event ) {
|
|
||||||
viewer.removeHandler( "add-layer-failed", addLayerFailed );
|
|
||||||
|
|
||||||
equal( viewer.getLayersCount(), 3 );
|
|
||||||
|
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
viewer.addLayer( options );
|
|
||||||
|
viewer.world.removeItem( item2 );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -129,7 +118,7 @@
|
|||||||
viewer.open( '/test/data/testpattern.dzi' );
|
viewer.open( '/test/data/testpattern.dzi' );
|
||||||
});
|
});
|
||||||
|
|
||||||
asyncTest( 'Sequences as layers', function() {
|
asyncTest( 'Sequences as items', function() {
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
tileSource: [{
|
tileSource: [{
|
||||||
@ -152,127 +141,17 @@
|
|||||||
viewer.addHandler( "open", function openHandler() {
|
viewer.addHandler( "open", function openHandler() {
|
||||||
viewer.removeHandler( "open", openHandler );
|
viewer.removeHandler( "open", openHandler );
|
||||||
|
|
||||||
viewer.addHandler( "add-layer-failed",
|
viewer.addHandler( "add-item-failed",
|
||||||
function addLayerFailedHandler( event ) {
|
function addItemFailedHandler( event ) {
|
||||||
viewer.removeHandler( "add-layer-failed", addLayerFailedHandler );
|
viewer.removeHandler( "add-item-failed", addItemFailedHandler );
|
||||||
equal( event.message, "Sequences can not be added as layers." );
|
equal( event.message, "[Viewer.addTiledImage] Sequences can not be added." );
|
||||||
equal( event.options, options, "Layer failed event should give the options." );
|
equal( event.options, options, "Item failed event should give the options." );
|
||||||
start();
|
start();
|
||||||
} );
|
} );
|
||||||
viewer.addLayer( options );
|
viewer.addTiledImage( options );
|
||||||
|
|
||||||
});
|
});
|
||||||
viewer.open( '/test/data/testpattern.dzi' );
|
viewer.open( '/test/data/testpattern.dzi' );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
asyncTest( 'Reassign base layer', function() {
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
tileSource: {
|
|
||||||
type: 'legacy-image-pyramid',
|
|
||||||
levels: [{
|
|
||||||
url: "data/A.png",
|
|
||||||
width: 1000,
|
|
||||||
height: 1000
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
level: 0
|
|
||||||
};
|
|
||||||
viewer.addHandler( "open", function openHandler( ) {
|
|
||||||
viewer.removeHandler( "open", openHandler );
|
|
||||||
var testPatternDrawer = viewer.drawer;
|
|
||||||
equal( viewer.drawer, testPatternDrawer, "Viewer.drawer should be set to testPatternDrawer." );
|
|
||||||
viewer.addHandler( "add-layer", function addLayerHandler( event ) {
|
|
||||||
viewer.removeHandler( "add-layer", addLayerHandler );
|
|
||||||
var aDrawer = event.drawer;
|
|
||||||
equal( viewer.drawer, aDrawer, "Viewer.drawer should be set to aDrawer." );
|
|
||||||
viewer.setLayerLevel( aDrawer, 1 );
|
|
||||||
equal( viewer.drawer, testPatternDrawer, "Viewer.drawer should be set back to testPatternDrawer." );
|
|
||||||
|
|
||||||
viewer.removeLayer( viewer.drawer );
|
|
||||||
equal( viewer.drawer, aDrawer, "Viewer.drawer must be reassigned when removing base layer." );
|
|
||||||
|
|
||||||
viewer.removeLayer( viewer.drawer );
|
|
||||||
ok( !viewer.isOpen(), "Viewer should be closed when removing last layer." );
|
|
||||||
|
|
||||||
start();
|
|
||||||
});
|
|
||||||
viewer.addLayer( options );
|
|
||||||
});
|
|
||||||
viewer.open( '/test/data/testpattern.dzi' );
|
|
||||||
});
|
|
||||||
|
|
||||||
asyncTest( 'Layers and sequences', function() {
|
|
||||||
expect( 1 );
|
|
||||||
|
|
||||||
// TODO: Remove workaround when issue #321 is fixed.
|
|
||||||
// https://github.com/openseadragon/openseadragon/issues/321
|
|
||||||
// viewer.open( [{
|
|
||||||
// type: 'legacy-image-pyramid',
|
|
||||||
// levels: [ {
|
|
||||||
// url: "data/A.png",
|
|
||||||
// width: 1000,
|
|
||||||
// height: 1000
|
|
||||||
// }]
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// type: 'legacy-image-pyramid',
|
|
||||||
// levels: [ {
|
|
||||||
// url: "data/BBlue.png",
|
|
||||||
// width: 1000,
|
|
||||||
// height: 1000
|
|
||||||
// }]}] );
|
|
||||||
|
|
||||||
viewer.close();
|
|
||||||
viewer = OpenSeadragon({
|
|
||||||
id: 'layersexample',
|
|
||||||
prefixUrl: '/build/openseadragon/images/',
|
|
||||||
springStiffness: 100, // Faster animation = faster tests
|
|
||||||
tileSources: [{
|
|
||||||
type: 'legacy-image-pyramid',
|
|
||||||
levels: [{
|
|
||||||
url: "data/A.png",
|
|
||||||
width: 1000,
|
|
||||||
height: 1000
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'legacy-image-pyramid',
|
|
||||||
levels: [{
|
|
||||||
url: "data/BBlue.png",
|
|
||||||
width: 1000,
|
|
||||||
height: 1000
|
|
||||||
}]
|
|
||||||
}]
|
|
||||||
});
|
|
||||||
// End workaround
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
tileSource: {
|
|
||||||
type: 'legacy-image-pyramid',
|
|
||||||
levels: [{
|
|
||||||
url: "data/CCyan.png",
|
|
||||||
width: 1000,
|
|
||||||
height: 1000
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
viewer.addHandler( "open", function openHandler() {
|
|
||||||
viewer.addHandler( "add-layer", function addLayerHandler( event ) {
|
|
||||||
viewer.removeHandler( "add-layer", addLayerHandler );
|
|
||||||
|
|
||||||
var layer = event.drawer;
|
|
||||||
try {
|
|
||||||
viewer.setLayerLevel( layer, 0 );
|
|
||||||
} catch (e) {
|
|
||||||
ok( true );
|
|
||||||
}
|
|
||||||
start();
|
|
||||||
} );
|
|
||||||
viewer.addLayer( options );
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user