2011-09-10 07:47:49 +02:00
|
|
|
$(function () {
|
2014-03-17 08:12:55 +01:00
|
|
|
'use strict';
|
2011-09-10 07:47:49 +02:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.module('dropdowns plugin')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should be defined on jquery object', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($(document.body).dropdown, 'dropdown method is defined')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.module('dropdowns', {
|
2015-02-26 08:20:42 +01:00
|
|
|
beforeEach: function () {
|
2014-04-22 07:03:33 +02:00
|
|
|
// 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()
|
|
|
|
},
|
2015-02-26 08:20:42 +01:00
|
|
|
afterEach: function () {
|
2014-04-22 07:03:33 +02:00
|
|
|
$.fn.dropdown = $.fn.bootstrapDropdown
|
|
|
|
delete $.fn.bootstrapDropdown
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should provide no conflict', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($.fn.dropdown, undefined, 'dropdown was set back to undefined (org value)')
|
2014-04-22 07:03:33 +02:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should return jquery collection containing the element', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2014-06-18 21:34:12 +02:00
|
|
|
var $el = $('<div/>')
|
|
|
|
var $dropdown = $el.bootstrapDropdown()
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($dropdown instanceof $, 'returns jquery collection')
|
|
|
|
assert.strictEqual($dropdown[0], $el[0], 'collection contains element')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should not open dropdown if target is disabled via attribute', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2015-03-06 13:34:28 +01:00
|
|
|
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 20:55:08 +01:00
|
|
|
QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-02-24 20:55:08 +01:00
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
|
|
|
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2015-02-25 02:53:39 +01:00
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
2015-03-06 13:34:28 +01:00
|
|
|
.trigger('click')
|
2015-02-24 20:55:08 +01:00
|
|
|
|
|
|
|
assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on click')
|
|
|
|
})
|
|
|
|
|
|
|
|
QUnit.test('should set aria-expanded="false" on target when dropdown menu is hidden', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-02-25 02:53:39 +01:00
|
|
|
var done = assert.async()
|
2015-02-24 20:55:08 +01:00
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
|
|
|
+ '<a href="#" class="dropdown-toggle" aria-expanded="false" 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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
|
|
|
|
|
|
|
$dropdown
|
|
|
|
.parent('.dropdown')
|
|
|
|
.on('hidden.bs.dropdown', function () {
|
|
|
|
assert.strictEqual($dropdown.attr('aria-expanded'), 'false', 'aria-expanded is set to string "false" on hide')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$dropdown.trigger('click')
|
|
|
|
$(document.body).trigger('click')
|
2015-02-24 20:55:08 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should not open dropdown if target is disabled via class', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2015-03-06 13:34:28 +01:00
|
|
|
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should add class open to menu if clicked', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2015-03-06 13:34:28 +01:00
|
|
|
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should test if element has a # before assuming it\'s a selector', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2015-03-06 13:34:28 +01:00
|
|
|
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should remove "open" class if body is clicked', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2014-06-18 21:34:12 +02:00
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
2015-03-06 13:34:28 +01:00
|
|
|
.trigger('click')
|
2014-06-18 21:34:12 +02:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
|
2015-03-06 13:34:28 +01:00
|
|
|
$(document.body).trigger('click')
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should remove "open" class if body is clicked, with multiple dropdowns', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(7)
|
2014-07-06 11:56:12 +02:00
|
|
|
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 <span class="caret"/></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"/></button>'
|
|
|
|
+ '<ul class="dropdown-menu">'
|
|
|
|
+ '<li><a href="#">Action 1</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</div>'
|
2014-06-18 21:34:12 +02:00
|
|
|
var $dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
|
|
|
|
var $first = $dropdowns.first()
|
|
|
|
var $last = $dropdowns.last()
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($dropdowns.length, 2, 'two dropdowns')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$first.trigger('click')
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($first.parents('.open').length, 1, '"open" class added on click')
|
|
|
|
assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open')
|
2015-03-06 13:34:28 +01:00
|
|
|
$(document.body).trigger('click')
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed')
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$last.trigger('click')
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($last.parent('.open').length, 1, '"open" class added on click')
|
|
|
|
assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open')
|
2015-03-06 13:34:28 +01:00
|
|
|
$(document.body).trigger('click')
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should fire show and hide event', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2014-06-18 21:34:12 +02:00
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2014-06-18 21:34:12 +02:00
|
|
|
$dropdown
|
2014-02-13 08:55:12 +01:00
|
|
|
.parent('.dropdown')
|
2014-04-04 03:13:16 +02:00
|
|
|
.on('show.bs.dropdown', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'show was fired')
|
2012-04-15 06:44:57 +02:00
|
|
|
})
|
2014-04-04 03:13:16 +02:00
|
|
|
.on('hide.bs.dropdown', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'hide was fired')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2011-09-10 07:47:49 +02:00
|
|
|
})
|
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$dropdown.trigger('click')
|
|
|
|
$(document.body).trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should fire shown and hidden event', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2014-07-06 11:56:12 +02:00
|
|
|
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><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
2014-06-18 21:34:12 +02:00
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2014-06-18 21:34:12 +02:00
|
|
|
$dropdown
|
2014-02-13 08:55:12 +01:00
|
|
|
.parent('.dropdown')
|
2014-04-04 03:13:16 +02:00
|
|
|
.on('shown.bs.dropdown', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'shown was fired')
|
2012-08-28 06:27:01 +02:00
|
|
|
})
|
2014-04-04 03:13:16 +02:00
|
|
|
.on('hidden.bs.dropdown', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'hidden was fired')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2012-09-27 10:31:40 +02:00
|
|
|
})
|
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$dropdown.trigger('click')
|
|
|
|
$(document.body).trigger('click')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2013-05-25 08:15:04 +02:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(3)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-11-12 01:18:06 +01:00
|
|
|
|
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
|
|
|
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
|
|
|
+ '<ul class="dropdown-menu" role="menu">'
|
|
|
|
+ '<li><a href="#">Secondary link</a></li>'
|
|
|
|
+ '<li><a href="#">Something else here</a></li>'
|
|
|
|
+ '<li class="divider"/>'
|
|
|
|
+ '<li><a href="#">Another link</a></li>'
|
|
|
|
+ '<li><input type="text" id="input"></li>'
|
|
|
|
+ '<li><textarea id="textarea"/></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
|
|
|
|
|
|
|
var $input = $('#input')
|
|
|
|
var $textarea = $('#textarea')
|
|
|
|
|
|
|
|
$dropdown
|
|
|
|
.parent('.dropdown')
|
|
|
|
.on('shown.bs.dropdown', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'shown was fired')
|
2014-11-12 01:18:06 +01:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$input.trigger('focus').trigger($.Event('keydown', { which: 38 }))
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($(document.activeElement).is($input), 'input still focused')
|
2014-11-12 01:18:06 +01:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$textarea.trigger('focus').trigger($.Event('keydown', { which: 38 }))
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($(document.activeElement).is($textarea), 'textarea still focused')
|
2014-11-12 01:18:06 +01:00
|
|
|
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2014-11-12 01:18:06 +01:00
|
|
|
})
|
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$dropdown.trigger('click')
|
2014-11-12 01:18:06 +01:00
|
|
|
})
|
|
|
|
|
2015-01-08 10:03:09 +01:00
|
|
|
QUnit.test('should skip disabled element when using keyboard navigation', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-01-08 10:03:09 +01:00
|
|
|
var dropdownHTML = '<ul class="tabs">'
|
|
|
|
+ '<li class="dropdown">'
|
|
|
|
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
|
|
|
|
+ '<ul class="dropdown-menu" role="menu">'
|
|
|
|
+ '<li class="disabled"><a href="#">Disabled link</a></li>'
|
|
|
|
+ '<li><a href="#">Another link</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
2015-03-06 13:34:28 +01:00
|
|
|
.trigger('click')
|
2015-01-08 10:03:09 +01:00
|
|
|
|
|
|
|
$dropdown.trigger($.Event('keydown', { which: 40 }))
|
|
|
|
$dropdown.trigger($.Event('keydown', { which: 40 }))
|
|
|
|
|
|
|
|
assert.ok(!$(document.activeElement).parent().is('.disabled'), '.disabled is not focused')
|
|
|
|
})
|
2015-03-16 14:33:42 +01:00
|
|
|
|
|
|
|
QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) {
|
|
|
|
assert.expect(1)
|
|
|
|
var dropdownHTML = '<div class="btn-group">'
|
|
|
|
+ '<button type="button" data-toggle="dropdown">Dropdown</button>'
|
|
|
|
+ '<ul class="dropdown-menu" role="menu">'
|
|
|
|
+ '<li><input id="textField" type="text" /></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</div>'
|
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
|
|
|
.trigger('click')
|
|
|
|
|
|
|
|
$('#textField').trigger('click')
|
|
|
|
|
|
|
|
assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open')
|
|
|
|
})
|
|
|
|
|
|
|
|
QUnit.test('should not close the dropdown if the user clicks on a textarea', function (assert) {
|
|
|
|
assert.expect(1)
|
|
|
|
var dropdownHTML = '<div class="btn-group">'
|
|
|
|
+ '<button type="button" data-toggle="dropdown">Dropdown</button>'
|
|
|
|
+ '<ul class="dropdown-menu" role="menu">'
|
|
|
|
+ '<li><textarea id="textArea"></textarea></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '</div>'
|
|
|
|
var $dropdown = $(dropdownHTML)
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
.find('[data-toggle="dropdown"]')
|
|
|
|
.bootstrapDropdown()
|
|
|
|
.trigger('click')
|
|
|
|
|
|
|
|
$('#textArea').trigger('click')
|
|
|
|
|
|
|
|
assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open')
|
|
|
|
})
|
2013-04-23 09:34:27 +02:00
|
|
|
})
|