annotate static/bootstrap/js/tests/unit/bootstrap-modal.js @ 88:a5a3d454eac9

Updated Bootstrap.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Apr 2013 08:08:12 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 $(function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 module("bootstrap-modal")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 test("should provide no conflict", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 var modal = $.fn.modal.noConflict()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 ok(!$.fn.modal, 'modal was set back to undefined (org value)')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 $.fn.modal = modal
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 test("should be defined on jquery object", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 var div = $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 ok(div.modal, 'modal method is defined')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 test("should return element", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 var div = $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 ok(div.modal() == div, 'document.body returned')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 $('#modal-test').remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 test("should expose defaults var for settings", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 ok($.fn.modal.defaults, 'default object exposed')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 test("should insert into dom when show method is called", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 ok($('#modal-test').length, 'modal insterted into dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 $(this).remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 .modal("show")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 test("should fire show event", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 .bind("show", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 ok(true, "show was called")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 $(this).remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 .modal("show")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 test("should not fire shown when default prevented", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 .bind("show", function (e) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 e.preventDefault()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 ok(true, "show was called")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 ok(false, "shown was called")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 .modal("show")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 test("should hide modal when hide is called", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 ok($('#modal-test').is(":visible"), 'modal visible')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 ok($('#modal-test').length, 'modal insterted into dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 $(this).modal("hide")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 .bind("hidden", function() {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 ok(!$('#modal-test').is(":visible"), 'modal hidden')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 $('#modal-test').remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 .modal("show")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85 test("should toggle when toggle is called", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 var div = $("<div id='modal-test'></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 div
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 ok($('#modal-test').is(":visible"), 'modal visible')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 ok($('#modal-test').length, 'modal insterted into dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 div.modal("toggle")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 .bind("hidden", function() {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 ok(!$('#modal-test').is(":visible"), 'modal hidden')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97 div.remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100 .modal("toggle")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103 test("should remove from dom when click [data-dismiss=modal]", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 div
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 ok($('#modal-test').is(":visible"), 'modal visible')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 ok($('#modal-test').length, 'modal insterted into dom')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 div.find('.close').click()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 .bind("hidden", function() {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 ok(!$('#modal-test').is(":visible"), 'modal hidden')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115 div.remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118 .modal("toggle")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 test("should allow modal close with 'backdrop:false'", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 stop()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 var div = $("<div>", { id: 'modal-test', "data-backdrop": false })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 div
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 .bind("shown", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 ok($('#modal-test').is(":visible"), 'modal visible')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 div.modal("hide")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130 .bind("hidden", function() {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 ok(!$('#modal-test').is(":visible"), 'modal hidden')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 div.remove()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 start()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 .modal("show")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 })