3 module( "tooltip: core" );
5 test( "markup structure", function() {
7 var element = $( "#tooltipped1" ).tooltip(),
8 tooltip = $( ".ui-tooltip" );
10 equal( element.attr( "aria-describedby" ), undefined, "no aria-describedby on init" );
11 equal( tooltip.length, 0, "no tooltip on init" );
13 element.tooltip( "open" );
14 tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
15 equal( tooltip.length, 1, "tooltip exists" );
16 equal( element.attr( "aria-describedby"), tooltip.attr( "id" ), "aria-describedby" );
17 ok( tooltip.hasClass( "ui-tooltip" ), "tooltip is .ui-tooltip" );
18 equal( tooltip.length, 1, ".ui-tooltip exists" );
19 equal( tooltip.find( ".ui-tooltip-content" ).length, 1,
20 ".ui-tooltip-content exists" );
23 test( "accessibility", function() {
28 element = $( "#multiple-describedby" ).tooltip();
30 element.tooltip( "open" );
31 tooltipId = element.data( "ui-tooltip-id" );
32 tooltip = $( "#" + tooltipId );
33 equal( tooltip.attr( "role" ), "tooltip", "role" );
34 equal( element.attr( "aria-describedby" ), "fixture-span " + tooltipId,
35 "multiple describedby when open" );
36 // strictEqual to distinguish between .removeAttr( "title" ) and .attr( "title", "" )
37 // support: jQuery <1.6.2
39 // We should use strictEqual( ..., undefined ) when dropping jQuery 1.6.1 support (or IE6/7)
40 ok( !element.attr( "title" ), "no title when open" );
41 element.tooltip( "close" );
42 equal( element.attr( "aria-describedby" ), "fixture-span",
43 "correct describedby when closed" );
44 equal( element.attr( "title" ), "...", "title restored when closed" );
47 test( "delegated removal", function() {
50 var container = $( "#contains-tooltipped" ).tooltip(),
51 element = $( "#contained-tooltipped" );
53 element.trigger( "mouseover" );
54 equal( $( ".ui-tooltip" ).length, 1 );
57 equal( $( ".ui-tooltip" ).length, 0 );
60 test( "nested tooltips", function() {
63 var child = $( "#contained-tooltipped" ),
64 parent = $( "#contains-tooltipped" ).tooltip({
69 parent.trigger( "mouseover" );
70 equal( $( ".ui-tooltip:visible" ).text(), "parent" );
72 child.trigger( "mouseover" );
73 equal( $( ".ui-tooltip" ).text(), "child" );
77 test( "form containing an input with name title", function() {
80 var form = $( "#tooltip-form" ).tooltip({
84 input = form.find( "[name=title]" );
86 equal( $( ".ui-tooltip" ).length, 0, "no tooltips on init" );
88 input.trigger( "mouseover" );
89 equal( $( ".ui-tooltip" ).length, 1, "tooltip for input" );
90 input.trigger( "mouseleave" );
91 equal( $( ".ui-tooltip" ).length, 0, "tooltip for input closed" );
93 form.trigger( "mouseover" );
94 equal( $( ".ui-tooltip" ).length, 0, "no tooltip for form" );
97 test( "tooltip on .ui-state-disabled element", function() {
100 var container = $( "#contains-tooltipped" ).tooltip(),
101 element = $( "#contained-tooltipped" ).addClass( "ui-state-disabled" );
103 element.trigger( "mouseover" );
104 equal( $( ".ui-tooltip" ).length, 1 );
107 equal( $( ".ui-tooltip" ).length, 0 );
110 // http://bugs.jqueryui.com/ticket/8740
111 asyncTest( "programmatic focus with async content", function() {
113 var element = $( "#tooltipped1" ).tooltip({
114 content: function( response ) {
115 setTimeout(function() {
121 element.bind( "tooltipopen", function( event ) {
122 deepEqual( event.originalEvent.type, "focusin" );
124 element.bind( "tooltipclose", function( event ) {
125 deepEqual( event.originalEvent.type, "focusout" );
129 setTimeout(function() {