Skip to content

Commit f06e518

Browse files
authored
Ensure e2e tests configure Optimized Checkout correctly (#4627)
* Refactor optimized checkout setup to ensure correct starting point for e2e tests * Changelog
1 parent abad813 commit f06e518

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* Fix - Display only Apple Pay and Google Pay buttons in the Customize page preview
3030
* Update - Add nightly task and WooCommerce tool to remove stale entries from our database cache
3131
* Dev - Make 'Add to cart' more robust in e2e tests
32+
* Dev - Ensure e2e tests enable or disable Optimized Checkout during setup
3233

3334
= 9.8.1 - 2025-08-15 =
3435
* Fix - Remove connection type requirement from PMC sync migration attempt

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
139139
* Fix - Display only Apple Pay and Google Pay buttons in the Customize page preview
140140
* Update - Add nightly task and WooCommerce tool to remove stale entries from our database cache
141141
* Dev - Make 'Add to cart' more robust in e2e tests
142+
* Dev - Ensure e2e tests enable or disable Optimized Checkout during setup
142143

143144
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/e2e/tests/default.setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ setup( 'Configure store for default tests', async ( { browser } ) => {
2424
await expect( page.getByLabel( 'Link by Stripe' ) ).toBeChecked();
2525

2626
await adminContext.close();
27+
28+
await admin.initializeOptimizedCheckout( browser, false );
2729
} );
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
1-
import { test as setup, expect } from '@playwright/test';
1+
import { test as setup } from '@playwright/test';
2+
import { initializeOptimizedCheckout } from '../utils/admin';
23

34
setup(
45
'Configure store for Optimized Checkout tests',
56
async ( { browser } ) => {
6-
const adminContext = await browser.newContext( {
7-
storageState: process.env.ADMINSTATE,
8-
} );
9-
10-
const page = await adminContext.newPage();
11-
12-
// Enable SPE in the admin.
13-
await page.goto(
14-
'/wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings'
15-
);
16-
17-
const checkbox = page.getByTestId(
18-
'optimized-checkout-element-checkbox'
19-
);
20-
const isChecked = await checkbox.isChecked();
21-
22-
if ( ! isChecked ) {
23-
await checkbox.click();
24-
await page.click( 'text=Save changes' );
25-
await expect(
26-
page.locator(
27-
'.components-snackbar__content:has-text("Settings saved.")'
28-
)
29-
).toBeVisible();
30-
await expect(
31-
page.getByTestId( 'optimized-checkout-element-checkbox' )
32-
).toBeChecked();
33-
}
34-
35-
await adminContext.close();
7+
await initializeOptimizedCheckout( browser, true );
368
}
379
);

tests/e2e/utils/admin.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,52 @@ export const updateStoreCurrency = async ( browser, currency ) => {
8080
await context.close();
8181
}
8282
};
83+
84+
/**
85+
* Enable or disable the Optimized Checkout feature in Stripe settings.
86+
*
87+
* @param {Browser} browser Playwright browser fixture.
88+
* @param {boolean} shouldEnable Whether to enable or disable the Optimized Checkout element.
89+
*/
90+
export const initializeOptimizedCheckout = async (
91+
browser,
92+
shouldEnable = true
93+
) => {
94+
const adminContext = await browser.newContext( {
95+
storageState: process.env.ADMINSTATE,
96+
} );
97+
98+
const page = await adminContext.newPage();
99+
100+
await page.goto(
101+
'/wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=settings'
102+
);
103+
104+
const checkbox = page.getByTestId( 'optimized-checkout-element-checkbox' );
105+
const isChecked = await checkbox.isChecked();
106+
107+
const updateNeeded =
108+
( shouldEnable && ! isChecked ) || ( ! shouldEnable && isChecked );
109+
110+
if ( updateNeeded ) {
111+
await checkbox.click();
112+
await page.click( 'text=Save changes' );
113+
await expect(
114+
page.locator(
115+
'.components-snackbar__content:has-text("Settings saved.")'
116+
)
117+
).toBeVisible();
118+
119+
if ( shouldEnable ) {
120+
await expect(
121+
page.getByTestId( 'optimized-checkout-element-checkbox' )
122+
).toBeChecked();
123+
} else {
124+
await expect(
125+
page.getByTestId( 'optimized-checkout-element-checkbox' )
126+
).not.toBeChecked();
127+
}
128+
}
129+
130+
await adminContext.close();
131+
};

0 commit comments

Comments
 (0)