Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to make sure we enforce focus on modal #27723

Merged
merged 1 commit into from
Nov 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})