Repository navigation
SQUARE-355: Duplicate credit card field rendered on checkout in Chrome (classic checkout) #571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bab1214
SQUARE-355: Prevent a duplicate card field when a checkout update lan…
faisal-alvi d2a0005
Merge branch 'trunk' into SQUARE-355
iamdharmesh 906361a
Await failed card cleanup before replaying queued refresh and add car…
faisal-alvi edc4eb5
Merge branch 'trunk' into SQUARE-355
faisal-alvi 6dd4b0b
Wrap Square SDK after it loads in card form lifecycle e2e tests
faisal-alvi 05060d8
Slim down card form race fix and simplify lifecycle e2e tests
faisal-alvi 816612b
Merge branch 'trunk' into SQUARE-355
iamdharmesh c414d42
Merge branch 'trunk' into SQUARE-355
iamdharmesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { chromium } from 'playwright'; | ||
| import { addOneOrMoreProductToCart } from '@woocommerce/e2e-utils-playwright'; | ||
|
|
||
| import { | ||
| fillAddressFields, | ||
| fillCreditCardFields, | ||
| visitCheckout, | ||
| doesProductExist, | ||
| createProduct, | ||
| placeOrder, | ||
| waitForUnBlock, | ||
| } from '../utils/helper'; | ||
|
|
||
| const cardFrame = '#wc-square-credit-card-container .sq-card-component'; | ||
|
|
||
| /** | ||
| * Recreates the conditions that rendered the card field twice: Square is slow to build the card, | ||
| * and another plugin (e.g. a delivery date picker) triggers a checkout update as the page loads. | ||
| * | ||
| * @param {Object} page Playwright page object. | ||
| */ | ||
| async function slowCardWithCheckoutUpdate( page ) { | ||
| await page.route( /squarecdn\.com|squareupsandbox\.com/, async ( route ) => { | ||
| await new Promise( ( resolve ) => setTimeout( resolve, 1500 ) ); | ||
| await route.continue().catch( () => {} ); | ||
| } ); | ||
|
|
||
| await page.addInitScript( () => { | ||
| document.addEventListener( 'DOMContentLoaded', () => { | ||
| jQuery( document.body ).one( 'updated_checkout', () => { | ||
| jQuery( document.body ).trigger( 'update_checkout' ); | ||
| } ); | ||
| } ); | ||
| } ); | ||
| } | ||
|
|
||
| test.beforeAll( 'Setup', async ( { baseURL } ) => { | ||
| const browser = await chromium.launch(); | ||
| const page = await browser.newPage(); | ||
|
|
||
| if ( ! ( await doesProductExist( baseURL, 'simple-product' ) ) ) { | ||
| await createProduct( page, { | ||
| name: 'Simple Product', | ||
| regularPrice: '14.99', | ||
| sku: 'simple-product', | ||
| } ); | ||
|
|
||
| await expect( page.getByText( 'Product published' ) ).toBeVisible(); | ||
| } | ||
|
|
||
| await browser.close(); | ||
| } ); | ||
|
|
||
| test( '[non-Block]: Checkout update while the card is loading renders a single card field @general', async ( { | ||
| page, | ||
| } ) => { | ||
| await slowCardWithCheckoutUpdate( page ); | ||
| await addOneOrMoreProductToCart( page, 'simple-product' ); | ||
| await visitCheckout( page, false ); | ||
| await fillAddressFields( page, false ); | ||
|
|
||
| await expect( page.locator( cardFrame ) ).toHaveCount( 1 ); | ||
| await fillCreditCardFields( page, true, false ); | ||
|
|
||
| // Give a late duplicate time to mount before checking again. | ||
| await page.waitForTimeout( 3000 ); | ||
| await expect( page.locator( cardFrame ) ).toHaveCount( 1 ); | ||
|
|
||
| await placeOrder( page, false ); | ||
| await expect( page.locator( '.entry-title' ) ).toHaveText( 'Order received' ); | ||
| } ); | ||
|
|
||
| test( '[non-Block]: Placing an order before the card field is ready shows an error and can be retried @general', async ( { | ||
| page, | ||
| } ) => { | ||
| await slowCardWithCheckoutUpdate( page ); | ||
| await addOneOrMoreProductToCart( page, 'simple-product' ); | ||
| await visitCheckout( page, false ); | ||
|
|
||
| await page.locator( 'label[for="payment_method_square_credit_card"]' ).click(); | ||
| await expect( page.locator( cardFrame ) ).toHaveCount( 0 ); | ||
| await page.locator( '#place_order' ).click(); | ||
|
|
||
| await expect( | ||
| page | ||
| .getByText( 'An error occurred, please try again or try an alternate form of payment.' ) | ||
| .first() | ||
| ).toBeVisible(); | ||
|
|
||
| await waitForUnBlock( page ); | ||
| await fillAddressFields( page, false ); | ||
| await fillCreditCardFields( page, true, false ); | ||
| await expect( page.locator( cardFrame ) ).toHaveCount( 1 ); | ||
|
|
||
| await placeOrder( page, false ); | ||
| await expect( page.locator( '.entry-title' ) ).toHaveText( 'Order received' ); | ||
| } ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.