1 $(function () { |
|
2 |
|
3 module("modal") |
|
4 |
|
5 test("should provide no conflict", function () { |
|
6 var modal = $.fn.modal.noConflict() |
|
7 ok(!$.fn.modal, 'modal was set back to undefined (org value)') |
|
8 $.fn.modal = modal |
|
9 }) |
|
10 |
|
11 test("should be defined on jquery object", function () { |
|
12 var div = $("<div id='modal-test'></div>") |
|
13 ok(div.modal, 'modal method is defined') |
|
14 }) |
|
15 |
|
16 test("should return element", function () { |
|
17 var div = $("<div id='modal-test'></div>") |
|
18 ok(div.modal() == div, 'document.body returned') |
|
19 $('#modal-test').remove() |
|
20 }) |
|
21 |
|
22 test("should expose defaults var for settings", function () { |
|
23 ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed') |
|
24 }) |
|
25 |
|
26 test("should insert into dom when show method is called", function () { |
|
27 stop() |
|
28 $.support.transition = false |
|
29 $("<div id='modal-test'></div>") |
|
30 .on("shown.bs.modal", function () { |
|
31 ok($('#modal-test').length, 'modal inserted into dom') |
|
32 $(this).remove() |
|
33 start() |
|
34 }) |
|
35 .modal("show") |
|
36 }) |
|
37 |
|
38 test("should fire show event", function () { |
|
39 stop() |
|
40 $.support.transition = false |
|
41 $("<div id='modal-test'></div>") |
|
42 .on("show.bs.modal", function () { |
|
43 ok(true, "show was called") |
|
44 }) |
|
45 .on("shown.bs.modal", function () { |
|
46 $(this).remove() |
|
47 start() |
|
48 }) |
|
49 .modal("show") |
|
50 }) |
|
51 |
|
52 test("should not fire shown when default prevented", function () { |
|
53 stop() |
|
54 $.support.transition = false |
|
55 $("<div id='modal-test'></div>") |
|
56 .on("show.bs.modal", function (e) { |
|
57 e.preventDefault() |
|
58 ok(true, "show was called") |
|
59 start() |
|
60 }) |
|
61 .on("shown.bs.modal", function () { |
|
62 ok(false, "shown was called") |
|
63 }) |
|
64 .modal("show") |
|
65 }) |
|
66 |
|
67 test("should hide modal when hide is called", function () { |
|
68 stop() |
|
69 $.support.transition = false |
|
70 |
|
71 $("<div id='modal-test'></div>") |
|
72 .on("shown.bs.modal", function () { |
|
73 ok($('#modal-test').is(":visible"), 'modal visible') |
|
74 ok($('#modal-test').length, 'modal inserted into dom') |
|
75 $(this).modal("hide") |
|
76 }) |
|
77 .on("hidden.bs.modal", function() { |
|
78 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
79 $('#modal-test').remove() |
|
80 start() |
|
81 }) |
|
82 .modal("show") |
|
83 }) |
|
84 |
|
85 test("should toggle when toggle is called", function () { |
|
86 stop() |
|
87 $.support.transition = false |
|
88 var div = $("<div id='modal-test'></div>") |
|
89 div |
|
90 .on("shown.bs.modal", function () { |
|
91 ok($('#modal-test').is(":visible"), 'modal visible') |
|
92 ok($('#modal-test').length, 'modal inserted into dom') |
|
93 div.modal("toggle") |
|
94 }) |
|
95 .on("hidden.bs.modal", function() { |
|
96 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
97 div.remove() |
|
98 start() |
|
99 }) |
|
100 .modal("toggle") |
|
101 }) |
|
102 |
|
103 test("should remove from dom when click [data-dismiss=modal]", function () { |
|
104 stop() |
|
105 $.support.transition = false |
|
106 var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>") |
|
107 div |
|
108 .on("shown.bs.modal", function () { |
|
109 ok($('#modal-test').is(":visible"), 'modal visible') |
|
110 ok($('#modal-test').length, 'modal inserted into dom') |
|
111 div.find('.close').click() |
|
112 }) |
|
113 .on("hidden.bs.modal", function() { |
|
114 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
115 div.remove() |
|
116 start() |
|
117 }) |
|
118 .modal("toggle") |
|
119 }) |
|
120 |
|
121 test("should allow modal close with 'backdrop:false'", function () { |
|
122 stop() |
|
123 $.support.transition = false |
|
124 var div = $("<div>", { id: 'modal-test', "data-backdrop": false }) |
|
125 div |
|
126 .on("shown.bs.modal", function () { |
|
127 ok($('#modal-test').is(":visible"), 'modal visible') |
|
128 div.modal("hide") |
|
129 }) |
|
130 .on("hidden.bs.modal", function() { |
|
131 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
132 div.remove() |
|
133 start() |
|
134 }) |
|
135 .modal("show") |
|
136 }) |
|
137 |
|
138 test("should close modal when clicking outside of modal-content", function () { |
|
139 stop() |
|
140 $.support.transition = false |
|
141 var div = $("<div id='modal-test'><div class='contents'></div></div>") |
|
142 div |
|
143 .bind("shown.bs.modal", function () { |
|
144 ok($('#modal-test').length, 'modal insterted into dom') |
|
145 $('.contents').click() |
|
146 ok($('#modal-test').is(":visible"), 'modal visible') |
|
147 $('#modal-test').click() |
|
148 }) |
|
149 .bind("hidden.bs.modal", function() { |
|
150 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
151 div.remove() |
|
152 start() |
|
153 }) |
|
154 .modal("show") |
|
155 }) |
|
156 |
|
157 test("should trigger hide event once when clicking outside of modal-content", function () { |
|
158 stop() |
|
159 $.support.transition = false |
|
160 var div = $("<div id='modal-test'><div class='contents'></div></div>") |
|
161 var triggered |
|
162 div |
|
163 .bind("shown.bs.modal", function () { |
|
164 triggered = 0 |
|
165 $('#modal-test').click() |
|
166 }) |
|
167 .one("hidden.bs.modal", function() { |
|
168 div.modal("show") |
|
169 }) |
|
170 .bind("hide.bs.modal", function () { |
|
171 triggered += 1 |
|
172 ok(triggered === 1, 'modal hide triggered once') |
|
173 start() |
|
174 }) |
|
175 .modal("show") |
|
176 }) |
|
177 |
|
178 test("should close reopened modal with [data-dismiss=modal] click", function () { |
|
179 stop() |
|
180 $.support.transition = false |
|
181 var div = $("<div id='modal-test'><div class='contents'><div id='close' data-dismiss='modal'></div></div></div>") |
|
182 div |
|
183 .bind("shown.bs.modal", function () { |
|
184 $('#close').click() |
|
185 ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
186 }) |
|
187 .one("hidden.bs.modal", function() { |
|
188 div.one('hidden.bs.modal', function () { |
|
189 start() |
|
190 }).modal("show") |
|
191 }) |
|
192 .modal("show") |
|
193 |
|
194 div.remove() |
|
195 }) |
|
196 }) |
|