0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-20 17:54:23 +01:00

Add unit test of aria-expanded to dropdown suite

Redo of #15876
This commit is contained in:
Kevin Kirsche 2015-02-24 14:55:08 -05:00 committed by Chris Rebert
parent ecd469ec16
commit 696fc2e53c

View File

@ -46,6 +46,53 @@ $(function () {
assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
})
QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) {
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>'
var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click()
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) {
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()
var done = assert.async()
$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()
})
$dropdown.click()
$(document.body).click()
})
QUnit.test('should not open dropdown if target is disabled via class', function (assert) {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'