openseadragon/test/basic.js

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2013-02-14 22:21:07 +04:00
(function() {
2013-03-07 23:52:01 +04:00
var viewer = null;
// ----------
asyncTest('Open', function() {
2013-03-07 22:44:08 +04:00
$(document).ready(function() {
2013-03-07 23:52:01 +04:00
viewer = OpenSeadragon({
2013-03-07 22:44:08 +04:00
id: 'example',
prefixUrl: '/build/openseadragon/images/',
tileSources: '/test/data/testpattern.dzi',
showNavigator: true
});
ok(viewer, 'Viewer exists');
2013-03-07 23:52:01 +04:00
var openHandler = function(eventSender, eventData) {
viewer.removeHandler('open', openHandler);
2013-03-07 22:44:08 +04:00
ok(true, 'Open event was sent');
ok(eventSender === viewer, 'Sender of open event was viewer');
ok(eventData, 'Handler also received event data');
2013-03-07 23:52:01 +04:00
ok(viewer.viewport, 'Viewport exists');
2013-03-07 22:44:08 +04:00
start();
2013-03-07 23:52:01 +04:00
};
viewer.addHandler('open', openHandler);
2013-03-07 22:44:08 +04:00
});
2013-03-07 23:52:01 +04:00
});
// ----------
asyncTest('Zoom', function() {
var viewport = viewer.viewport;
ok(viewport.getZoom() === 1, 'We start out unzoomed');
var zoomHandler = function() {
viewer.removeHandler('animationfinish', zoomHandler);
ok(viewport.getZoom() === 2, 'Zoomed correctly');
start();
};
viewer.addHandler('animationfinish', zoomHandler);
viewport.zoomTo(2);
});
// ----------
asyncTest('Pan', function() {
var viewport = viewer.viewport;
var center = viewport.getCenter();
ok(center.x === 0.5 && center.y === 0.5, 'We start out unpanned');
var panHandler = function() {
viewer.removeHandler('animationfinish', panHandler);
center = viewport.getCenter();
ok(center.x === 0.1 && center.y === 0.1, 'Panned correctly');
start();
};
viewer.addHandler('animationfinish', panHandler);
viewport.panTo(new OpenSeadragon.Point(0.1, 0.1));
});
// ----------
asyncTest('Close', function() {
var closeHandler = function() {
viewer.removeHandler('close', closeHandler);
ok(true, 'Close event was sent');
start();
};
viewer.addHandler('close', closeHandler);
viewer.close();
});
2013-02-14 22:21:07 +04:00
})();