2015-04-07 00:28:55 +00:00
|
|
|
define( [
|
2016-04-06 13:59:12 +00:00
|
|
|
"qunit",
|
2015-04-07 00:28:55 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"./helper",
|
2015-07-15 02:12:14 +00:00
|
|
|
"ui/widgets/tooltip"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, testHelper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
var beforeAfterEach = testHelper.beforeAfterEach;
|
|
|
|
|
|
|
|
QUnit.module( "tooltip: methods", beforeAfterEach() );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-10-05 16:52:02 +00:00
|
|
|
var element = $( "#tooltipped1" );
|
|
|
|
|
2015-04-07 00:28:55 +00:00
|
|
|
assert.domEqual( "#tooltipped1", function() {
|
2012-10-05 16:52:02 +00:00
|
|
|
element.tooltip().tooltip( "destroy" );
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2011-05-28 21:36:57 +00:00
|
|
|
|
2015-08-21 04:04:13 +00:00
|
|
|
// Make sure that open tooltips are removed on destroy
|
2015-04-07 00:28:55 +00:00
|
|
|
assert.domEqual( "#tooltipped1", function() {
|
2012-10-05 16:52:02 +00:00
|
|
|
element
|
|
|
|
.tooltip()
|
2015-08-24 12:50:46 +00:00
|
|
|
.tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) )
|
2012-10-05 16:52:02 +00:00
|
|
|
.tooltip( "destroy" );
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0 );
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "open/close", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2011-05-28 20:20:46 +00:00
|
|
|
$.fx.off = true;
|
2012-04-19 02:36:15 +00:00
|
|
|
var tooltip,
|
|
|
|
element = $( "#tooltipped1" ).tooltip();
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
|
2011-05-28 21:36:57 +00:00
|
|
|
|
2011-05-28 17:30:00 +00:00
|
|
|
element.tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":visible" ) );
|
2011-05-28 21:36:57 +00:00
|
|
|
|
2011-05-28 20:20:46 +00:00
|
|
|
element.tooltip( "close" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":hidden" ) );
|
2011-05-28 20:20:46 +00:00
|
|
|
$.fx.off = false;
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2010-04-15 07:45:35 +00:00
|
|
|
|
2012-10-05 15:26:49 +00:00
|
|
|
// #8626 - Calling open() without an event
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "open/close with tracking", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-10-05 15:26:49 +00:00
|
|
|
$.fx.off = true;
|
|
|
|
var tooltip,
|
2015-08-24 12:50:46 +00:00
|
|
|
element = $( "#tooltipped1" ).tooltip( { track: true } );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
|
2012-10-05 15:26:49 +00:00
|
|
|
|
|
|
|
element.tooltip( "open" );
|
|
|
|
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":visible" ) );
|
2012-10-05 15:26:49 +00:00
|
|
|
|
|
|
|
element.tooltip( "close" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":hidden" ) );
|
2012-10-05 15:26:49 +00:00
|
|
|
$.fx.off = false;
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2012-10-05 15:26:49 +00:00
|
|
|
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "enable/disable", function( assert ) {
|
|
|
|
assert.expect( 11 );
|
2011-05-30 00:50:21 +00:00
|
|
|
$.fx.off = true;
|
2012-04-19 02:36:15 +00:00
|
|
|
var tooltip,
|
|
|
|
element = $( "#tooltipped1" ).tooltip();
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
|
|
|
element.tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":visible" ) );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
|
|
|
element.tooltip( "disable" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0, "no tooltip when disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-01-30 16:01:32 +00:00
|
|
|
assert.lacksClasses( element.tooltip( "widget" ), "ui-state-disabled" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( !element.tooltip( "widget" ).attr( "aria-disabled" ), "element doesn't get aria-disabled" );
|
2015-01-30 16:01:32 +00:00
|
|
|
assert.lacksClasses( element.tooltip( "widget" ), "ui-tooltip-disabled" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( tooltip.attr( "title" ), null, "title removed on disable" );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
|
|
|
element.tooltip( "open" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 0, "open does nothing when disabled" );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
|
|
|
element.tooltip( "enable" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( element.attr( "title" ), "anchortitle", "title restored on enable" );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
2013-12-24 02:40:30 +00:00
|
|
|
// #9719 - Title should be preserved after disabling twice
|
|
|
|
element.tooltip( "disable" );
|
|
|
|
element.tooltip( "disable" );
|
|
|
|
element.tooltip( "enable" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( element.attr( "title" ), "anchortitle", "title restored on enable after being disabled twice" );
|
2013-12-24 02:40:30 +00:00
|
|
|
|
2011-05-30 00:50:21 +00:00
|
|
|
element.tooltip( "open" );
|
2012-05-22 15:06:44 +00:00
|
|
|
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.ok( tooltip.is( ":visible" ) );
|
2011-05-30 00:50:21 +00:00
|
|
|
$.fx.off = false;
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2011-05-30 00:50:21 +00:00
|
|
|
|
2016-04-20 17:07:53 +00:00
|
|
|
QUnit.test( "enable/disable delegated", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
var element = $( "#qunit-fixture" ).tooltip();
|
|
|
|
var tooltipped = $( "#tooltipped1" );
|
|
|
|
|
|
|
|
element.tooltip( "disable" );
|
|
|
|
element.tooltip( "enable" );
|
|
|
|
|
|
|
|
tooltipped.trigger( "mouseover" );
|
|
|
|
assert.equal( $( ".ui-tooltip" ).length, 1, "open" );
|
|
|
|
|
|
|
|
element.tooltip( "destroy" );
|
|
|
|
} );
|
|
|
|
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "widget", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-08-27 00:21:24 +00:00
|
|
|
var element = $( "#tooltipped1" ).tooltip(),
|
|
|
|
widgetElement = element.tooltip( "widget" );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( widgetElement.length, 1, "one element" );
|
|
|
|
assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2010-07-30 12:30:43 +00:00
|
|
|
|
2016-04-06 13:59:12 +00:00
|
|
|
QUnit.test( "preserve changes to title attributes on close and destroy", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2013-12-03 04:03:55 +00:00
|
|
|
var element = $( "#tooltipped1" ),
|
|
|
|
changed = "changed title text",
|
|
|
|
original = "original title text",
|
|
|
|
tests = [];
|
|
|
|
|
|
|
|
// 1. Changes to title attribute are preserved on close()
|
|
|
|
tests[ 0 ] = { title: changed, expected: changed, method: "close" };
|
2015-08-24 12:50:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
// 2. Changes to title attribute are preserved on destroy()
|
2015-08-24 12:50:46 +00:00
|
|
|
tests[ 1 ] = { title: changed, expected: changed, method: "destroy" };
|
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
// 3. Changes to title attribute are NOT preserved when set to empty string on close()
|
|
|
|
tests[ 2 ] = { title: "", expected: original, method: "close" };
|
2015-08-24 12:50:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
// 4. Changes to title attribute are NOT preserved when set to empty string on destroy()
|
|
|
|
tests[ 3 ] = { title: "", expected: original, method: "destroy" };
|
2015-08-24 12:50:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
// 5. Changes to title attribute NOT preserved when attribute has been removed on close()
|
|
|
|
tests[ 4 ] = { expected: original, method: "close" };
|
2015-08-24 12:50:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
// 6. Changes to title attribute NOT preserved when attribute has been removed on destroy()
|
|
|
|
tests[ 5 ] = { expected: original, method: "destroy" };
|
|
|
|
|
|
|
|
$.each( tests, function( index, test ) {
|
2015-01-12 16:19:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
element.attr( "title", original ).tooltip()
|
|
|
|
.tooltip( "open", $.Event( "mouseover", { target: element[ 0 ] } ) );
|
|
|
|
if ( test.title ) {
|
|
|
|
element.attr( "title", test.title );
|
|
|
|
} else {
|
|
|
|
element.removeAttr( "title" );
|
|
|
|
}
|
|
|
|
element.tooltip( test.method );
|
2016-04-06 13:59:12 +00:00
|
|
|
assert.equal( $( "#tooltipped1" ).attr( "title" ), test.expected );
|
2015-01-12 16:19:46 +00:00
|
|
|
|
2013-12-03 04:03:55 +00:00
|
|
|
} );
|
2015-08-24 12:50:46 +00:00
|
|
|
} );
|
2013-12-03 04:03:55 +00:00
|
|
|
|
2015-04-07 00:28:55 +00:00
|
|
|
} );
|