@@ -34,7 +34,9 @@ test("init", function() {
34
34
} ) ;
35
35
36
36
test ( "destroy" , function ( ) {
37
- expect ( 7 ) ;
37
+ expect ( 17 ) ;
38
+
39
+ var el , el2 ;
38
40
39
41
$ ( "#dialog1, #form-dialog" ) . hide ( ) ;
40
42
domEqual ( "#dialog1" , function ( ) {
@@ -57,6 +59,35 @@ test("destroy", function() {
57
59
domEqual ( "#dialog1" , function ( ) {
58
60
$ ( "#dialog1" ) . dialog ( ) . dialog ( "destroy" ) ;
59
61
} ) ;
62
+
63
+ // Don't throw errors when destroying a never opened modal dialog (#9004)
64
+ $ ( "#dialog1" ) . dialog ( { autoOpen : false , modal : true } ) . dialog ( "destroy" ) ;
65
+ equal ( $ ( ".ui-widget-overlay" ) . length , 0 , "overlay does not exist" ) ;
66
+ equal ( $ . ui . dialog . overlayInstances , 0 , "overlayInstances equals the number of open overlays" ) ;
67
+
68
+ el = $ ( "#dialog1" ) . dialog ( { modal : true } ) ,
69
+ el2 = $ ( "#dialog2" ) . dialog ( { modal : true } ) ;
70
+ equal ( $ ( ".ui-widget-overlay" ) . length , 2 , "overlays created when dialogs are open" ) ;
71
+ equal ( $ . ui . dialog . overlayInstances , 2 , "overlayInstances equals the number of open overlays" ) ;
72
+ el . dialog ( "close" ) ;
73
+ equal ( $ ( ".ui-widget-overlay" ) . length , 1 , "overlay remains after closing one dialog" ) ;
74
+ equal ( $ . ui . dialog . overlayInstances , 1 , "overlayInstances equals the number of open overlays" ) ;
75
+ el . dialog ( "destroy" ) ;
76
+ equal ( $ ( ".ui-widget-overlay" ) . length , 1 , "overlay remains after destroying one dialog" ) ;
77
+ equal ( $ . ui . dialog . overlayInstances , 1 , "overlayInstances equals the number of open overlays" ) ;
78
+ el2 . dialog ( "destroy" ) ;
79
+ equal ( $ ( ".ui-widget-overlay" ) . length , 0 , "overlays removed when all dialogs are destoryed" ) ;
80
+ equal ( $ . ui . dialog . overlayInstances , 0 , "overlayInstances equals the number of open overlays" ) ;
81
+ } ) ;
82
+
83
+ asyncTest ( "#9000: Dialog leaves broken event handler after close/destroy in certain cases" , function ( ) {
84
+ expect ( 1 ) ;
85
+ $ ( "#dialog1" ) . dialog ( { modal :true } ) . dialog ( "close" ) . dialog ( "destroy" ) ;
86
+ setTimeout ( function ( ) {
87
+ $ ( "#favorite-animal" ) . focus ( ) ;
88
+ ok ( true , "close and destroy modal dialog before its really opened" ) ;
89
+ start ( ) ;
90
+ } , 2 ) ;
60
91
} ) ;
61
92
62
93
test ( "#4980: Destroy should place element back in original DOM position" , function ( ) {
0 commit comments