mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Autocomplete tests: Cleanup.
This commit is contained in:
parent
72f82df577
commit
7af03b73ea
@ -39,8 +39,8 @@
|
|||||||
<ol id="qunit-tests"></ol>
|
<ol id="qunit-tests"></ol>
|
||||||
<div id="qunit-fixture">
|
<div id="qunit-fixture">
|
||||||
|
|
||||||
<div id="ac-wrap1" class="ac-wrap"></div>
|
<div id="autocomplete-wrap1" class="autocomplete-wrap"></div>
|
||||||
<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo"></div>
|
<div id="autocomplete-wrap2" class="autocomplete-wrap"><input id="autocomplete" class="foo"></div>
|
||||||
<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
|
<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
|
||||||
<textarea id="autocomplete-textarea"></textarea>
|
<textarea id="autocomplete-textarea"></textarea>
|
||||||
|
|
||||||
|
@ -2,46 +2,55 @@
|
|||||||
|
|
||||||
module( "autocomplete: options" );
|
module( "autocomplete: options" );
|
||||||
|
|
||||||
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ];
|
var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby",
|
||||||
|
"python", "c", "scala", "groovy", "haskell", "perl" ];
|
||||||
|
|
||||||
test( "appendTo", function() {
|
test( "appendTo", function() {
|
||||||
expect( 8 );
|
expect( 8 );
|
||||||
var detached = $( "<div>" ),
|
var detached = $( "<div>" ),
|
||||||
element = $( "#autocomplete" ).autocomplete();
|
element = $( "#autocomplete" ).autocomplete();
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], document.body,
|
||||||
|
"defaults to body" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete({
|
||||||
appendTo: ".ac-wrap"
|
appendTo: ".autocomplete-wrap"
|
||||||
});
|
});
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "first found element" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
||||||
equal( $( "#ac-wrap2 .ui-autocomplete" ).length, 0, "only appends to one element" );
|
$( "#autocomplete-wrap1" )[ 0 ], "first found element" );
|
||||||
|
equal( $( "#autocomplete-wrap2 .ui-autocomplete" ).length, 0,
|
||||||
|
"only appends to one element" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
$( "#ac-wrap2" ).addClass( "ui-front" );
|
$( "#autocomplete-wrap2" ).addClass( "ui-front" );
|
||||||
element.autocomplete();
|
element.autocomplete();
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap2" )[0], "null, inside .ui-front" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
||||||
|
$( "#autocomplete-wrap2" )[ 0 ], "null, inside .ui-front" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
$( "#ac-wrap2" ).removeClass( "ui-front" );
|
$( "#autocomlete-wrap2" ).removeClass( "ui-front" );
|
||||||
|
|
||||||
element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
|
element.autocomplete().autocomplete( "option", "appendTo", "#autocomplete-wrap1" );
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ],
|
||||||
|
$( "#autocomplete-wrap1" )[ 0 ], "modified after init" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete({
|
||||||
appendTo: detached
|
appendTo: detached
|
||||||
});
|
});
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached jQuery object" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
|
"detached jQuery object" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete({
|
element.autocomplete({
|
||||||
appendTo: detached[0]
|
appendTo: detached[ 0 ]
|
||||||
});
|
});
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
|
"detached DOM element" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
|
|
||||||
element.autocomplete().autocomplete( "option", "appendTo", detached );
|
element.autocomplete().autocomplete( "option", "appendTo", detached );
|
||||||
equal( element.autocomplete( "widget" ).parent()[0], detached[0], "detached DOM element via option()" );
|
equal( element.autocomplete( "widget" ).parent()[ 0 ], detached[ 0 ],
|
||||||
|
"detached DOM element via option()" );
|
||||||
element.autocomplete( "destroy" );
|
element.autocomplete( "destroy" );
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,8 +60,13 @@ function autoFocusTest( afValue, focusedLength ) {
|
|||||||
delay: 0,
|
delay: 0,
|
||||||
source: data,
|
source: data,
|
||||||
open: function() {
|
open: function() {
|
||||||
equal( element.autocomplete( "widget" ).children( ".ui-menu-item:first" ).find( ".ui-state-focus" ).length,
|
equal(
|
||||||
focusedLength, "first item is " + (afValue ? "" : "not") + " auto focused" );
|
element.autocomplete( "widget" )
|
||||||
|
.children( ".ui-menu-item:first" )
|
||||||
|
.find( ".ui-state-focus" )
|
||||||
|
.length,
|
||||||
|
focusedLength,
|
||||||
|
"first item is " + (afValue ? "" : "not") + " auto focused" );
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user