@@ -12,7 +12,8 @@ define([
12
12
'uiRegistry' ,
13
13
'Magento_Ui/js/form/client' ,
14
14
'jquery' ,
15
- 'mageUtils'
15
+ 'mageUtils' ,
16
+ 'jquery/ui'
16
17
] , function ( _ , registry , Constr , $ , utils ) {
17
18
'use strict' ;
18
19
@@ -78,8 +79,8 @@ define([
78
79
79
80
utils . filterFormData = jasmine . createSpy ( ) . and . returnValue ( data ) ;
80
81
utils . serialize = jasmine . createSpy ( ) . and . returnValue ( data ) ;
81
- $ . ajax = jasmine . createSpy ( ) ;
82
82
83
+ $ . ajax = jasmine . createSpy ( ) ;
83
84
obj . save ( data ) ;
84
85
expect ( utils . filterFormData ) . toHaveBeenCalledWith ( data ) ;
85
86
expect ( utils . serialize ) . toHaveBeenCalledWith ( data ) ;
@@ -93,6 +94,56 @@ define([
93
94
94
95
expect ( $ . ajax ) . not . toHaveBeenCalled ( ) ;
95
96
} ) ;
97
+ it ( 'Check call "beforeSave" method. Check "success" ajax callback with success response.' , function ( ) {
98
+ var request ;
99
+
100
+ $ . ajax = jasmine . createSpy ( ) . and . callFake ( function ( req ) {
101
+ request = req . success ;
102
+ } ) ;
103
+ $ . fn . notification = jasmine . createSpy ( ) ;
104
+ obj . urls . beforeSave = 'requestPath' ;
105
+ obj . save ( ) ;
106
+
107
+ expect ( request ( { error : false } ) ) . toBe ( true ) ;
108
+ expect ( $ ( 'body' ) . notification ) . not . toHaveBeenCalledWith ( 'clear' ) ;
109
+ } ) ;
110
+
111
+ it ( 'Check call "beforeSave" method. Check "success" ajax callback with error response.' , function ( ) {
112
+ var request ,
113
+ notificationArguments ;
114
+
115
+ $ . ajax = jasmine . createSpy ( ) . and . callFake ( function ( req ) {
116
+ request = req . success ;
117
+ } ) ;
118
+ $ . fn . notification = jasmine . createSpy ( ) ;
119
+ obj . urls . beforeSave = 'requestPath' ;
120
+ obj . save ( ) ;
121
+
122
+ notificationArguments = {
123
+ error : true ,
124
+ message : 1 ,
125
+ insertMethod : jasmine . any ( Function )
126
+ } ;
127
+
128
+ expect ( request ( {
129
+ error : true ,
130
+ messages : [ 1 ]
131
+ } ) ) . toBeUndefined ( ) ;
132
+ expect ( $ ( 'body' ) . notification . calls . allArgs ( ) ) . toEqual ( [ [ 'clear' ] , [ 'add' , notificationArguments ] ] ) ;
133
+ } ) ;
134
+ it ( 'Check call "beforeSave" method. Check "complete" ajax callback with error response.' , function ( ) {
135
+ var request ;
136
+
137
+ $ . ajax = jasmine . createSpy ( ) . and . callFake ( function ( req ) {
138
+ request = req . complete ;
139
+ } ) ;
140
+ $ . fn . trigger = jasmine . createSpy ( ) ;
141
+ obj . urls . beforeSave = 'requestPath' ;
142
+ obj . save ( ) ;
143
+
144
+ expect ( request ( ) ) . toBeUndefined ( ) ;
145
+ expect ( $ ( 'body' ) . trigger ) . toHaveBeenCalledWith ( 'processStop' ) ;
146
+ } ) ;
96
147
} ) ;
97
148
98
149
describe ( '"initialize" method' , function ( ) {
0 commit comments