Commit 9ab32d1202f for woocommerce

commit 9ab32d1202f3a0803260601f4b5a4b812e4ea991
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date:   Thu Jul 9 15:03:49 2026 +0300

    e2e tests: fix flaky Legacy MiniCart blocks e2e specs by waiting on settled cart state (#66429)

diff --git a/plugins/woocommerce/changelog/testops-216-flaky-minicart-product-button-e2e b/plugins/woocommerce/changelog/testops-216-flaky-minicart-product-button-e2e
new file mode 100644
index 00000000000..d8a9d865b03
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-216-flaky-minicart-product-button-e2e
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Stabilize flaky Legacy MiniCart blocks e2e specs (mini-cart variation attributes and product-button rapid-click) by waiting on settled cart state instead of racing Interactivity-API/AJAX updates.
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart.block_theme.spec.ts
index 6e278500b1b..19596aaa996 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart.block_theme.spec.ts
@@ -590,10 +590,30 @@ test.describe( `${ blockData.name } Block (variation attributes)`, () => {
 		await page
 			.getByLabel( 'Shade', { exact: true } )
 			.selectOption( 'Red & Blue' );
+
+		// The classic variable-product Add to cart button only registers a
+		// selection once the variations script has processed it. Until then the
+		// hidden `variation_id` input stays at "0" and clicking is a silent
+		// no-op (the disabled state is class-based, which Playwright's
+		// actionability checks ignore). Wait for the variation to be registered
+		// (a positive, non-zero variation id) before clicking.
+		await expect( page.locator( 'input.variation_id' ) ).toHaveValue(
+			/^[1-9][0-9]*$/
+		);
 		await page
 			.getByRole( 'button', { name: 'Add to cart', exact: true } )
 			.click();

+		// Wait for a definitive "added to cart" confirmation before navigating
+		// to the shop. The single-product Add to cart is a form submission; if
+		// we navigate away before it settles the item may not be in the cart
+		// when the mini-cart opens, which is what makes the assertions below
+		// race the add-to-cart request. Scope to the success notice (role=alert)
+		// so we don't match unrelated page text.
+		await expect(
+			page.getByRole( 'alert' ).getByText( /added to your cart/i )
+		).toBeVisible();
+
 		// Open the mini-cart.
 		await frontendUtils.goToShop();
 		await miniCartUtils.openMiniCart();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
index c5053a49b2c..bb13d363760 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-button/product-button.classic_theme.spec.ts
@@ -69,6 +69,7 @@ test.describe( `${ blockData.name } Block`, () => {

 	test( 'should compound quantity when rapidly clicking same button', async ( {
 		frontendUtils,
+		page,
 	} ) => {
 		const blocks = await frontendUtils.getBlockByName( blockData.slug );
 		const block = blocks.first();
@@ -77,11 +78,20 @@ test.describe( `${ blockData.name } Block`, () => {
 			state: 'detached',
 		} );

+		// Set up waitForResponse BEFORE the clicks to avoid a race condition:
+		// on fast networks the batched Store API request may complete before we
+		// start listening. Asserting before the request settles is what makes
+		// this test flaky. Mirrors the add-to-cart-with-options rapid-click test.
+		const batchPromise = page.waitForResponse( '**/wc/store/v1/batch**' );
+
 		// Click the same button 3 times rapidly.
 		await block.click();
 		await block.click();
 		await block.click();

+		// Wait for the batched add-to-cart request to complete before asserting.
+		await batchPromise;
+
 		// All 3 clicks should compound to "3 in cart".
 		await expect( block.getByRole( 'button' ) ).toHaveText( '3 in cart', {
 			timeout: 15000,