Tests: Fix tooltip tests by destroying tooltips

Some tests were not properly destroying tooltips which made tests
start to fail with the new QUnit.

Ref gh-2157
This commit is contained in:
Michał Gołębiowski-Owczarek 2023-03-30 10:09:12 +02:00 committed by Michał Gołębiowski-Owczarek
parent 0977ea1b48
commit 9dc2bf9737
5 changed files with 34 additions and 5 deletions

View File

@ -26,6 +26,8 @@ QUnit.test( "markup structure", function( assert ) {
assert.equal( tooltip.length, 1, ".ui-tooltip exists" );
assert.equal( tooltip.find( ".ui-tooltip-content" ).length, 1,
".ui-tooltip-content exists" );
element.tooltip( "destroy" );
} );
QUnit.test( "accessibility", function( assert ) {
@ -95,6 +97,8 @@ QUnit.test( "nested tooltips", function( assert ) {
child.trigger( "mouseover" );
assert.equal( $( ".ui-tooltip" ).text(), "child" );
parent.tooltip( "destroy" );
} );
// #8742
@ -148,6 +152,7 @@ QUnit.test( "programmatic focus with async content", function( assert ) {
element.on( "tooltipclose", function( event ) {
assert.deepEqual( event.originalEvent.type, "focusout" );
element.tooltip( "destroy" );
ready();
} );
@ -249,6 +254,7 @@ QUnit.test( "remove conflicting attributes from live region", function( assert )
"no name attributes within live region" );
assert.equal( $( ".ui-helper-hidden-accessible [id]" ).length, 0,
"no id attributes within live region" );
$( "#tooltipped1" ).tooltip( "destroy" );
}
} )
.tooltip( "open" );

View File

@ -16,6 +16,8 @@ QUnit.test( "tooltipClass", function( assert ) {
tooltipClass: "custom"
} ).tooltip( "open" );
assert.hasClasses( $( "#" + element.data( "ui-tooltip-id" ) ), "custom" );
element.tooltip( "destroy" );
} );
} );

View File

@ -28,6 +28,7 @@ QUnit.test( "programmatic triggers", function( assert ) {
assert.strictEqual( ui.tooltip[ 0 ], tooltip[ 0 ], "ui.tooltip" );
} );
element.tooltip( "close" );
element.tooltip( "destroy" );
} );
QUnit.test( "mouse events", function( assert ) {
@ -44,6 +45,7 @@ QUnit.test( "mouse events", function( assert ) {
} );
element.trigger( "focusout" );
element.trigger( "mouseleave" );
element.tooltip( "destroy" );
} );
QUnit.test( "focus events", function( assert ) {
@ -60,6 +62,7 @@ QUnit.test( "focus events", function( assert ) {
} );
element.trigger( "mouseleave" );
element.trigger( "focusout" );
element.tooltip( "destroy" );
} );
} );

View File

@ -96,6 +96,8 @@ QUnit.test( "enable/disable", function( assert ) {
tooltip = $( "#" + element.data( "ui-tooltip-id" ) );
assert.ok( tooltip.is( ":visible" ) );
$.fx.off = false;
element.tooltip( "destroy" );
} );
QUnit.test( "enable/disable delegated", function( assert ) {
@ -118,6 +120,8 @@ QUnit.test( "widget", function( assert ) {
widgetElement = element.tooltip( "widget" );
assert.equal( widgetElement.length, 1, "one element" );
assert.strictEqual( widgetElement[ 0 ], element[ 0 ], "same element" );
element.tooltip( "destroy" );
} );
QUnit.test( "preserve changes to title attributes on close and destroy", function( assert ) {

View File

@ -12,16 +12,18 @@ QUnit.module( "tooltip: options", beforeAfterEach() );
QUnit.test( "disabled: true", function( assert ) {
assert.expect( 1 );
$( "#tooltipped1" ).tooltip( {
var element = $( "#tooltipped1" ).tooltip( {
disabled: true
} ).tooltip( "open" );
assert.equal( $( ".ui-tooltip" ).length, 0 );
element.tooltip( "destroy" );
} );
QUnit.test( "content: default", function( assert ) {
assert.expect( 1 );
var element = $( "#tooltipped1" ).tooltip().tooltip( "open" );
assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "anchortitle" );
element.tooltip( "destroy" );
} );
QUnit.test( "content: default; HTML escaping", function( assert ) {
@ -36,6 +38,7 @@ QUnit.test( "content: default; HTML escaping", function( assert ) {
assert.equal( $.ui.tooltip.hacked, false, "script did not execute" );
assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), scriptText,
"correct tooltip text" );
element.tooltip( "destroy" );
} );
QUnit.test( "content: return string", function( assert ) {
@ -46,6 +49,7 @@ QUnit.test( "content: return string", function( assert ) {
}
} ).tooltip( "open" );
assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring" );
element.tooltip( "destroy" );
} );
QUnit.test( "content: return jQuery", function( assert ) {
@ -59,6 +63,7 @@ QUnit.test( "content: return jQuery", function( assert ) {
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" );
element.tooltip( "destroy" );
} );
QUnit.test( "content: sync + async callback", function( assert ) {
@ -72,6 +77,8 @@ QUnit.test( "content: sync + async callback", function( assert ) {
response( "customstring2" );
setTimeout( function() {
assert.deepEqual( $( "#" + element.data( "ui-tooltip-id" ) ).text(), "customstring2" );
element.tooltip( "destroy" );
ready();
}, 13 );
}, 13 );
@ -94,6 +101,8 @@ QUnit.test( "content: async callback loses focus before load", function( assert
setTimeout( function() {
assert.ok( !$( "#" + element.data( "ui-tooltip-id" ) ).is( ":visible" ),
"Tooltip should not display" );
element.tooltip( "destroy" );
ready();
} );
} );
@ -117,6 +126,8 @@ QUnit.test( "content: change while open", function( assert ) {
return "new";
} );
assert.equal( ui.tooltip.text(), "new", "updated content" );
element.tooltip( "destroy" );
} );
element.tooltip( "open" );
@ -129,7 +140,7 @@ QUnit.test( "content: string", function( assert ) {
open: function( event, ui ) {
assert.equal( ui.tooltip.text(), "just a string" );
}
} ).tooltip( "open" );
} ).tooltip( "open" ).tooltip( "destroy" );
} );
QUnit.test( "content: element", function( assert ) {
@ -141,7 +152,7 @@ QUnit.test( "content: element", function( assert ) {
open: function( event, ui ) {
assert.equal( ui.tooltip.children().html().toLowerCase(), content );
}
} ).tooltip( "open" );
} ).tooltip( "open" ).tooltip( "destroy" );
} );
QUnit.test( "content: jQuery", function( assert ) {
@ -153,7 +164,7 @@ QUnit.test( "content: jQuery", function( assert ) {
open: function( event, ui ) {
assert.equal( ui.tooltip.children().html().toLowerCase(), content );
}
} ).tooltip( "open" );
} ).tooltip( "open" ).tooltip( "destroy" );
} );
QUnit.test( "items", function( assert ) {
@ -217,14 +228,17 @@ QUnit.test( "track + show delay", function( assert ) {
topVal + offsetVal, 0.5,
"top position"
);
element.tooltip( "destroy" );
} );
QUnit.test( "track and programmatic focus", function( assert ) {
assert.expect( 1 );
$( "#qunit-fixture div input" ).tooltip( {
var element = $( "#qunit-fixture div input" ).tooltip( {
track: true
} ).trigger( "focus" );
assert.equal( "inputtitle", $( ".ui-tooltip" ).text() );
element.tooltip( "destroy" );
} );
} );