123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- $(function () {
- module("bootstrap-dropdowns")
- test("should provide no conflict", function () {
- var dropdown = $.fn.dropdown.noConflict()
- ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)')
- $.fn.dropdown = dropdown
- })
- test("should be defined on jquery object", function () {
- ok($(document.body).dropdown, 'dropdown method is defined')
- })
- test("should return element", function () {
- var el = $("<div />")
- ok(el.dropdown()[0] === el[0], 'same element returned')
- })
- test("should not open dropdown if target is disabled", function () {
- var dropdownHTML = '<ul class="tabs">'
- + '<li class="dropdown">'
- + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>'
- + '<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>'
- , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- })
- test("should not open dropdown if target is disabled", function () {
- var dropdownHTML = '<ul class="tabs">'
- + '<li class="dropdown">'
- + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>'
- + '<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>'
- , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- })
- test("should add class open to menu if clicked", function () {
- var dropdownHTML = '<ul class="tabs">'
- + '<li class="dropdown">'
- + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
- + '<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>'
- , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- })
- test("should test if element has a # before assuming it's a selector", function () {
- var dropdownHTML = '<ul class="tabs">'
- + '<li class="dropdown">'
- + '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
- + '<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>'
- , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- })
- test("should remove open class if body clicked", function () {
- var dropdownHTML = '<ul class="tabs">'
- + '<li class="dropdown">'
- + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
- + '<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>'
- , dropdown = $(dropdownHTML)
- .appendTo('#qunit-fixture')
- .find('[data-toggle="dropdown"]')
- .dropdown()
- .click()
- ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
- $('body').click()
- ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
- 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("")
- })
- })
|