diff options
Diffstat (limited to 'tests/unit/tooltip/options.js')
-rw-r--r-- | tests/unit/tooltip/options.js | 107 |
1 files changed, 55 insertions, 52 deletions
diff --git a/tests/unit/tooltip/options.js b/tests/unit/tooltip/options.js index a35d140fb..6dec36a6c 100644 --- a/tests/unit/tooltip/options.js +++ b/tests/unit/tooltip/options.js @@ -1,26 +1,27 @@ define( [ + "qunit", "jquery", "ui/widgets/tooltip" -], function( $ ) { +], function( QUnit, $ ) { -module( "tooltip: options" ); +QUnit.module( "tooltip: options" ); -test( "disabled: true", function() { - expect( 1 ); +QUnit.test( "disabled: true", function( assert ) { + assert.expect( 1 ); $( "#tooltipped1" ).tooltip( { disabled: true } ).tooltip( "open" ); - equal( $( ".ui-tooltip" ).length, 0 ); + assert.equal( $( ".ui-tooltip" ).length, 0 ); } ); -test( "content: default", function() { - expect( 1 ); +QUnit.test( "content: default", function( assert ) { + assert.expect( 1 ); var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" ); } ); -test( "content: default; HTML escaping", function() { - expect( 2 ); +QUnit.test( "content: default; HTML escaping", function( assert ) { + assert.expect( 2 ); var scriptText = "<script>$.ui.tooltip.hacked = true;</script>", element = $( "#tooltipped1" ); @@ -28,45 +29,46 @@ test( "content: default; HTML escaping", function() { element.attr( "title", scriptText ) .tooltip() .tooltip( "open" ); - equal( $.ui.tooltip.hacked, false, "script did not execute" ); - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, + assert.equal( $.ui.tooltip.hacked, false, "script did not execute" ); + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText, "correct tooltip text" ); } ); -test( "content: return string", function() { - expect( 1 ); +QUnit.test( "content: return string", function( assert ) { + assert.expect( 1 ); var element = $( "#tooltipped1" ).tooltip( { content: function() { return "customstring"; } } ).tooltip( "open" ); - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); } ); -test( "content: return jQuery", function() { - expect( 2 ); +QUnit.test( "content: return jQuery", function( assert ) { + assert.expect( 2 ); var element = $( "#tooltipped1" ).tooltip( { content: function() { return $( "<div id='unique'>" ).html( "cu<b id='bold'>s</b>tomstring" ); } } ).tooltip( "open" ), liveRegion = element.tooltip( "instance" ).liveRegion; - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); - equal( liveRegion.children().last().html().toLowerCase(), "<div>cu<b>s</b>tomstring</div>", + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" ); + assert.equal( liveRegion.children().last().html().toLowerCase(), "<div>cu<b>s</b>tomstring</div>", "The accessibility live region will strip the ids but keep the structure" ); } ); -asyncTest( "content: sync + async callback", function() { - expect( 2 ); +QUnit.test( "content: sync + async callback", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var element = $( "#tooltipped1" ).tooltip( { content: function( response ) { setTimeout( function() { - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "loading..." ); + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "loading..." ); response( "customstring2" ); setTimeout( function() { - deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring2" ); - start(); + assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring2" ); + ready(); }, 13 ); }, 13 ); return "loading..."; @@ -75,8 +77,9 @@ asyncTest( "content: sync + async callback", function() { } ); // http://bugs.jqueryui.com/ticket/8740 -asyncTest( "content: async callback loses focus before load", function() { - expect( 1 ); +QUnit.test( "content: async callback loses focus before load", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#tooltipped1" ).tooltip( { content: function( response ) { @@ -85,9 +88,9 @@ asyncTest( "content: async callback loses focus before load", function() { setTimeout( function() { response( "sometext" ); setTimeout( function() { - ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ), + assert.ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ), "Tooltip should not display" ); - start(); + ready(); } ); } ); } ); @@ -96,8 +99,8 @@ asyncTest( "content: async callback loses focus before load", function() { element.trigger( "mouseover" ); } ); -test( "content: change while open", function() { - expect( 2 ) ; +QUnit.test( "content: change while open", function( assert ) { + assert.expect( 2 ) ; var element = $( "#tooltipped1" ).tooltip( { content: function() { return "old"; @@ -105,52 +108,52 @@ test( "content: change while open", function() { } ); element.one( "tooltipopen", function( event, ui ) { - equal( ui.tooltip.text(), "old", "original content" ); + assert.equal( ui.tooltip.text(), "old", "original content" ); element.tooltip( "option", "content", function() { return "new"; } ); - equal( ui.tooltip.text(), "new", "updated content" ); + assert.equal( ui.tooltip.text(), "new", "updated content" ); } ); element.tooltip( "open" ); } ); -test( "content: string", function() { - expect( 1 ); +QUnit.test( "content: string", function( assert ) { + assert.expect( 1 ); $( "#tooltipped1" ).tooltip( { content: "just a string", open: function( event, ui ) { - equal( ui.tooltip.text(), "just a string" ); + assert.equal( ui.tooltip.text(), "just a string" ); } } ).tooltip( "open" ); } ); -test( "content: element", function() { - expect( 1 ); +QUnit.test( "content: element", function( assert ) { + assert.expect( 1 ); var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", element = $( content )[ 0 ]; $( "#tooltipped1" ).tooltip( { content: element, open: function( event, ui ) { - equal( ui.tooltip.children().html().toLowerCase(), content ); + assert.equal( ui.tooltip.children().html().toLowerCase(), content ); } } ).tooltip( "open" ); } ); -test( "content: jQuery", function() { - expect( 1 ); +QUnit.test( "content: jQuery", function( assert ) { + assert.expect( 1 ); var content = "<p>this is a <i>test</i> of the emergency broadcast system.</p>", element = $( content ); $( "#tooltipped1" ).tooltip( { content: element, open: function( event, ui ) { - equal( ui.tooltip.children().html().toLowerCase(), content ); + assert.equal( ui.tooltip.children().html().toLowerCase(), content ); } } ).tooltip( "open" ); } ); -test( "items", function() { - expect( 2 ); +QUnit.test( "items", function( assert ) { + assert.expect( 2 ); var event, element = $( "#qunit-fixture" ).tooltip( { items: "#fixture-span" @@ -159,18 +162,18 @@ test( "items", function() { event = $.Event( "mouseenter" ); event.target = $( "#fixture-span" )[ 0 ]; element.tooltip( "open", event ); - deepEqual( $( "#" + $( "#fixture-span" ).data( "ui-tooltip-id" ) ).text(), "title-text" ); + assert.deepEqual( $( "#" + $( "#fixture-span" ).data( "ui-tooltip-id" ) ).text(), "title-text" ); // Make sure default [title] doesn't get used event.target = $( "#tooltipped1" )[ 0 ]; element.tooltip( "open", event ); - deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined ); + assert.deepEqual( $( "#tooltipped1" ).data( "ui-tooltip-id" ), undefined ); element.tooltip( "destroy" ); } ); -test( "track + show delay", function() { - expect( 2 ); +QUnit.test( "track + show delay", function( assert ) { + assert.expect( 2 ); var event, leftVal = 314, topVal = 159, @@ -200,16 +203,16 @@ test( "track + show delay", function() { event.pageY = topVal; element.trigger( event ); - equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" ); - equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" ); + assert.equal( $( ".ui-tooltip" ).css( "left" ), leftVal + offsetVal + "px" ); + assert.equal( $( ".ui-tooltip" ).css( "top" ), topVal + offsetVal + "px" ); } ); -test( "track and programmatic focus", function() { - expect( 1 ); +QUnit.test( "track and programmatic focus", function( assert ) { + assert.expect( 1 ); $( "#qunit-fixture div input" ).tooltip( { track: true } ).trigger( "focus" ); - equal( "inputtitle", $( ".ui-tooltip" ).text() ); + assert.equal( "inputtitle", $( ".ui-tooltip" ).text() ); } ); } ); |