@@ -18,6 +18,7 @@ import {
18
18
usePaymentRequestButtonSize ,
19
19
usePaymentRequestButtonTheme ,
20
20
useWooPayEnabledSettings ,
21
+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings ,
21
22
} from '../../../data' ;
22
23
import WCPaySettingsContext from 'wcpay/settings/wcpay-settings-context' ;
23
24
@@ -31,6 +32,7 @@ jest.mock( '../../../data', () => ( {
31
32
usePaymentRequestButtonTheme : jest . fn ( ) . mockReturnValue ( [ 'dark' ] ) ,
32
33
useWooPayEnabledSettings : jest . fn ( ) ,
33
34
useWooPayShowIncompatibilityNotice : jest . fn ( ) . mockReturnValue ( false ) ,
35
+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings : jest . fn ( ) ,
34
36
} ) ) ;
35
37
36
38
jest . mock ( '../payment-request-button-preview' ) ;
@@ -51,6 +53,11 @@ const getMockPaymentRequestEnabledSettings = (
51
53
52
54
const getMockWooPayEnabledSettings = ( isEnabled ) => [ isEnabled ] ;
53
55
56
+ const getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings = (
57
+ isEnabled ,
58
+ updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler
59
+ ) => [ isEnabled , updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler ] ;
60
+
54
61
const getMockPaymentRequestLocations = (
55
62
isCheckoutEnabled ,
56
63
isProductPageEnabled ,
@@ -102,6 +109,15 @@ const renderWithSettingsProvider = ( ui ) =>
102
109
103
110
describe ( 'PaymentRequestSettings' , ( ) => {
104
111
beforeEach ( ( ) => {
112
+ // Mock the global wcpaySettings
113
+ global . wcpaySettings = {
114
+ accountStatus : { } ,
115
+ restUrl : 'http://example.com/wp-json/' ,
116
+ featureFlags : {
117
+ isDynamicCheckoutPlaceOrderButtonEnabled : true ,
118
+ } ,
119
+ } ;
120
+
105
121
usePaymentRequestEnabledSettings . mockReturnValue (
106
122
getMockPaymentRequestEnabledSettings ( true , jest . fn ( ) )
107
123
) ;
@@ -113,6 +129,13 @@ describe( 'PaymentRequestSettings', () => {
113
129
useWooPayEnabledSettings . mockReturnValue (
114
130
getMockWooPayEnabledSettings ( true )
115
131
) ;
132
+
133
+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings . mockReturnValue (
134
+ getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings (
135
+ false ,
136
+ jest . fn ( )
137
+ )
138
+ ) ;
116
139
} ) ;
117
140
118
141
it ( 'renders enable settings with defaults' , ( ) => {
@@ -121,9 +144,36 @@ describe( 'PaymentRequestSettings', () => {
121
144
) ;
122
145
123
146
// confirm checkbox groups displayed
124
- const [ enableCheckbox ] = screen . queryAllByRole ( 'checkbox' ) ;
147
+ const checkboxes = screen . queryAllByRole ( 'checkbox' ) ;
125
148
126
- expect ( enableCheckbox ) . toBeInTheDocument ( ) ;
149
+ expect ( checkboxes ) . toHaveLength ( 5 ) ; // Apple/Google Pay in payment methods, express buttons, and 3 location checkboxes
150
+ } ) ;
151
+
152
+ it ( 'renders Apple Pay / Google Pay in payment methods checkbox when feature flag is enabled' , ( ) => {
153
+ renderWithSettingsProvider (
154
+ < PaymentRequestSettings section = "enable" />
155
+ ) ;
156
+
157
+ expect (
158
+ screen . getByLabelText (
159
+ 'Enable Apple Pay / Google Pay as options in the payment methods list'
160
+ )
161
+ ) . toBeInTheDocument ( ) ;
162
+ } ) ;
163
+
164
+ it ( 'does not render Apple Pay / Google Pay in payment methods checkbox when feature flag is disabled' , ( ) => {
165
+ // Mock the feature flag as disabled
166
+ global . wcpaySettings . featureFlags . isDynamicCheckoutPlaceOrderButtonEnabled = false ;
167
+
168
+ renderWithSettingsProvider (
169
+ < PaymentRequestSettings section = "enable" />
170
+ ) ;
171
+
172
+ expect (
173
+ screen . queryByLabelText (
174
+ 'Enable Apple Pay / Google Pay as options in the payment methods list'
175
+ )
176
+ ) . not . toBeInTheDocument ( ) ;
127
177
} ) ;
128
178
129
179
it ( 'triggers the hooks when the enable setting is being interacted with' , async ( ) => {
@@ -148,12 +198,61 @@ describe( 'PaymentRequestSettings', () => {
148
198
expect ( screen . getByLabelText ( 'Show on product page' ) ) . toBeChecked ( ) ;
149
199
expect ( screen . getByLabelText ( 'Show on cart page' ) ) . toBeChecked ( ) ;
150
200
151
- await userEvent . click ( screen . getByLabelText ( / E n a b l e A p p l e P a y / ) ) ;
201
+ await userEvent . click (
202
+ screen . getByLabelText ( / E n a b l e A p p l e P a y .* e x p r e s s p a y m e n t b u t t o n s / )
203
+ ) ;
152
204
expect ( updateIsPaymentRequestEnabledHandler ) . toHaveBeenCalledWith (
153
205
false
154
206
) ;
155
207
} ) ;
156
208
209
+ it ( 'triggers the Apple Pay / Google Pay in payment methods hook when the checkbox is interacted with' , async ( ) => {
210
+ const updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler = jest . fn ( ) ;
211
+
212
+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings . mockReturnValue (
213
+ getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings (
214
+ true ,
215
+ updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler
216
+ )
217
+ ) ;
218
+
219
+ renderWithSettingsProvider (
220
+ < PaymentRequestSettings section = "enable" />
221
+ ) ;
222
+
223
+ expect (
224
+ updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler
225
+ ) . not . toHaveBeenCalled ( ) ;
226
+
227
+ await userEvent . click (
228
+ screen . getByLabelText (
229
+ 'Enable Apple Pay / Google Pay as options in the payment methods list'
230
+ )
231
+ ) ;
232
+ expect (
233
+ updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler
234
+ ) . toHaveBeenCalledWith ( false ) ;
235
+ } ) ;
236
+
237
+ it ( 'displays the correct checked state for Apple Pay / Google Pay in payment methods checkbox' , ( ) => {
238
+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings . mockReturnValue (
239
+ getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings (
240
+ true ,
241
+ jest . fn ( )
242
+ )
243
+ ) ;
244
+
245
+ renderWithSettingsProvider (
246
+ < PaymentRequestSettings section = "enable" />
247
+ ) ;
248
+
249
+ expect (
250
+ screen . getByLabelText (
251
+ 'Enable Apple Pay / Google Pay as options in the payment methods list'
252
+ )
253
+ ) . toBeChecked ( ) ;
254
+ } ) ;
255
+
157
256
it ( 'renders general settings with defaults' , ( ) => {
158
257
renderWithSettingsProvider (
159
258
< PaymentRequestSettings section = "general" />
0 commit comments