5 test("should provide no conflict", function () {
6 var dropdown = $.fn.dropdown.noConflict()
7 ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)')
8 $.fn.dropdown = dropdown
11 test("should be defined on jquery object", function () {
12 ok($(document.body).dropdown, 'dropdown method is defined')
15 test("should return element", function () {
17 ok(el.dropdown()[0] === el[0], 'same element returned')
20 test("should not open dropdown if target is disabled", function () {
21 var dropdownHTML = '<ul class="tabs">'
22 + '<li class="dropdown">'
23 + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>'
24 + '<ul class="dropdown-menu">'
25 + '<li><a href="#">Secondary link</a></li>'
26 + '<li><a href="#">Something else here</a></li>'
27 + '<li class="divider"></li>'
28 + '<li><a href="#">Another link</a></li>'
32 , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
34 ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
37 test("should not open dropdown if target is disabled", function () {
38 var dropdownHTML = '<ul class="tabs">'
39 + '<li class="dropdown">'
40 + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>'
41 + '<ul class="dropdown-menu">'
42 + '<li><a href="#">Secondary link</a></li>'
43 + '<li><a href="#">Something else here</a></li>'
44 + '<li class="divider"></li>'
45 + '<li><a href="#">Another link</a></li>'
49 , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
51 ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
54 test("should add class open to menu if clicked", function () {
55 var dropdownHTML = '<ul class="tabs">'
56 + '<li class="dropdown">'
57 + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
58 + '<ul class="dropdown-menu">'
59 + '<li><a href="#">Secondary link</a></li>'
60 + '<li><a href="#">Something else here</a></li>'
61 + '<li class="divider"></li>'
62 + '<li><a href="#">Another link</a></li>'
66 , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
68 ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
71 test("should test if element has a # before assuming it's a selector", function () {
72 var dropdownHTML = '<ul class="tabs">'
73 + '<li class="dropdown">'
74 + '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
75 + '<ul class="dropdown-menu">'
76 + '<li><a href="#">Secondary link</a></li>'
77 + '<li><a href="#">Something else here</a></li>'
78 + '<li class="divider"></li>'
79 + '<li><a href="#">Another link</a></li>'
83 , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
85 ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
89 test("should remove open class if body clicked", function () {
90 var dropdownHTML = '<ul class="tabs">'
91 + '<li class="dropdown">'
92 + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
93 + '<ul class="dropdown-menu">'
94 + '<li><a href="#">Secondary link</a></li>'
95 + '<li><a href="#">Something else here</a></li>'
96 + '<li class="divider"></li>'
97 + '<li><a href="#">Another link</a></li>'
101 , dropdown = $(dropdownHTML)
102 .appendTo('#qunit-fixture')
103 .find('[data-toggle="dropdown"]')
107 ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
109 ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
113 test("should remove open class if body clicked, with multiple drop downs", function () {
116 + ' <li><a href="#menu1">Menu 1</a></li>'
117 + ' <li class="dropdown" id="testmenu">'
118 + ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
119 + ' <ul class="dropdown-menu" role="menu">'
120 + ' <li><a href="#sub1">Submenu 1</a></li>'
124 + '<div class="btn-group">'
125 + ' <button class="btn">Actions</button>'
126 + ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
127 + ' <ul class="dropdown-menu">'
128 + ' <li><a href="#">Action 1</a></li>'
131 , dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
132 , first = dropdowns.first()
133 , last = dropdowns.last()
135 ok(dropdowns.length == 2, "Should be two dropdowns")
138 ok(first.parents('.open').length == 1, 'open class added on click')
139 ok($('#qunit-fixture .open').length == 1, 'only one object is open')
141 ok($("#qunit-fixture .open").length === 0, 'open class removed')
144 ok(last.parent('.open').length == 1, 'open class added on click')
145 ok($('#qunit-fixture .open').length == 1, 'only one object is open')
147 ok($("#qunit-fixture .open").length === 0, 'open class removed')
149 $("#qunit-fixture").html("")
152 test("should fire show and hide event", function () {
153 var dropdownHTML = '<ul class="tabs">'
154 + '<li class="dropdown">'
155 + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
156 + '<ul class="dropdown-menu">'
157 + '<li><a href="#">Secondary link</a></li>'
158 + '<li><a href="#">Something else here</a></li>'
159 + '<li class="divider"></li>'
160 + '<li><a href="#">Another link</a></li>'
164 , dropdown = $(dropdownHTML)
165 .appendTo('#qunit-fixture')
166 .find('[data-toggle="dropdown"]')
173 .bind('show.bs.dropdown', function () {
174 ok(true, 'show was called')
176 .bind('hide.bs.dropdown', function () {
177 ok(true, 'hide was called')
182 $(document.body).click()
186 test("should fire shown and hiden event", function () {
187 var dropdownHTML = '<ul class="tabs">'
188 + '<li class="dropdown">'
189 + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
190 + '<ul class="dropdown-menu">'
191 + '<li><a href="#">Secondary link</a></li>'
192 + '<li><a href="#">Something else here</a></li>'
193 + '<li class="divider"></li>'
194 + '<li><a href="#">Another link</a></li>'
198 , dropdown = $(dropdownHTML)
199 .appendTo('#qunit-fixture')
200 .find('[data-toggle="dropdown"]')
207 .bind('shown.bs.dropdown', function () {
208 ok(true, 'show was called')
210 .bind('hidden.bs.dropdown', function () {
211 ok(true, 'hide was called')
216 $(document.body).click()