corrade-http-templates – Blame information for rev 62
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
62 | office | 1 | define( [ |
2 | "qunit", |
||
3 | "jquery", |
||
4 | "ui/widgets/dialog" |
||
5 | ], function( QUnit, $ ) { |
||
6 | |||
7 | QUnit.module( "dialog: methods", { |
||
8 | afterEach: function() { |
||
9 | $( "body>.ui-dialog" ).remove(); |
||
10 | } |
||
11 | } ); |
||
12 | |||
13 | QUnit.test( "init", function( assert ) { |
||
14 | assert.expect( 6 ); |
||
15 | |||
16 | $( "<div></div>" ).appendTo( "body" ).dialog().remove(); |
||
17 | assert.ok( true, ".dialog() called on element" ); |
||
18 | |||
19 | $( [] ).dialog().remove(); |
||
20 | assert.ok( true, ".dialog() called on empty collection" ); |
||
21 | |||
22 | $( "<div></div>" ).dialog().remove(); |
||
23 | assert.ok( true, ".dialog() called on disconnected DOMElement - never connected" ); |
||
24 | |||
25 | $( "<div></div>" ).appendTo( "body" ).remove().dialog().remove(); |
||
26 | assert.ok( true, ".dialog() called on disconnected DOMElement - removed" ); |
||
27 | |||
28 | var element = $( "<div></div>" ).dialog(); |
||
29 | element.dialog( "option", "foo" ); |
||
30 | element.remove(); |
||
31 | assert.ok( true, "arbitrary option getter after init" ); |
||
32 | |||
33 | $( "<div></div>" ).dialog().dialog( "option", "foo", "bar" ).remove(); |
||
34 | assert.ok( true, "arbitrary option setter after init" ); |
||
35 | } ); |
||
36 | |||
37 | QUnit.test( "destroy", function( assert ) { |
||
38 | assert.expect( 17 ); |
||
39 | |||
40 | var element, element2; |
||
41 | |||
42 | $( "#dialog1, #form-dialog" ).hide(); |
||
43 | assert.domEqual( "#dialog1", function() { |
||
44 | var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); |
||
45 | assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); |
||
46 | assert.equal( dialog.index(), 0 ); |
||
47 | } ); |
||
48 | assert.domEqual( "#form-dialog", function() { |
||
49 | var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" ); |
||
50 | assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); |
||
51 | assert.equal( dialog.index(), 2 ); |
||
52 | } ); |
||
53 | |||
54 | // Ensure dimensions are restored (#8119) |
||
55 | $( "#dialog1" ).show().css( { |
||
56 | width: "400px", |
||
57 | minHeight: "100px", |
||
58 | height: "200px" |
||
59 | } ); |
||
60 | assert.domEqual( "#dialog1", function() { |
||
61 | $( "#dialog1" ).dialog().dialog( "destroy" ); |
||
62 | } ); |
||
63 | |||
64 | // Don't throw errors when destroying a never opened modal dialog (#9004) |
||
65 | $( "#dialog1" ).dialog( { autoOpen: false, modal: true } ).dialog( "destroy" ); |
||
66 | assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" ); |
||
67 | assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); |
||
68 | |||
69 | element = $( "#dialog1" ).dialog( { modal: true } ), |
||
70 | element2 = $( "#dialog2" ).dialog( { modal: true } ); |
||
71 | assert.equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" ); |
||
72 | assert.equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" ); |
||
73 | element.dialog( "close" ); |
||
74 | assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" ); |
||
75 | assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); |
||
76 | element.dialog( "destroy" ); |
||
77 | assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" ); |
||
78 | assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); |
||
79 | element2.dialog( "destroy" ); |
||
80 | assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" ); |
||
81 | assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); |
||
82 | } ); |
||
83 | |||
84 | QUnit.test( "#9000: Dialog leaves broken event handler after close/destroy in certain cases", function( assert ) { |
||
85 | var ready = assert.async(); |
||
86 | assert.expect( 1 ); |
||
87 | $( "#dialog1" ).dialog( { modal:true } ).dialog( "close" ).dialog( "destroy" ); |
||
88 | setTimeout( function() { |
||
89 | $( "#favorite-animal" ).trigger( "focus" ); |
||
90 | assert.ok( true, "close and destroy modal dialog before its really opened" ); |
||
91 | ready(); |
||
92 | } ); |
||
93 | } ); |
||
94 | |||
95 | QUnit.test( "#4980: Destroy should place element back in original DOM position", function( assert ) { |
||
96 | assert.expect( 2 ); |
||
97 | var container = $( "<div id='container'><div id='modal'>Content</div></div>" ), |
||
98 | modal = container.find( "#modal" ); |
||
99 | modal.dialog(); |
||
100 | assert.ok( !$.contains( container[ 0 ], modal[ 0 ] ), "dialog should move modal element to outside container element" ); |
||
101 | modal.dialog( "destroy" ); |
||
102 | assert.ok( $.contains( container[ 0 ], modal[ 0 ] ), "dialog(destroy) should place element back in original DOM position" ); |
||
103 | } ); |
||
104 | |||
105 | QUnit.test( "enable/disable disabled", function( assert ) { |
||
106 | assert.expect( 3 ); |
||
107 | var element = $( "<div></div>" ).dialog(); |
||
108 | element.dialog( "disable" ); |
||
109 | assert.equal( element.dialog( "option", "disabled" ), false, "disable method doesn't do anything" ); |
||
110 | assert.lacksClasses( element, "ui-dialog-disabled ui-state-disabled", "disable method doesn't add classes" ); |
||
111 | assert.ok( !element.dialog( "widget" ).attr( "aria-disabled" ), "disable method doesn't add aria-disabled" ); |
||
112 | } ); |
||
113 | |||
114 | QUnit.test( "close", function( assert ) { |
||
115 | assert.expect( 3 ); |
||
116 | |||
117 | var element, |
||
118 | expected = $( "<div></div>" ).dialog(), |
||
119 | actual = expected.dialog( "close" ); |
||
120 | assert.equal( actual, expected, "close is chainable" ); |
||
121 | |||
122 | element = $( "<div></div>" ).dialog(); |
||
123 | assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible before close method called" ); |
||
124 | element.dialog( "close" ); |
||
125 | assert.ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden after close method called" ); |
||
126 | } ); |
||
127 | |||
128 | QUnit.test( "isOpen", function( assert ) { |
||
129 | assert.expect( 4 ); |
||
130 | |||
131 | var element = $( "<div></div>" ).dialog(); |
||
132 | assert.equal( element.dialog( "isOpen" ), true, "dialog is open after init" ); |
||
133 | element.dialog( "close" ); |
||
134 | assert.equal( element.dialog( "isOpen" ), false, "dialog is closed" ); |
||
135 | element.remove(); |
||
136 | |||
137 | element = $( "<div></div>" ).dialog( { autoOpen: false } ); |
||
138 | assert.equal( element.dialog( "isOpen" ), false, "dialog is closed after init" ); |
||
139 | element.dialog( "open" ); |
||
140 | assert.equal( element.dialog( "isOpen" ), true, "dialog is open" ); |
||
141 | element.remove(); |
||
142 | } ); |
||
143 | |||
144 | QUnit.test( "moveToTop", function( assert ) { |
||
145 | assert.expect( 5 ); |
||
146 | function order() { |
||
147 | var actual = $( ".ui-dialog" ).map( function() { |
||
148 | return +$( this ).css( "z-index" ); |
||
149 | } ).get(); |
||
150 | assert.deepEqual( actual, $.makeArray( arguments ) ); |
||
151 | } |
||
152 | var dialog1, dialog2, |
||
153 | focusOn = "dialog1"; |
||
154 | dialog1 = $( "#dialog1" ).dialog( { |
||
155 | focus: function() { |
||
156 | assert.equal( focusOn, "dialog1" ); |
||
157 | } |
||
158 | } ); |
||
159 | focusOn = "dialog2"; |
||
160 | dialog2 = $( "#dialog2" ).dialog( { |
||
161 | focus: function() { |
||
162 | assert.equal( focusOn, "dialog2" ); |
||
163 | } |
||
164 | } ); |
||
165 | order( 100, 101 ); |
||
166 | focusOn = "dialog1"; |
||
167 | dialog1.dialog( "moveToTop" ); |
||
168 | order( 102, 101 ); |
||
169 | } ); |
||
170 | |||
171 | QUnit.test( "moveToTop: content scroll stays intact", function( assert ) { |
||
172 | assert.expect( 2 ); |
||
173 | var otherDialog = $( "#dialog1" ).dialog(), |
||
174 | scrollDialog = $( "#form-dialog" ).dialog( { |
||
175 | height: 200 |
||
176 | } ); |
||
177 | scrollDialog.scrollTop( 50 ); |
||
178 | assert.equal( scrollDialog.scrollTop(), 50 ); |
||
179 | |||
180 | otherDialog.dialog( "moveToTop" ); |
||
181 | assert.equal( scrollDialog.scrollTop(), 50 ); |
||
182 | } ); |
||
183 | |||
184 | QUnit.test( "open", function( assert ) { |
||
185 | assert.expect( 3 ); |
||
186 | var element, |
||
187 | expected = $( "<div></div>" ).dialog(), |
||
188 | actual = expected.dialog( "open" ); |
||
189 | assert.equal( actual, expected, "open is chainable" ); |
||
190 | |||
191 | element = $( "<div></div>" ).dialog( { autoOpen: false } ); |
||
192 | assert.ok( element.dialog( "widget" ).is( ":hidden" ) && !element.dialog( "widget" ).is( ":visible" ), "dialog hidden before open method called" ); |
||
193 | element.dialog( "open" ); |
||
194 | assert.ok( element.dialog( "widget" ).is( ":visible" ) && !element.dialog( "widget" ).is( ":hidden" ), "dialog visible after open method called" ); |
||
195 | } ); |
||
196 | |||
197 | // http://bugs.jqueryui.com/ticket/6137 |
||
198 | QUnit.test( "Ensure form elements don't reset when opening a dialog", function( assert ) { |
||
199 | assert.expect( 2 ); |
||
200 | |||
201 | var d1 = $( "<form><input type='radio' name='radio' id='a' value='a' checked='checked'></input>" + |
||
202 | "<input type='radio' name='radio' id='b' value='b'>b</input></form>" ).appendTo( "body" ).dialog( { autoOpen: false } ); |
||
203 | |||
204 | d1.find( "#b" ).prop( "checked", true ); |
||
205 | assert.equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); |
||
206 | |||
207 | d1.dialog( "open" ); |
||
208 | assert.equal( d1.find( "input:checked" ).val(), "b", "checkbox b is checked" ); |
||
209 | |||
210 | d1.remove(); |
||
211 | } ); |
||
212 | |||
213 | QUnit.test( "#8958: dialog can be opened while opening", function( assert ) { |
||
214 | var ready = assert.async(); |
||
215 | assert.expect( 1 ); |
||
216 | |||
217 | var element = $( "<div>" ).dialog( { |
||
218 | autoOpen: false, |
||
219 | modal: true, |
||
220 | open: function() { |
||
221 | assert.equal( $( ".ui-widget-overlay" ).length, 1 ); |
||
222 | ready(); |
||
223 | } |
||
224 | } ); |
||
225 | |||
226 | // Support: IE8 |
||
227 | // For some reason the #favorite-color input doesn't get focus if we don't |
||
228 | // focus the body first, causing the test to hang. |
||
229 | $( "body" ).trigger( "focus" ); |
||
230 | |||
231 | $( "#favorite-animal" ) |
||
232 | |||
233 | // We focus the input to start the test. Once it receives focus, the |
||
234 | // dialog will open. Opening the dialog, will cause an element inside |
||
235 | // the dialog to gain focus, thus blurring the input. |
||
236 | .on( "focus", function() { |
||
237 | element.dialog( "open" ); |
||
238 | } ) |
||
239 | |||
240 | // When the input blurs, the dialog is in the process of opening. We |
||
241 | // try to open the dialog again, to make sure that dialogs properly |
||
242 | // handle a call to the open() method during the process of the dialog |
||
243 | // being opened. |
||
244 | .on( "blur", function() { |
||
245 | element.dialog( "open" ); |
||
246 | } ) |
||
247 | .trigger( "focus" ); |
||
248 | } ); |
||
249 | |||
250 | QUnit.test( "#5531: dialog width should be at least minWidth on creation", function( assert ) { |
||
251 | assert.expect( 4 ); |
||
252 | var element = $( "<div></div>" ).dialog( { |
||
253 | width: 200, |
||
254 | minWidth: 300 |
||
255 | } ); |
||
256 | |||
257 | assert.equal( element.dialog( "option", "width" ), 300, "width is minWidth" ); |
||
258 | element.dialog( "option", "width", 200 ); |
||
259 | assert.equal( element.dialog( "option", "width" ), 300, "width unchanged when set to < minWidth" ); |
||
260 | element.dialog( "option", "width", 320 ); |
||
261 | assert.equal( element.dialog( "option", "width" ), 320, "width changed if set to > minWidth" ); |
||
262 | element.remove(); |
||
263 | |||
264 | element = $( "<div></div>" ).dialog( { |
||
265 | minWidth: 300 |
||
266 | } ); |
||
267 | assert.ok( element.dialog( "option", "width" ) >= 300, "width is at least 300" ); |
||
268 | element.remove(); |
||
269 | |||
270 | } ); |
||
271 | |||
272 | } ); |