diff --git a/paypal/js/frontend.js b/paypal/js/frontend.js index 39b5f95adb..e956b07bd3 100644 --- a/paypal/js/frontend.js +++ b/paypal/js/frontend.js @@ -947,6 +947,7 @@ const supportedColors = [ 'silver', 'black', 'white' ]; const supportedColorsMap = { + paypal: [ 'gold', 'blue' ], venmo: [ 'blue' ], paylater: [ 'gold', 'blue' ] }; diff --git a/tests/js/paypalBootstrap.test.mjs b/tests/js/paypalBootstrap.test.mjs index c6c4ba37dc..57ee64d211 100644 --- a/tests/js/paypalBootstrap.test.mjs +++ b/tests/js/paypalBootstrap.test.mjs @@ -200,3 +200,44 @@ test( 'cancelling while another order is still in flight leaves Submit state alo assert.equal( result.running, 1 ); assert.deepEqual( result.updated, [] ); } ); + +/** + * Run the real createPayPalButton() and return the config passed to paypal.Buttons(). + * + * @param {string} fundingSource The PayPal FUNDING constant. + * @param {string} color The saved button color. + * + * @return {Object} The button config. + */ +function createButtonConfig( fundingSource, color ) { + const start = source.indexOf( '\tfunction createPayPalButton(' ); + const end = source.indexOf( '\n\t// ---- Google Pay ----', start ); + assert.ok( start >= 0 && end > start, 'Button creation boundaries must exist.' ); + let config; + const context = { + frmPayPalVars: { buttonStyle: { color, label: 'paypal' } }, + paypal: { + Buttons: buttonConfig => { + config = buttonConfig; + } + }, + onApprove() {}, + onError() {}, + onCancel() {}, + createOrder() {}, + createSubscription() {}, + }; + runInNewContext( `${ source.slice( start, end ) }\ncreatePayPalButton( fundingSource, false );`, { ...context, fundingSource } ); + return config; +} + +test( 'the PayPal button keeps every color PayPal supports for it', () => { + [ 'gold', 'blue', 'silver', 'white', 'black' ].forEach( color => { + assert.equal( createButtonConfig( 'paypal', color ).style.color, color ); + } ); +} ); + +test( 'a funding source drops a color it does not support', () => { + assert.equal( 'color' in createButtonConfig( 'venmo', 'gold' ).style, false ); + assert.equal( 'color' in createButtonConfig( 'paypal', 'purple' ).style, false ); +} );