jquery-ui/tests/unit/autocomplete/methods.js

50 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

define( [
2016-04-03 14:51:14 +00:00
"qunit",
"jquery",
"ui/widgets/autocomplete"
2016-04-03 14:51:14 +00:00
], function( QUnit, $ ) {
2010-01-20 14:00:14 +00:00
2016-04-03 14:51:14 +00:00
QUnit.module( "autocomplete: methods" );
2010-01-20 14:00:14 +00:00
2016-04-03 14:51:14 +00:00
QUnit.test( "destroy", function( assert ) {
assert.expect( 1 );
assert.domEqual( "#autocomplete", function() {
2011-06-13 18:09:44 +00:00
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
} );
} );
2010-01-20 14:00:14 +00:00
2016-04-03 14:51:14 +00:00
QUnit.test( "search, close", function( assert ) {
assert.expect( 6 );
2011-06-13 18:09:44 +00:00
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ],
element = $( "#autocomplete" ).autocomplete( {
2011-06-13 18:09:44 +00:00
source: data,
minLength: 0
} ),
2011-06-13 18:09:44 +00:00
menu = element.autocomplete( "widget" );
2016-04-03 14:51:14 +00:00
assert.ok( menu.is( ":hidden" ), "menu is hidden on init" );
2011-06-13 18:09:44 +00:00
element.autocomplete( "search" );
2016-04-03 14:51:14 +00:00
assert.ok( menu.is( ":visible" ), "menu is visible after search" );
assert.equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" );
2010-01-20 14:00:14 +00:00
2011-06-13 18:09:44 +00:00
element.val( "has" ).autocomplete( "search" );
2016-04-03 14:51:14 +00:00
assert.equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" );
2010-01-20 14:00:14 +00:00
2011-06-13 18:09:44 +00:00
element.autocomplete( "search", "ja" );
2016-04-03 14:51:14 +00:00
assert.equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" );
element.autocomplete( "close" );
2016-04-03 14:51:14 +00:00
assert.ok( menu.is( ":hidden" ), "menu is hidden after close" );
} );
2010-01-20 14:00:14 +00:00
2016-04-03 14:51:14 +00:00
QUnit.test( "widget", function( assert ) {
assert.expect( 2 );
var element = $( "#autocomplete" ).autocomplete(),
widgetElement = element.autocomplete( "widget" );
2016-04-03 14:51:14 +00:00
assert.equal( widgetElement.length, 1, "one element" );
assert.hasClasses( widgetElement, "ui-menu" );
} );
} );