2015-04-03 19:57:57 +00:00
|
|
|
define( [
|
2016-04-03 14:51:14 +00:00
|
|
|
"qunit",
|
2015-04-03 19:57:57 +00:00
|
|
|
"jquery",
|
2020-05-16 07:16:24 +00:00
|
|
|
"lib/helper",
|
2015-07-15 01:56:36 +00:00
|
|
|
"ui/widgets/autocomplete"
|
2020-05-16 07:16:24 +00:00
|
|
|
], function( QUnit, $, helper ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "autocomplete: methods", { afterEach: helper.moduleAfterEach } );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "destroy", function( assert ) {
|
|
|
|
assert.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
|
|
|
|
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" ],
|
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
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden on init" );
|
2012-01-31 19:21:18 +00:00
|
|
|
|
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'" );
|
2012-01-31 19:21:18 +00:00
|
|
|
|
|
|
|
element.autocomplete( "close" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.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
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "widget", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2012-08-27 00:15:03 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete(),
|
|
|
|
widgetElement = element.autocomplete( "widget" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.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
|
|
|
} );
|