2011-09-10 07:47:49 +02:00
|
|
|
$(function () {
|
|
|
|
|
|
|
|
module("bootstrap-dropdowns")
|
|
|
|
|
|
|
|
test("should be defined on jquery object", function () {
|
|
|
|
ok($(document.body).dropdown, 'dropdown method is defined')
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should return element", function () {
|
|
|
|
ok($(document.body).dropdown()[0] == document.body, 'document.body returned')
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should add class open to menu if clicked", function () {
|
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
2011-12-21 03:02:47 +01:00
|
|
|
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
2011-09-10 07:47:49 +02:00
|
|
|
+ '<ul class="dropdown-menu">'
|
|
|
|
+ '<li><a href="#">Secondary link</a></li>'
|
|
|
|
+ '<li><a href="#">Something else here</a></li>'
|
|
|
|
+ '<li class="divider"></li>'
|
|
|
|
+ '<li><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2011-12-21 03:02:47 +01:00
|
|
|
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
|
2011-09-10 07:47:49 +02:00
|
|
|
|
2011-12-21 03:02:47 +01:00
|
|
|
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
2011-09-10 07:47:49 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
test("should remove open class if body clicked", function () {
|
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
2011-12-21 03:02:47 +01:00
|
|
|
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
2011-09-10 07:47:49 +02:00
|
|
|
+ '<ul class="dropdown-menu">'
|
|
|
|
+ '<li><a href="#">Secondary link</a></li>'
|
|
|
|
+ '<li><a href="#">Something else here</a></li>'
|
|
|
|
+ '<li class="divider"></li>'
|
|
|
|
+ '<li><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2011-12-21 03:02:47 +01:00
|
|
|
, dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.dropdown()
|
|
|
|
.click()
|
|
|
|
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
|
2011-09-10 07:47:49 +02:00
|
|
|
$('body').click()
|
2011-12-21 03:02:47 +01:00
|
|
|
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
|
2011-09-10 07:47:49 +02:00
|
|
|
dropdown.remove()
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|