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 ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( "autocomplete: options", { afterEach: helper.moduleAfterEach } );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2013-04-30 14:27:22 +00:00
|
|
|
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby",
|
|
|
|
"python", "c", "scala", "groovy", "haskell", "perl" ];
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "appendTo: null", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2014-01-20 21:13:55 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete();
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
|
2013-04-30 14:27:22 +00:00
|
|
|
"defaults to body" );
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2014-01-20 21:13:55 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "appendTo: explicit", function( assert ) {
|
|
|
|
assert.expect( 6 );
|
2014-01-20 21:13:55 +00:00
|
|
|
var detached = $( "<div>" ),
|
|
|
|
element = $( "#autocomplete" );
|
2010-07-21 18:54:20 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
element.autocomplete( {
|
2013-04-30 14:27:22 +00:00
|
|
|
appendTo: ".autocomplete-wrap"
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
2013-04-30 14:27:22 +00:00
|
|
|
$( "#autocomplete-wrap1" )[ 0 ], "first found element" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
|
2013-04-30 14:27:22 +00:00
|
|
|
"only appends to one element" );
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
2010-07-21 18:54:20 +00:00
|
|
|
|
2013-04-30 14:27:22 +00:00
|
|
|
element.autocomplete().autocomplete( "option", "appendTo", "#autocomplete-wrap1" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
2013-04-30 14:27:22 +00:00
|
|
|
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
2012-11-28 15:33:44 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
element.autocomplete( {
|
2012-11-28 15:33:44 +00:00
|
|
|
appendTo: detached
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
2013-04-30 14:27:22 +00:00
|
|
|
"detached jQuery object" );
|
2012-11-28 15:33:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
element.autocomplete( {
|
2013-04-30 14:27:22 +00:00
|
|
|
appendTo: detached[ 0 ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
2013-04-30 14:27:22 +00:00
|
|
|
"detached DOM element" );
|
2012-11-28 15:33:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
2012-12-07 16:58:58 +00:00
|
|
|
|
|
|
|
element.autocomplete().autocomplete( "option", "appendTo", detached );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
2013-04-30 14:27:22 +00:00
|
|
|
"detached DOM element via option()" );
|
2012-12-07 16:58:58 +00:00
|
|
|
element.autocomplete( "destroy" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-07-21 18:54:20 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "appendTo: ui-front", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2014-01-20 21:13:55 +00:00
|
|
|
var element = $( "#autocomplete" );
|
|
|
|
|
|
|
|
$( "#autocomplete-wrap2" ).addClass( "ui-front" );
|
|
|
|
element.autocomplete();
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
2014-01-20 21:13:55 +00:00
|
|
|
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
|
|
|
|
element.autocomplete( "destroy" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
element.autocomplete( {
|
2014-01-20 21:13:55 +00:00
|
|
|
appendTo: $()
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
2014-02-21 12:35:04 +00:00
|
|
|
$( "#autocomplete-wrap2" )[ 0 ], "empty jQuery object, inside .ui-front" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2014-01-20 21:13:55 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
function autoFocusTest( assert, afValue, focusedLength ) {
|
|
|
|
var ready = assert.async();
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-03-15 13:36:36 +00:00
|
|
|
autoFocus: afValue,
|
2011-03-15 12:42:28 +00:00
|
|
|
delay: 0,
|
|
|
|
source: data,
|
2012-10-23 14:36:42 +00:00
|
|
|
open: function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal(
|
2013-04-30 14:27:22 +00:00
|
|
|
element.autocomplete( "widget" )
|
2015-01-19 16:00:57 +00:00
|
|
|
.find( ".ui-menu-item-wrapper.ui-state-active" )
|
2013-04-30 14:27:22 +00:00
|
|
|
.length,
|
|
|
|
focusedLength,
|
2015-08-21 04:11:54 +00:00
|
|
|
"first item is " + ( afValue ? "" : "not" ) + " auto focused" );
|
2016-04-03 14:51:14 +00:00
|
|
|
ready();
|
2011-03-15 12:42:28 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2015-05-14 01:54:08 +00:00
|
|
|
element.val( "ja" ).trigger( "keydown" );
|
2011-03-15 13:36:36 +00:00
|
|
|
}
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "autoFocus: false", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
autoFocusTest( assert, false, 0 );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-03-15 12:42:28 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "autoFocus: true", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
autoFocusTest( assert, true, 1 );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-07-21 18:54:20 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "delay", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 2 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: data,
|
2015-02-17 15:11:58 +00:00
|
|
|
delay: 25
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
2015-05-14 01:54:08 +00:00
|
|
|
element.val( "ja" ).trigger( "keydown" );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "menu is open after delay" );
|
|
|
|
ready();
|
2015-02-17 15:11:58 +00:00
|
|
|
}, 50 );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-07-30 16:59:33 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "disabled", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 5 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: data,
|
2013-03-14 23:08:21 +00:00
|
|
|
delay: 0
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2013-03-14 23:08:21 +00:00
|
|
|
menu = element.autocomplete( "disable" ).autocomplete( "widget" );
|
2015-05-14 01:54:08 +00:00
|
|
|
element.val( "ja" ).trigger( "keydown" );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ) );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-01-30 14:56:42 +00:00
|
|
|
assert.lacksClasses( element, "ui-state-disabled" );
|
|
|
|
assert.hasClasses( menu, "ui-autocomplete-disabled" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( !element.attr( "aria-disabled" ), "element doesn't get aria-disabled" );
|
2013-03-14 23:08:21 +00:00
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ) );
|
|
|
|
ready();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "minLength", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: data
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
element.autocomplete( "search", "" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
|
|
|
element.autocomplete( "option", "minLength", 0 );
|
|
|
|
element.autocomplete( "search", "" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "minLength, exceed then drop below", function( assert ) {
|
|
|
|
var ready = assert.async();
|
|
|
|
assert.expect( 4 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2012-02-11 15:12:51 +00:00
|
|
|
minLength: 2,
|
|
|
|
source: function( req, res ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( req.term, "12", "correct search term" );
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
res( [ "item" ] );
|
|
|
|
} );
|
2012-02-11 15:12:51 +00:00
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2012-02-11 15:12:51 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
2012-02-11 15:12:51 +00:00
|
|
|
element.autocomplete( "search", "12" );
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
2012-02-11 15:12:51 +00:00
|
|
|
element.autocomplete( "search", "1" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
setTimeout( function() {
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden after searches" );
|
|
|
|
ready();
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
|
|
|
} );
|
2012-02-11 15:12:51 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "minLength, exceed then drop below then exceed", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2012-02-15 16:41:30 +00:00
|
|
|
var _res = [],
|
2015-08-21 04:11:54 +00:00
|
|
|
element = $( "#autocomplete" ).autocomplete( {
|
2012-02-15 16:41:30 +00:00
|
|
|
minLength: 2,
|
|
|
|
source: function( req, res ) {
|
|
|
|
_res.push( res );
|
|
|
|
}
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2012-02-15 16:41:30 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
// Trigger a valid search
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden before first search" );
|
2012-02-15 16:41:30 +00:00
|
|
|
element.autocomplete( "search", "12" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
// Trigger a search below the minLength, to turn on cancelSearch flag
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":hidden" ), "menu is hidden before second search" );
|
2012-02-15 16:41:30 +00:00
|
|
|
element.autocomplete( "search", "1" );
|
|
|
|
|
2015-08-21 04:11:54 +00:00
|
|
|
// Trigger a valid search
|
2012-02-15 16:41:30 +00:00
|
|
|
element.autocomplete( "search", "13" );
|
2015-08-21 04:11:54 +00:00
|
|
|
|
|
|
|
// React as if the first search was cancelled (default ajax behavior)
|
|
|
|
_res[ 0 ]( [] );
|
|
|
|
|
|
|
|
// React to second search
|
|
|
|
_res[ 1 ]( [ "13" ] );
|
2012-02-15 16:41:30 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.ok( menu.is( ":visible" ), "menu is visible after searches" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2012-02-11 15:12:51 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "source, local string array", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: data
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
element.val( "ja" ).autocomplete( "search" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-06-13 18:09:44 +00:00
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
function sourceTest( assert, source, async ) {
|
|
|
|
var ready;
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: source
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
function result() {
|
2014-01-22 15:40:19 +00:00
|
|
|
var items = menu.find( ".ui-menu-item" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( items.length, 3, "Should find three results." );
|
|
|
|
assert.deepEqual( items.eq( 0 ).data( "ui-autocomplete-item" ), {
|
2014-01-22 15:40:19 +00:00
|
|
|
label: "java",
|
|
|
|
value: "java"
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.deepEqual( items.eq( 1 ).data( "ui-autocomplete-item" ), {
|
2014-01-22 15:40:19 +00:00
|
|
|
label: "javascript",
|
|
|
|
value: "javascript"
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.deepEqual( items.eq( 2 ).data( "ui-autocomplete-item" ), {
|
2014-01-22 15:40:19 +00:00
|
|
|
label: "clojure",
|
|
|
|
value: "clojure"
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "destroy" );
|
|
|
|
if ( async ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
ready();
|
2011-06-13 18:09:44 +00:00
|
|
|
}
|
2010-01-20 14:00:14 +00:00
|
|
|
}
|
2011-06-13 18:09:44 +00:00
|
|
|
if ( async ) {
|
2016-04-03 14:51:14 +00:00
|
|
|
ready = assert.async();
|
2011-06-13 18:09:44 +00:00
|
|
|
$( document ).one( "ajaxStop", result );
|
2011-08-03 20:12:46 +00:00
|
|
|
}
|
2014-01-22 15:40:19 +00:00
|
|
|
element.val( "j" ).autocomplete( "search" );
|
2011-08-03 20:12:46 +00:00
|
|
|
if ( !async ) {
|
2010-01-20 14:00:14 +00:00
|
|
|
result();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 14:51:14 +00:00
|
|
|
QUnit.test( "source, local object array, only labels", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
|
|
|
sourceTest( assert, [
|
2014-01-22 15:40:19 +00:00
|
|
|
{ label: "java", value: null },
|
|
|
|
{ label: "php", value: null },
|
|
|
|
{ label: "coldfusion", value: "" },
|
|
|
|
{ label: "javascript", value: "" },
|
|
|
|
{ label: "clojure" }
|
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( "source, local object array, only values", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
|
|
|
sourceTest( assert, [
|
2014-01-22 15:40:19 +00:00
|
|
|
{ value: "java", label: null },
|
|
|
|
{ value: "php", label: null },
|
|
|
|
{ value: "coldfusion", label: "" },
|
|
|
|
{ value: "javascript", label: "" },
|
|
|
|
{ value: "clojure" }
|
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( "source, url string with remote json string array", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
|
|
|
sourceTest( assert, "remote_string_array.txt", true );
|
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( "source, url string with remote json object array, only value properties", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
|
|
|
sourceTest( assert, "remote_object_array_values.txt", true );
|
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( "source, url string with remote json object array, only label properties", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
|
|
|
sourceTest( assert, "remote_object_array_labels.txt", true );
|
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( "source, custom", function( assert ) {
|
|
|
|
assert.expect( 5 );
|
|
|
|
sourceTest( assert, function( request, response ) {
|
|
|
|
assert.equal( request.term, "j" );
|
2015-08-21 04:11:54 +00:00
|
|
|
response( [
|
2014-01-22 15:40:19 +00:00
|
|
|
"java",
|
|
|
|
{ label: "javascript", value: null },
|
|
|
|
{ value: "clojure", label: null }
|
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( "source, update after init", function( assert ) {
|
|
|
|
assert.expect( 2 );
|
2015-08-21 04:11:54 +00:00
|
|
|
var element = $( "#autocomplete" ).autocomplete( {
|
2011-06-13 18:09:44 +00:00
|
|
|
source: [ "java", "javascript", "haskell" ]
|
2015-08-21 04:11:54 +00:00
|
|
|
} ),
|
2011-06-13 18:09:44 +00:00
|
|
|
menu = element.autocomplete( "widget" );
|
|
|
|
element.val( "ja" ).autocomplete( "search" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
|
2011-06-13 18:09:44 +00:00
|
|
|
element.autocomplete( "option", "source", [ "php", "asp" ] );
|
|
|
|
element.val( "ph" ).autocomplete( "search" );
|
2016-04-03 14:51:14 +00:00
|
|
|
assert.equal( menu.find( ".ui-menu-item" ).text(), "php" );
|
2015-08-21 04:11:54 +00:00
|
|
|
} );
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2015-04-03 19:57:57 +00:00
|
|
|
} );
|