2010-01-20 14:00:14 +00:00
|
|
|
/*
|
|
|
|
* autocomplete_events.js
|
|
|
|
*/
|
|
|
|
(function($) {
|
|
|
|
|
2010-03-11 03:28:00 +00:00
|
|
|
module("autocomplete: events", {
|
|
|
|
teardown: function() {
|
|
|
|
$( ":ui-autocomplete" ).autocomplete( "destroy" );
|
|
|
|
}
|
|
|
|
});
|
2010-01-20 14:00:14 +00:00
|
|
|
|
2011-03-22 18:07:49 +00:00
|
|
|
var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ];
|
2010-01-20 14:00:14 +00:00
|
|
|
|
|
|
|
test("all events", function() {
|
2011-03-22 18:07:49 +00:00
|
|
|
expect(14);
|
2010-01-20 14:00:14 +00:00
|
|
|
var ac = $("#autocomplete").autocomplete({
|
2011-03-15 09:48:31 +00:00
|
|
|
autoFocus: false,
|
2010-01-20 14:00:14 +00:00
|
|
|
delay: 0,
|
|
|
|
source: data,
|
|
|
|
search: function(event) {
|
|
|
|
same(event.type, "autocompletesearch");
|
|
|
|
},
|
2011-03-22 18:07:49 +00:00
|
|
|
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 );
|
|
|
|
},
|
2010-01-20 14:00:14 +00:00
|
|
|
open: function(event) {
|
|
|
|
same(event.type, "autocompleteopen");
|
|
|
|
},
|
|
|
|
focus: function(event, ui) {
|
|
|
|
same(event.type, "autocompletefocus");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2010-01-20 14:00:14 +00:00
|
|
|
},
|
|
|
|
close: function(event) {
|
|
|
|
same(event.type, "autocompleteclose");
|
2010-10-26 13:05:38 +00:00
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
2010-01-20 14:00:14 +00:00
|
|
|
},
|
|
|
|
select: function(event, ui) {
|
|
|
|
same(event.type, "autocompleteselect");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2010-01-20 14:00:14 +00:00
|
|
|
},
|
2010-04-08 10:05:52 +00:00
|
|
|
change: function(event, ui) {
|
2010-01-20 14:00:14 +00:00
|
|
|
same(event.type, "autocompletechange");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2010-02-02 14:04:50 +00:00
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
2010-04-08 10:05:52 +00:00
|
|
|
start();
|
2010-01-20 14:00:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
stop();
|
2011-03-22 18:07:49 +00:00
|
|
|
ac.focus().val("j").keydown();
|
2010-01-20 14:00:14 +00:00
|
|
|
setTimeout(function() {
|
2010-02-02 14:04:50 +00:00
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
2011-02-24 09:22:51 +00:00
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
|
2011-02-24 21:54:54 +00:00
|
|
|
// blurring through jQuery causes a bug in IE 6 which causes the
|
|
|
|
// autocompletechange event to occur twice
|
|
|
|
ac[0].blur();
|
2011-02-24 09:22:51 +00:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("all events - contenteditable", function() {
|
2011-03-22 18:07:49 +00:00
|
|
|
expect(14);
|
2011-02-24 09:22:51 +00:00
|
|
|
var ac = $("#autocomplete-contenteditable").autocomplete({
|
2011-03-15 09:48:31 +00:00
|
|
|
autoFocus: false,
|
2011-02-24 09:22:51 +00:00
|
|
|
delay: 0,
|
|
|
|
source: data,
|
|
|
|
search: function(event) {
|
|
|
|
same(event.type, "autocompletesearch");
|
|
|
|
},
|
2011-03-22 18:07:49 +00:00
|
|
|
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 );
|
|
|
|
},
|
2011-02-24 09:22:51 +00:00
|
|
|
open: function(event) {
|
|
|
|
same(event.type, "autocompleteopen");
|
|
|
|
},
|
|
|
|
focus: function(event, ui) {
|
|
|
|
same(event.type, "autocompletefocus");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2011-02-24 09:22:51 +00:00
|
|
|
},
|
|
|
|
close: function(event) {
|
|
|
|
same(event.type, "autocompleteclose");
|
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
|
|
|
},
|
|
|
|
select: function(event, ui) {
|
|
|
|
same(event.type, "autocompleteselect");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2011-02-24 09:22:51 +00:00
|
|
|
},
|
|
|
|
change: function(event, ui) {
|
|
|
|
same(event.type, "autocompletechange");
|
2011-03-22 18:07:49 +00:00
|
|
|
same(ui.item, {label:"Java", value:"Java"});
|
2011-02-24 09:22:51 +00:00
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stop();
|
2011-03-22 18:07:49 +00:00
|
|
|
ac.focus().text("j").keydown();
|
2011-02-24 09:22:51 +00:00
|
|
|
setTimeout(function() {
|
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
2010-01-20 14:00:14 +00:00
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
|
2011-02-24 21:54:54 +00:00
|
|
|
// blurring through jQuery causes a bug in IE 6 which causes the
|
|
|
|
// autocompletechange event to occur twice
|
|
|
|
ac[0].blur();
|
2010-01-20 14:00:14 +00:00
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
2010-04-08 10:05:52 +00:00
|
|
|
test("change without selection", function() {
|
|
|
|
expect(2);
|
|
|
|
stop();
|
|
|
|
var ac = $("#autocomplete").autocomplete({
|
|
|
|
delay: 0,
|
|
|
|
source: data,
|
|
|
|
change: function(event, ui) {
|
|
|
|
same(event.type, "autocompletechange");
|
|
|
|
same(ui.item, null);
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
});
|
2010-04-13 10:04:05 +00:00
|
|
|
ac.triggerHandler("focus");
|
|
|
|
ac.val("ja").triggerHandler("blur");
|
2010-04-08 10:05:52 +00:00
|
|
|
});
|
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
same( ac.val(), "java" );
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
ok(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stop();
|
|
|
|
ac.val("ja").keydown();
|
|
|
|
setTimeout(function() {
|
2010-02-02 14:04:50 +00:00
|
|
|
same( $(".ui-menu:visible").length, 0 );
|
2010-01-20 14:00:14 +00:00
|
|
|
ac.val("java").keydown();
|
|
|
|
setTimeout(function() {
|
2010-02-02 14:04:50 +00:00
|
|
|
same( $(".ui-menu:visible").length, 1 );
|
2010-01-20 14:00:14 +00:00
|
|
|
same( $(".ui-menu .ui-menu-item").length, 2 );
|
|
|
|
start();
|
|
|
|
}, 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();
|
|
|
|
setTimeout(function() {
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
same( ac.val(), customVal );
|
|
|
|
start();
|
|
|
|
}, 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();
|
|
|
|
setTimeout(function() {
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.ENTER });
|
|
|
|
same( ac.val(), customVal );
|
|
|
|
start();
|
|
|
|
}, 50);
|
|
|
|
});
|
|
|
|
|
2011-05-11 11:19:46 +00:00
|
|
|
/* TODO previous fix broke more than it fixed, disabling this for now - messed up regular menu select event
|
2011-05-10 14:54:13 +00:00
|
|
|
test("blur without selection", function() {
|
|
|
|
expect(1);
|
|
|
|
var ac = $("#autocomplete").autocomplete({
|
|
|
|
delay: 0,
|
|
|
|
source: data
|
|
|
|
});
|
|
|
|
stop();
|
|
|
|
ac.val("j").keydown();
|
|
|
|
setTimeout(function() {
|
|
|
|
$( ".ui-menu-item" ).first().simulate("mouseover");
|
|
|
|
ac.simulate("keydown", { keyCode: $.ui.keyCode.TAB });
|
|
|
|
same( ac.val(), "j" );
|
|
|
|
start();
|
|
|
|
}, 50);
|
|
|
|
});
|
2011-05-11 11:19:46 +00:00
|
|
|
*/
|
2011-05-10 14:54:13 +00:00
|
|
|
|
2010-01-20 14:00:14 +00:00
|
|
|
})(jQuery);
|