@@ -53,62 +53,45 @@ define([
53
53
54
54
expect ( type ) . toEqual ( 'object' ) ;
55
55
} ) ;
56
- it ( 'Check "beforeSave" method. Check call "filterFormData" inside themselves.' , function ( ) {
56
+ it ( 'Check "beforeSave" method. ' +
57
+ 'Check calls "filterFormData", "serialize" and "ajax" inside themselves.' , function ( ) {
57
58
var data = {
58
59
key : {
59
60
anotherKey : 'value'
60
61
} ,
61
62
anotherKey : [ ]
62
- } ;
63
+ } ,
64
+ params ;
63
65
64
66
obj . urls . beforeSave = 'requestPath' ;
65
67
obj . selectorPrefix = 'selectorPrefix' ;
66
68
obj . messagesClass = 'messagesClass' ;
67
- utils . filterFormData = jasmine . createSpy ( ) . and . returnValue ( utils . filterFormData ( data ) ) ;
68
-
69
- obj . save ( data ) ;
70
- expect ( utils . filterFormData ) . toHaveBeenCalledWith ( data ) ;
71
- } ) ;
72
- it ( 'Check "beforeSave" method. Check call "serialize" inside themselves.' , function ( ) {
73
- var data = {
74
- key : {
75
- anotherKey : 'value'
76
- } ,
77
- anotherKey : [ ]
78
- } ;
79
69
80
- obj . urls . beforeSave = 'requestPath' ;
81
- obj . selectorPrefix = 'selectorPrefix' ;
82
- obj . messagesClass = 'messagesClass' ;
83
- utils . serialize = jasmine . createSpy ( ) . and . returnValue ( utils . serialize ( data ) ) ;
70
+ params = {
71
+ url : obj . urls . beforeSave ,
72
+ data : _ . extend ( data , {
73
+ form_key : 'magentoFormKey'
74
+ } ) ,
75
+ success : jasmine . any ( Function ) ,
76
+ complete : jasmine . any ( Function )
77
+ } ;
78
+
79
+ utils . filterFormData = jasmine . createSpy ( ) . and . returnValue ( data ) ;
80
+ utils . serialize = jasmine . createSpy ( ) . and . returnValue ( data ) ;
81
+ $ . ajax = jasmine . createSpy ( ) ;
84
82
85
83
obj . save ( data ) ;
84
+ expect ( utils . filterFormData ) . toHaveBeenCalledWith ( data ) ;
86
85
expect ( utils . serialize ) . toHaveBeenCalledWith ( data ) ;
87
- } ) ;
88
- it ( 'Check "beforeSave" method. Check call "ajax" inside themselves.' , function ( ) {
89
- var data = {
90
- key : {
91
- anotherKey : 'value'
92
- } ,
93
- 'anotherKey-prepared-for-send' : [ ]
94
- } ,
95
- result = {
96
- url : obj . urls . beforeSave ,
97
- data : {
98
- 'key[anotherKey]' : 'value' ,
99
- 'form_key' : 'magentoFormKey'
100
- } ,
101
- success : jasmine . any ( Function ) ,
102
- complete : jasmine . any ( Function )
103
- } ;
86
+ expect ( $ . ajax ) . toHaveBeenCalledWith ( params ) ;
104
87
105
- obj . urls . beforeSave = 'requestPath' ;
106
- obj . selectorPrefix = 'selectorPrefix' ;
107
- obj . messagesClass = 'messagesClass' ;
88
+ } ) ;
89
+ it ( 'Check call "beforeSave" method without parameters' , function ( ) {
108
90
$ . ajax = jasmine . createSpy ( ) ;
91
+ obj . urls . beforeSave = null ;
92
+ obj . save ( ) ;
109
93
110
- obj . save ( data ) ;
111
- expect ( $ . ajax ) . toHaveBeenCalledWith ( result ) ;
94
+ expect ( $ . ajax ) . not . toHaveBeenCalled ( ) ;
112
95
} ) ;
113
96
} ) ;
114
97
0 commit comments