Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Morgan <mlmorg@gmail.com>2012-04-26 22:09:20 +0400
committerMatt Morgan <mlmorg@gmail.com>2012-04-26 22:09:20 +0400
commitbf9d8fcc070fa826c342282e102fe00e1af76d10 (patch)
tree4e436dc3a31c9aa231a156a09953ae08b2a3ddc6 /js/tests/unit/bootstrap-typeahead.js
parentb261f9781bbf31f499cb55c49451dc0c0ad43062 (diff)
Alter typeahead to accept synchronous/asynchronous data source via function/callback
Diffstat (limited to 'js/tests/unit/bootstrap-typeahead.js')
-rw-r--r--js/tests/unit/bootstrap-typeahead.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js
index 4e2428d6a4..25d4cafd8e 100644
--- a/js/tests/unit/bootstrap-typeahead.js
+++ b/js/tests/unit/bootstrap-typeahead.js
@@ -52,6 +52,42 @@ $(function () {
typeahead.$menu.remove()
})
+ test("should accept data source via synchronous function", function () {
+ var $input = $('<input />').typeahead({
+ source: function () {
+ return ['aa', 'ab', 'ac']
+ }
+ })
+ , typeahead = $input.data('typeahead')
+
+ $input.val('a')
+ typeahead.lookup()
+
+ ok(typeahead.$menu.is(":visible"), 'typeahead is visible')
+ equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
+ equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
+
+ typeahead.$menu.remove()
+ })
+
+ test("should accept data source via asynchronous function", function () {
+ var $input = $('<input />').typeahead({
+ source: function (query, process) {
+ process(['aa', 'ab', 'ac'])
+ }
+ })
+ , typeahead = $input.data('typeahead')
+
+ $input.val('a')
+ typeahead.lookup()
+
+ ok(typeahead.$menu.is(":visible"), 'typeahead is visible')
+ equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
+ equals(typeahead.$menu.find('.active').length, 1, 'one item is active')
+
+ typeahead.$menu.remove()
+ })
+
test("should not explode when regex chars are entered", function () {
var $input = $('<input />').typeahead({
source: ['aa', 'ab', 'ac', 'mdo*', 'fat+']