0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-14 02:24:00 +01:00
Bootstrap/js/tests/unit/bootstrap-modal.js

152 lines
4.8 KiB
JavaScript
Raw Normal View History

$(function () {
module("bootstrap-modal")
test("should be defined on jquery object", function () {
2011-09-10 21:49:21 +02:00
var div = $("<div id='modal-test'></div>")
ok(div.modal, 'modal method is defined')
})
2011-09-10 21:49:21 +02:00
test("should return element", function () {
var div = $("<div id='modal-test'></div>")
ok(div.modal() == div, 'document.body returned')
})
2011-09-10 21:49:21 +02:00
test("should expose defaults var for settings", function () {
ok($.fn.modal.defaults, 'default object exposed')
})
2011-09-12 07:58:51 +02:00
test("should insert into dom when show method is called", function () {
2011-09-11 07:14:57 +02:00
stop()
2011-09-10 21:49:21 +02:00
$.support.transition = false
var div = $("<div id='modal-test'></div>")
2011-09-11 07:14:57 +02:00
div
.modal()
2011-09-12 07:58:51 +02:00
.modal("show")
.bind("shown", function () {
2011-09-11 07:14:57 +02:00
ok($('#modal-test').length, 'modal insterted into dom')
start()
div.remove()
})
})
2011-09-12 07:58:51 +02:00
test("should hide modal when hide is called", function () {
2011-09-11 07:14:57 +02:00
stop()
2011-09-10 21:49:21 +02:00
$.support.transition = false
var div = $("<div id='modal-test'></div>")
2011-09-11 07:14:57 +02:00
div
.modal()
2011-09-12 07:58:51 +02:00
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
2011-09-11 07:14:57 +02:00
ok($('#modal-test').length, 'modal insterted into dom')
2011-09-12 07:58:51 +02:00
div.modal("hide")
2011-09-11 07:14:57 +02:00
})
2011-09-12 07:58:51 +02:00
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
2011-09-11 07:14:57 +02:00
start()
div.remove()
})
2011-09-12 07:58:51 +02:00
.modal("show")
})
2011-09-10 21:49:21 +02:00
test("should toggle when toggle is called", function () {
2011-09-11 07:14:57 +02:00
stop()
$.support.transition = false
2011-09-10 21:49:21 +02:00
var div = $("<div id='modal-test'></div>")
2011-09-11 07:14:57 +02:00
div
.modal()
2011-09-12 07:58:51 +02:00
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
2011-09-11 07:14:57 +02:00
ok($('#modal-test').length, 'modal insterted into dom')
2011-09-12 07:58:51 +02:00
div.modal("toggle")
2011-09-11 07:14:57 +02:00
})
2011-09-12 07:58:51 +02:00
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
2011-09-11 07:14:57 +02:00
start()
div.remove()
})
2011-09-12 07:58:51 +02:00
.modal("toggle")
})
2011-09-10 21:49:21 +02:00
test("should remove from dom when click .close", function () {
2011-09-11 07:14:57 +02:00
stop()
2011-09-10 21:49:21 +02:00
$.support.transition = false
var div = $("<div id='modal-test'><span class='close'></span></div>")
2011-09-11 07:14:57 +02:00
div
.modal()
2011-09-12 07:58:51 +02:00
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
2011-09-11 07:14:57 +02:00
ok($('#modal-test').length, 'modal insterted into dom')
div.find('.close').click()
})
2011-09-12 07:58:51 +02:00
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
2011-09-11 07:14:57 +02:00
start()
div.remove()
})
2011-09-12 07:58:51 +02:00
.modal("toggle")
2011-09-10 21:49:21 +02:00
})
test("should add backdrop when desired", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal({backdrop:true})
.modal("show")
.bind("shown", function () {
equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom')
start()
div.remove()
$('.modal-backdrop').remove()
})
})
test("should not add backdrop when not desired", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal({backdrop:false})
.modal("show")
.bind("shown", function () {
equal($('.modal-backdrop').length, 0, 'modal backdrop not inserted into dom')
start()
div.remove()
})
})
test("should close backdrop when clicked", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal({backdrop:true})
.modal("show")
.bind("shown", function () {
equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom')
$('.modal-backdrop').click()
equal($('.modal-backdrop').length, 0, 'modal backdrop removed from dom')
start()
div.remove()
})
})
test("should not close backdrop when click disabled", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal({backdrop: 'static'})
.modal("show")
.bind("shown", function () {
equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom')
$('.modal-backdrop').click()
equal($('.modal-backdrop').length, 1, 'modal backdrop still in dom')
start()
div.remove()
$('.modal-backdrop').remove()
})
})
})