2015-04-07 00:23:50 +00:00
define ( [
2016-04-03 16:10:09 +00:00
"qunit" ,
2015-04-07 00:23:50 +00:00
"jquery" ,
2020-05-16 07:16:24 +00:00
"lib/helper" ,
2015-04-07 14:55:52 +00:00
"./helper" ,
2015-07-15 01:59:10 +00:00
"ui/widgets/dialog" ,
2015-07-15 02:01:41 +00:00
"ui/effects/effect-blind" ,
"ui/effects/effect-explode"
2020-05-16 07:16:24 +00:00
] , function ( QUnit , $ , helper , testHelper ) {
2009-02-02 14:36:08 +00:00
2020-05-16 07:16:24 +00:00
QUnit . module ( "dialog: options" , { afterEach : helper . moduleAfterEach } ) ;
2009-02-02 14:36:08 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "appendTo" , function ( assert ) {
assert . expect ( 16 ) ;
2012-12-07 19:54:21 +00:00
var detached = $ ( "<div>" ) ,
2015-08-24 12:59:54 +00:00
element = $ ( "#dialog1" ) . dialog ( {
2013-01-26 10:03:14 +00:00
modal : true
2015-08-24 12:59:54 +00:00
} ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , document . body , "defaults to body" ) ;
assert . equal ( $ ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , document . body , "overlay defaults to body" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
2013-01-26 10:03:14 +00:00
appendTo : ".wrap" ,
modal : true
2015-08-24 12:59:54 +00:00
} ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , $ ( "#wrap1" ) [ 0 ] , "first found element" ) ;
assert . equal ( $ ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , $ ( "#wrap1" ) [ 0 ] , "overlay first found element" ) ;
assert . equal ( $ ( "#wrap2 .ui-dialog" ) . length , 0 , "only appends to one element" ) ;
assert . equal ( $ ( "#wrap2 .ui-widget-overlay" ) . length , 0 , "overlay only appends to one element" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
2013-01-26 10:03:14 +00:00
appendTo : null ,
modal : true
2015-08-24 12:59:54 +00:00
} ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , document . body , "null" ) ;
assert . equal ( $ ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , document . body , "overlay null" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
2013-01-26 10:03:14 +00:00
autoOpen : false ,
modal : true
2015-08-24 12:59:54 +00:00
} ) . dialog ( "option" , "appendTo" , "#wrap1" ) . dialog ( "open" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , $ ( "#wrap1" ) [ 0 ] , "modified after init" ) ;
assert . equal ( $ ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , $ ( "#wrap1" ) [ 0 ] , "overlay modified after init" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
2013-01-26 10:03:14 +00:00
appendTo : detached ,
modal : true
2015-08-24 12:59:54 +00:00
} ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , detached [ 0 ] , "detached jQuery object" ) ;
assert . equal ( detached . find ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , detached [ 0 ] , "overlay detached jQuery object" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
appendTo : detached [ 0 ] ,
2013-01-26 10:03:14 +00:00
modal : true
2015-08-24 12:59:54 +00:00
} ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , detached [ 0 ] , "detached DOM element" ) ;
assert . equal ( detached . find ( ".ui-widget-overlay" ) . parent ( ) [ 0 ] , detached [ 0 ] , "overlay detached DOM element" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( {
2013-01-26 10:03:14 +00:00
autoOpen : false ,
modal : true
2015-08-24 12:59:54 +00:00
} ) . dialog ( "option" , "appendTo" , detached ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . parent ( ) [ 0 ] , detached [ 0 ] , "detached DOM element via option()" ) ;
assert . equal ( detached . find ( ".ui-widget-overlay" ) . length , 0 , "overlay detached DOM element via option()" ) ;
2012-12-07 19:54:21 +00:00
element . dialog ( "destroy" ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2012-12-07 19:54:21 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "autoOpen" , function ( assert ) {
assert . expect ( 2 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { autoOpen : false } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( ! element . dialog ( "widget" ) . is ( ":visible" ) , ".dialog({ autoOpen: false })" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { autoOpen : true } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( element . dialog ( "widget" ) . is ( ":visible" ) , ".dialog({ autoOpen: true })" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "buttons" , function ( assert ) {
assert . expect ( 21 ) ;
2009-02-04 04:35:18 +00:00
2012-04-19 14:27:06 +00:00
var btn , i , newButtons ,
buttons = {
2012-11-03 20:17:16 +00:00
"Ok" : function ( ev ) {
2016-04-03 16:10:09 +00:00
assert . ok ( true , "button click fires callback" ) ;
assert . equal ( this , element [ 0 ] , "context of callback" ) ;
assert . equal ( ev . target , btn [ 0 ] , "event target" ) ;
2012-11-03 20:17:16 +00:00
} ,
"Cancel" : function ( ev ) {
2016-04-03 16:10:09 +00:00
assert . ok ( true , "button click fires callback" ) ;
assert . equal ( this , element [ 0 ] , "context of callback" ) ;
assert . equal ( ev . target , btn [ 1 ] , "event target" ) ;
2012-11-03 20:17:16 +00:00
}
2009-02-04 04:35:18 +00:00
} ,
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { buttons : buttons } ) ;
2009-02-04 04:35:18 +00:00
2013-01-31 05:38:20 +00:00
btn = element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( btn . length , 2 , "number of buttons" ) ;
2009-02-04 04:35:18 +00:00
2012-04-19 14:27:06 +00:00
i = 0 ;
2015-08-24 12:59:54 +00:00
$ . each ( buttons , function ( key ) {
2016-04-03 16:10:09 +00:00
assert . equal ( btn . eq ( i ) . text ( ) , key , "text of button " + ( i + 1 ) ) ;
2009-02-04 04:35:18 +00:00
i ++ ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2015-01-30 14:57:04 +00:00
assert . hasClasses ( btn . parent ( ) , "ui-dialog-buttonset" ) ;
assert . hasClasses ( element . parent ( ) , "ui-dialog-buttons" ) ;
2012-02-28 14:56:32 +00:00
2015-08-24 12:59:54 +00:00
btn . trigger ( "click" ) ;
2009-02-04 04:35:18 +00:00
2012-04-19 14:27:06 +00:00
newButtons = {
2012-10-23 14:36:42 +00:00
"Close" : function ( ev ) {
2016-04-03 16:10:09 +00:00
assert . ok ( true , "button click fires callback" ) ;
assert . equal ( this , element [ 0 ] , "context of callback" ) ;
assert . equal ( ev . target , btn [ 0 ] , "event target" ) ;
2009-02-04 04:35:18 +00:00
}
} ;
2016-04-03 16:10:09 +00:00
assert . deepEqual ( element . dialog ( "option" , "buttons" ) , buttons , ".dialog('option', 'buttons') getter" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "buttons" , newButtons ) ;
2016-04-03 16:10:09 +00:00
assert . deepEqual ( element . dialog ( "option" , "buttons" ) , newButtons , ".dialog('option', 'buttons', ...) setter" ) ;
2009-02-04 04:35:18 +00:00
2013-01-31 05:38:20 +00:00
btn = element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( btn . length , 1 , "number of buttons after setter" ) ;
2015-08-24 12:59:54 +00:00
btn . trigger ( "click" ) ;
2009-02-04 04:35:18 +00:00
i = 0 ;
2015-08-24 12:59:54 +00:00
$ . each ( newButtons , function ( key ) {
2016-04-03 16:10:09 +00:00
assert . equal ( btn . eq ( i ) . text ( ) , key , "text of button " + ( i + 1 ) ) ;
2009-02-04 04:35:18 +00:00
i += 1 ;
2015-08-24 12:59:54 +00:00
} ) ;
2012-02-28 14:56:32 +00:00
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "buttons" , null ) ;
2013-01-31 05:38:20 +00:00
btn = element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( btn . length , 0 , "all buttons have been removed" ) ;
assert . equal ( element . find ( ".ui-dialog-buttonset" ) . length , 0 , "buttonset has been removed" ) ;
2015-01-30 14:57:04 +00:00
assert . lacksClasses ( element . parent ( ) , "ui-dialog-buttons" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "buttons - advanced" , function ( assert ) {
assert . expect ( 7 ) ;
2010-08-31 14:17:53 +00:00
2012-11-03 20:17:16 +00:00
var buttons ,
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( {
2012-11-03 20:17:16 +00:00
buttons : [
{
text : "a button" ,
"class" : "additional-class" ,
id : "my-button-id" ,
click : function ( ) {
2016-04-03 16:10:09 +00:00
assert . equal ( this , element [ 0 ] , "correct context" ) ;
2012-11-16 18:26:22 +00:00
} ,
2014-03-28 14:48:18 +00:00
icon : "ui-icon-cancel" ,
showLabel : false
2010-08-31 14:17:53 +00:00
}
2012-11-03 20:17:16 +00:00
]
2015-08-24 12:59:54 +00:00
} ) ;
2012-11-03 20:17:16 +00:00
2013-01-31 05:38:20 +00:00
buttons = element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( buttons . length , 1 , "correct number of buttons" ) ;
assert . equal ( buttons . attr ( "id" ) , "my-button-id" , "correct id" ) ;
2019-12-08 21:23:08 +00:00
assert . equal ( String . prototype . trim . call ( buttons . text ( ) ) , "a button" , "correct label" ) ;
2015-01-30 14:57:04 +00:00
assert . hasClasses ( buttons , "additional-class" ) ;
2016-04-03 16:10:09 +00:00
assert . deepEqual ( buttons . button ( "option" , "icon" ) , "ui-icon-cancel" ) ;
assert . equal ( buttons . button ( "option" , "showLabel" ) , false ) ;
2015-05-14 01:57:04 +00:00
buttons . trigger ( "click" ) ;
2010-08-31 14:17:53 +00:00
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2010-08-31 14:17:53 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "#9043: buttons with Array.prototype modification" , function ( assert ) {
assert . expect ( 1 ) ;
2013-02-01 13:59:55 +00:00
Array . prototype . test = $ . noop ;
var element = $ ( "<div></div>" ) . dialog ( ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane" ) . length , 0 ,
2013-02-01 13:59:55 +00:00
"no button pane" ) ;
element . remove ( ) ;
delete Array . prototype . test ;
2015-08-24 12:59:54 +00:00
} ) ;
2013-02-01 13:59:55 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "closeOnEscape" , function ( assert ) {
assert . expect ( 6 ) ;
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { closeOnEscape : false } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( true , "closeOnEscape: false" ) ;
assert . ok ( element . dialog ( "widget" ) . is ( ":visible" ) && ! element . dialog ( "widget" ) . is ( ":hidden" ) , "dialog is open before ESC" ) ;
2015-08-24 12:59:54 +00:00
element . simulate ( "keydown" , { keyCode : $ . ui . keyCode . ESCAPE } )
. simulate ( "keypress" , { keyCode : $ . ui . keyCode . ESCAPE } )
. simulate ( "keyup" , { keyCode : $ . ui . keyCode . ESCAPE } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( element . dialog ( "widget" ) . is ( ":visible" ) && ! element . dialog ( "widget" ) . is ( ":hidden" ) , "dialog is open after ESC" ) ;
2015-08-24 12:59:54 +00:00
element . remove ( ) ;
element = $ ( "<div></div>" ) . dialog ( { closeOnEscape : true } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( true , "closeOnEscape: true" ) ;
assert . ok ( element . dialog ( "widget" ) . is ( ":visible" ) && ! element . dialog ( "widget" ) . is ( ":hidden" ) , "dialog is open before ESC" ) ;
2015-08-24 12:59:54 +00:00
element . simulate ( "keydown" , { keyCode : $ . ui . keyCode . ESCAPE } )
. simulate ( "keypress" , { keyCode : $ . ui . keyCode . ESCAPE } )
. simulate ( "keyup" , { keyCode : $ . ui . keyCode . ESCAPE } ) ;
2016-04-03 16:10:09 +00:00
assert . ok ( element . dialog ( "widget" ) . is ( ":hidden" ) && ! element . dialog ( "widget" ) . is ( ":visible" ) , "dialog is closed after ESC" ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "closeText" , function ( assert ) {
assert . expect ( 4 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( ) ;
2019-12-08 21:23:08 +00:00
assert . equal ( String . prototype . trim . call ( element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . text ( ) ) , "Close" ,
2015-08-24 12:59:54 +00:00
"default close text" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { closeText : "foo" } ) ;
2019-12-08 21:23:08 +00:00
assert . equal ( String . prototype . trim . call ( element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . text ( ) ) , "foo" ,
2015-08-24 12:59:54 +00:00
"closeText on init" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( ) . dialog ( "option" , "closeText" , "bar" ) ;
2019-12-08 21:23:08 +00:00
assert . equal ( String . prototype . trim . call ( element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . text ( ) ) , "bar" ,
2015-08-24 12:59:54 +00:00
"closeText via option method" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-10-28 18:11:07 +00:00
element = $ ( "<div></div>" ) . dialog ( { closeText : "<span>foo</span>" } ) ;
2019-12-08 21:23:08 +00:00
assert . equal ( String . prototype . trim . call ( element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . text ( ) ) , "<span>foo</span>" ,
2015-10-28 18:11:07 +00:00
"closeText is escaped" ) ;
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "draggable" , function ( assert ) {
assert . expect ( 4 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { draggable : false } ) ;
2012-11-03 20:17:16 +00:00
2016-04-03 16:10:09 +00:00
testHelper . testDrag ( assert , element , 50 , - 50 , 0 , 0 ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "draggable" , true ) ;
2016-04-03 16:10:09 +00:00
testHelper . testDrag ( assert , element , 50 , - 50 , 50 , - 50 ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { draggable : true } ) ;
2016-04-03 16:10:09 +00:00
testHelper . testDrag ( assert , element , 50 , - 50 , 50 , - 50 ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "draggable" , false ) ;
2016-04-03 16:10:09 +00:00
testHelper . testDrag ( assert , element , 50 , - 50 , 0 , 0 ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "height" , function ( assert ) {
assert . expect ( 4 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( ) ;
2019-12-08 21:23:08 +00:00
assert . ok ( Math . abs ( element . dialog ( "widget" ) . outerHeight ( ) - 150 ) < 0.25 ,
"default height within 0.25 from expected" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { height : 237 } ) ;
2019-12-08 21:23:08 +00:00
assert . ok ( Math . abs ( element . dialog ( "widget" ) . outerHeight ( ) - 237 ) < 0.25 ,
"explicit height within 0.25 from expected" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( ) ;
element . dialog ( "option" , "height" , 238 ) ;
2019-12-08 21:23:08 +00:00
assert . ok ( Math . abs ( element . dialog ( "widget" ) . outerHeight ( ) - 238 ) < 0.25 ,
"explicit height set after init within 0.25 from expected" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2012-02-28 14:56:32 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . css ( "padding" , "20px" )
. dialog ( { height : 240 } ) ;
2019-12-08 21:23:08 +00:00
assert . ok ( Math . abs ( element . dialog ( "widget" ) . outerHeight ( ) - 240 ) < 0.25 ,
"explicit height with padding within 0.25 from expected" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "maxHeight" , function ( assert ) {
assert . expect ( 3 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { maxHeight : 200 } ) ;
testHelper . drag ( element , ".ui-resizable-s" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 200 , 1 , "maxHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { maxHeight : 200 } ) ;
testHelper . drag ( element , ".ui-resizable-n" , - 1000 , - 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 200 , 1 , "maxHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { maxHeight : 200 } ) . dialog ( "option" , "maxHeight" , 300 ) ;
testHelper . drag ( element , ".ui-resizable-s" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 300 , 1 , "maxHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "maxWidth" , function ( assert ) {
assert . expect ( 3 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { maxWidth : 200 } ) ;
testHelper . drag ( element , ".ui-resizable-e" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 200 , 1 , "maxWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { maxWidth : 200 } ) ;
testHelper . drag ( element , ".ui-resizable-w" , - 1000 , - 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 200 , 1 , "maxWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { maxWidth : 200 } ) . dialog ( "option" , "maxWidth" , 300 ) ;
testHelper . drag ( element , ".ui-resizable-w" , - 1000 , - 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 300 , 1 , "maxWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "minHeight" , function ( assert ) {
assert . expect ( 3 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { minHeight : 10 } ) ;
testHelper . drag ( element , ".ui-resizable-s" , - 1000 , - 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 10 , 1 , "minHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { minHeight : 10 } ) ;
testHelper . drag ( element , ".ui-resizable-n" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 10 , 1 , "minHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { minHeight : 10 } ) . dialog ( "option" , "minHeight" , 30 ) ;
testHelper . drag ( element , ".ui-resizable-n" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . height ( ) , 30 , 1 , "minHeight" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "minWidth" , function ( assert ) {
assert . expect ( 3 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( { minWidth : 10 } ) ;
testHelper . drag ( element , ".ui-resizable-e" , - 1000 , - 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 10 , 1 , "minWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { minWidth : 10 } ) ;
testHelper . drag ( element , ".ui-resizable-w" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 10 , 1 , "minWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { minWidth : 30 } ) . dialog ( "option" , "minWidth" , 30 ) ;
testHelper . drag ( element , ".ui-resizable-w" , 1000 , 1000 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 30 , 1 , "minWidth" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "position, default center on window" , function ( assert ) {
assert . expect ( 2 ) ;
2012-12-22 20:46:57 +00:00
2015-08-21 04:11:21 +00:00
// Dialogs alter the window width and height in Firefox
2012-12-22 20:46:57 +00:00
// so we collect that information before creating the dialog
2014-10-20 23:18:34 +00:00
// Support: Firefox
2012-12-22 20:46:57 +00:00
var winWidth = $ ( window ) . width ( ) ,
winHeight = $ ( window ) . height ( ) ,
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( ) ,
dialog = element . dialog ( "widget" ) ,
2012-04-19 14:27:06 +00:00
offset = dialog . offset ( ) ;
2015-03-31 20:52:28 +00:00
assert . close ( offset . left , Math . round ( winWidth / 2 - dialog . outerWidth ( ) / 2 ) + $ ( window ) . scrollLeft ( ) , 1 , "dialog left position of center on window on initilization" ) ;
assert . close ( offset . top , Math . round ( winHeight / 2 - dialog . outerHeight ( ) / 2 ) + $ ( window ) . scrollTop ( ) , 1 , "dialog top position of center on window on initilization" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-09-19 14:03:53 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "position, right bottom at right bottom via ui.position args" , function ( assert ) {
assert . expect ( 2 ) ;
2012-11-09 20:02:12 +00:00
2015-08-21 04:11:21 +00:00
// Dialogs alter the window width and height in Firefox
2012-12-22 20:46:57 +00:00
// so we collect that information before creating the dialog
2014-10-20 23:18:34 +00:00
// Support: Firefox
2012-12-22 20:46:57 +00:00
var winWidth = $ ( window ) . width ( ) ,
winHeight = $ ( window ) . height ( ) ,
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( {
2012-12-22 20:46:57 +00:00
position : {
my : "right bottom" ,
at : "right bottom"
}
2015-08-24 12:59:54 +00:00
} ) ,
dialog = element . dialog ( "widget" ) ,
2012-12-22 20:46:57 +00:00
offset = dialog . offset ( ) ;
2015-03-31 20:52:28 +00:00
assert . close ( offset . left , winWidth - dialog . outerWidth ( ) + $ ( window ) . scrollLeft ( ) , 1 , "dialog left position of right bottom at right bottom on initilization" ) ;
assert . close ( offset . top , winHeight - dialog . outerHeight ( ) + $ ( window ) . scrollTop ( ) , 1 , "dialog top position of right bottom at right bottom on initilization" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2010-06-06 22:00:49 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "position, at another element" , function ( assert ) {
assert . expect ( 4 ) ;
2015-08-24 12:59:54 +00:00
var parent = $ ( "<div></div>" ) . css ( {
2012-12-26 13:08:48 +00:00
position : "absolute" ,
2012-04-19 14:27:06 +00:00
top : 400 ,
left : 600 ,
height : 10 ,
width : 10
2015-08-24 12:59:54 +00:00
} ) . appendTo ( "body" ) ,
2012-04-19 14:27:06 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( {
2012-04-19 14:27:06 +00:00
position : {
my : "left top" ,
at : "left top" ,
2012-12-22 20:46:57 +00:00
of : parent ,
collision : "none"
2012-04-19 14:27:06 +00:00
}
2015-08-24 12:59:54 +00:00
} ) ,
2010-06-06 22:00:49 +00:00
2015-08-24 12:59:54 +00:00
dialog = element . dialog ( "widget" ) ,
2012-04-19 14:27:06 +00:00
offset = dialog . offset ( ) ;
2010-06-06 22:00:49 +00:00
2015-03-31 20:52:28 +00:00
assert . close ( offset . left , 600 , 1 , "dialog left position at another element on initilization" ) ;
assert . close ( offset . top , 400 , 1 , "dialog top position at another element on initilization" ) ;
2010-06-06 22:00:49 +00:00
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "position" , {
2010-06-06 22:00:49 +00:00
my : "left top" ,
at : "right bottom" ,
2012-12-22 20:46:57 +00:00
of : parent ,
collision : "none"
2015-08-24 12:59:54 +00:00
} ) ;
2010-06-06 22:00:49 +00:00
2012-04-19 14:27:06 +00:00
offset = dialog . offset ( ) ;
2010-07-16 12:50:40 +00:00
2015-03-31 20:52:28 +00:00
assert . close ( offset . left , 610 , 1 , "dialog left position at another element via setting option" ) ;
assert . close ( offset . top , 410 , 1 , "dialog top position at another element via setting option" ) ;
2010-06-06 22:00:49 +00:00
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2010-06-06 22:00:49 +00:00
parent . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2010-06-06 22:00:49 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "resizable" , function ( assert ) {
assert . expect ( 4 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 50 , 50 , "[default]" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "resizable" , false ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 0 , 0 , "disabled after init" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { resizable : false } ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 0 , 0 , "disabled in init options" ) ;
2015-08-24 12:59:54 +00:00
element . dialog ( "option" , "resizable" , true ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 50 , 50 , "enabled after init" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "title" , function ( assert ) {
assert . expect ( 11 ) ;
2009-02-04 04:35:18 +00:00
function titleText ( ) {
2015-08-24 12:59:54 +00:00
return element . dialog ( "widget" ) . find ( ".ui-dialog-title" ) . html ( ) ;
2009-02-04 04:35:18 +00:00
}
2013-01-31 05:38:20 +00:00
var element = $ ( "<div></div>" ) . dialog ( ) ;
2015-08-24 12:59:54 +00:00
2016-04-03 16:10:09 +00:00
// Some browsers return a non-breaking space and some return " "
2012-11-15 15:47:36 +00:00
// so we generate a non-breaking space for comparison
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , $ ( "<span> </span>" ) . html ( ) , "[default]" ) ;
assert . equal ( element . dialog ( "option" , "title" ) , null , "option not changed" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2012-11-09 17:26:30 +00:00
2013-01-31 05:38:20 +00:00
element = $ ( "<div title='foo'>" ) . dialog ( ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , "foo" , "title in element attribute" ) ;
assert . equal ( element . dialog ( "option" , "title" ) , "foo" , "option updated from attribute" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { title : "foo" } ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , "foo" , "title in init options" ) ;
assert . equal ( element . dialog ( "option" , "title" ) , "foo" , "opiton set from options hash" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div title='foo'>" ) . dialog ( { title : "bar" } ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , "bar" , "title in init options should override title in element attribute" ) ;
assert . equal ( element . dialog ( "option" , "title" ) , "bar" , "opiton set from options hash" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2013-01-31 05:38:20 +00:00
element = $ ( "<div></div>" ) . dialog ( ) . dialog ( "option" , "title" , "foo" ) ;
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , "foo" , "title after init" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-21 04:11:21 +00:00
// Make sure attroperties are properly ignored - #5742 - .attr() might return a DOMElement
2013-01-31 05:38:20 +00:00
element = $ ( "<form><input name='title'></form>" ) . dialog ( ) ;
2015-08-24 12:59:54 +00:00
2016-04-03 16:10:09 +00:00
// Some browsers return a non-breaking space and some return " "
2012-11-09 17:26:30 +00:00
// so we get the text to normalize to the actual non-breaking space
2016-04-03 16:10:09 +00:00
assert . equal ( titleText ( ) , $ ( "<span> </span>" ) . html ( ) , "[default]" ) ;
assert . equal ( element . dialog ( "option" , "title" ) , null , "option not changed" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-04 04:35:18 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "width" , function ( assert ) {
assert . expect ( 3 ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 300 , 1 , "default width" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2009-02-04 04:35:18 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { width : 437 } ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 437 , 1 , "explicit width" ) ;
element . dialog ( "option" , "width" , 438 ) ;
assert . close ( element . dialog ( "widget" ) . width ( ) , 438 , 1 , "explicit width after init" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2009-02-02 14:36:08 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "#4826: setting resizable false toggles resizable on dialog" , function ( assert ) {
assert . expect ( 6 ) ;
2012-12-08 01:06:29 +00:00
var i ,
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { resizable : false } ) ;
2012-12-08 01:06:29 +00:00
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 0 , 0 , "[default]" ) ;
2015-08-24 12:59:54 +00:00
for ( i = 0 ; i < 2 ; i ++ ) {
element . dialog ( "close" ) . dialog ( "open" ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 0 , 0 , "initialized with resizable false toggle (" + ( i + 1 ) + ")" ) ;
2012-12-08 01:06:29 +00:00
}
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2012-12-08 01:06:29 +00:00
2015-08-24 12:59:54 +00:00
element = $ ( "<div></div>" ) . dialog ( { resizable : true } ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 50 , 50 , "[default]" ) ;
2015-08-24 12:59:54 +00:00
for ( i = 0 ; i < 2 ; i ++ ) {
element . dialog ( "close" ) . dialog ( "option" , "resizable" , false ) . dialog ( "open" ) ;
2016-04-03 16:10:09 +00:00
testHelper . shouldResize ( assert , element , 0 , 0 , "set option resizable false toggle (" + ( i + 1 ) + ")" ) ;
2012-12-08 01:06:29 +00:00
}
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2012-12-08 01:06:29 +00:00
2015-08-24 12:59:54 +00:00
} ) ;
2012-12-08 01:06:29 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "#8051 - 'Explode' dialog animation causes crash in IE 6, 7 and 8" , function ( assert ) {
var ready = assert . async ( ) ;
assert . expect ( 1 ) ;
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( {
2013-01-30 18:30:37 +00:00
show : "explode" ,
focus : function ( ) {
2016-04-03 16:10:09 +00:00
assert . ok ( true , "dialog opened with animation" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2016-04-03 16:10:09 +00:00
ready ( ) ;
2013-01-30 18:30:37 +00:00
}
2015-08-24 12:59:54 +00:00
} ) ;
} ) ;
2013-01-30 18:30:37 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "#4421 - Focus lost from dialog which uses show-effect" , function ( assert ) {
var ready = assert . async ( ) ;
assert . expect ( 1 ) ;
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( {
2013-01-30 18:30:37 +00:00
show : "blind" ,
focus : function ( ) {
2016-04-03 16:10:09 +00:00
assert . equal ( element . dialog ( "widget" ) . find ( document . activeElement ) . length , 1 , "dialog maintains focus" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2016-04-03 16:10:09 +00:00
ready ( ) ;
2013-01-30 18:30:37 +00:00
}
2015-08-24 12:59:54 +00:00
} ) ;
} ) ;
2013-01-30 18:30:37 +00:00
2016-04-03 16:10:09 +00:00
QUnit . test ( "Open followed by close during show effect" , function ( assert ) {
var ready = assert . async ( ) ;
assert . expect ( 1 ) ;
2015-08-24 12:59:54 +00:00
var element = $ ( "<div></div>" ) . dialog ( {
2013-01-30 18:30:37 +00:00
show : "blind" ,
close : function ( ) {
2016-04-03 16:10:09 +00:00
assert . ok ( true , "dialog closed properly during animation" ) ;
2013-01-31 05:38:20 +00:00
element . remove ( ) ;
2016-04-03 16:10:09 +00:00
ready ( ) ;
2013-01-30 18:30:37 +00:00
}
2015-08-24 12:59:54 +00:00
} ) ;
2013-01-30 18:30:37 +00:00
setTimeout ( function ( ) {
2015-08-24 12:59:54 +00:00
element . dialog ( "close" ) ;
2013-01-30 18:30:37 +00:00
} , 100 ) ;
2015-08-24 12:59:54 +00:00
} ) ;
2013-01-30 18:30:37 +00:00
2015-04-07 00:23:50 +00:00
} ) ;