@@ -15,24 +15,84 @@ describe( 'Modal:', function() {
15
15
describe ( 'Modals' , function ( ) {
16
16
it ( 'Should open and close correctly' , function ( done ) {
17
17
modal1 . modal ( ) ;
18
+ expect ( modal1 ) . toBeHidden ( 'Modal should be hidden' ) ;
18
19
19
20
click ( trigger1 [ 0 ] ) ;
20
21
21
22
setTimeout ( function ( ) {
23
+ expect ( modal1 ) . toBeVisible ( 'Modal should be shown' ) ;
24
+ expect ( modal1 . hasClass ( 'open' ) ) . toEqual ( true , 'Modal should have class open' ) ;
25
+
22
26
// Check overlay is attached
23
27
var overlay = modal1 . modal ( 'getInstance' ) . $overlay ;
24
28
var overlayInDOM = $ . contains ( document , overlay [ 0 ] ) ;
25
29
expect ( overlayInDOM ) . toEqual ( true , 'Overlay should be attached on open' ) ;
26
30
27
31
click ( overlay [ 0 ] ) ;
28
32
setTimeout ( function ( ) {
33
+ expect ( modal1 . hasClass ( 'open' ) ) . toEqual ( false , 'Modal should have class open removed' ) ;
34
+
29
35
var overlayInDOM = $ . contains ( document , overlay [ 0 ] ) ;
30
36
expect ( overlayInDOM ) . toEqual ( false , 'Overlay should be removed on close' ) ;
31
37
32
38
done ( ) ;
33
39
} , 500 ) ;
34
40
} , 500 ) ;
35
41
} ) ;
42
+
43
+ it ( 'Should have a dismissible option' , function ( done ) {
44
+ modal1 . modal ( {
45
+ dismissible : false
46
+ } ) ;
47
+
48
+ click ( trigger1 [ 0 ] ) ;
49
+ setTimeout ( function ( ) {
50
+ expect ( modal1 ) . toBeVisible ( 'Modal should be shown' ) ;
51
+ var overlay = modal1 . modal ( 'getInstance' ) . $overlay ;
52
+ var overlayInDOM = $ . contains ( document , overlay [ 0 ] ) ;
53
+ expect ( overlayInDOM ) . toEqual ( true , 'Overlay should be attached on open' ) ;
54
+
55
+ click ( overlay [ 0 ] ) ;
56
+ setTimeout ( function ( ) {
57
+ expect ( modal1 ) . toBeVisible ( 'Modal should be shown' ) ;
58
+ var overlayInDOM = $ . contains ( document , overlay [ 0 ] ) ;
59
+ expect ( overlayInDOM ) . toEqual ( true , 'modal should not be dismissable' ) ;
60
+
61
+ done ( ) ;
62
+ } , 500 ) ;
63
+ } , 500 ) ;
64
+ } ) ;
65
+
66
+ it ( 'Should have callbacks' , function ( done ) {
67
+ var readyTest = false ;
68
+ var completeTest = false ;
69
+ modal1 . modal ( {
70
+ ready : function ( ) {
71
+ readyTest = true ;
72
+ } ,
73
+ complete : function ( ) {
74
+ completeTest = true ;
75
+ }
76
+ } ) ;
77
+
78
+ expect ( readyTest ) . toEqual ( false , 'callback not yet fired' ) ;
79
+ expect ( completeTest ) . toEqual ( false , 'callback not yet fired' ) ;
80
+
81
+ click ( trigger1 [ 0 ] ) ;
82
+ setTimeout ( function ( ) {
83
+ expect ( readyTest ) . toEqual ( true , 'callback fired' ) ;
84
+ expect ( completeTest ) . toEqual ( false , 'callback not yet fired' ) ;
85
+
86
+ var overlay = modal1 . modal ( 'getInstance' ) . $overlay ;
87
+ click ( overlay [ 0 ] ) ;
88
+ setTimeout ( function ( ) {
89
+ expect ( readyTest ) . toEqual ( true , 'callback fired' ) ;
90
+ expect ( completeTest ) . toEqual ( true , 'callback fired' ) ;
91
+
92
+ done ( ) ;
93
+ } , 500 ) ;
94
+ } , 500 ) ;
95
+ } ) ;
36
96
} ) ;
37
97
38
98
} ) ;
0 commit comments