From: Pierre-Denis Vanduynslager Date: Sat, 21 Jan 2017 04:02:19 +0000 (-0500) Subject: Add unit test for keyboard navigation X-Git-Tag: v4.0.0-beta~166^2~96^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a783a42554e4bd0de8ba26c89aeed8cc717c91c;p=thirdparty%2Fbootstrap.git Add unit test for keyboard navigation --- diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index fc418f5211..f5142d8b75 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -450,6 +450,40 @@ $(function () { $dropdown.trigger($.Event('keydown', { which: 40 })) $dropdown.trigger($.Event('keydown', { which: 40 })) + }) + + QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) { + assert.expect(4) + var done = assert.async() + var dropdownHTML = '
' + + '' + + '
' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { which: 40 })) + assert.ok($(document.activeElement)[0] === $('#item1')[0], 'item1 is focused') + + $(document.activeElement).trigger($.Event('keydown', { which: 40 })) + assert.ok($(document.activeElement)[0] === $('#item2')[0], 'item2 is focused') + + $(document.activeElement).trigger($.Event('keydown', { which: 38 })) + assert.ok($(document.activeElement)[0] === $('#item1')[0], 'item1 is focused') + done() + }) + $dropdown.trigger('click') assert.ok(!$(document.activeElement).is('.disabled'), '.disabled is not focused') })