aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit/bootstrap-dropdown.js
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2012-10-29 22:01:58 -0700
committerMark Otto <[email protected]>2012-10-29 22:01:58 -0700
commitb5af762ef59e1fa97f4386f5feadb67aa5183fef (patch)
tree3bcd0841e6938379e8c8ae7259ee16f27a49ea41 /js/tests/unit/bootstrap-dropdown.js
parent7426ced0fb288a9e86f18da1849ad74f652d219a (diff)
parent68cfedb34af198f178128f8c9bc8ea164e44304a (diff)
downloadbootstrap-2.2.0.tar.xz
bootstrap-2.2.0.zip
Merge branch '2.1.2-wip'v2.2.0
Conflicts: js/bootstrap-dropdown.js
Diffstat (limited to 'js/tests/unit/bootstrap-dropdown.js')
-rw-r--r--js/tests/unit/bootstrap-dropdown.js42
1 files changed, 41 insertions, 1 deletions
diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js
index 3a617692b..3788209ec 100644
--- a/js/tests/unit/bootstrap-dropdown.js
+++ b/js/tests/unit/bootstrap-dropdown.js
@@ -7,7 +7,8 @@ $(function () {
})
test("should return element", function () {
- ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
+ var el = $("<div />")
+ ok(el.dropdown()[0] === el[0], 'same element returned')
})
test("should not open dropdown if target is disabled", function () {
@@ -102,4 +103,43 @@ $(function () {
dropdown.remove()
})
+ test("should remove open class if body clicked, with multiple drop downs", function () {
+ var dropdownHTML =
+ '<ul class="nav">'
+ + ' <li><a href="#menu1">Menu 1</a></li>'
+ + ' <li class="dropdown" id="testmenu">'
+ + ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
+ + ' <ul class="dropdown-menu" role="menu">'
+ + ' <li><a href="#sub1">Submenu 1</a></li>'
+ + ' </ul>'
+ + ' </li>'
+ + '</ul>'
+ + '<div class="btn-group">'
+ + ' <button class="btn">Actions</button>'
+ + ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
+ + ' <ul class="dropdown-menu">'
+ + ' <li><a href="#">Action 1</a></li>'
+ + ' </ul>'
+ + '</div>'
+ , dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
+ , first = dropdowns.first()
+ , last = dropdowns.last()
+
+ ok(dropdowns.length == 2, "Should be two dropdowns")
+
+ first.click()
+ ok(first.parents('.open').length == 1, 'open class added on click')
+ ok($('#qunit-fixture .open').length == 1, 'only one object is open')
+ $('body').click()
+ ok($("#qunit-fixture .open").length === 0, 'open class removed')
+
+ last.click()
+ ok(last.parent('.open').length == 1, 'open class added on click')
+ ok($('#qunit-fixture .open').length == 1, 'only one object is open')
+ $('body').click()
+ ok($("#qunit-fixture .open").length === 0, 'open class removed')
+
+ $("#qunit-fixture").html("")
+ })
+
}) \ No newline at end of file