$(function () {
'use strict';
module('dropdowns plugin')
test('should be defined on jquery object', function () {
ok($(document.body).dropdown, 'dropdown method is defined')
})
module('dropdowns', {
setup: function () {
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
$.fn.bootstrapDropdown = $.fn.dropdown.noConflict()
},
teardown: function () {
$.fn.dropdown = $.fn.bootstrapDropdown
delete $.fn.bootstrapDropdown
}
})
test('should provide no conflict', function () {
ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)')
})
test('should return element', function () {
var el = $('
')
ok(el.bootstrapDropdown()[0] === el[0], 'same element returned')
})
test('should not open dropdown if target is disabled', function () {
var dropdownHTML = '
'
var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test('should not open dropdown if target is disabled', function () {
var dropdownHTML = '
'
var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test('should add class open to menu if clicked', function () {
var dropdownHTML = '
'
var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().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 = '
'
var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test('should remove open class if body clicked', function () {
var dropdownHTML = '
'
var dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown()
.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 = '
'
var dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
var first = dropdowns.first()
var 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('')
})
test('should fire show and hide event', function () {
var dropdownHTML = '