Skip to content

Commit 3634860

Browse files
Add e2e tests for express checkout (Link) (#3846)
* Add e2e test for Link in product page * Add e2e test for enabling Link in settings * Add e2e tests for other pages * Make adding to cart step less flaky * Add changelog and readme entries --------- Co-authored-by: Diego Curbelo <[email protected]>
1 parent 344996f commit 3634860

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.2.0 - xxxx-xx-xx =
4+
* Dev - Add new E2E tests for Link express checkout.
45
* Add - Add Amazon Pay to block cart and block checkout.
56
* Fix - Remove intentional delay when displaying tax-related notice for express checkout, causing click event to time out.
67
* Fix - Fixes an issue when saving Bancontact and iDEAL methods with SEPA Direct Debit disabled.

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.2.0 - xxxx-xx-xx =
114+
* Dev - Add new E2E tests for Link express checkout.
114115
* Add - Add Amazon Pay to block cart and block checkout.
115116
* Fix - Remove intentional delay when displaying tax-related notice for express checkout, causing click event to time out.
116117
* Fix - Fixes an issue when saving Bancontact and iDEAL methods with SEPA Direct Debit disabled.

tests/e2e/tests/default.setup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ setup( 'Disable legacy checkout experience', async ( { browser } ) => {
2121
page.getByTestId( 'legacy-checkout-experience-checkbox' )
2222
).not.toBeChecked();
2323
} );
24+
25+
setup( 'enable Link', async ( { browser } ) => {
26+
const adminContext = await browser.newContext( {
27+
storageState: process.env.ADMINSTATE,
28+
} );
29+
const page = await adminContext.newPage();
30+
31+
await page.goto(
32+
'/wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=methods'
33+
);
34+
await page.getByLabel( 'Link by Stripe Input' ).check();
35+
await page.click( 'text=Save changes' );
36+
37+
await expect( page.getByText( 'Settings saved.' ) ).toBeDefined();
38+
await expect( page.getByLabel( 'Link by Stripe Input' ) ).toBeChecked();
39+
} );
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { test, expect } = require( '@playwright/test' );
2+
3+
const addProductToCart = async ( page, productSlug = 'beanie' ) => {
4+
// Add a product to the cart
5+
await page.goto( `/product/${ productSlug }` );
6+
7+
const addToCartButton = await page.getByRole( 'button', {
8+
name: 'Add to cart',
9+
} );
10+
await expect( addToCartButton ).toBeEnabled();
11+
await addToCartButton.dispatchEvent( 'click' );
12+
13+
// Wait for the cart update to complete - look for success message or cart count update
14+
await expect(
15+
page.getByText( 'has been added to your cart' )
16+
).toBeVisible();
17+
};
18+
19+
const testLink = async ( page, navigateTo, isBlockPage = false ) => {
20+
await page.goto( navigateTo );
21+
22+
let frameLocator;
23+
if ( isBlockPage ) {
24+
frameLocator = await page.frameLocator(
25+
'#express-payment-method-express_checkout_element_link iframe[name^="__privateStripeFrame"]'
26+
);
27+
} else {
28+
frameLocator = await page.frameLocator(
29+
'#wc-stripe-express-checkout-element-link iframe[name^="__privateStripeFrame"]'
30+
);
31+
}
32+
const linkButton = await frameLocator.getByRole( 'button', {
33+
name: 'Pay with Link',
34+
} );
35+
await expect( linkButton ).toBeEnabled();
36+
37+
const context = await page.context();
38+
const [ popup ] = await Promise.all( [
39+
context.waitForEvent( 'page' ),
40+
linkButton.dispatchEvent( 'click' ),
41+
] );
42+
43+
// Check that the payment modal gets loaded.
44+
await popup.waitForLoadState();
45+
46+
// Back in the main window, check that Link's "Continue payment" button is visible.
47+
const continuePaymentButton = await page.getByRole( 'button', {
48+
name: 'Continue payment',
49+
} );
50+
await expect( continuePaymentButton ).toBeVisible();
51+
};
52+
53+
test.describe( 'customer can use Link express checkout', () => {
54+
test( 'inside the product page', async ( { page } ) =>
55+
await testLink( page, '/product/beanie' ) );
56+
57+
test( 'inside the cart page (classic)', async ( { page } ) => {
58+
await addProductToCart( page );
59+
await testLink( page, '/cart-shortcode', false );
60+
} );
61+
62+
test( 'inside the checkout page (classic)', async ( { page } ) => {
63+
await addProductToCart( page );
64+
await testLink( page, '/checkout-shortcode', false );
65+
} );
66+
67+
test( 'inside the cart page (block)', async ( { page } ) => {
68+
await addProductToCart( page );
69+
await testLink( page, '/cart', true );
70+
} );
71+
72+
test( 'inside the checkout page (block)', async ( { page } ) => {
73+
await addProductToCart( page );
74+
await testLink( page, '/checkout', true );
75+
} );
76+
} );

0 commit comments

Comments
 (0)