@@ -41,38 +41,40 @@ define(['squire'
41
41
42
42
expect ( placeOrderMixins [ 'Magento_ReCaptchaCheckout/js/model/place-order-mixin' ] ) . toBe ( true ) ;
43
43
} ) ;
44
+ } ) ;
45
+
46
+ describe ( 'Magento_Checkout/js/action/redirect-on-success is called' , function ( ) {
47
+ var recaptchaId = 'recaptcha-checkout-place-order' ,
48
+ messageContainer = jasmine . createSpy ( 'messageContainer' ) ,
49
+ payload = { } ,
50
+ serviceUrl = 'test' ,
44
51
45
- it ( 'Magento_Checkout/js/action/redirect-on-success is called' , function ( ) {
46
- let recaptchaId = 'recaptcha-checkout-place-order' ,
47
- messageContainer = jasmine . createSpy ( 'messageContainer' ) ,
48
- payload = { } ,
49
- serviceUrl = 'test' ,
50
-
51
- /**
52
- * Order place action mock
53
- *
54
- * @returns {{fail: fail, done: (function(Function): *)} }
55
- */
56
- action = function ( ) {
57
- return {
58
- /**
59
- * Success result for request
60
- *
61
- * @param {Function } handler
62
- * @returns {* }
63
- */
64
- done : function ( handler ) {
65
- handler ( ) ;
66
- return this ;
67
- } ,
68
-
69
- /**
70
- * Fail result for request
71
- */
72
- fail : function ( ) { }
73
- } ;
52
+ /**
53
+ * Order place action mock
54
+ *
55
+ * @returns {{fail: fail, done: (function(Function): *)} }
56
+ */
57
+ action = function ( ) {
58
+ return {
59
+ /**
60
+ * Success result for request
61
+ *
62
+ * @param {Function } handler
63
+ * @returns {* }
64
+ */
65
+ done : function ( handler ) {
66
+ handler ( ) ;
67
+ return this ;
68
+ } ,
69
+
70
+ /**
71
+ * Fail result for request
72
+ */
73
+ fail : function ( ) { }
74
74
} ;
75
+ } ;
75
76
77
+ it ( 'Only PlaceOrder button triggers place order action' , function ( ) {
76
78
/**
77
79
* Triggers declared listener
78
80
*
@@ -93,9 +95,39 @@ define(['squire'
93
95
registry . addListener = function ( id , func ) {
94
96
registry . _listeners [ id ] = func ;
95
97
} ;
98
+
96
99
registry . removeListener = jasmine . createSpy ( ) ;
97
100
mixin ( ) ( action , serviceUrl , payload , messageContainer ) ;
98
101
expect ( registry . removeListener ) . toHaveBeenCalledWith ( recaptchaId ) ;
99
102
} ) ;
103
+
104
+ it ( 'PlaceOrder Listener is called for invisible google recaptcha' , function ( ) {
105
+ /**
106
+ * Triggers declared listener
107
+ *
108
+ * @returns {* }
109
+ */
110
+ registry . triggers [ recaptchaId ] = function ( ) {
111
+ if ( registry . _listeners [ recaptchaId ] !== undefined ) {
112
+ return registry . _listeners [ recaptchaId ] ( 'token' ) ;
113
+ }
114
+ } ;
115
+
116
+ /**
117
+ * Registers a listener
118
+ *
119
+ * @param id
120
+ * @param func
121
+ */
122
+ registry . addListener = function ( id , func ) {
123
+ registry . _listeners [ id ] = func ;
124
+ } ;
125
+
126
+ registry . _isInvisibleType [ recaptchaId ] = true ;
127
+ registry . removeListener = jasmine . createSpy ( ) ;
128
+ mixin ( ) ( action , serviceUrl , payload , messageContainer ) ;
129
+
130
+ expect ( registry . removeListener ) . not . toHaveBeenCalled ( ) ;
131
+ } ) ;
100
132
} ) ;
101
133
} ) ;
0 commit comments