@@ -18,6 +18,7 @@ import {
1818 usePaymentRequestButtonSize ,
1919 usePaymentRequestButtonTheme ,
2020 useWooPayEnabledSettings ,
21+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings ,
2122} from '../../../data' ;
2223import WCPaySettingsContext from 'wcpay/settings/wcpay-settings-context' ;
2324
@@ -31,6 +32,7 @@ jest.mock( '../../../data', () => ( {
3132 usePaymentRequestButtonTheme : jest . fn ( ) . mockReturnValue ( [ 'dark' ] ) ,
3233 useWooPayEnabledSettings : jest . fn ( ) ,
3334 useWooPayShowIncompatibilityNotice : jest . fn ( ) . mockReturnValue ( false ) ,
35+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings : jest . fn ( ) ,
3436} ) ) ;
3537
3638jest . mock ( '../payment-request-button-preview' ) ;
@@ -51,6 +53,11 @@ const getMockPaymentRequestEnabledSettings = (
5153
5254const getMockWooPayEnabledSettings = ( isEnabled ) => [ isEnabled ] ;
5355
56+ const getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings = (
57+ isEnabled ,
58+ updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler
59+ ) => [ isEnabled , updateIsAppleGooglePayInPaymentMethodsOptionsEnabledHandler ] ;
60+
5461const getMockPaymentRequestLocations = (
5562 isCheckoutEnabled ,
5663 isProductPageEnabled ,
@@ -102,6 +109,15 @@ const renderWithSettingsProvider = ( ui ) =>
102109
103110describe ( 'PaymentRequestSettings' , ( ) => {
104111 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+
105121 usePaymentRequestEnabledSettings . mockReturnValue (
106122 getMockPaymentRequestEnabledSettings ( true , jest . fn ( ) )
107123 ) ;
@@ -113,6 +129,13 @@ describe( 'PaymentRequestSettings', () => {
113129 useWooPayEnabledSettings . mockReturnValue (
114130 getMockWooPayEnabledSettings ( true )
115131 ) ;
132+
133+ useAppleGooglePayInPaymentMethodsOptionsEnabledSettings . mockReturnValue (
134+ getMockAppleGooglePayInPaymentMethodsOptionsEnabledSettings (
135+ false ,
136+ jest . fn ( )
137+ )
138+ ) ;
116139 } ) ;
117140
118141 it ( 'renders enable settings with defaults' , ( ) => {
@@ -121,9 +144,36 @@ describe( 'PaymentRequestSettings', () => {
121144 ) ;
122145
123146 // confirm checkbox groups displayed
124- const [ enableCheckbox ] = screen . queryAllByRole ( 'checkbox' ) ;
147+ const checkboxes = screen . queryAllByRole ( 'checkbox' ) ;
125148
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 ( ) ;
127177 } ) ;
128178
129179 it ( 'triggers the hooks when the enable setting is being interacted with' , async ( ) => {
@@ -148,12 +198,61 @@ describe( 'PaymentRequestSettings', () => {
148198 expect ( screen . getByLabelText ( 'Show on product page' ) ) . toBeChecked ( ) ;
149199 expect ( screen . getByLabelText ( 'Show on cart page' ) ) . toBeChecked ( ) ;
150200
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+ ) ;
152204 expect ( updateIsPaymentRequestEnabledHandler ) . toHaveBeenCalledWith (
153205 false
154206 ) ;
155207 } ) ;
156208
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+
157256 it ( 'renders general settings with defaults' , ( ) => {
158257 renderWithSettingsProvider (
159258 < PaymentRequestSettings section = "general" />
0 commit comments