define( [ "qunit", "jquery", "ui/widgets/dialog" ], function( QUnit, $ ) { QUnit.module( "dialog: methods", { afterEach: function() { $( "body>.ui-dialog" ).remove(); } } ); QUnit.test( "init", function( assert ) { assert.expect( 6 ); $( "
" ).appendTo( "body" ).dialog().remove(); assert.ok( true, ".dialog() called on element" ); $( [] ).dialog().remove(); assert.ok( true, ".dialog() called on empty collection" ); $( "" ).dialog().remove(); assert.ok( true, ".dialog() called on disconnected DOMElement - never connected" ); $( "" ).appendTo( "body" ).remove().dialog().remove(); assert.ok( true, ".dialog() called on disconnected DOMElement - removed" ); var element = $( "" ).dialog(); element.dialog( "option", "foo" ); element.remove(); assert.ok( true, "arbitrary option getter after init" ); $( "" ).dialog().dialog( "option", "foo", "bar" ).remove(); assert.ok( true, "arbitrary option setter after init" ); } ); QUnit.test( "destroy", function( assert ) { assert.expect( 17 ); var element, element2; $( "#dialog1, #form-dialog" ).hide(); assert.domEqual( "#dialog1", function() { var dialog = $( "#dialog1" ).dialog().dialog( "destroy" ); assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); assert.equal( dialog.index(), 0 ); } ); assert.domEqual( "#form-dialog", function() { var dialog = $( "#form-dialog" ).dialog().dialog( "destroy" ); assert.equal( dialog.parent()[ 0 ], $( "#qunit-fixture" )[ 0 ] ); assert.equal( dialog.index(), 2 ); } ); // Ensure dimensions are restored (#8119) $( "#dialog1" ).show().css( { width: "400px", minHeight: "100px", height: "200px" } ); assert.domEqual( "#dialog1", function() { $( "#dialog1" ).dialog().dialog( "destroy" ); } ); // Don't throw errors when destroying a never opened modal dialog (#9004) $( "#dialog1" ).dialog( { autoOpen: false, modal: true } ).dialog( "destroy" ); assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlay does not exist" ); assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); element = $( "#dialog1" ).dialog( { modal: true } ), element2 = $( "#dialog2" ).dialog( { modal: true } ); assert.equal( $( ".ui-widget-overlay" ).length, 2, "overlays created when dialogs are open" ); assert.equal( $( document ).data( "ui-dialog-overlays" ), 2, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "close" ); assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after closing one dialog" ); assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element.dialog( "destroy" ); assert.equal( $( ".ui-widget-overlay" ).length, 1, "overlay remains after destroying one dialog" ); assert.equal( $( document ).data( "ui-dialog-overlays" ), 1, "ui-dialog-overlays equals the number of open overlays" ); element2.dialog( "destroy" ); assert.equal( $( ".ui-widget-overlay" ).length, 0, "overlays removed when all dialogs are destoryed" ); assert.equal( $( document ).data( "ui-dialog-overlays" ), undefined, "ui-dialog-overlays equals the number of open overlays" ); } ); QUnit.test( "#9000: Dialog leaves broken event handler after close/destroy in certain cases", function( assert ) { var ready = assert.async(); assert.expect( 1 ); $( "#dialog1" ).dialog( { modal:true } ).dialog( "close" ).dialog( "destroy" ); setTimeout( function() { $( "#favorite-animal" ).trigger( "focus" ); assert.ok( true, "close and destroy modal dialog before its really opened" ); ready(); } ); } ); QUnit.test( "#4980: Destroy should place element back in original DOM position", function( assert ) { assert.expect( 2 ); var container = $( "