diff options
Diffstat (limited to 'tests/unit/tooltip')
-rw-r--r-- | tests/unit/tooltip/tooltip.html | 60 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_core.js | 27 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_defaults.js | 5 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_events.js | 118 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_methods.js | 66 | ||||
-rw-r--r-- | tests/unit/tooltip/tooltip_options.js | 105 |
6 files changed, 229 insertions, 152 deletions
diff --git a/tests/unit/tooltip/tooltip.html b/tests/unit/tooltip/tooltip.html index 189c75261..21eff51fd 100644 --- a/tests/unit/tooltip/tooltip.html +++ b/tests/unit/tooltip/tooltip.html @@ -1,30 +1,29 @@ -<!DOCTYPE html> +<!doctype html> <html lang="en"> <head> - <meta charset="UTF-8" /> + <meta charset="utf-8"> <title>jQuery UI Tooltip Test Suite</title> - <link type="text/css" href="../../../themes/base/jquery.ui.tooltip.css" rel="stylesheet" /> - - <script type="text/javascript" src="../../../jquery-1.5.1.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.position.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.tooltip.js"></script> - - <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/> - <script type="text/javascript" src="../../../external/qunit.js"></script> - <script type="text/javascript" src="../../jquery.simulate.js"></script> - <script type="text/javascript" src="../testsuite.js"></script> - - <script type="text/javascript" src="tooltip_core.js"></script> - <script type="text/javascript" src="tooltip_defaults.js"></script> - <script type="text/javascript" src="tooltip_events.js"></script> - <script type="text/javascript" src="tooltip_methods.js"></script> - <script type="text/javascript" src="tooltip_options.js"></script> - - <script type="text/javascript" src="../swarminject.js"></script> - + <link rel="stylesheet" href="../../../themes/base/jquery.ui.tooltip.css"> + + <script src="../../../jquery-1.5.1.js"></script> + <script src="../../../ui/jquery.ui.core.js"></script> + <script src="../../../ui/jquery.ui.widget.js"></script> + <script src="../../../ui/jquery.ui.position.js"></script> + <script src="../../../ui/jquery.ui.tooltip.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="tooltip_defaults.js"></script> + <script src="tooltip_core.js"></script> + <script src="tooltip_events.js"></script> + <script src="tooltip_methods.js"></script> + <script src="tooltip_options.js"></script> + + <script src="../swarminject.js"></script> </head> <body> @@ -32,16 +31,15 @@ <h2 id="qunit-banner"></h2> <div id="qunit-testrunner-toolbar"></div> <h2 id="qunit-userAgent"></h2> -<ol id="qunit-tests"> -</ol> - +<ol id="qunit-tests"></ol> <div id="qunit-fixture"> - <div> - <a id="tooltipped1" href="#" title="anchortitle">anchor</a> - <input title="inputtitle" /> - <span id="fixture-span" data-tooltip="text">span</span> - </div> + +<div> + <a id="tooltipped1" href="#" title="anchortitle">anchor</a> + <input title="inputtitle"> + <span id="fixture-span" title="title-text">span</span> </div> +</div> </body> </html> diff --git a/tests/unit/tooltip/tooltip_core.js b/tests/unit/tooltip/tooltip_core.js index 247927df4..d18b85398 100644 --- a/tests/unit/tooltip/tooltip_core.js +++ b/tests/unit/tooltip/tooltip_core.js @@ -1,11 +1,26 @@ -/* - * tooltip_core.js - */ +(function( $ ) { +module( "tooltip: core" ); -(function($) { +test( "markup structure", function() { + expect( 6 ); + var element = $( "#tooltipped1" ).tooltip(), + tooltip = $( ".ui-tooltip" ); -module("tooltip: core"); + equal( element.attr( "aria-describedby" ), undefined, "no aria-describedby on init" ); + equal( tooltip.length, 0, "no tooltip on init" ); + element.tooltip( "open" ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); + equal( tooltip.length, 1, "tooltip exists" ); + ok( tooltip.hasClass( "ui-tooltip" ), "tooltip is .ui-tooltip" ); + equal( tooltip.length, 1, ".ui-tooltip exists" ); + equal( tooltip.find( ".ui-tooltip-content" ).length, 1, + ".ui-tooltip-content exists" ); +}); -})(jQuery); +test( "accessibility", function() { + // TODO: add tests +}); + +}( jQuery ) ); diff --git a/tests/unit/tooltip/tooltip_defaults.js b/tests/unit/tooltip/tooltip_defaults.js index 5f304f497..ded3d4558 100644 --- a/tests/unit/tooltip/tooltip_defaults.js +++ b/tests/unit/tooltip/tooltip_defaults.js @@ -1,11 +1,12 @@ commonWidgetTests( "tooltip", { defaults: { + content: function() {}, disabled: false, items: "[title]", - content: $.ui.tooltip.prototype.options.content, position: { my: "left+15 center", - at: "right center" + at: "right center", + collision: "flip fit" }, tooltipClass: null, diff --git a/tests/unit/tooltip/tooltip_events.js b/tests/unit/tooltip/tooltip_events.js index 5c915ae30..61026882e 100644 --- a/tests/unit/tooltip/tooltip_events.js +++ b/tests/unit/tooltip/tooltip_events.js @@ -1,54 +1,76 @@ -/* - * tooltip_events.js - */ -(function($) { - -module("tooltip: events"); - -test("programmatic triggers", function() { - expect(2); - var e = $("#tooltipped1").tooltip({ - open: function(event, ui) { - same( event.type, "tooltipopen" ); - }, - close: function(event, ui) { - same( event.type, "tooltipclose" ); - } - }); - e.tooltip("open").tooltip("close"); - e.tooltip("destroy"); +(function( $ ) { + +module( "tooltip: events" ); + +test( "programmatic triggers", function() { + expect( 2 ); + 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( "close" ); +}); + +test( "mouse events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "mouseover" ); + }); + element.trigger( "mouseover" ); + + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "mouseleave" ); + }); + element.trigger( "mouseleave" ); }); -test("mouse events", function() { - expect(4); - var e = $("#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" ); - } - }); - e.trigger("mouseover").trigger("mouseleave"); - e.tooltip("destroy"); +test( "focus events", function() { + 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( "blur" ); }); -test("focus events", function() { - expect(4); - var e = $("#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" ); - } - }); - e.trigger("focus").trigger("blur"); - e.tooltip("destroy"); +test( "mixed events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "focusin" ); + }); + element[0].focus(); + + element.one( "tooltipopen", function() { + ok( false, "open triggered while already open" ); + }); + element.trigger( "mouseover" ); + + element.bind( "tooltipclose", function( event ) { + ok( false, "close triggered while still focused" ); + }); + element.trigger( "mouseleave" ); + element.unbind( "tooltipclose" ); + + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "blur" ); + }); + element[0].blur(); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/tooltip/tooltip_methods.js b/tests/unit/tooltip/tooltip_methods.js index 496a5fdb7..798d55896 100644 --- a/tests/unit/tooltip/tooltip_methods.js +++ b/tests/unit/tooltip/tooltip_methods.js @@ -1,22 +1,57 @@ -/* - * tooltip_methods.js - */ -(function($) { +(function( $ ) { +module( "tooltip: methods" ); -module("tooltip: methods"); +test( "destroy", function() { + expect( 2 ); + domEqual( "#tooltipped1", function() { + $( "#tooltipped1" ).tooltip().tooltip( "destroy" ); + }); -test("destroy", function() { - var beforeHtml = $("#tooltipped1").parent().html(); - var afterHtml = $("#tooltipped1").tooltip().tooltip("destroy").parent().html(); - equal( afterHtml, beforeHtml ); + // make sure that open tooltips are removed on destroy + $( "#tooltipped1" ).tooltip().tooltip( "open" ).tooltip( "destroy" ); + equal( $( ".ui-tooltip" ).length, 0 ); }); -test("open", function() { - var e = $("#tooltipped1").tooltip(); - e.tooltip("open"); - ok( $(".ui-tooltip").is(":visible") ); - $(":ui-tooltip").tooltip("destroy"); +test( "open/close", function() { + expect( 3 ); + $.fx.off = true; + var element = $( "#tooltipped1" ).tooltip(); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); + + element.tooltip( "open" ); + var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + + element.tooltip( "close" ); + ok( tooltip.is( ":hidden" ) ); + $.fx.off = false; +}); + +test( "enable/disable", function() { + expect( 7 ); + $.fx.off = true; + var element = $( "#tooltipped1" ).tooltip(); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); + + element.tooltip( "open" ); + var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + + element.tooltip( "disable" ); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip when disabled" ); + equal( tooltip.attr( "title" ), "", "title removed on disable" ); + + element.tooltip( "open" ); + equal( $( ".ui-tooltip" ).length, 0, "open does nothing when disabled" ); + + element.tooltip( "enable" ); + equal( element.attr( "title" ), "anchortitle", "title restored on enable" ); + + element.tooltip( "open" ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + $.fx.off = false; }); /* @@ -29,5 +64,4 @@ test("widget", function() { }); */ - -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/tooltip/tooltip_options.js b/tests/unit/tooltip/tooltip_options.js index 37a468489..04bb4c6a4 100644 --- a/tests/unit/tooltip/tooltip_options.js +++ b/tests/unit/tooltip/tooltip_options.js @@ -1,66 +1,73 @@ -/* - * tooltip_options.js - */ -(function($) { - -module("tooltip: options", { - teardown: function() { - $(":ui-tooltip").tooltip("destroy"); - } -}); +(function( $ ) { +module( "tooltip: options" ); -test("option: items", function() { - var event = $.Event("mouseenter"); - event.target = $("[data-tooltip]"); - $("#qunit-fixture").tooltip({ - items: "[data-tooltip]", - content: function() { - return $(this).attr("data-tooltip"); - } - }).tooltip("open", event); - same( $( "#" + $("#fixture-span").attr("aria-describedby") ).text(), "text" ); +test( "content: default", function() { + var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "anchortitle" ); }); -test("content: default", function() { - $("#tooltipped1").tooltip().tooltip("open"); - same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "anchortitle" ); -}); - -test("content: return string", function() { - $("#tooltipped1").tooltip({ +test( "content: return string", function() { + var element = $( "#tooltipped1" ).tooltip({ content: function() { return "customstring"; } - }).tooltip("open"); - same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "customstring" ); + }).tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" ); }); -test("content: return jQuery", function() { - $("#tooltipped1").tooltip({ +test( "content: return jQuery", function() { + var element = $( "#tooltipped1" ).tooltip({ content: function() { - return $("<div></div>").html("cu<b>s</b>tomstring"); + return $( "<div>" ).html( "cu<b>s</b>tomstring" ); } - }).tooltip("open"); - same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "customstring" ); + }).tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" ); }); -/* -TODO broken, probably related to async content -test("content: callback string", function() { - stop(); - $("#tooltipped1").tooltip({ - content: function(response) { - response("customstring2"); +asyncTest( "content: sync + async callback", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip({ + content: function( response ) { setTimeout(function() { - //console.log($("#tooltipped1").attr("aria-describedby")) - same( $( "#" + $("#tooltipped1").attr("aria-describedby") ).text(), "customstring2" ); - start(); - }, 100) + same( $( "#" + element.attr("aria-describedby") ).text(), "loading..." ); + + response( "customstring2" ); + setTimeout(function() { + same( $( "#" + element.attr("aria-describedby") ).text(), "customstring2" ); + start(); + }, 13 ); + }, 13 ); + return "loading..."; } - }).tooltip("open"); - + }).tooltip( "open" ); +}); + +test( "items", function() { + expect( 2 ); + var element = $( "#qunit-fixture" ).tooltip({ + items: "#fixture-span" + }); + + var event = $.Event( "mouseenter" ); + event.target = $( "#fixture-span" )[ 0 ]; + element.tooltip( "open", event ); + same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" ); + + // make sure default [title] doesn't get used + event.target = $( "#tooltipped1" )[ 0 ]; + element.tooltip( "open", event ); + same( $( "#tooltipped1" ).attr( "aria-describedby" ), undefined ); + + element.tooltip( "destroy" ); +}); + +test( "tooltipClass", function() { + expect( 1 ) + var element = $( "#tooltipped1" ).tooltip({ + tooltipClass: "custom" + }).tooltip( "open" ); + ok( $( "#" + element.attr( "aria-describedby" ) ).hasClass( "custom" ) ); }); -*/ -})(jQuery); +}( jQuery ) ); |