Skip to content
Permalink
Browse files

Autocomplete tests: Cleanup.

  • Loading branch information
scottgonzalez committed Jun 13, 2011
1 parent ba9bd20 commit 2bc66279912b460f572abff0d502e8e2c9c285a7
@@ -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>
@@ -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 ) );

0 comments on commit 2bc6627

Please sign in to comment.
You can’t perform that action at this time.