@@ -11,29 +11,28 @@ define([
11
11
] , function ( $ ) {
12
12
'use strict' ;
13
13
14
- /*
15
- * jQuery ui version 1.9.2 belongs to the adminhtml.
16
- *
17
- * This test will fail on frontend since mage/backend/form only belongs to backend.
18
- */
19
14
describe ( 'Test for mage/form jQuery plugin' , function ( ) {
20
15
var id = 'edit_form' ,
21
16
elementId = '#' + id ;
17
+
22
18
beforeEach ( function ( ) {
23
19
var element = $ ( '<form id="' + id + '" action="action/url" method="GET" target="_self" ></form>' ) ;
20
+
24
21
element . appendTo ( 'body' ) ;
25
22
} ) ;
26
23
afterEach ( function ( ) {
27
24
$ ( elementId ) . remove ( ) ;
28
25
} ) ;
29
26
it ( 'check if form can be initialized' , function ( ) {
30
27
var form = $ ( elementId ) . form ( ) ;
28
+
31
29
expect ( form . is ( ':mage-form' ) ) . toBeTruthy ( ) ;
32
30
} ) ;
33
31
it ( 'check get handlers' , function ( ) {
34
32
var form = $ ( elementId ) . form ( ) ,
35
33
handlersData = form . form ( 'option' , 'handlersData' ) ,
36
34
handlers = [ ] ;
35
+
37
36
$ . each ( handlersData , function ( key ) {
38
37
handlers . push ( key ) ;
39
38
} ) ;
@@ -46,6 +45,7 @@ define([
46
45
target : form . attr ( 'target' ) ,
47
46
method : form . attr ( 'method' )
48
47
} ;
48
+
49
49
form . data ( 'mageForm' ) . _storeAttribute ( 'action' ) ;
50
50
form . data ( 'mageForm' ) . _storeAttribute ( 'target' ) ;
51
51
form . data ( 'mageForm' ) . _storeAttribute ( 'method' ) ;
@@ -57,6 +57,7 @@ define([
57
57
var form = $ ( elementId ) . form ( ) ,
58
58
submitted = false ,
59
59
handlersData = form . form ( 'option' , 'handlersData' ) ;
60
+
60
61
form . on ( 'submit' , function ( e ) {
61
62
submitted = true ;
62
63
e . stopImmediatePropagation ( ) ;
@@ -78,6 +79,7 @@ define([
78
79
arg : 'value'
79
80
}
80
81
} ;
82
+
81
83
form . data ( 'mageForm' ) . _storeAttribute ( 'action' ) ;
82
84
expect ( form . data ( 'mageForm' ) . _getActionUrl ( testArgs ) ) . toBe ( action + '/arg/value/' ) ;
83
85
expect ( form . data ( 'mageForm' ) . _getActionUrl ( testUrl ) ) . toBe ( testUrl ) ;
@@ -103,6 +105,7 @@ define([
103
105
}
104
106
} ,
105
107
processedData = form . data ( 'mageForm' ) . _processData ( testSimpleData ) ;
108
+
106
109
expect ( form . data ( 'mageForm' ) . oldAttributes . action ) . toBe ( initialFormAttrs . action ) ;
107
110
expect ( form . data ( 'mageForm' ) . oldAttributes . target ) . toBe ( initialFormAttrs . target ) ;
108
111
expect ( form . data ( 'mageForm' ) . oldAttributes . method ) . toBe ( initialFormAttrs . method ) ;
@@ -140,6 +143,7 @@ define([
140
143
method : 'POST'
141
144
} ,
142
145
resultData = $ . extend ( true , { } , testHandler , beforeSubmitData , eventData ) ;
146
+
143
147
form . data ( 'mageForm' ) . _storeAttribute ( 'action' ) ;
144
148
resultData = form . data ( 'mageForm' ) . _processData ( resultData ) ;
145
149
testForm . prop ( resultData ) ;
@@ -162,6 +166,7 @@ define([
162
166
save : { }
163
167
}
164
168
} ) ;
169
+
165
170
form . data ( 'mageForm' ) . _storeAttribute ( 'action' ) ;
166
171
form . data ( 'mageForm' ) . _storeAttribute ( 'target' ) ;
167
172
form . data ( 'mageForm' ) . _storeAttribute ( 'method' ) ;
@@ -218,7 +223,9 @@ define([
218
223
method = $ . mage . form . _proto . _buildURL ,
219
224
quantity = dataProvider . length ,
220
225
i = 0 ;
226
+
221
227
expect ( quantity ) . toBeTruthy ( ) ;
228
+
222
229
for ( i ; i < quantity ; i ++ ) {
223
230
expect ( dataProvider [ i ] . expected ) . toBe ( method . apply ( null , dataProvider [ i ] . params ) ) ;
224
231
}
0 commit comments