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

49 lines
1.4 KiB
JavaScript
Raw Normal View History

define( [
"jquery",
"ui/autocomplete"
], 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
test( "destroy", function( assert ) {
2011-06-13 18:09:44 +00:00
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
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" ],
element = $( "#autocomplete" ).autocomplete({
source: data,
minLength: 0
}),
menu = element.autocomplete( "widget" );
ok( menu.is( ":hidden" ), "menu is hidden on init" );
2011-06-13 18:09:44 +00:00
element.autocomplete( "search" );
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'" );
element.autocomplete( "close" );
ok( menu.is( ":hidden" ), "menu is hidden after close" );
2011-06-13 18:09:44 +00:00
});
2010-01-20 14:00:14 +00:00
test( "widget", function( assert ) {
expect( 2 );
var element = $( "#autocomplete" ).autocomplete(),
widgetElement = element.autocomplete( "widget" );
equal( widgetElement.length, 1, "one element" );
assert.hasClasses( widgetElement, "ui-menu" );
});
} );