@@ -7,6 +7,13 @@ module('data-confirm', {
7
7
text : 'my social security number'
8
8
} ) ) ;
9
9
10
+ $ ( '#qunit-fixture' ) . append ( $ ( '<button />' , {
11
+ 'data-url' : '/echo' ,
12
+ 'data-remote' : 'true' ,
13
+ 'data-confirm' : 'Are you absolutely sure?' ,
14
+ text : 'Click me'
15
+ } ) ) ;
16
+
10
17
this . windowConfirm = window . confirm ;
11
18
} ,
12
19
teardown : function ( ) {
@@ -35,6 +42,28 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm yes.', 6, fun
35
42
. trigger ( 'click' ) ;
36
43
} ) ;
37
44
45
+ asyncTest ( 'clicking on a button with data-confirm attribute. Confirm yes.' , 6 , function ( ) {
46
+ var message ;
47
+ // auto-confirm:
48
+ window . confirm = function ( msg ) { message = msg ; return true } ;
49
+
50
+ $ ( 'button[data-confirm]' )
51
+ . bind ( 'confirm:complete' , function ( e , data ) {
52
+ App . assertCallbackInvoked ( 'confirm:complete' ) ;
53
+ ok ( data == true , 'confirm:complete passes in confirm answer (true)' ) ;
54
+ } )
55
+ . bind ( 'ajax:success' , function ( e , data , status , xhr ) {
56
+ console . log ( xhr ) ;
57
+ App . assertCallbackInvoked ( 'ajax:success' ) ;
58
+ App . assertRequestPath ( data , '/echo' ) ;
59
+ App . assertGetRequest ( data ) ;
60
+
61
+ equal ( message , 'Are you absolutely sure?' ) ;
62
+ start ( ) ;
63
+ } )
64
+ . trigger ( 'click' ) ;
65
+ } ) ;
66
+
38
67
asyncTest ( 'clicking on a link with data-confirm attribute. Confirm No.' , 3 , function ( ) {
39
68
var message ;
40
69
// auto-decline:
@@ -56,8 +85,28 @@ asyncTest('clicking on a link with data-confirm attribute. Confirm No.', 3, func
56
85
} , 50 ) ;
57
86
} ) ;
58
87
88
+ asyncTest ( 'clicking on a button with data-confirm attribute. Confirm No.' , 3 , function ( ) {
89
+ var message ;
90
+ // auto-decline:
91
+ window . confirm = function ( msg ) { message = msg ; return false } ;
92
+
93
+ $ ( 'button[data-confirm]' )
94
+ . bind ( 'confirm:complete' , function ( e , data ) {
95
+ App . assertCallbackInvoked ( 'confirm:complete' ) ;
96
+ ok ( data == false , 'confirm:complete passes in confirm answer (false)' ) ;
97
+ } )
98
+ . bind ( 'ajax:beforeSend' , function ( e , data , status , xhr ) {
99
+ App . assertCallbackNotInvoked ( 'ajax:beforeSend' ) ;
100
+ } )
101
+ . trigger ( 'click' ) ;
102
+
103
+ setTimeout ( function ( ) {
104
+ equal ( message , 'Are you absolutely sure?' ) ;
105
+ start ( ) ;
106
+ } , 50 ) ;
107
+ } ) ;
59
108
60
- asyncTest ( 'binding to confirm event and returning false' , 1 , function ( ) {
109
+ asyncTest ( 'binding to confirm event of a link and returning false' , 1 , function ( ) {
61
110
// redefine confirm function so we can make sure it's not called
62
111
window . confirm = function ( msg ) {
63
112
ok ( false , 'confirm dialog should not be called' ) ;
@@ -78,7 +127,28 @@ asyncTest('binding to confirm event and returning false', 1, function() {
78
127
} , 50 ) ;
79
128
} ) ;
80
129
81
- asyncTest ( 'binding to confirm:complete event and returning false' , 2 , function ( ) {
130
+ asyncTest ( 'binding to confirm event of a button and returning false' , 1 , function ( ) {
131
+ // redefine confirm function so we can make sure it's not called
132
+ window . confirm = function ( msg ) {
133
+ ok ( false , 'confirm dialog should not be called' ) ;
134
+ } ;
135
+
136
+ $ ( 'button[data-confirm]' )
137
+ . bind ( 'confirm' , function ( ) {
138
+ App . assertCallbackInvoked ( 'confirm' ) ;
139
+ return false ;
140
+ } )
141
+ . bind ( 'confirm:complete' , function ( ) {
142
+ App . assertCallbackNotInvoked ( 'confirm:complete' ) ;
143
+ } )
144
+ . trigger ( 'click' ) ;
145
+
146
+ setTimeout ( function ( ) {
147
+ start ( ) ;
148
+ } , 50 ) ;
149
+ } ) ;
150
+
151
+ asyncTest ( 'binding to confirm:complete event of a link and returning false' , 2 , function ( ) {
82
152
// auto-confirm:
83
153
window . confirm = function ( msg ) {
84
154
ok ( true , 'confirm dialog should be called' ) ;
@@ -99,3 +169,25 @@ asyncTest('binding to confirm:complete event and returning false', 2, function()
99
169
start ( ) ;
100
170
} , 50 ) ;
101
171
} ) ;
172
+
173
+ asyncTest ( 'binding to confirm:complete event of a button and returning false' , 2 , function ( ) {
174
+ // auto-confirm:
175
+ window . confirm = function ( msg ) {
176
+ ok ( true , 'confirm dialog should be called' ) ;
177
+ return true ;
178
+ } ;
179
+
180
+ $ ( 'button[data-confirm]' )
181
+ . bind ( 'confirm:complete' , function ( ) {
182
+ App . assertCallbackInvoked ( 'confirm:complete' ) ;
183
+ return false ;
184
+ } )
185
+ . bind ( 'ajax:beforeSend' , function ( ) {
186
+ App . assertCallbackNotInvoked ( 'ajax:beforeSend' ) ;
187
+ } )
188
+ . trigger ( 'click' ) ;
189
+
190
+ setTimeout ( function ( ) {
191
+ start ( ) ;
192
+ } , 50 ) ;
193
+ } ) ;
0 commit comments