info@54
|
1 |
$(function () {
|
info@54
|
2 |
|
info@54
|
3 |
module("dropdowns")
|
info@54
|
4 |
|
info@54
|
5 |
test("should provide no conflict", function () {
|
info@54
|
6 |
var dropdown = $.fn.dropdown.noConflict()
|
info@54
|
7 |
ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)')
|
info@54
|
8 |
$.fn.dropdown = dropdown
|
info@54
|
9 |
})
|
info@54
|
10 |
|
info@54
|
11 |
test("should be defined on jquery object", function () {
|
info@54
|
12 |
ok($(document.body).dropdown, 'dropdown method is defined')
|
info@54
|
13 |
})
|
info@54
|
14 |
|
info@54
|
15 |
test("should return element", function () {
|
info@54
|
16 |
var el = $("<div />")
|
info@54
|
17 |
ok(el.dropdown()[0] === el[0], 'same element returned')
|
info@54
|
18 |
})
|
info@54
|
19 |
|
info@54
|
20 |
test("should not open dropdown if target is disabled", function () {
|
info@54
|
21 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
22 |
+ '<li class="dropdown">'
|
info@54
|
23 |
+ '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>'
|
info@54
|
24 |
+ '<ul class="dropdown-menu">'
|
info@54
|
25 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
26 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
27 |
+ '<li class="divider"></li>'
|
info@54
|
28 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
29 |
+ '</ul>'
|
info@54
|
30 |
+ '</li>'
|
info@54
|
31 |
+ '</ul>'
|
info@54
|
32 |
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
|
info@54
|
33 |
|
info@54
|
34 |
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
info@54
|
35 |
})
|
info@54
|
36 |
|
info@54
|
37 |
test("should not open dropdown if target is disabled", function () {
|
info@54
|
38 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
39 |
+ '<li class="dropdown">'
|
info@54
|
40 |
+ '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>'
|
info@54
|
41 |
+ '<ul class="dropdown-menu">'
|
info@54
|
42 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
43 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
44 |
+ '<li class="divider"></li>'
|
info@54
|
45 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
46 |
+ '</ul>'
|
info@54
|
47 |
+ '</li>'
|
info@54
|
48 |
+ '</ul>'
|
info@54
|
49 |
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
|
info@54
|
50 |
|
info@54
|
51 |
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
info@54
|
52 |
})
|
info@54
|
53 |
|
info@54
|
54 |
test("should add class open to menu if clicked", function () {
|
info@54
|
55 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
56 |
+ '<li class="dropdown">'
|
info@54
|
57 |
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
info@54
|
58 |
+ '<ul class="dropdown-menu">'
|
info@54
|
59 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
60 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
61 |
+ '<li class="divider"></li>'
|
info@54
|
62 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
63 |
+ '</ul>'
|
info@54
|
64 |
+ '</li>'
|
info@54
|
65 |
+ '</ul>'
|
info@54
|
66 |
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
|
info@54
|
67 |
|
info@54
|
68 |
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
info@54
|
69 |
})
|
info@54
|
70 |
|
info@54
|
71 |
test("should test if element has a # before assuming it's a selector", function () {
|
info@54
|
72 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
73 |
+ '<li class="dropdown">'
|
info@54
|
74 |
+ '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
info@54
|
75 |
+ '<ul class="dropdown-menu">'
|
info@54
|
76 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
77 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
78 |
+ '<li class="divider"></li>'
|
info@54
|
79 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
80 |
+ '</ul>'
|
info@54
|
81 |
+ '</li>'
|
info@54
|
82 |
+ '</ul>'
|
info@54
|
83 |
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
|
info@54
|
84 |
|
info@54
|
85 |
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
info@54
|
86 |
})
|
info@54
|
87 |
|
info@54
|
88 |
|
info@54
|
89 |
test("should remove open class if body clicked", function () {
|
info@54
|
90 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
91 |
+ '<li class="dropdown">'
|
info@54
|
92 |
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
info@54
|
93 |
+ '<ul class="dropdown-menu">'
|
info@54
|
94 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
95 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
96 |
+ '<li class="divider"></li>'
|
info@54
|
97 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
98 |
+ '</ul>'
|
info@54
|
99 |
+ '</li>'
|
info@54
|
100 |
+ '</ul>'
|
info@54
|
101 |
, dropdown = $(dropdownHTML)
|
info@54
|
102 |
.appendTo('#qunit-fixture')
|
info@54
|
103 |
.find('[data-toggle="dropdown"]')
|
info@54
|
104 |
.dropdown()
|
info@54
|
105 |
.click()
|
info@54
|
106 |
|
info@54
|
107 |
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
info@54
|
108 |
$('body').click()
|
info@54
|
109 |
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
|
info@54
|
110 |
dropdown.remove()
|
info@54
|
111 |
})
|
info@54
|
112 |
|
info@54
|
113 |
test("should remove open class if body clicked, with multiple drop downs", function () {
|
info@54
|
114 |
var dropdownHTML =
|
info@54
|
115 |
'<ul class="nav">'
|
info@54
|
116 |
+ ' <li><a href="#menu1">Menu 1</a></li>'
|
info@54
|
117 |
+ ' <li class="dropdown" id="testmenu">'
|
info@54
|
118 |
+ ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>'
|
info@54
|
119 |
+ ' <ul class="dropdown-menu" role="menu">'
|
info@54
|
120 |
+ ' <li><a href="#sub1">Submenu 1</a></li>'
|
info@54
|
121 |
+ ' </ul>'
|
info@54
|
122 |
+ ' </li>'
|
info@54
|
123 |
+ '</ul>'
|
info@54
|
124 |
+ '<div class="btn-group">'
|
info@54
|
125 |
+ ' <button class="btn">Actions</button>'
|
info@54
|
126 |
+ ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>'
|
info@54
|
127 |
+ ' <ul class="dropdown-menu">'
|
info@54
|
128 |
+ ' <li><a href="#">Action 1</a></li>'
|
info@54
|
129 |
+ ' </ul>'
|
info@54
|
130 |
+ '</div>'
|
info@54
|
131 |
, dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
|
info@54
|
132 |
, first = dropdowns.first()
|
info@54
|
133 |
, last = dropdowns.last()
|
info@54
|
134 |
|
info@54
|
135 |
ok(dropdowns.length == 2, "Should be two dropdowns")
|
info@54
|
136 |
|
info@54
|
137 |
first.click()
|
info@54
|
138 |
ok(first.parents('.open').length == 1, 'open class added on click')
|
info@54
|
139 |
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
|
info@54
|
140 |
$('body').click()
|
info@54
|
141 |
ok($("#qunit-fixture .open").length === 0, 'open class removed')
|
info@54
|
142 |
|
info@54
|
143 |
last.click()
|
info@54
|
144 |
ok(last.parent('.open').length == 1, 'open class added on click')
|
info@54
|
145 |
ok($('#qunit-fixture .open').length == 1, 'only one object is open')
|
info@54
|
146 |
$('body').click()
|
info@54
|
147 |
ok($("#qunit-fixture .open").length === 0, 'open class removed')
|
info@54
|
148 |
|
info@54
|
149 |
$("#qunit-fixture").html("")
|
info@54
|
150 |
})
|
info@54
|
151 |
|
info@54
|
152 |
test("should fire show and hide event", function () {
|
info@54
|
153 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
154 |
+ '<li class="dropdown">'
|
info@54
|
155 |
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
info@54
|
156 |
+ '<ul class="dropdown-menu">'
|
info@54
|
157 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
158 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
159 |
+ '<li class="divider"></li>'
|
info@54
|
160 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
161 |
+ '</ul>'
|
info@54
|
162 |
+ '</li>'
|
info@54
|
163 |
+ '</ul>'
|
info@54
|
164 |
, dropdown = $(dropdownHTML)
|
info@54
|
165 |
.appendTo('#qunit-fixture')
|
info@54
|
166 |
.find('[data-toggle="dropdown"]')
|
info@54
|
167 |
.dropdown()
|
info@54
|
168 |
|
info@54
|
169 |
stop()
|
info@54
|
170 |
|
info@54
|
171 |
dropdown
|
info@54
|
172 |
.parent('.dropdown')
|
info@54
|
173 |
.bind('show.bs.dropdown', function () {
|
info@54
|
174 |
ok(true, 'show was called')
|
info@54
|
175 |
})
|
info@54
|
176 |
.bind('hide.bs.dropdown', function () {
|
info@54
|
177 |
ok(true, 'hide was called')
|
info@54
|
178 |
start()
|
info@54
|
179 |
})
|
info@54
|
180 |
|
info@54
|
181 |
dropdown.click()
|
info@54
|
182 |
$(document.body).click()
|
info@54
|
183 |
})
|
info@54
|
184 |
|
info@54
|
185 |
|
info@54
|
186 |
test("should fire shown and hiden event", function () {
|
info@54
|
187 |
var dropdownHTML = '<ul class="tabs">'
|
info@54
|
188 |
+ '<li class="dropdown">'
|
info@54
|
189 |
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
info@54
|
190 |
+ '<ul class="dropdown-menu">'
|
info@54
|
191 |
+ '<li><a href="#">Secondary link</a></li>'
|
info@54
|
192 |
+ '<li><a href="#">Something else here</a></li>'
|
info@54
|
193 |
+ '<li class="divider"></li>'
|
info@54
|
194 |
+ '<li><a href="#">Another link</a></li>'
|
info@54
|
195 |
+ '</ul>'
|
info@54
|
196 |
+ '</li>'
|
info@54
|
197 |
+ '</ul>'
|
info@54
|
198 |
, dropdown = $(dropdownHTML)
|
info@54
|
199 |
.appendTo('#qunit-fixture')
|
info@54
|
200 |
.find('[data-toggle="dropdown"]')
|
info@54
|
201 |
.dropdown()
|
info@54
|
202 |
|
info@54
|
203 |
stop()
|
info@54
|
204 |
|
info@54
|
205 |
dropdown
|
info@54
|
206 |
.parent('.dropdown')
|
info@54
|
207 |
.bind('shown.bs.dropdown', function () {
|
info@54
|
208 |
ok(true, 'show was called')
|
info@54
|
209 |
})
|
info@54
|
210 |
.bind('hidden.bs.dropdown', function () {
|
info@54
|
211 |
ok(true, 'hide was called')
|
info@54
|
212 |
start()
|
info@54
|
213 |
})
|
info@54
|
214 |
|
info@54
|
215 |
dropdown.click()
|
info@54
|
216 |
$(document.body).click()
|
info@54
|
217 |
})
|
info@54
|
218 |
|
info@54
|
219 |
})
|