jquery-ui/tests/unit/tooltip/events.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

define( [
2016-04-06 13:59:12 +00:00
"qunit",
"jquery",
"./helper",
"ui/widgets/tooltip"
], function( QUnit, $, testHelper ) {
"use strict";
var beforeAfterEach = testHelper.beforeAfterEach;
QUnit.module( "tooltip: events", beforeAfterEach() );
2016-04-06 13:59:12 +00:00
QUnit.test( "programmatic triggers", function( assert ) {
assert.expect( 4 );
var tooltip,
element = $( "#tooltipped1" ).tooltip();
element.one( "tooltipopen", function( event, ui ) {
tooltip = ui.tooltip;
2016-04-06 13:59:12 +00:00
assert.ok( !( "originalEvent" in event ), "open" );
assert.strictEqual( ui.tooltip[ 0 ],
2015-08-24 12:50:46 +00:00
$( "#" + element.data( "ui-tooltip-id" ) )[ 0 ], "ui.tooltip" );
} );
element.tooltip( "open" );
element.one( "tooltipclose", function( event, ui ) {
2016-04-06 13:59:12 +00:00
assert.ok( !( "originalEvent" in event ), "close" );
assert.strictEqual( ui.tooltip[ 0 ], tooltip[ 0 ], "ui.tooltip" );
2015-08-24 12:50:46 +00:00
} );
element.tooltip( "close" );
2015-08-24 12:50:46 +00:00
} );
2016-04-06 13:59:12 +00:00
QUnit.test( "mouse events", function( assert ) {
assert.expect( 2 );
var element = $( "#tooltipped1" ).tooltip();
element.on( "tooltipopen", function( event ) {
2016-04-06 13:59:12 +00:00
assert.deepEqual( event.originalEvent.type, "mouseover" );
2015-08-24 12:50:46 +00:00
} );
element.trigger( "mouseover" );
element.on( "tooltipclose", function( event ) {
2016-04-06 13:59:12 +00:00
assert.deepEqual( event.originalEvent.type, "mouseleave" );
2015-08-24 12:50:46 +00:00
} );
element.trigger( "focusout" );
element.trigger( "mouseleave" );
2015-08-24 12:50:46 +00:00
} );
2016-04-06 13:59:12 +00:00
QUnit.test( "focus events", function( assert ) {
assert.expect( 2 );
var element = $( "#tooltipped1" ).tooltip();
element.on( "tooltipopen", function( event ) {
2016-04-06 13:59:12 +00:00
assert.deepEqual( event.originalEvent.type, "focusin" );
2015-08-24 12:50:46 +00:00
} );
element.trigger( "focusin" );
element.on( "tooltipclose", function( event ) {
2016-04-06 13:59:12 +00:00
assert.deepEqual( event.originalEvent.type, "focusout" );
2015-08-24 12:50:46 +00:00
} );
element.trigger( "mouseleave" );
element.trigger( "focusout" );
2015-08-24 12:50:46 +00:00
} );
} );