66// Dialog Test Helper Functions
77//
88
9+ var defaults = {
10+ autoOpen : true ,
11+ buttons : { } ,
12+ disabled : false ,
13+ dialogClass : null ,
14+ draggable : true ,
15+ height : 200 ,
16+ maxHeight : null ,
17+ maxWidth : null ,
18+ minHeight : 100 ,
19+ minWidth : 150 ,
20+ modal : false ,
21+ overlay : { } ,
22+ position : 'center' ,
23+ resizable : true ,
24+ stack : true ,
25+ title : null ,
26+ width : 300
27+ } ;
28+
929var el ,
1030 offsetBefore , offsetAfter ,
1131 heightBefore , heightAfter ,
@@ -29,6 +49,9 @@ var drag = function(handle, dx, dy) {
2949 offsetBefore = d . offset ( ) ;
3050 heightBefore = d . height ( ) ;
3151 widthBefore = d . width ( ) ;
52+ //this mouseover is to work around a limitation in resizable
53+ //TODO: fix resizable so handle doesn't require mouseover in order to be used
54+ $ ( handle , d ) . simulate ( "mouseover" ) ;
3255 $ ( handle , d ) . simulate ( "drag" , {
3356 dx : dx || 0 ,
3457 dy : dy || 0
@@ -39,10 +62,10 @@ var drag = function(handle, dx, dy) {
3962 widthAfter = d . width ( ) ;
4063}
4164
42- var moved = function ( dx , dy , msg ) {
65+ var moved = function ( dx , dy , msg ) {
4366 msg = msg ? msg + "." : "" ;
4467 var actual = { left : offsetAfter . left , top : offsetAfter . top } ;
45- var expected = { left : offsetBefore . left + dx , top : offsetAfter . top } ;
68+ var expected = { left : offsetBefore . left + dx , top : offsetBefore . top + dy } ;
4669 compare2 ( actual , expected , 'dragged[' + dragged . dx + ', ' + dragged . dy + '] ' + msg ) ;
4770}
4871
@@ -58,6 +81,25 @@ function shouldnotmove(why) {
5881 moved ( 0 , 0 , why ) ;
5982}
6083
84+ var resized = function ( dw , dh , msg ) {
85+ msg = msg ? msg + "." : "" ;
86
FEEA
code>+ var actual = { width : widthAfter , height : heightAfter } ;
87+ var expected = { width : widthBefore + dw , height : heightBefore + dh } ;
88+ compare2 ( actual , expected , 'resized[' + dragged . dx + ', ' + dragged . dy + '] ' + msg ) ;
89+ }
90+
91+ function shouldresize ( why ) {
92+ var handle = $ ( ".ui-resizable-se" , dlg ( ) ) ;
93+ drag ( handle , 50 , 50 ) ;
94+ resized ( 50 , 50 , why ) ;
95+ }
96+
97+ function shouldnotresize ( why ) {
98+ var handle = $ ( ".ui-resizable-se" , dlg ( ) ) ;
99+ drag ( handle , 50 , 50 ) ;
100+ resized ( 0 , 0 , why ) ;
101+ }
102+
61103var border = function ( el , side ) { return parseInt ( el . css ( 'border-' + side + '-width' ) ) ; }
62104
63105var margin = function ( el , side ) { return parseInt ( el . css ( 'margin-' + side ) ) ; }
@@ -74,18 +116,18 @@ test("init", function() {
74116 $ ( [ ] ) . dialog ( ) . remove ( ) ;
75117 ok ( true , '.dialog() called on empty collection' ) ;
76118
77- $ ( " <div/>" ) . dialog ( ) . remove ( ) ;
119+ $ ( ' <div/>' ) . dialog ( ) . remove ( ) ;
78120 ok ( true , '.dialog() called on disconnected DOMElement' ) ;
79121
80- $ ( " <div/>" ) . dialog ( ) . dialog ( "foo" ) . remove ( ) ;
122+ $ ( ' <div/>' ) . dialog ( ) . dialog ( "foo" ) . remove ( ) ;
81123 ok ( true , 'arbitrary method called after init' ) ;
82124
83- el = $ ( " <div/>" ) . dialog ( )
125+ el = $ ( ' <div/>' ) . dialog ( )
84126 var foo = el . data ( "foo.dialog" ) ;
85127 el . remove ( ) ;
86128 ok ( true , 'arbitrary option getter after init' ) ;
87129
88- $ ( " <div/>" ) . dialog ( ) . data ( "foo.dialog" , "bar" ) . remove ( ) ;
130+ $ ( ' <div/>' ) . dialog ( ) . data ( "foo.dialog" , "bar" ) . remove ( ) ;
89131 ok( true , 'arbitrary option setter after init' ) ;
90132} ) ;
91133
@@ -98,18 +140,18 @@ test("destroy", function() {
98140 $ ( [ ] ) . dialog ( ) . dialog ( "destroy" ) . remove ( ) ;
99141 ok ( true , '.dialog("destroy") called on empty collection' ) ;
100142
101- $ ( " <div/>" ) . dialog ( ) . dialog ( "destroy" ) . remove ( ) ;
143+ $ ( ' <div/>' ) . dialog ( ) . dialog ( "destroy" ) . remove ( ) ;
102144 ok ( true , '.dialog("destroy") called on disconnected DOMElement' ) ;
103145
104- $ ( " <div/>" ) . dialog ( ) . dialog ( "destroy" ) . dialog ( "foo" ) . remove ( ) ;
146+ $ ( ' <div/>' ) . dialog ( ) . dialog ( "destroy" ) . dialog ( "foo" ) . remove ( ) ;
105147 ok ( true , 'arbitrary method called after destroy' ) ;
106148
107- el = $ ( " <div/>" ) . dialog ( ) ;
149+ el = $ ( ' <div/>' ) . dialog ( ) ;
108150 var foo = el . dialog ( "destroy" ) . data ( "foo.dialog" ) ;
109151 el . remove ( ) ;
110152 ok ( true , 'arbitrary option getter after destroy' ) ;
111153
112- $ ( " <div/>" ) . dialog ( ) . dialog ( "destroy" ) . data ( "foo.dialog" , "bar" ) . remove ( ) ;
154+ $ ( ' <div/>' ) . dialog ( ) . dialog ( "destroy" ) . data ( "foo.dialog" , "bar" ) . remove ( ) ;
113155 ok ( true , 'arbitrary option setter after destroy' ) ;
114156} ) ;
115157
@@ -137,24 +179,6 @@ test("element types", function() {
137179
138180test ( "defaults" , function ( ) {
139181 el = $ ( '<div/>' ) . dialog ( ) ;
140- var defaults = {
141- autoOpen : true ,
142- buttons : { } ,
143- disabled : false ,
144- draggable : true ,
145- height : 200 ,
146- maxHeight : null ,
147- maxWidth : null ,
148- minHeight : 100 ,
149- minWidth : 150 ,
150- modal : false ,
151- overlay : { } ,
152- position : 'center' ,
153- resizable : true ,
154- stack : true ,
155- title : null ,
156- width : 300
157- } ;
158182 $ . each ( defaults , function ( key , val ) {
159183 var actual = el . data ( key + ".dialog" ) , expected = val ,
160184 method = ( expected && expected . constructor == Object ) ?
@@ -168,18 +192,16 @@ module("dialog: Options");
168192
169193test ( "autoOpen" , function ( ) {
170194 expect ( 2 ) ;
171-
172- el = $ ( "<div/>" ) . dialog ( { autoOpen : false } ) ;
173- isNotOpen ( '.dialog({ autoOpen: false })' ) ;
195+ el = $ ( '<div/>' ) . dialog ( { autoOpen : false } ) ;
196+ isNotOpen ( '.dialog({ autoOpen: false })' ) ;
174197 el . remove ( ) ;
175-
176- el = $ ( "<div/>" ) . dialog ( { autoOpen : true } ) ;
177- isOpen ( '.dialog({ autoOpen: true })' ) ;
198+ el = $ ( '<div/>' ) . dialog ( { autoOpen : true } ) ;
199+ isOpen ( '.dialog({ autoOpen: true })' ) ;
178200 el . remove ( ) ;
179201} ) ;
180202
181203test ( "buttons" , function ( ) {
182- expect ( 10 ) ;
204+ expect ( 14 ) ;
183205 var buttons = {
184206 "Ok" : function ( ev , ui ) {
185207 ok ( true , "button click fires callback" ) ;
@@ -192,7 +214,7 @@ test("buttons", function() {
192214 equals ( ev . target , btn [ 1 ] , "event target" ) ;
193215 }
194216 }
195- el = $ ( " <div/>" ) . dialog ( { buttons : buttons } ) ;
217+ el = $ ( ' <div/>' ) . dialog ( { buttons : buttons } ) ;
196218 var btn = $ ( "button" , dlg ( ) ) ;
197219 equals ( btn . length , 2 , "number of buttons" ) ;
198220 var i = 0 ;
@@ -202,68 +224,153 @@ test("buttons", function() {
202224 } ) ;
203225 equals ( btn . parent ( ) . attr ( 'className' ) , 'ui-dialog-buttonpane' , "buttons in container" ) ;
204226 btn . trigger ( "click" ) ;
227+
228+ var newButtons = {
229+ "Close" : function ( ) { }
230+ }
231+
232+ equals ( el . data ( "buttons.dialog" ) , buttons , '.data("buttons.dialog") getter' ) ;
233+ el . data ( "buttons.dialog" , newButtons ) ;
234+ equals ( el . data ( "buttons.dialog" ) , newButtons , '.data("buttons.dialog", ...) setter' ) ;
235+
236+ btn = $ ( "button" , dlg ( ) ) ;
237+ equals ( btn . length , 1 , "number of buttons after setter" ) ;
238+ var i = 0 ;
239+ $ . each ( newButtons , function ( key , val ) {
240+ equals ( btn . eq ( i ) . text ( ) , key , "text of button " + ( i + 1 ) ) ;
241+ i += 1 ;
242+ } ) ;
243+
244+ el . remove ( ) ;
245+ } ) ;
246+
247+ test ( "dialogClass" , function ( ) {
248+ expect ( 4 ) ;
249+ el = $ ( '<div/>' ) . dialog ( ) ;
250+ equals ( dlg ( ) . is ( ".foo" ) , false , 'dialogClass not specified. foo class added' ) ;
251+ el . remove ( ) ;
252+ el = $ ( '<div/>' ) . dialog ( { dialogClass : "foo" } ) ;
253+ equals ( dlg ( ) . is ( ".foo" ) , true , 'dialogClass in init. foo class added' ) ;
254+ el . remove ( ) ;
255+ el = $ ( '<div/>' ) . dialog ( { dialogClass : "foo bar" } ) ;
256+ equals ( dlg ( ) . is ( ".foo" ) , true , 'dialogClass in init, two classes. foo class added' ) ;
257+ equals ( dlg ( ) . is ( ".bar" ) , true , 'dialogClass in init, two classes. bar class added' ) ;
205258 el . remove ( ) ;
206259} ) ;
207260
208261test ( "draggable" , function ( ) {
209- el = $ ( "<div/>" ) . dialog ( { draggable : false } ) ;
210- shouldnotmove ( ) ;
262+ expect ( 2 ) ;
263+ el = $ ( '<div/>' ) . dialog ( { draggable : false } ) ;
264+ shouldnotmove ( ) ;
211265 el . remove ( ) ;
212- el = $ ( " <div/>" ) . dialog ( { draggable : true } ) ;
213- shouldmove ( ) ;
266+ el = $ ( ' <div/>' ) . dialog ( { draggable : true } ) ;
267+ shouldmove ( ) ;
214268 el . remove ( ) ;
215269} ) ;
216270
217271test ( "height" , function ( ) {
218- el = $ ( "<div/>" ) . dialog ( ) ;
219- equals ( dlg ( ) . height ( ) , 200 , "default height" ) ;
272+ expect ( 2 ) ;
273+ el = $ ( '<div/>' ) . dialog ( ) ;
274+ equals ( dlg ( ) . height ( ) , defaults . height , "default height" ) ;
220275 el . remove ( ) ;
221- el = $ ( " <div/>" ) . dialog ( { height : 437 } ) ;
222- equals ( dlg ( ) . height ( ) , 437 , "default height" ) ;
276+ el = $ ( ' <div/>' ) . dialog ( { height : 437 } ) ;
277+ equals ( dlg ( ) . height ( ) , 437 , "explicit height" ) ;
223278 el . remove ( ) ;
224279} ) ;
225280
226281test ( "maxHeight" , function ( ) {
227- el = $ ( "<div/>" ) . dialog ( { maxHeight : 400 } ) ;
228- drag ( '.ui-resizable-s' , 1000 , 1000 ) ;
229- equals ( heightAfter , 400 , "maxHeight" ) ;
282+ expect ( 2 ) ;
283+ el = $ ( '<div/>' ) . dialog ( { maxHeight : 400 } ) ;
284+ drag ( '.ui-resizable-s' , 1000 , 1000 ) ;
285+ equals ( heightAfter , 400 , "maxHeight" ) ;
230286 el . remove ( ) ;
231- el = $ ( " <div/>" ) . dialog ( { maxHeight : 400 } ) ;
232- drag ( '.ui-resizable-n' , - 1000 , - 1000 ) ;
233- equals ( heightAfter , 400 , "maxHeight" ) ;
287+ el = $ ( ' <div/>' ) . dialog ( { maxHeight : 400 } ) ;
288+ drag ( '.ui-resizable-n' , - 1000 , - 1000 ) ;
289+ equals ( heightAfter , 400 , "maxHeight" ) ;
234290 el . remove ( ) ;
235291} ) ;
236292
237293test ( "maxWidth" , function ( ) {
238- el = $ ( "<div/>" ) . dialog ( { maxWidth : 400 } ) ;
239- drag ( '.ui-resizable-e' , 1000 , 1000 ) ;
240- equals ( widthAfter , 400 , "maxWidth" ) ;
294+ expect ( 2 ) ;
295+ el = $ ( '<div/>' ) . dialog ( { maxWidth : 400 } ) ;
296+ drag ( '.ui-resizable-e' , 1000 , 1000 ) ;
297+ equals ( widthAfter , 400 , "maxWidth" ) ;
241298 el . remove ( ) ;
242- el = $ ( " <div/>" ) . dialog ( { maxWidth : 400 } ) ;
243- drag ( '.ui-resizable-w' , - 1000 , - 1000 ) ;
244- equals ( widthAfter , 400 , "maxWidth" ) ;
299+ el = $ ( ' <div/>' ) . dialog ( { maxWidth : 400 } ) ;
300+ drag ( '.ui-resizable-w' , - 1000 , - 1000 ) ;
301+ equals ( widthAfter , 400 , "maxWidth" ) ;
245302 el . remove ( ) ;
246303} ) ;
247304
248305test ( "minHeight" , function ( ) {
249- el = $ ( "<div/>" ) . dialog ( { minHeight : 10 } ) ;
250- drag ( '.ui-resizable-s' , - 1000 , - 1000 ) ;
251- equals ( heightAfter , 10 , "minHeight" ) ;
306+ expect ( 2 ) ;
307+ el = $ ( '<div/>' ) . dialog ( { minHeight : 10 } ) ;
308+ drag ( '.ui-resizable-s' , - 1000 , - 1000 ) ;
309+ equals ( heightAfter , 10 , "minHeight" ) ;
252310 el . remove ( ) ;
253- el = $ ( " <div/>" ) . dialog ( { minHeight : 10 } ) ;
254- drag ( '.ui-resizable-n' , 1000 , 1000 ) ;
255- equals ( heightAfter , 10 , "minHeight" ) ;
311+ el = $ ( ' <div/>' ) . dialog ( { minHeight : 10 } ) ;
312+ drag ( '.ui-resizable-n' , 1000 , 1000 ) ;
313+ equals ( heightAfter , 10 , "minHeight" ) ;
256314 el . remove ( ) ;
257315} ) ;
258316
259317test ( "minWidth" , function ( ) {
260- el = $ ( "<div/>" ) . dialog ( { minWidth : 10 } ) ;
261- drag ( '.ui-resizable-e' , - 1000 , - 1000 ) ;
262- equals ( widthAfter , 10 , "minWidth" ) ;
318+ expect ( 2 ) ;
319+ el = $ ( '<div/>' ) . dialog ( { minWidth : 10 } ) ;
320+ drag ( '.ui-resizable-e' , - 1000 , - 1000 ) ;
321+ equals ( widthAfter , 10 , "minWidth" ) ;
322+ el . remove ( ) ;
323+ el = $ ( '<div/>' ) . dialog ( { minWidth : 10 } ) ;
324+ drag ( '.ui-resizable-w' , 1000 , 1000 ) ;
325+ equals ( widthAfter , 10 , "minWidth" ) ;
326+ el . remove ( ) ;
327+ } ) ;
328+
329+ test ( "modal" , function ( ) {
330+ ok ( false , "missing test" ) ;
331+ } ) ;
332+
333+ test ( "overlay" , function ( ) {
334+ ok ( false , "missing test" ) ;
335+ } ) ;
336+
337+ test ( "position" , function ( ) {
338+ ok ( false , "missing test" ) ;
339+ } ) ;
340+
341+ test ( "resizable" , function ( ) {
342+ expect ( 2 ) ;
343+ el = $ ( '<div/>' ) . dialog ( ) ;
344+ shouldresize ( "[default]" ) ;
345+ el . remove ( ) ;
346+ el = $ ( '<div/>' ) . dialog ( { resizable : false } ) ;
347+ shouldnotresize ( "disabled in init options" ) ;
348+ el . remove ( ) ;
349+
350+ } ) ;
351+
352+ test ( "stack" , function ( ) {
353+ ok ( false , "missing test" ) ;
354+ } ) ;
355+
356+ test ( "title" , function ( ) {
357+ expect ( 4 ) ;
358+ function titleText ( ) {
359+ return dlg ( ) . find ( ".ui-dialog-title" ) . text ( ) ;
360+ }
361+ el = $ ( '<div/>' ) . dialog ( ) ; equals ( titleText ( ) , "" , "[default]" ) ; el . remove ( ) ;
362+ el = $ ( '<div title="foo"/>' ) . dialog ( ) ; equals ( titleText ( ) , "foo" , "title in element attribute" ) ; el . remove ( ) ;
363+ el = $ ( '<div/>' ) . dialog ( { title : 'foo' } ) ; equals ( titleText ( ) , "foo" , "title in init options" ) ; el . remove ( ) ;
364+ el = $ ( '<div title="foo"/>' ) . dialog ( { title : 'bar' } ) ; equals ( titleText ( ) , "bar" , "title in init options should override title in element attribute" ) ; el . remove ( ) ;
365+ } ) ;
366+
367+ test ( "width" , function ( ) {
368+ expect ( 2 ) ;
369+ el = $ ( '<div/>' ) . dialog ( ) ;
370+ equals ( dlg ( ) . width ( ) , defaults . width , "default width" ) ;
263371 el . remove ( ) ;
264- el = $ ( "<div/>" ) . dialog ( { minWidth : 10 } ) ;
265- drag ( '.ui-resizable-w' , 1000 , 1000 ) ;
266- equals ( widthAfter , 10 , "minWidth" ) ;
372+ el = $ ( '<div/>' ) . dialog ( { width : 437 } ) ;
373+ equals ( dlg ( ) . width ( ) , 437 , "explicit width" ) ;
267374 el . remove ( ) ;
268375} ) ;
269376
@@ -297,7 +404,7 @@ test("open", function() {
297404
298405test ( "close" , function ( ) {
299406 expect ( 2 ) ;
300- el = $ ( " <div/>" ) . dialog ( {
407+ el = $ ( ' <div/>' ) . dialog ( {
301408 close : function ( ev , ui ) {
302409 ok ( true , '.dialog("close") fires close callback' ) ;
303410 equals ( this , el [ 0 ] , "context of callback" ) ;
0 commit comments