aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohann-S <[email protected]>2018-11-25 17:20:55 +0100
committerXhmikosR <[email protected]>2018-11-25 18:20:55 +0200
commit32ab52ba2e9dc2549304fcef14dede7806384f34 (patch)
tree5a3fc3a76c04c68fb245d0e446c79792c4c79fc6 /js
parent72bd3f5930f7da9a58e5f90c58a681aedae1a2d0 (diff)
downloadbootstrap-32ab52ba2e9dc2549304fcef14dede7806384f34.tar.xz
bootstrap-32ab52ba2e9dc2549304fcef14dede7806384f34.zip
Add test to make sure we enforce focus on modal (#27723)
Diffstat (limited to 'js')
-rw-r--r--js/tests/unit/modal.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index 1156ce0c7..8e67d83a0 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -735,4 +735,45 @@ $(function () {
done()
}).bootstrapModal('show')
})
+
+ QUnit.test('should enforce focus', function (assert) {
+ assert.expect(4)
+ var done = assert.async()
+
+ var $modal = $([
+ '<div id="modal-test" data-show="false">',
+ ' <div class="modal-dialog">',
+ ' <div class="modal-content">',
+ ' <div class="modal-body" />',
+ ' </div>',
+ ' </div>',
+ '</div>'
+ ].join(''))
+ .bootstrapModal()
+ .appendTo('#qunit-fixture')
+
+ var modal = $modal.data('bs.modal')
+ var spy = sinon.spy(modal, '_enforceFocus')
+ var spyDocOff = sinon.spy($(document), 'off')
+ var spyDocOn = sinon.spy($(document), 'on')
+
+ $modal.one('shown.bs.modal', function () {
+ assert.ok(spy.called, '_enforceFocus called')
+ assert.ok(spyDocOff.withArgs('focusin.bs.modal'))
+ assert.ok(spyDocOn.withArgs('focusin.bs.modal'))
+
+ var spyFocus = sinon.spy(modal._element, 'focus')
+ var event = $.Event('focusin', {
+ target: $('#qunit-fixture')[0]
+ })
+
+ $(document).one('focusin', function () {
+ assert.ok(spyFocus.called)
+ done()
+ })
+
+ $(document).trigger(event)
+ })
+ .bootstrapModal('show')
+ })
})