Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding "linger" unit tests

  • Loading branch information...
commit a8eab235d3e52e3cd695520504bb6cd08a84606c 1 parent 9f6476b
Michael Helgeson authored
View
45 event.linger/test/binding.js
@@ -0,0 +1,45 @@
+module("Bind Method");
+
+$.each(['lingerstart','linger','lingerend'],function( i, type ){
+
+ test('"'+ type +'"', function(){
+
+ expect( 14 );
+
+ // make sure the event handler gets bound to the element
+ var $elem = $('<div />'),
+ elem = $elem[0],
+ count = 0,
+ fn = function(){
+ count += 1;
+ },
+ opts = {
+ speed: 111,
+ delay: 222,
+ persist: 333
+ },
+ data;
+
+ ok( $elem.bind( type, fn )[0] == elem, ".bind('"+ type +"', fn )" );
+ ok( $.data( elem, $.event.special.linger.datakey ), "linger data exists" );
+ ok( $.data( elem, "events" ), "event data exists" );
+ ok( $.data( elem, "events" )[ type ][0], type +" event handler added" );
+
+ ok( $elem.trigger( type )[0] == elem, ".trigger('"+ type +"')" );
+ ok( count == 1, "handler was triggered");
+
+ ok( $elem.unbind( type )[0] == elem, ".unbind('"+ type +"')" );
+ ok( !$.data( elem, "events" ), "event data removed" );
+ ok( !$.data( elem, $.event.special.linger.datakey ), "linger data removed" );
+
+ ok( $elem.bind( type, opts, fn )[0] == elem, ".bind('"+ type +"', data, fn )" );
+ ok( data = $.data( elem, $.event.special.linger.datakey ), "linger data exists" );
+
+ ok( data.speed == opts.speed, "'speed' option stored" );
+ ok( data.delay == opts.delay, "'delay' option stored" );
+ ok( data.persist == opts.persist, "'persist' option stored" );
+
+ $elem.remove();
+
+ });
+});
View
111 event.linger/test/handlers.js
@@ -0,0 +1,111 @@
+;(function(){
+
+ module("Event Handlers");
+
+ // a simple re-usable test harness object
+ var obj = {
+ init: function( opts ){
+ obj.$div = $('<div />')
+ .css({
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ height: 100,
+ width: 100
+ })
+ .append('<div class="child" />')
+ .appendTo( document.body )
+ .bind("lingerstart linger lingerend", opts || {}, function( event ){
+ obj[ event.type ] += 1;
+ return obj.returned[ event.type ];
+ });
+ $.extend( obj, { lingerstart:0, linger:0, lingerend:0 });
+ obj.returned = {};
+ },
+ done: function(){
+ obj.$div.remove();
+ start();
+ }
+ };
+
+ asyncTest('"lingerstart" return false',function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init();
+ // set the return value
+ obj.returned['lingerstart'] = false;
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 100 ms (persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.lingerstart, 1, "lingerstart");
+ equals( obj.linger, 0, "linger");
+ equals( obj.lingerend, 0, "lingerend");
+ obj.done();
+ }, 100 );
+ }, 100 );
+
+ });
+
+ asyncTest('"linger" return false',function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ persist:100 });
+ // set the return value
+ obj.returned['linger'] = false;
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 300 ms (3x default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 100 ms (persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.lingerstart, 1, "lingerstart");
+ equals( obj.linger, 3, "linger");
+ equals( obj.lingerend, 0, "lingerend");
+ obj.done();
+ }, 100 );
+ }, 350 );
+
+ });
+
+ asyncTest('"lingerend" return false',function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ persist:100 });
+ // set the return value
+ obj.returned['lingerend'] = false;
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 300 ms (3x persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.lingerstart, 1, "lingerstart");
+ equals( obj.linger, 1, "linger");
+ equals( obj.lingerend, 3, "lingerend");
+ obj.done();
+ }, 350 );
+ }, 300 );
+ });
+
+})();
View
24 event.linger/test/index.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link href="../../img/favicon.ico" rel="shortcut icon" />
+<link href="../../jquery/qunit.css" rel="stylesheet" />
+<script src="../../jquery/jquery.js"></script>
+<script src="../../jquery/qunit.js"></script>
+<script src="../../fire/jquery.fire.js"></script>
+<script src="../jquery.event.linger.js"></script>
+<script src="./requirements.js"></script>
+<script src="./binding.js"></script>
+<script src="./method.js"></script>
+<script src="./interaction.js"></script>
+<script src="./handlers.js"></script>
+<title>ThreeDubMedia &middot; jQuery.event.linger.js</title>
+</head>
+<body>
+<h1 id="qunit-header">jQuery.event.linger.js Unit Tests</h1>
+<h2 id="qunit-banner"></h2>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
+</body>
+</html>
View
231 event.linger/test/interaction.js
@@ -0,0 +1,231 @@
+;(function(){
+
+ module("Interaction");
+
+ // a simple re-usable test harness object
+ var obj = {
+ init: function( opts ){
+ obj.$div = $('<div />')
+ .css({
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ height: 100,
+ width: 100
+ })
+ .append('<div class="child" />')
+ .appendTo( document.body )
+ .bind("lingerstart linger lingerend", opts || {}, function( event ){
+ obj.counts[ event.type ] += 1;
+ });
+ obj.counts = { lingerstart:0, linger:0, lingerend:0 };
+ },
+ done: function(){
+ obj.$div.remove();
+ start();
+ }
+ };
+
+ asyncTest("defaults",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init();
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 400 ms (default persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 1, "lingerend");
+ obj.done();
+ }, 400 );
+ }, 100 );
+ });
+
+ asyncTest("speed (miss)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ speed:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:63, pageY:67 }); // move > 20 pixels (custom speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 400 ms (default persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 0, "linger");
+ equals( obj.counts.lingerend, 0, "lingerend");
+ obj.done();
+ }, 400 );
+ }, 100 );
+ });
+
+ asyncTest("speed (hit)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ speed:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:62, pageY:66 }); // move <= 20 pixels (custom speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 400 ms (default persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 1, "lingerend");
+ obj.done();
+ }, 400 );
+ }, 100 );
+ });
+
+ asyncTest("delay (miss)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ delay:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait < 200 ms (custom delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 400 ms (default persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 0, "linger");
+ equals( obj.counts.lingerend, 0, "lingerend");
+ obj.done();
+ }, 400 );
+ }, 100 );
+ });
+
+ asyncTest("delay (hit)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ delay:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 200 ms (custom delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 400 ms (default persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 1, "lingerend");
+ obj.done();
+ }, 400 );
+ }, 200 );
+ });
+
+ asyncTest("persist (miss)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ persist:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait < 200 ms (custom persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 0, "lingerend");
+ setTimeout(function(){
+ obj.done();
+ }, 100 );
+ }, 100 );
+ }, 100 );
+ });
+
+ asyncTest("persist (hit)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ persist:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 });
+ // wait 200 ms (custom persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 1, "lingerend");
+ obj.done();
+ }, 200 );
+ }, 100 );
+
+ });
+
+ asyncTest("persist (re-enter)",function(){
+
+ expect( 3 );
+
+ // prep interaction
+ obj.init({ persist:200 });
+ // simulate interaction
+ obj.$div
+ .fire("mouseover",{ pageX:50, pageY:50 })
+ .fire("mousemove",{ pageX:56, pageY:58 }); // move <= 10 pixels (default speed)
+ // wait 100 ms (default delay)
+ setTimeout(function(){
+ obj.$div.fire("mouseout",{ pageX:51, pageY:51 })
+ // wait < 200 ms (custom persist)
+ setTimeout(function(){
+ // re-enter the element
+ obj.$div.fire("mouseover",{ pageX:50, pageY:50 });
+ // wait 200 ms (custom persist)
+ setTimeout(function(){
+ // inspect results
+ equals( obj.counts.lingerstart, 1, "lingerstart");
+ equals( obj.counts.linger, 1, "linger");
+ equals( obj.counts.lingerend, 0, "lingerend");
+ obj.done();
+ }, 200 );
+ }, 100 );
+ }, 100 );
+
+ });
+
+})();
+
View
43 event.linger/test/method.js
@@ -0,0 +1,43 @@
+module("Linger Method");
+
+$.each(['start','','end'],function( i, type ){
+
+ test('"linger'+ type +'"',function(){
+
+ expect( 11 );
+
+ // make sure the event handler gets bound to the element
+ var $elem = $('<div />'),
+ elem = $elem[0],
+ count = 0,
+ fn = function(){
+ count += 1;
+ },
+ opts = {
+ speed: 111,
+ delay: 222,
+ persist: 333
+ },
+ data;
+
+ ok( $elem.linger( type, fn )[0] == elem, ".linger("+( type ? "'"+ type +"'," : "" )+" fn )" );
+ ok( $.data( elem, $.event.special.linger.datakey ), "linger data exists" );
+ ok( $.data( elem, "events" ), "event data exists" );
+ ok( $.data( elem, "events" )[ 'linger'+type ][0], 'linger'+ type +" event handler added" );
+
+ ok( $elem.linger( type )[0] == elem, ".linger("+( type ? "'"+ type +"'" : "" )+")" );
+ ok( count == 1, "handler was triggered");
+
+ $elem.unbind( type );
+
+ ok( $elem.linger( type, fn, opts )[0] == elem, ".linger("+( type ? "'"+ type +"'," : "" )+" fn, opts )" );
+ ok( data = $.data( elem, $.event.special.linger.datakey ), "linger data exists" );
+
+ ok( data.speed == opts.speed, "'speed' option stored" );
+ ok( data.delay == opts.delay, "'delay' option stored" );
+ ok( data.persist == opts.persist, "'persist' option stored" );
+
+ $elem.remove();
+
+ });
+});
View
23 event.linger/test/requirements.js
@@ -0,0 +1,23 @@
+module("Requirements");
+
+test("jQuery",function(){
+
+ expect( 2 );
+
+ // make sure the right jquery is included
+ ok( window.jQuery, "jQuery exists" );
+ ok( parseFloat( jQuery([]).jquery ) >= 1.4, "jQuery version is 1.4 or greater" );
+
+});
+
+test("Installation",function(){
+
+ expect( 4 );
+
+ // make sure the event interface is complete
+ ok( jQuery.event.special.lingerstart, "LINGERSTART special event is defined" );
+ ok( jQuery.event.special.linger, "LINGER special event is defined" );
+ ok( jQuery.event.special.lingerend, "LINGEREND special event is defined" );
+ ok( jQuery([]).linger, "$('...').linger() method is defined" );
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.