2015-04-03 19:57:57 +00:00
|
|
|
define( [
|
|
|
|
"jquery",
|
2015-07-15 01:56:36 +00:00
|
|
|
"ui/widgets/autocomplete"
|
2015-04-03 19:57:57 +00:00
|
|
|
], function( $ ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
module( "autocomplete: methods" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-04-03 19:57:57 +00:00
|
|
|
test( "destroy", function( assert ) {
|
2011-06-13 18:09:44 +00:00
|
|
|
expect( 1 );
|
2015-04-03 19:57:57 +00:00
|
|
|
assert.domEqual( "#autocomplete", function() {
|
2011-06-13 18:09:44 +00:00
|
|
|
$( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2012-01-31 19:21:18 +00:00
|
|
|
test( "search, close", function() {
|
|
|
|
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" ],
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: data,
|
|
|
|
minLength: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
2012-01-31 19:21:18 +00:00
|
|
|
|
|
|
|
ok( menu.is( ":hidden" ), "menu is hidden on init" );
|
|
|
|
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "search" );
|
2012-01-31 19:21:18 +00:00
|
|
|
ok( menu.is( ":visible" ), "menu is visible after search" );
|
2011-06-13 18:09:44 +00:00
|
|
|
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" );
|
|
|
|
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" );
|
|
|
|
equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" );
|
2012-01-31 19:21:18 +00:00
|
|
|
|
|
|
|
element.autocomplete( "close" );
|
|
|
|
ok( menu.is( ":hidden" ), "menu is hidden after close" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-01-30 14:56:42 +00:00
|
|
|
test( "widget", function( assert ) {
|
2012-08-27 00:15:03 +00:00
|
|
|
expect( 2 );
|
|
|
|
var element = $( "#autocomplete" ).autocomplete(),
|
|
|
|
widgetElement = element.autocomplete( "widget" );
|
|
|
|
equal( widgetElement.length, 1, "one element" );
|
2015-01-30 14:56:42 +00:00
|
|
|
assert.hasClasses( widgetElement, "ui-menu" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-08-27 00:15:03 +00:00
|
|
|
|
2015-04-03 19:57:57 +00:00
|
|
|
} );
|