2011-09-10 01:47:49 -04:00
|
|
|
$(function () {
|
2014-03-17 03:12:55 -04:00
|
|
|
'use strict';
|
2011-09-10 01:47:49 -04:00
|
|
|
|
2014-04-22 01:03:33 -04:00
|
|
|
module('modal plugin')
|
2014-02-13 02:55:12 -05:00
|
|
|
|
|
|
|
test('should be defined on jquery object', function () {
|
|
|
|
var div = $('<div id="modal-test"></div>')
|
|
|
|
ok(div.modal, 'modal method is defined')
|
|
|
|
})
|
|
|
|
|
2014-04-22 01:03:33 -04:00
|
|
|
module('modal', {
|
2014-03-17 03:12:55 -04:00
|
|
|
setup: function () {
|
2014-04-22 01:03:33 -04:00
|
|
|
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
|
|
|
|
$.fn.bootstrapModal = $.fn.modal.noConflict()
|
|
|
|
},
|
2014-03-17 03:12:55 -04:00
|
|
|
teardown: function () {
|
2014-04-22 01:03:33 -04:00
|
|
|
$.fn.modal = $.fn.bootstrapModal
|
|
|
|
delete $.fn.bootstrapModal
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should provide no conflict', function () {
|
2014-05-19 03:47:06 -04:00
|
|
|
ok(!$.fn.modal, 'modal was set back to undefined (orig value)')
|
2014-04-22 01:03:33 -04:00
|
|
|
})
|
|
|
|
|
2014-02-13 02:55:12 -05:00
|
|
|
test('should return element', function () {
|
|
|
|
var div = $('<div id="modal-test"></div>')
|
2014-04-22 01:03:33 -04:00
|
|
|
ok(div.bootstrapModal() == div, 'document.body returned')
|
2014-02-13 02:55:12 -05:00
|
|
|
$('#modal-test').remove()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should expose defaults var for settings', function () {
|
2014-04-22 01:03:33 -04:00
|
|
|
ok($.fn.bootstrapModal.Constructor.DEFAULTS, 'default object exposed')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should insert into dom when show method is called', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
$('<div id="modal-test"></div>')
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok($('#modal-test').length, 'modal inserted into dom')
|
|
|
|
$(this).remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should fire show event', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
$('<div id="modal-test"></div>')
|
|
|
|
.on('show.bs.modal', function () {
|
|
|
|
ok(true, 'show was called')
|
|
|
|
})
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
$(this).remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should not fire shown when default prevented', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
$('<div id="modal-test"></div>')
|
|
|
|
.on('show.bs.modal', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
ok(true, 'show was called')
|
|
|
|
start()
|
|
|
|
})
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok(false, 'shown was called')
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should hide modal when hide is called', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
|
|
|
|
$('<div id="modal-test"></div>')
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok($('#modal-test').is(':visible'), 'modal visible')
|
|
|
|
ok($('#modal-test').length, 'modal inserted into dom')
|
2014-04-22 01:03:33 -04:00
|
|
|
$(this).bootstrapModal('hide')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
$('#modal-test').remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should toggle when toggle is called', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var div = $('<div id="modal-test"></div>')
|
|
|
|
div
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok($('#modal-test').is(':visible'), 'modal visible')
|
|
|
|
ok($('#modal-test').length, 'modal inserted into dom')
|
2014-04-22 01:03:33 -04:00
|
|
|
div.bootstrapModal('toggle')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
div.remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('toggle')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
2014-04-19 20:45:56 -04:00
|
|
|
test('should remove from dom when click [data-dismiss="modal"]', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var div = $('<div id="modal-test"><span class="close" data-dismiss="modal"></span></div>')
|
|
|
|
div
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok($('#modal-test').is(':visible'), 'modal visible')
|
|
|
|
ok($('#modal-test').length, 'modal inserted into dom')
|
|
|
|
div.find('.close').click()
|
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
div.remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('toggle')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should allow modal close with "backdrop:false"', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var div = $('<div>', { id: 'modal-test', 'data-backdrop': false })
|
|
|
|
div
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
ok($('#modal-test').is(':visible'), 'modal visible')
|
2014-04-22 01:03:33 -04:00
|
|
|
div.bootstrapModal('hide')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
div.remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should close modal when clicking outside of modal-content', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var div = $('<div id="modal-test"><div class="contents"></div></div>')
|
|
|
|
div
|
2014-04-03 21:13:16 -04:00
|
|
|
.on('shown.bs.modal', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
ok($('#modal-test').length, 'modal insterted into dom')
|
|
|
|
$('.contents').click()
|
|
|
|
ok($('#modal-test').is(':visible'), 'modal visible')
|
|
|
|
$('#modal-test').click()
|
|
|
|
})
|
2014-04-03 21:13:16 -04:00
|
|
|
.on('hidden.bs.modal', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
div.remove()
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should trigger hide event once when clicking outside of modal-content', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
|
|
|
|
var triggered
|
|
|
|
var div = $('<div id="modal-test"><div class="contents"></div></div>')
|
|
|
|
|
|
|
|
div
|
2014-04-03 21:13:16 -04:00
|
|
|
.on('shown.bs.modal', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
triggered = 0
|
|
|
|
$('#modal-test').click()
|
|
|
|
})
|
2014-04-03 21:13:16 -04:00
|
|
|
.on('hide.bs.modal', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
triggered += 1
|
|
|
|
ok(triggered === 1, 'modal hide triggered once')
|
|
|
|
start()
|
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
|
|
|
|
2014-04-19 20:45:56 -04:00
|
|
|
test('should close reopened modal with [data-dismiss="modal"] click', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var div = $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>')
|
|
|
|
div
|
2014-04-03 21:13:16 -04:00
|
|
|
.on('shown.bs.modal', function () {
|
2014-02-13 02:55:12 -05:00
|
|
|
$('#close').click()
|
|
|
|
ok(!$('#modal-test').is(':visible'), 'modal hidden')
|
|
|
|
})
|
|
|
|
.one('hidden.bs.modal', function () {
|
|
|
|
div.one('hidden.bs.modal', function () {
|
2013-08-10 16:35:20 -04:00
|
|
|
start()
|
2014-04-22 01:03:33 -04:00
|
|
|
}).bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
})
|
2014-04-22 01:03:33 -04:00
|
|
|
.bootstrapModal('show')
|
2014-02-13 02:55:12 -05:00
|
|
|
|
|
|
|
div.remove()
|
|
|
|
})
|
2014-05-19 04:25:52 -04:00
|
|
|
|
|
|
|
test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var toggleBtn = $('<button data-toggle="modal" data-target="#modal-test">Launch modal</button>').appendTo('#qunit-fixture')
|
|
|
|
var div = $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>')
|
|
|
|
div
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
window.setTimeout(function () { // give the focus restoration callback a chance to run
|
|
|
|
equal(document.activeElement, toggleBtn[0], 'toggling element is once again focused')
|
|
|
|
div.remove()
|
|
|
|
toggleBtn.remove()
|
|
|
|
start()
|
|
|
|
}, 0)
|
|
|
|
})
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
$('#close').click()
|
|
|
|
})
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
toggleBtn.click()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('should not restore focus to toggling element if the associated show event gets prevented', function () {
|
|
|
|
stop()
|
|
|
|
$.support.transition = false
|
|
|
|
var toggleBtn = $('<button data-toggle="modal" data-target="#modal-test">Launch modal</button>').appendTo('#qunit-fixture')
|
|
|
|
var otherBtn = $('<button id="other-btn">Golden boy</button>').appendTo('#qunit-fixture')
|
|
|
|
var div = $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"></div></div></div>')
|
|
|
|
div
|
|
|
|
.one('show.bs.modal', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
otherBtn.focus()
|
|
|
|
window.setTimeout(function () { // give the focus event from the previous line a chance to run
|
|
|
|
div.bootstrapModal('show')
|
|
|
|
}, 0)
|
|
|
|
})
|
|
|
|
.on('hidden.bs.modal', function () {
|
|
|
|
window.setTimeout(function () { // give the focus restoration callback a chance to run (except it shouldn't run in this case)
|
|
|
|
equal(document.activeElement, otherBtn[0], 'show was prevented, so focus should not have been restored to toggling element')
|
|
|
|
div.remove()
|
|
|
|
toggleBtn.remove()
|
|
|
|
otherBtn.remove()
|
|
|
|
start()
|
|
|
|
}, 0)
|
|
|
|
})
|
|
|
|
.on('shown.bs.modal', function () {
|
|
|
|
$('#close').click()
|
|
|
|
})
|
|
|
|
.appendTo('#qunit-fixture')
|
|
|
|
toggleBtn.click()
|
|
|
|
})
|
2013-04-23 03:34:27 -04:00
|
|
|
})
|