From e9a648cd39dc6b5e0f126b7272adeac816ece758 Mon Sep 17 00:00:00 2001 From: Erlend Halvorsen Date: Thu, 27 Sep 2012 10:31:40 +0200 Subject: Fixed bug in dropdown toggle where menu would only clear on the first drop down --- js/tests/unit/bootstrap-dropdown.js | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'js/tests') 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 = $("
") + 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 = + '' + + '
' + + ' ' + + ' ' + + ' ' + + '
' + , 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 -- cgit v1.2.3