From 0bbf6bc58a1957fdfa05fe7c7a2d543f34976096 Mon Sep 17 00:00:00 2001 From: Mark Salsbery Date: Fri, 30 Aug 2013 10:09:22 -0700 Subject: [PATCH] Unit tests for canvas drag, release, click events --- test/events.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/test/events.js b/test/events.js index 5a77b29a..b2e71eb6 100644 --- a/test/events.js +++ b/test/events.js @@ -42,8 +42,8 @@ // ---------- asyncTest( 'addHandler with userData', function () { - var userData = { item1: 'Test user data', item2: Math.random() }; - var originalUserData = { item1: userData.item1, item2: userData.item2 }; + var userData = { item1: 'Test user data', item2: Math.random() }, + originalUserData = { item1: userData.item1, item2: userData.item2 }; var openHandler = function ( eventSender, eventData ) { viewer.removeHandler( 'open', openHandler ); @@ -62,8 +62,10 @@ // ---------- asyncTest( 'canvas-drag canvas-release canvas-click', function () { - var dragCount = 10; - var dragMovesHandled = 0; + var dragCount = 10, + dragMovesHandled = 0, + releasesHandled = 0, + releasesExpected = 1; var openHandler = function ( eventSender, eventData ) { viewer.removeHandler( 'open', openHandler ); @@ -72,30 +74,30 @@ viewer.addHandler( 'canvas-release', canvasReleaseHandler ); viewer.addHandler( 'canvas-click', canvasClickHandler ); - Util.simulateViewerClickWithDrag( { - viewer: viewer, - widthFactor: 0.25, - heightFactor: 0.25, - dragCount: dragCount, - dragDx: 1, - dragDy: 1 + Util.simulateViewerClickWithDrag( { + viewer: viewer, + widthFactor: 0.25, + heightFactor: 0.25, + dragCount: dragCount, + dragDx: 1, + dragDy: 1 } ); }; var canvasDragHandler = function ( eventSender, eventData ) { - dragMovesHandled += 1; + dragMovesHandled++; }; var canvasReleaseHandler = function ( eventSender, eventData ) { - ok( true, 'canvas-release event handled' ); + releasesHandled++; }; var canvasClickHandler = function ( eventSender, eventData ) { viewer.removeHandler( 'canvas-drag', canvasDragHandler ); viewer.removeHandler( 'canvas-release', canvasReleaseHandler ); viewer.removeHandler( 'canvas-click', canvasClickHandler ); - ok( true, 'canvas-click event handled' ); - equal( dragMovesHandled, dragCount, "'canvas-drag' event count matches 'mousemove' event count" ); + equal( dragMovesHandled, dragCount, "'canvas-drag' event count matches 'mousemove' event count (" + dragCount + ")" ); + equal( releasesHandled, releasesExpected, "'canvas-release' event count matches expected (" + releasesExpected + ")" ); viewer.close(); start(); };