]> source.dussan.org Git - jquery-ui.git/commitdiff
Tooltip tests: Refactored and added some tests.
authorScott González <scott.gonzalez@gmail.com>
Sat, 28 May 2011 20:20:46 +0000 (16:20 -0400)
committerScott González <scott.gonzalez@gmail.com>
Sat, 28 May 2011 20:20:46 +0000 (16:20 -0400)
tests/unit/tooltip/tooltip_events.js
tests/unit/tooltip/tooltip_methods.js

index 287c390731cf4fe52810e878350854b3849b4e28..515760b2863d49781478b2b9f8909a01e56a500b 100644 (file)
@@ -4,45 +4,47 @@ module( "tooltip: events" );
 
 test( "programmatic triggers", function() {
        expect( 2 );
-       var element = $( "#tooltipped1" ).tooltip({
-               open: function( event, ui ) {
-                       same( event.type, "tooltipopen" );
-               },
-               close: function( event, ui ) {
-                       same( event.type, "tooltipclose" );
-               }
+       var element = $( "#tooltipped1" ).tooltip();
+
+       element.one( "tooltipopen", function( event ) {
+               ok( !( "originalEvent" in event ), "open" );
+       });
+       element.tooltip( "open" );
+
+       element.one( "tooltipclose", function( event ) {
+               ok( !( "originalEvent" in event ), "close" );
        });
-       element.tooltip( "open" ).tooltip( "close" );
+       element.tooltip( "close" );
 });
 
 test( "mouse events", function() {
-       expect( 4 );
-       var element = $( "#tooltipped1" ).tooltip({
-               open: function( event, ui ) {
-                       same( event.type, "tooltipopen" );
-                       same( event.originalEvent.type, "mouseover" );
-               },
-               close: function( event, ui ) {
-                       same( event.type, "tooltipclose" );
-                       same( event.originalEvent.type, "mouseleave" );
-               }
+       expect( 2 );
+       var element = $( "#tooltipped1" ).tooltip();
+
+       element.one( "tooltipopen", function( event ) {
+               same( event.originalEvent.type, "mouseover" );
        });
-       element.trigger( "mouseover" ).trigger( "mouseleave" );
+       element.trigger( "mouseover" );
+
+       element.one( "tooltipclose", function( event ) {
+               same( event.originalEvent.type, "mouseleave" );
+       });
+       element.trigger( "mouseleave" );
 });
 
 test( "focus events", function() {
-       expect( 4 );
-       var element = $( "#tooltipped1" ).tooltip({
-               open: function( event, ui ) {
-                       same( event.type, "tooltipopen" );
-                       same( event.originalEvent.type, "focusin" );
-               },
-               close: function( event, ui ) {
-                       same( event.type, "tooltipclose" );
-                       same( event.originalEvent.type, "blur" );
-               }
+       expect( 2 );
+       var element = $( "#tooltipped1" ).tooltip();
+
+       element.one( "tooltipopen", function( event ) {
+               same( event.originalEvent.type, "focusin" );
+       });
+       element.trigger( "focusin" );
+
+       element.one( "tooltipclose", function( event ) {
+               same( event.originalEvent.type, "blur" );
        });
-       element.trigger( "focus" ).trigger( "blur" );
+       element.trigger( "blur" );
 });
 
 }( jQuery ) );
index cb99ea457c517326e4f1c52b4f180b180ff3a33d..1487672cbd8547d7c7221075e138dbf144bd4464 100644 (file)
@@ -3,15 +3,25 @@
 module( "tooltip: methods" );
 
 test( "destroy", function() {
-       var beforeHtml = $( "#tooltipped1" ).parent().html();
-       var afterHtml = $( "#tooltipped1" ).tooltip().tooltip( "destroy" ).parent().html();
-       equal( afterHtml, beforeHtml );
+       domEqual( "#tooltipped1", function() {
+               $( "#tooltipped1" ).tooltip().tooltip( "destroy" );
+       });
 });
 
-test( "open", function() {
+test( "open/close", function() {
+       expect( 3 );
+       $.fx.off = true;
        var element = $( "#tooltipped1" ).tooltip();
+       equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
+$( ".ui-tooltip" ).each(function() {
+       console.log( $( this ).html() );
+});
        element.tooltip( "open" );
-       ok( $( ".ui-tooltip" ).is( ":visible" ) );
+       var tooltip = $( "#" + element.attr( "aria-describedby" ) );
+       ok( tooltip.is( ":visible" ) );
+       element.tooltip( "close" );
+       ok( tooltip.is( ":hidden" ) );
+       $.fx.off = false;
 });
 
 /*