aboutsummaryrefslogtreecommitdiff
path: root/js/tests
diff options
context:
space:
mode:
authorJacob Thornton <[email protected]>2012-06-02 21:57:18 -0700
committerJacob Thornton <[email protected]>2012-06-02 21:57:18 -0700
commit4a276b1620f84da7343635731f6b3dbfa301d381 (patch)
tree8bb846859d4e4335cd52d5b6fc7eb154c2d9a643 /js/tests
parent91a7274a43836484cdf27e34c45856e4b715f778 (diff)
parentaf14f6db5dddd15556b2c932e29ea1fc7a811594 (diff)
downloadbootstrap-4a276b1620f84da7343635731f6b3dbfa301d381.tar.xz
bootstrap-4a276b1620f84da7343635731f6b3dbfa301d381.zip
Merge pull request #3682 from mlmorg/2.1.0-wip
Alter typeahead to accept synchronous/asynchronous data source
Diffstat (limited to 'js/tests')
-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 4e2428d6a..25d4cafd8 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+']