1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/js/tests/unit/modal.js

157 lines
5 KiB
JavaScript
Raw Normal View History

$(function () {
2013-05-16 14:06:30 -04:00
module("modal")
test("should provide no conflict", function () {
var modal = $.fn.modal.noConflict()
ok(!$.fn.modal, 'modal was set back to undefined (org value)')
$.fn.modal = modal
})
test("should be defined on jquery object", function () {
2011-09-10 15:49:21 -04:00
var div = $("<div id='modal-test'></div>")
ok(div.modal, 'modal method is defined')
})
2011-09-10 15:49:21 -04:00
test("should return element", function () {
var div = $("<div id='modal-test'></div>")
ok(div.modal() == div, 'document.body returned')
$('#modal-test').remove()
})
2011-09-10 15:49:21 -04:00
test("should expose defaults var for settings", function () {
2013-05-16 20:44:50 -04:00
ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed')
})
2011-09-12 01:58:51 -04:00
test("should insert into dom when show method is called", function () {
2011-09-11 01:14:57 -04:00
stop()
2011-09-10 15:49:21 -04:00
$.support.transition = false
$("<div id='modal-test'></div>")
.on("shown.bs.modal", function () {
2013-05-23 02:17:39 -04:00
ok($('#modal-test').length, 'modal inserted into dom')
$(this).remove()
2011-09-11 01:14:57 -04:00
start()
})
.modal("show")
})
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()
})
.modal("show")
})
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")
})
.modal("show")
})
2011-09-12 01:58:51 -04:00
test("should hide modal when hide is called", function () {
2011-09-11 01:14:57 -04:00
stop()
2011-09-10 15:49:21 -04:00
$.support.transition = false
$("<div id='modal-test'></div>")
.on("shown.bs.modal", function () {
2011-09-12 01:58:51 -04:00
ok($('#modal-test').is(":visible"), 'modal visible')
2013-05-23 02:17:39 -04:00
ok($('#modal-test').length, 'modal inserted into dom')
$(this).modal("hide")
2011-09-11 01:14:57 -04:00
})
.on("hidden.bs.modal", function() {
2011-09-12 01:58:51 -04:00
ok(!$('#modal-test').is(":visible"), 'modal hidden')
$('#modal-test').remove()
2011-09-11 01:14:57 -04:00
start()
})
2011-09-12 01:58:51 -04:00
.modal("show")
})
2011-09-10 15:49:21 -04:00
test("should toggle when toggle is called", function () {
2011-09-11 01:14:57 -04:00
stop()
$.support.transition = false
2011-09-10 15:49:21 -04:00
var div = $("<div id='modal-test'></div>")
2011-09-11 01:14:57 -04:00
div
.on("shown.bs.modal", function () {
2011-09-12 01:58:51 -04:00
ok($('#modal-test').is(":visible"), 'modal visible')
2013-05-23 02:17:39 -04:00
ok($('#modal-test').length, 'modal inserted into dom')
2011-09-12 01:58:51 -04:00
div.modal("toggle")
2011-09-11 01:14:57 -04:00
})
.on("hidden.bs.modal", function() {
2011-09-12 01:58:51 -04:00
ok(!$('#modal-test').is(":visible"), 'modal hidden')
2011-09-11 01:14:57 -04:00
div.remove()
start()
2011-09-11 01:14:57 -04:00
})
2011-09-12 01:58:51 -04:00
.modal("toggle")
})
test("should remove from dom when click [data-dismiss=modal]", function () {
2011-09-11 01:14:57 -04:00
stop()
2011-09-10 15:49:21 -04:00
$.support.transition = false
var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
2011-09-11 01:14:57 -04:00
div
.on("shown.bs.modal", function () {
2011-09-12 01:58:51 -04:00
ok($('#modal-test').is(":visible"), 'modal visible')
2013-05-23 02:17:39 -04:00
ok($('#modal-test').length, 'modal inserted into dom')
2011-09-11 01:14:57 -04:00
div.find('.close').click()
})
.on("hidden.bs.modal", function() {
2011-09-12 01:58:51 -04:00
ok(!$('#modal-test').is(":visible"), 'modal hidden')
2011-09-11 01:14:57 -04:00
div.remove()
start()
2011-09-11 01:14:57 -04:00
})
2011-09-12 01:58:51 -04:00
.modal("toggle")
2011-09-10 15:49:21 -04:00
})
2013-03-01 00:15:33 -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 () {
2013-03-01 00:15:33 -05:00
ok($('#modal-test').is(":visible"), 'modal visible')
div.modal("hide")
})
.on("hidden.bs.modal", function() {
2013-03-01 00:15:33 -05:00
ok(!$('#modal-test').is(":visible"), 'modal hidden')
div.remove()
start()
})
.modal("show")
})
2013-07-18 02:01:33 -04: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
.bind("shown.bs.modal", function () {
ok($('#modal-test').length, 'modal insterted into dom')
$('.contents').click()
ok($('#modal-test').is(":visible"), 'modal visible')
$('#modal-test').click()
})
.bind("hidden.bs.modal", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
div.remove()
start()
})
.modal("show")
})
})