Unit tests for userData in events (issue #203)

This commit is contained in:
Mark Salsbery 2013-08-28 05:50:22 -07:00
parent c7f184f199
commit 853a141994
2 changed files with 64 additions and 0 deletions

63
test/events.js Normal file
View File

@ -0,0 +1,63 @@
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
(function () {
var viewer;
module( 'Events', {
setup: function () {
var example = $( '<div id="example"></div>' ).appendTo( "#qunit-fixture" );
testLog.reset();
viewer = OpenSeadragon( {
id: 'example',
prefixUrl: '/build/openseadragon/images/',
springStiffness: 100 // Faster animation = faster tests
} );
},
teardown: function () {
if ( viewer && viewer.close ) {
viewer.close();
}
viewer = null;
}
} );
// ----------
asyncTest( 'addHandler without userData', function () {
var openHandler = function ( eventSender, eventData ) {
viewer.removeHandler( 'open', openHandler );
ok( eventData, 'Event handler received event data' );
if ( eventData ) {
strictEqual( eventData.userData, null, 'User data defaulted to null' );
}
viewer.close();
start();
};
viewer.addHandler( 'open', openHandler );
viewer.open( '/test/data/testpattern.dzi' );
} );
// ----------
asyncTest( 'addHandler with userData', function () {
var userData = { item1: 'Test user data', item2: Math.random() };
var originalUserData = { item1: userData.item1, item2: userData.item2 };
var openHandler = function ( eventSender, eventData ) {
viewer.removeHandler( 'open', openHandler );
ok( eventData, 'Event handler received event data' );
ok( eventData && eventData.userData, 'Event handler received user data' );
if ( eventData && eventData.userData ) {
deepEqual( eventData.userData, originalUserData, 'User data was untouched' );
}
viewer.close();
start();
};
viewer.addHandler( 'open', openHandler, userData );
viewer.open( '/test/data/testpattern.dzi' );
} );
} )();

View File

@ -21,5 +21,6 @@
<script src="/test/strings.js"></script>
<script src="/test/formats.js"></script>
<script src="/test/utils.js"></script>
<script src="/test/events.js"></script>
</body>
</html>