aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2011-06-13 14:09:44 -0400
committerScott González <scott.gonzalez@gmail.com>2011-06-13 14:09:44 -0400
commit2bc66279912b460f572abff0d502e8e2c9c285a7 (patch)
tree7e98e13c905e72b5e92e77d4583aa82f5cd2af48 /tests
parentba9bd20c0d5a6ede11a536da9024bb1a582d131f (diff)
downloadjquery-ui-2bc66279912b460f572abff0d502e8e2c9c285a7.tar.gz
jquery-ui-2bc66279912b460f572abff0d502e8e2c9c285a7.zip
Autocomplete tests: Cleanup.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/autocomplete/autocomplete.html60
-rw-r--r--tests/unit/autocomplete/autocomplete_core.js106
-rw-r--r--tests/unit/autocomplete/autocomplete_events.js337
-rw-r--r--tests/unit/autocomplete/autocomplete_methods.js55
-rw-r--r--tests/unit/autocomplete/autocomplete_options.js317
5 files changed, 405 insertions, 470 deletions
diff --git a/tests/unit/autocomplete/autocomplete.html b/tests/unit/autocomplete/autocomplete.html
index 8f1d9db9a..a69562d3f 100644
--- a/tests/unit/autocomplete/autocomplete.html
+++ b/tests/unit/autocomplete/autocomplete.html
@@ -1,46 +1,44 @@
-<!DOCTYPE html>
+<!doctype html>
<html lang="en">
<head>
- <meta charset="UTF-8" />
+ <meta charset="utf-8">
<title>jQuery UI Autocomplete Test Suite</title>
- <link type="text/css" href="../../../themes/base/jquery.ui.autocomplete.css" rel="stylesheet" />
-
- <script type="text/javascript" src="../../../jquery-1.5.1.js"></script>
- <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
- <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
- <script type="text/javascript" src="../../../ui/jquery.ui.position.js"></script>
- <script type="text/javascript" src="../../../ui/jquery.ui.menu.js"></script>
- <script type="text/javascript" src="../../../ui/jquery.ui.autocomplete.js"></script>
-
- <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
- <script type="text/javascript" src="../../../external/qunit.js"></script>
- <script type="text/javascript" src="../../jquery.simulate.js"></script>
- <script type="text/javascript" src="../testsuite.js"></script>
-
- <script type="text/javascript" src="autocomplete_core.js"></script>
- <script type="text/javascript" src="autocomplete_defaults.js"></script>
- <script type="text/javascript" src="autocomplete_events.js"></script>
- <script type="text/javascript" src="autocomplete_methods.js"></script>
- <script type="text/javascript" src="autocomplete_options.js"></script>
-
- <script type="text/javascript" src="../swarminject.js"></script>
+ <link rel="stylesheet" href="../../../themes/base/jquery.ui.autocomplete.css">
+
+ <script src="../../../jquery-1.5.1.js"></script>
+ <script src="../../../ui/jquery.ui.core.js"></script>
+ <script src="../../../ui/jquery.ui.widget.js"></script>
+ <script src="../../../ui/jquery.ui.position.js"></script>
+ <script src="../../../ui/jquery.ui.menu.js"></script>
+ <script src="../../../ui/jquery.ui.autocomplete.js"></script>
+
+ <link rel="stylesheet" href="../../../external/qunit.css">
+ <script src="../../../external/qunit.js"></script>
+ <script src="../../jquery.simulate.js"></script>
+ <script src="../testsuite.js"></script>
+
+ <script src="autocomplete_defaults.js"></script>
+ <script src="autocomplete_core.js"></script>
+ <script src="autocomplete_events.js"></script>
+ <script src="autocomplete_methods.js"></script>
+ <script src="autocomplete_options.js"></script>
+
+ <script src="../swarminject.js"></script>
</head>
-<body id="body">
+<body>
<h1 id="qunit-header">jQuery UI Autocomplete Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
-<ol id="qunit-tests">
-</ol>
-
+<ol id="qunit-tests"></ol>
<div id="qunit-fixture">
- <div id="ac-wrap1" class="ac-wrap"></div>
- <div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo" /></div>
- <div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
-</div>
+<div id="ac-wrap1" class="ac-wrap"></div>
+<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo" /></div>
+<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div>
+</div>
</body>
</html>
diff --git a/tests/unit/autocomplete/autocomplete_core.js b/tests/unit/autocomplete/autocomplete_core.js
index 19f52dc15..3f92aa01f 100644
--- a/tests/unit/autocomplete/autocomplete_core.js
+++ b/tests/unit/autocomplete/autocomplete_core.js
@@ -1,73 +1,83 @@
-/*
- * autocomplete_core.js
- */
+(function( $ ) {
+module( "autocomplete: core" );
-(function($) {
+asyncTest( "close-on-blur is properly delayed", function() {
+ expect( 3 );
+ var element = $( "#autocomplete" )
+ .autocomplete({
+ source: [ "java", "javascript" ]
+ })
+ .val( "ja" )
+ .autocomplete( "search" ),
+ menu = element.autocomplete( "widget" );
-module("autocomplete: core", {
- teardown: function() {
- $( ":ui-autocomplete" ).autocomplete( "destroy" );
- }
-});
-
-test("close-on-blur is properly delayed", function() {
- var ac = $("#autocomplete").autocomplete({
- source: ["java", "javascript"]
- }).val("ja").autocomplete("search");
- same( $(".ui-menu:visible").length, 1 );
- ac.blur();
- same( $(".ui-menu:visible").length, 1 );
- stop();
+ ok( menu.is( ":visible" ) );
+ element.blur();
+ ok( menu.is( ":visible" ) );
setTimeout(function() {
- same( $(".ui-menu:visible").length, 0 );
+ ok( menu.is( ":hidden") );
start();
- }, 200);
+ }, 200 );
});
-test("close-on-blur is cancelled when starting a search", function() {
- var ac = $("#autocomplete").autocomplete({
- source: ["java", "javascript"]
- }).val("ja").autocomplete("search");
- same( $(".ui-menu:visible").length, 1 );
- ac.blur();
- same( $(".ui-menu:visible").length, 1 );
- ac.autocomplete("search");
- stop();
+asyncTest( "close-on-blur is cancelled when starting a search", function() {
+ expect( 3 );
+ var element = $( "#autocomplete" )
+ .autocomplete({
+ source: [ "java", "javascript" ]
+ })
+ .val( "ja" )
+ .autocomplete( "search" ),
+ menu = element.autocomplete( "widget" );
+
+ ok( menu.is( ":visible" ) );
+ element.blur();
+ ok( menu.is( ":visible" ) );
+ element.autocomplete( "search" );
setTimeout(function() {
- same( $(".ui-menu:visible").length, 1 );
+ ok( menu.is( ":visible" ) );
start();
- }, 200);
+ }, 200 );
});
test( "prevent form submit on enter when menu is active", function() {
- var event;
- var ac = $( "#autocomplete" ).autocomplete({
- source: [ "java", "javascript" ]
- }).val( "ja" ).autocomplete( "search" );
-
+ expect( 2 );
+ var event,
+ element = $( "#autocomplete" )
+ .autocomplete({
+ source: [ "java", "javascript" ]
+ })
+ .val( "ja" )
+ .autocomplete( "search" ),
+ menu = element.autocomplete( "widget" );
+
event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.DOWN;
- ac.trigger( event );
- same( $( ".ui-menu-item:has(.ui-state-focus)" ).length, 1, "menu item is active" );
-
+ element.trigger( event );
+ deepEqual( menu.find( ".ui-menu-item:has(.ui-state-focus)" ).length, 1, "menu item is active" );
+
event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER;
- ac.trigger( event );
+ element.trigger( event );
ok( event.isDefaultPrevented(), "default action is prevented" );
});
test( "allow form submit on enter when menu is not active", function() {
- var event;
- var ac = $( "#autocomplete" ).autocomplete({
- autoFocus: false,
- source: [ "java", "javascript" ]
- }).val( "ja" ).autocomplete( "search" );
-
+ expect( 1 );
+ var event,
+ element = $( "#autocomplete" )
+ .autocomplete({
+ autoFocus: false,
+ source: [ "java", "javascript" ]
+ })
+ .val( "ja" )
+ .autocomplete( "search" );
+
event = $.Event( "keydown" );
event.keyCode = $.ui.keyCode.ENTER;
- ac.trigger( event );
+ element.trigger( event );
ok( !event.isDefaultPrevented(), "default action is prevented" );
});
-})(jQuery);
+}( jQuery ) );
diff --git a/tests/unit/autocomplete/autocomplete_events.js b/tests/unit/autocomplete/autocomplete_events.js
index c884733d6..c6d42ddcc 100644
--- a/tests/unit/autocomplete/autocomplete_events.js
+++ b/tests/unit/autocomplete/autocomplete_events.js
@@ -1,206 +1,197 @@
-/*
- * autocomplete_events.js
- */
-(function($) {
+(function( $ ) {
-module("autocomplete: events", {
- teardown: function() {
- $( ":ui-autocomplete" ).autocomplete( "destroy" );
- }
-});
+module( "autocomplete: events" );
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
-test("all events", function() {
- expect(14);
- var ac = $("#autocomplete").autocomplete({
- autoFocus: false,
- delay: 0,
- source: data,
- search: function(event) {
- same(event.type, "autocompletesearch");
- },
- response: function(event, ui) {
- same(event.type, "autocompleteresponse");
- same(ui.content, [
- { label: "Clojure", value: "Clojure" },
- { label: "Java", value: "Java" },
- { label: "JavaScript", value: "JavaScript" }
- ]);
- ui.content.splice( 0, 1 );
- },
- open: function(event) {
- same(event.type, "autocompleteopen");
- },
- focus: function(event, ui) {
- same(event.type, "autocompletefocus");
- same(ui.item, {label:"Java", value:"Java"});
- },
- close: function(event) {
- same(event.type, "autocompleteclose");
- same( $(".ui-menu:visible").length, 0 );
- },
- select: function(event, ui) {
- same(event.type, "autocompleteselect");
- same(ui.item, {label:"Java", value:"Java"});
- },
- change: function(event, ui) {
- same(event.type, "autocompletechange");
- same(ui.item, {label:"Java", value:"Java"});
- same( $(".ui-menu:visible").length, 0 );
- start();
- }
- });
- stop();
- ac.focus().val("j").keydown();
+asyncTest( "all events", function() {
+ expect( 13 );
+ var element = $( "#autocomplete" )
+ .autocomplete({
+ autoFocus: false,
+ delay: 0,
+ source: data,
+ search: function( event ) {
+ equal( event.originalEvent.type, "keydown", "search originalEvent" );
+ },
+ response: function( event, ui ) {
+ deepEqual( ui.content, [
+ { label: "Clojure", value: "Clojure" },
+ { label: "Java", value: "Java" },
+ { label: "JavaScript", value: "JavaScript" }
+ ], "response ui.content" );
+ ui.content.splice( 0, 1 );
+ },
+ open: function( event ) {
+ ok( menu.is( ":visible" ), "menu open on open" );
+ },
+ focus: function( event, ui ) {
+ equal( event.originalEvent.type, "menufocus", "focus originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" );
+ },
+ close: function( event ) {
+ equal( event.originalEvent.type, "menuselect", "close originalEvent" );
+ ok( menu.is( ":hidden" ), "menu closed on close" );
+ },
+ select: function( event, ui ) {
+ equal( event.originalEvent.type, "menuselect", "select originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" );
+ },
+ change: function( event, ui ) {
+ equal( event.originalEvent.type, "blur", "change originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "chnage ui.item" );
+ ok( menu.is( ":hidden" ), "menu closed on change" );
+ start();
+ }
+ }),
+ menu = element.autocomplete( "widget" );
+
+ element.focus().val( "j" ).keydown();
setTimeout(function() {
- same( $(".ui-menu:visible").length, 1 );
- ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
- ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
+ ok( menu.is( ":visible" ), "menu is visible after delay" );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
// blurring through jQuery causes a bug in IE 6 which causes the
// autocompletechange event to occur twice
- ac[0].blur();
- }, 50);
+ element[0].blur();
+ }, 50 );
});
-test("all events - contenteditable", function() {
- expect(14);
- var ac = $("#autocomplete-contenteditable").autocomplete({
- autoFocus: false,
- delay: 0,
- source: data,
- search: function(event) {
- same(event.type, "autocompletesearch");
- },
- response: function(event, ui) {
- same(event.type, "autocompleteresponse");
- same(ui.content, [
- { label: "Clojure", value: "Clojure" },
- { label: "Java", value: "Java" },
- { label: "JavaScript", value: "JavaScript" }
- ]);
- ui.content.splice( 0, 1 );
- },
- open: function(event) {
- same(event.type, "autocompleteopen");
- },
- focus: function(event, ui) {
- same(event.type, "autocompletefocus");
- same(ui.item, {label:"Java", value:"Java"});
- },
- close: function(event) {
- same(event.type, "autocompleteclose");
- same( $(".ui-menu:visible").length, 0 );
- },
- select: function(event, ui) {
- same(event.type, "autocompleteselect");
- same(ui.item, {label:"Java", value:"Java"});
- },
- change: function(event, ui) {
- same(event.type, "autocompletechange");
- same(ui.item, {label:"Java", value:"Java"});
- same( $(".ui-menu:visible").length, 0 );
- start();
- }
- });
- stop();
- ac.focus().text("j").keydown();
+asyncTest( "all events - contenteditable", function() {
+ expect( 13 );
+ var element = $( "#autocomplete-contenteditable" )
+ .autocomplete({
+ autoFocus: false,
+ delay: 0,
+ source: data,
+ search: function( event ) {
+ equal( event.originalEvent.type, "keydown", "search originalEvent" );
+ },
+ response: function( event, ui ) {
+ deepEqual( ui.content, [
+ { label: "Clojure", value: "Clojure" },
+ { label: "Java", value: "Java" },
+ { label: "JavaScript", value: "JavaScript" }
+ ], "response ui.content" );
+ ui.content.splice( 0, 1 );
+ },
+ open: function( event ) {
+ ok( menu.is( ":visible" ), "menu open on open" );
+ },
+ focus: function( event, ui ) {
+ equal( event.originalEvent.type, "menufocus", "focus originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" );
+ },
+ close: function( event ) {
+ equal( event.originalEvent.type, "menuselect", "close originalEvent" );
+ ok( menu.is( ":hidden" ), "menu closed on close" );
+ },
+ select: function( event, ui ) {
+ equal( event.originalEvent.type, "menuselect", "select originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" );
+ },
+ change: function( event, ui ) {
+ equal( event.originalEvent.type, "blur", "change originalEvent" );
+ deepEqual( ui.item, { label: "Java", value: "Java" }, "chnage ui.item" );
+ ok( menu.is( ":hidden" ), "menu closed on change" );
+ start();
+ }
+ }),
+ menu = element.autocomplete( "widget" );
+
+ element.focus().text( "j" ).keydown();
setTimeout(function() {
- same( $(".ui-menu:visible").length, 1 );
- ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
- ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
- // blurring through jQuery causes a bug in IE 6 which causes the
+ ok( menu.is( ":visible" ), "menu is visible after delay" );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ // TODO: blurring through jQuery causes a bug in IE 6 which causes the
// autocompletechange event to occur twice
- ac[0].blur();
- }, 50);
+ element[0].blur();
+ }, 50 );
});
-test("change without selection", function() {
- expect(2);
- stop();
- var ac = $("#autocomplete").autocomplete({
+asyncTest( "change without selection", function() {
+ expect( 1 );
+ var element = $( "#autocomplete" ).autocomplete({
delay: 0,
source: data,
- change: function(event, ui) {
- same(event.type, "autocompletechange");
- same(ui.item, null);
+ change: function( event, ui ) {
+ strictEqual( ui.item, null );
start();
}
});
- ac.triggerHandler("focus");
- ac.val("ja").triggerHandler("blur");
+ element.triggerHandler( "focus" );
+ element.val( "ja" ).triggerHandler( "blur" );
});
-test("cancel search", function() {
- expect(6);
- var first = true;
- var ac = $("#autocomplete").autocomplete({
- delay: 0,
- source: data,
- search: function() {
- if (first) {
- same( ac.val(), "ja" );
- first = false;
- return false;
+asyncTest( "cancel search", function() {
+ expect( 6 );
+ var first = true,
+ element = $( "#autocomplete" ).autocomplete({
+ delay: 0,
+ source: data,
+ search: function() {
+ if ( first ) {
+ equal( element.val(), "ja", "val on first search" );
+ first = false;
+ return false;
+ }
+ equal( element.val(), "java", "val on second search" );
+ },
+ open: function() {
+ ok( true, "menu opened" );
}
- same( ac.val(), "java" );
- },
- open: function() {
- ok(true);
- }
- });
- stop();
- ac.val("ja").keydown();
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).keydown();
setTimeout(function() {
- same( $(".ui-menu:visible").length, 0 );
- ac.val("java").keydown();
+ ok( menu.is( ":hidden" ), "menu is hidden after first search" );
+ element.val( "java" ).keydown();
setTimeout(function() {
- same( $(".ui-menu:visible").length, 1 );
- same( $(".ui-menu .ui-menu-item").length, 2 );
+ ok( menu.is( ":visible" ), "menu is visible after second search" );
+ equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" );
start();
- }, 50);
- }, 50);
+ }, 50 );
+ }, 50 );
});
-test("cancel focus", function() {
- expect(1);
- var customVal = 'custom value';
- var ac = $("#autocomplete").autocomplete({
- delay: 0,
- source: data,
- focus: function(event, ui) {
- $(this).val(customVal);
- return false;
- }
- });
- stop();
- ac.val("ja").keydown();
+asyncTest( "cancel focus", function() {
+ expect( 1 );
+ var customVal = "custom value";
+ element = $( "#autocomplete" ).autocomplete({
+ delay: 0,
+ source: data,
+ focus: function( event, ui ) {
+ $( this ).val( customVal );
+ return false;
+ }
+ });
+ element.val( "ja" ).keydown();
setTimeout(function() {
- ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
- same( ac.val(), customVal );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ equal( element.val(), customVal );
start();
- }, 50);
+ }, 50 );
});
-test("cancel select", function() {
- expect(1);
- var customVal = 'custom value';
- var ac = $("#autocomplete").autocomplete({
- delay: 0,
- source: data,
- select: function(event, ui) {
- $(this).val(customVal);
- return false;
- }
- });
- stop();
- ac.val("ja").keydown();
+asyncTest( "cancel select", function() {
+ expect( 1 );
+ var customVal = "custom value",
+ element = $( "#autocomplete" ).autocomplete({
+ delay: 0,
+ source: data,
+ select: function( event, ui ) {
+ $( this ).val( customVal );
+ return false;
+ }
+ });
+ element.val( "ja" ).keydown();
setTimeout(function() {
- ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
- ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
- same( ac.val(), customVal );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
+ element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
+ equal( element.val(), customVal );
start();
- }, 50);
+ }, 50 );
});
/* TODO previous fix broke more than it fixed, disabling this for now - messed up regular menu select event
@@ -215,10 +206,10 @@ test("blur without selection", function() {
setTimeout(function() {
$( ".ui-menu-item" ).first().simulate("mouseover");
ac.simulate("keydown", { keyCode: $.ui.keyCode.TAB });
- same( ac.val(), "j" );
+ deepEqual( ac.val(), "j" );
start();
}, 50);
});
*/
-})(jQuery);
+}( jQuery ) );
diff --git a/tests/unit/autocomplete/autocomplete_methods.js b/tests/unit/autocomplete/autocomplete_methods.js
index 1043e47ba..3fe035d28 100644
--- a/tests/unit/autocomplete/autocomplete_methods.js
+++ b/tests/unit/autocomplete/autocomplete_methods.js
@@ -1,39 +1,30 @@
-/*
- * autocomplete_methods.js
- */
-(function($) {
+(function( $ ) {
+module( "autocomplete: methods" );
-module("autocomplete: methods", {
- teardown: function() {
- $( ":ui-autocomplete" ).autocomplete( "destroy" );
- }
+test( "destroy", function() {
+ expect( 1 );
+ domEqual( "#autocomplete", function() {
+ $( "#autocomplete" ).autocomplete().autocomplete( "destroy" );
+ });
});
-test("destroy", function() {
- domEqual("#autocomplete", function() {
- $("#autocomplete").autocomplete().autocomplete("destroy");
- });
-})
+test( "search", function() {
+ expect( 3 );
+ 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" );
+ element.autocomplete( "search" );
+ equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" );
-var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
+ element.val( "has" ).autocomplete( "search" );
+ equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" );
-test("search", function() {
- var ac = $("#autocomplete").autocomplete({
- source: data,
- minLength: 0
- });
- ac.autocomplete("search");
- same( $(".ui-menu .ui-menu-item").length, data.length, "all items for a blank search" );
-
- ac.val("has");
- ac.autocomplete("search")
- same( $(".ui-menu .ui-menu-item").text(), "haskell", "only one item for set input value" );
-
- ac.autocomplete("search", "ja");
- same( $(".ui-menu .ui-menu-item").length, 2, "only java and javascript for 'ja'" );
-
- $("#autocomplete").autocomplete("destroy");
-})
+ element.autocomplete( "search", "ja" );
+ equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" );
+});
-})(jQuery);
+}( jQuery ) );
diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js
index f2da2f4aa..01c4e9fef 100644
--- a/tests/unit/autocomplete/autocomplete_options.js
+++ b/tests/unit/autocomplete/autocomplete_options.js
@@ -1,247 +1,192 @@
-/*
- * autocomplete_options.js
- */
-(function($) {
-
-module("autocomplete: options", {
- teardown: function() {
- $( ":ui-autocomplete" ).autocomplete( "destroy" );
- }
-});
-
+(function( $ ) {
-/* disabled until autocomplete actually has built-in support for caching
-// returns at most 4 items
-function source(request) {
- ok(true, "handling a request");
- switch(request.term) {
- case "cha":
- return ["Common Pochard", "Common Chiffchaff", "Common Chaffinch", "Iberian Chiffchaff"]
- case "chaf":
- case "chaff":
- return ["Common Chiffchaff", "Common Chaffinch", "Iberian Chiffchaff"]
- case "chaffi":
- return ["Common Chaffinch"]
- case "schi":
- return ["schifpre"]
- }
-}
+module( "autocomplete: options" );
-function search(input) {
- var autocomplete = input.data("autocomplete");
- autocomplete.search("cha");
- autocomplete.close();
- autocomplete.search("chaf");
- autocomplete.close();
- autocomplete.search("chaff");
- autocomplete.close();
- autocomplete.search("chaffi");
- autocomplete.close();
- autocomplete.search("schi");
-}
-
-test("cache: default", function() {
- expect(2);
- search($("#autocomplete").autocomplete({
- source: source
- }));
-});
-
-test("cache: {limit:4}", function() {
- expect(3);
- search($("#autocomplete").autocomplete({
- cache: {
- limit: 4
- },
- source: source
- }));
-});
-
-test("cache: false", function() {
- expect(5);
- search($("#autocomplete").autocomplete({
- cache: false,
- source: source
- }));
-});
-*/
-
-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() {
- var ac = $( "#autocomplete" ).autocomplete();
- same( ac.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
- ac.autocomplete( "destroy" );
-
- ac.autocomplete({
- appendTo: "#ac-wrap2"
- });
- same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap2" )[0], "id" );
- ac.autocomplete( "destroy" );
+ expect( 5 );
+ var element = $( "#autocomplete" ).autocomplete();
+ equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
+ element.autocomplete( "destroy" );
- ac.autocomplete({
+ element.autocomplete({
appendTo: ".ac-wrap"
});
- same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "class" );
- same( $( "#ac-wrap2 .ui-autocomplete").length, 0, "class - only appends to one element")
- ac.autocomplete( "destroy" );
+ equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "first found element" );
+ equal( $( "#ac-wrap2 .ui-autocomplete" ).length, 0, "only appends to one element" );
+ element.autocomplete( "destroy" );
- ac.autocomplete({
+ element.autocomplete({
appendTo: null
});
- same( ac.autocomplete( "widget" ).parent()[0], document.body, "null" );
- ac.autocomplete( "destroy" );
-
- ac.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
- same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
- ac.autocomplete( "destroy" );
+ equal( element.autocomplete( "widget" ).parent()[0], document.body, "null" );
+ element.autocomplete( "destroy" );
+
+ element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
+ equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
+ element.autocomplete( "destroy" );
});
function autoFocusTest( afValue, focusedLength ) {
- var ac = $( "#autocomplete" ).autocomplete({
+ var element = $( "#autocomplete" ).autocomplete({
autoFocus: afValue,
delay: 0,
source: data,
open: function( event, ui ) {
- equal( ac.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length, focusedLength, "first item is " + afValue ? "" : "not" + " auto focused" );
- start();
+ equal( element.autocomplete( "widget" ).children( ".ui-menu-item:first .ui-state-focus" ).length,
+ focusedLength, "first item is " + (afValue ? "" : "not") + " auto focused" );
+ start();
}
});
- ac.val( "ja" ).keydown();
+ element.val( "ja" ).keydown();
stop();
}
test( "autoFocus: false", function() {
+ expect( 1 );
autoFocusTest( false, 0 );
});
test( "autoFocus: true", function() {
+ expect( 1 );
autoFocusTest( true, 1 );
});
-test("delay", function() {
- var ac = $("#autocomplete").autocomplete({
- source: data,
- delay: 50
- });
- ac.val("ja").keydown();
-
- same( $(".ui-menu:visible").length, 0 );
-
- // wait half a second for the default delay to open the menu
- stop();
- setTimeout(function() {
- same( $(".ui-menu:visible").length, 1 );
- ac.autocomplete("destroy");
- start();
- }, 100);
-});
+asyncTest( "delay", function() {
+ expect( 2 );
+ var element = $( "#autocomplete" ).autocomplete({
+ source: data,
+ delay: 50
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).keydown();
+
+ ok( menu.is( ":hidden" ), "menu is closed immediately after search" );
-test("disabled", function() {
- var ac = $("#autocomplete").autocomplete({
- source: data,
- delay: 0,
- disabled: true
- });
- ac.val("ja").keydown();
-
- same( $(".ui-menu:visible").length, 0 );
-
- stop();
setTimeout(function() {
- same( $(".ui-menu:visible").length, 0 );
- ac.autocomplete("destroy");
+ ok( menu.is( ":visible" ), "menu is open after delay" );
start();
- }, 50);
+ }, 100 );
});
-test("minLength", function() {
- var ac = $("#autocomplete").autocomplete({
- source: data
- });
- ac.autocomplete("search", "");
- same( $(".ui-menu:visible").length, 0, "blank not enough for minLength: 1" );
-
- ac.autocomplete("option", "minLength", 0);
- ac.autocomplete("search", "");
- same( $(".ui-menu:visible").length, 1, "blank enough for minLength: 0" );
- ac.autocomplete("destroy");
-});
+asyncTest( "disabled", function() {
+ expect( 2 );
+ var element = $( "#autocomplete" ).autocomplete({
+ source: data,
+ delay: 0,
+ disabled: true
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).keydown();
-test("source, local string array", function() {
- var ac = $("#autocomplete").autocomplete({
- source: data
- });
- ac.val("ja").autocomplete("search");
- same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
- ac.autocomplete("destroy");
-});
+ ok( menu.is( ":hidden" ) );
-function source_test(source, async) {
- var ac = $("#autocomplete").autocomplete({
- source: source
- });
- ac.val("ja").autocomplete("search");
- function result(){
- same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
- ac.autocomplete("destroy");
- async && start();
+ setTimeout(function() {
+ ok( menu.is( ":hidden" ) );
+ start();
+ }, 50 );
+});
+
+test( "minLength", function() {
+ expect( 2 );
+ var element = $( "#autocomplete" ).autocomplete({
+ source: data
+ }),
+ menu = element.autocomplete( "widget" );
+ element.autocomplete( "search", "" );
+ ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" );
+
+ element.autocomplete( "option", "minLength", 0 );
+ element.autocomplete( "search", "" );
+ ok( menu.is( ":visible" ), "blank enough for minLength: 0" );
+});
+
+test( "source, local string array", function() {
+ expect( 1 );
+ var element = $( "#autocomplete" ).autocomplete({
+ source: data
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).autocomplete( "search" );
+ equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
+});
+
+function sourceTest( source, async ) {
+ var element = $( "#autocomplete" ).autocomplete({
+ source: source
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).autocomplete( "search" );
+ function result() {
+ equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
+ element.autocomplete( "destroy" );
+ if ( async ) {
+ start();
+ }
}
- if (async) {
+ if ( async ) {
stop();
- $(document).one("ajaxStop", result);
+ $( document ).one( "ajaxStop", result );
} else {
result();
}
}
-test("source, local object array, only label property", function() {
- source_test([
- {label:"java"},
- {label:"php"},
- {label:"coldfusion"},
- {label:"javascript"}
+test( "source, local object array, only label property", function() {
+ expect( 1 );
+ sourceTest([
+ { label: "java" },
+ { label: "php" },
+ { label: "coldfusion" },
+ { label: "javascript" }
]);
});
-test("source, local object array, only value property", function() {
- source_test([
- {value:"java"},
- {value:"php"},
- {value:"coldfusion"},
- {value:"javascript"}
+test( "source, local object array, only value property", function() {
+ expect( 1 );
+ sourceTest([
+ { value: "java" },
+ { value: "php" },
+ { value: "coldfusion" },
+ { value: "javascript" }
]);
});
-test("source, url string with remote json string array", function() {
- source_test("remote_string_array.txt", true);
+test( "source, url string with remote json string array", function() {
+ expect( 1 );
+ sourceTest( "remote_string_array.txt", true );
});
-test("source, url string with remote json object array, only value properties", function() {
- source_test("remote_object_array_values.txt", true);
+test( "source, url string with remote json object array, only value properties", function() {
+ expect( 1 );
+ sourceTest( "remote_object_array_values.txt", true );
});
-test("source, url string with remote json object array, only label properties", function() {
- source_test("remote_object_array_labels.txt", true);
+test( "source, url string with remote json object array, only label properties", function() {
+ expect( 1 );
+ sourceTest( "remote_object_array_labels.txt", true );
});
-test("source, custom", function() {
- source_test(function(request, response) {
- same( request.term, "ja" );
- response(["java", "javascript"]);
+test( "source, custom", function() {
+ expect( 2 );
+ sourceTest(function( request, response ) {
+ equal( request.term, "ja" );
+ response( ["java", "javascript"] );
});
});
-test("source, update after init", function() {
- var ac = $("#autocomplete").autocomplete({
- source: ["java", "javascript", "haskell"]
- });
- ac.val("ja").autocomplete("search");
- same( $(".ui-menu .ui-menu-item").text(), "javajavascript" );
- ac.autocomplete("option", "source", ["php", "asp"]);
- ac.val("ph").autocomplete("search");
- same( $(".ui-menu .ui-menu-item").text(), "php" );
- ac.autocomplete("destroy");
+test( "source, update after init", function() {
+ expect( 2 );
+ var element = $( "#autocomplete" ).autocomplete({
+ source: [ "java", "javascript", "haskell" ]
+ }),
+ menu = element.autocomplete( "widget" );
+ element.val( "ja" ).autocomplete( "search" );
+ equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" );
+ element.autocomplete( "option", "source", [ "php", "asp" ] );
+ element.val( "ph" ).autocomplete( "search" );
+ equal( menu.find( ".ui-menu-item" ).text(), "php" );
});
-})(jQuery);
+}( jQuery ) );