Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions paypal/js/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@

const supportedColors = [ 'silver', 'black', 'white' ];
const supportedColorsMap = {
paypal: [ 'gold', 'blue' ],
venmo: [ 'blue' ],
paylater: [ 'gold', 'blue' ]
};
Expand Down
41 changes: 41 additions & 0 deletions tests/js/paypalBootstrap.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onApprove'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onApprove'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

onError() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onError'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onError'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

onCancel() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onCancel'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'onCancel'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

createOrder() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'createOrder'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'createOrder'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

createSubscription() {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'createSubscription'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty method 'createSubscription'


Having empty functions hurts readability, and is considered a code-smell. There's almost always a way to avoid using them. If you must use one, consider adding a comment to inform the reader of its purpose.

};
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 );
} );
Loading