1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,151 @@ |
1 |
+$(function () { |
|
2 |
+ |
|
3 |
+ module("bootstrap-modal") |
|
4 |
+ |
|
5 |
+ test("should be defined on jquery object", function () { |
|
6 |
+ var div = $("<div id='modal-test'></div>") |
|
7 |
+ ok(div.modal, 'modal method is defined') |
|
8 |
+ }) |
|
9 |
+ |
|
10 |
+ test("should return element", function () { |
|
11 |
+ var div = $("<div id='modal-test'></div>") |
|
12 |
+ ok(div.modal() == div, 'div element returned') |
|
13 |
+ }) |
|
14 |
+ |
|
15 |
+ test("should expose defaults var for settings", function () { |
|
16 |
+ ok($.fn.modal.defaults, 'default object exposed') |
|
17 |
+ }) |
|
18 |
+ |
|
19 |
+ test("should insert into dom when show method is called", function () { |
|
20 |
+ stop() |
|
21 |
+ $.support.transition = false |
|
22 |
+ var div = $("<div id='modal-test'></div>") |
|
23 |
+ div |
|
24 |
+ .modal() |
|
25 |
+ .bind("shown", function () { |
|
26 |
+ ok($('#modal-test').length, 'modal insterted into dom') |
|
27 |
+ start() |
|
28 |
+ div.remove() |
|
29 |
+ }) |
|
30 |
+ .modal("show") |
|
31 |
+ }) |
|
32 |
+ |
|
33 |
+ test("should hide modal when hide is called", function () { |
|
34 |
+ stop() |
|
35 |
+ $.support.transition = false |
|
36 |
+ var div = $("<div id='modal-test'></div>") |
|
37 |
+ div |
|
38 |
+ .modal() |
|
39 |
+ .bind("shown", function () { |
|
40 |
+ ok($('#modal-test').is(":visible"), 'modal visible') |
|
41 |
+ ok($('#modal-test').length, 'modal insterted into dom') |
|
42 |
+ div.modal("hide") |
|
43 |
+ }) |
|
44 |
+ .bind("hidden", function() { |
|
45 |
+ ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
46 |
+ start() |
|
47 |
+ div.remove() |
|
48 |
+ }) |
|
49 |
+ .modal("show") |
|
50 |
+ }) |
|
51 |
+ |
|
52 |
+ test("should toggle when toggle is called", function () { |
|
53 |
+ stop() |
|
54 |
+ $.support.transition = false |
|
55 |
+ var div = $("<div id='modal-test'></div>") |
|
56 |
+ div |
|
57 |
+ .modal() |
|
58 |
+ .bind("shown", function () { |
|
59 |
+ ok($('#modal-test').is(":visible"), 'modal visible') |
|
60 |
+ ok($('#modal-test').length, 'modal insterted into dom') |
|
61 |
+ div.modal("toggle") |
|
62 |
+ }) |
|
63 |
+ .bind("hidden", function() { |
|
64 |
+ ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
65 |
+ start() |
|
66 |
+ div.remove() |
|
67 |
+ }) |
|
68 |
+ .modal("toggle") |
|
69 |
+ }) |
|
70 |
+ |
|
71 |
+ test("should remove from dom when click .close", function () { |
|
72 |
+ stop() |
|
73 |
+ $.support.transition = false |
|
74 |
+ var div = $("<div id='modal-test'><span class='close'></span></div>") |
|
75 |
+ div |
|
76 |
+ .modal() |
|
77 |
+ .bind("shown", function () { |
|
78 |
+ ok($('#modal-test').is(":visible"), 'modal visible') |
|
79 |
+ ok($('#modal-test').length, 'modal insterted into dom') |
|
80 |
+ div.find('.close').click() |
|
81 |
+ }) |
|
82 |
+ .bind("hidden", function() { |
|
83 |
+ ok(!$('#modal-test').is(":visible"), 'modal hidden') |
|
84 |
+ start() |
|
85 |
+ div.remove() |
|
86 |
+ }) |
|
87 |
+ .modal("toggle") |
|
88 |
+ }) |
|
89 |
+ |
|
90 |
+ test("should add backdrop when desired", function () { |
|
91 |
+ stop() |
|
92 |
+ $.support.transition = false |
|
93 |
+ var div = $("<div id='modal-test'></div>") |
|
94 |
+ div |
|
95 |
+ .modal({ backdrop:true }) |
|
96 |
+ .bind("shown", function () { |
|
97 |
+ equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') |
|
98 |
+ start() |
|
99 |
+ div.remove() |
|
100 |
+ $('.modal-backdrop').remove() |
|
101 |
+ }) |
|
102 |
+ .modal("show") |
|
103 |
+ }) |
|
104 |
+ |
|
105 |
+ test("should not add backdrop when not desired", function () { |
|
106 |
+ stop() |
|
107 |
+ $.support.transition = false |
|
108 |
+ var div = $("<div id='modal-test'></div>") |
|
109 |
+ div |
|
110 |
+ .modal({backdrop:false}) |
|
111 |
+ .bind("shown", function () { |
|
112 |
+ equal($('.modal-backdrop').length, 0, 'modal backdrop not inserted into dom') |
|
113 |
+ start() |
|
114 |
+ div.remove() |
|
115 |
+ }) |
|
116 |
+ .modal("show") |
|
117 |
+ }) |
|
118 |
+ |
|
119 |
+ test("should close backdrop when clicked", function () { |
|
120 |
+ stop() |
|
121 |
+ $.support.transition = false |
|
122 |
+ var div = $("<div id='modal-test'></div>") |
|
123 |
+ div |
|
124 |
+ .modal({backdrop:true}) |
|
125 |
+ .bind("shown", function () { |
|
126 |
+ equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') |
|
127 |
+ $('.modal-backdrop').click() |
|
128 |
+ equal($('.modal-backdrop').length, 0, 'modal backdrop removed from dom') |
|
129 |
+ start() |
|
130 |
+ div.remove() |
|
131 |
+ }) |
|
132 |
+ .modal("show") |
|
133 |
+ }) |
|
134 |
+ |
|
135 |
+ test("should not close backdrop when click disabled", function () { |
|
136 |
+ stop() |
|
137 |
+ $.support.transition = false |
|
138 |
+ var div = $("<div id='modal-test'></div>") |
|
139 |
+ div |
|
140 |
+ .modal({backdrop: 'static'}) |
|
141 |
+ .bind("shown", function () { |
|
142 |
+ equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') |
|
143 |
+ $('.modal-backdrop').click() |
|
144 |
+ equal($('.modal-backdrop').length, 1, 'modal backdrop still in dom') |
|
145 |
+ start() |
|
146 |
+ div.remove() |
|
147 |
+ $('.modal-backdrop').remove() |
|
148 |
+ }) |
|
149 |
+ .modal("show") |
|
150 |
+ }) |
|
151 |
+}) |