Commit 8685c578b06 for woocommerce

commit 8685c578b06e04b5f79d47e87b187c5278d0eece
Author: Taha Paksu <3295+tpaksu@users.noreply.github.com>
Date:   Mon Oct 12 15:29:24 2026 +0300

    [tests] Use the real cart store in the checkout shipping-method block test (#69705)

    * test: use the real cart store and pin the pickup-only address prompt for the shipping-method block

    * Remove hand-added changelog; let the PR automation create it

    * Add changefile(s) from automation for the following project(s): woocommerce

    * Update plugins/woocommerce/changelog/69705-wooplug-7841-shipping-method-test-followup

    Co-authored-by: Raluca Stan <ralucastn@gmail.com>

    * Update plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/test/block.tsx

    Co-authored-by: Raluca Stan <ralucastn@gmail.com>

    * Add changefile(s) from automation for the following project(s): woocommerce

    ---------

    Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
    Co-authored-by: Raluca Stan <ralucastn@gmail.com>

diff --git a/plugins/woocommerce/changelog/69705-wooplug-7841-shipping-method-test-followup b/plugins/woocommerce/changelog/69705-wooplug-7841-shipping-method-test-followup
new file mode 100644
index 00000000000..f02bcf26816
--- /dev/null
+++ b/plugins/woocommerce/changelog/69705-wooplug-7841-shipping-method-test-followup
@@ -0,0 +1,5 @@
+Significance: patch
+Type: dev
+Comment: Refine the checkout shipping-method block JS test (use the real cart store, pin the pickup-only address prompt); no production change.
+
+
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/test/block.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/test/block.tsx
index 704069a6294..6f56b23df05 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/test/block.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-shipping-method-block/test/block.tsx
@@ -1,9 +1,9 @@
 /**
  * External dependencies
  */
-import { render, screen } from '@testing-library/react';
+import { render, screen, act } from '@testing-library/react';
 import { dispatch } from '@wordpress/data';
-import { useShippingData } from '@woocommerce/base-context/hooks';
+import { cartStore, validationStore } from '@woocommerce/block-data';

 /**
  * Internal dependencies
@@ -41,37 +41,6 @@ jest.mock( '@woocommerce/settings', () => {
 	};
 } );

-jest.mock( '@woocommerce/base-context/hooks', () => ( {
-	...jest.requireActual( '@woocommerce/base-context/hooks' ),
-	useShippingData: jest.fn(),
-} ) );
-
-// The component selects only from the cart store, to decide whether anything is still
-// deliverable; answer that one and let any other store resolve for real. The validation store
-// the tests drive is read inside cart/utils.ts rather than here, so it works because the mock
-// spreads the real module, not because of this fall-through.
-let mockPackages: ReturnType< typeof generateShippingPackage >[] = [];
-
-jest.mock( '@wordpress/data', () => {
-	const actualModule = jest.requireActual( '@wordpress/data' );
-	return {
-		...actualModule,
-		useSelect: (
-			mapSelect: ( select: typeof actualModule.select ) => unknown
-		) =>
-			mapSelect( ( storeName: { name?: string } | string ) => {
-				const name =
-					typeof storeName === 'string' ? storeName : storeName?.name;
-				if ( name === 'wc/store/cart' ) {
-					return { getShippingRates: () => mockPackages };
-				}
-				return actualModule.select( storeName );
-			} ),
-	};
-} );
-
-const VALIDATION_STORE = 'wc/store/validation';
-
 const deliveryRate = generateShippingRate( {
 	rateId: 'flat_rate:1',
 	name: 'Flat rate',
@@ -89,7 +58,9 @@ const collectionRate = generateShippingRate( {
 } );

 /**
- * Put the store in one shape and render the two options.
+ * Seed the cart store with the given rates and render the two options.
+ *
+ * Both the component's own cart selector and the real useShippingData read these seeded rates.
  *
  * @param options                     The shopper's situation.
  * @param options.costRequiresAddress Whether the merchant hid costs until an address is entered.
@@ -109,19 +80,21 @@ const renderWith = ( {
 	showPrice?: boolean;
 } ) => {
 	mockShippingCostRequiresAddress = costRequiresAddress;
-	mockPackages = [
-		generateShippingPackage( { packageId: 0, shippingRates: offers } ),
-	];
-
-	dispatch( VALIDATION_STORE ).clearValidationErrors();
-	if ( addressIncomplete ) {
-		dispatch( VALIDATION_STORE ).setValidationErrors( {
-			shipping_city: { message: 'Enter a city', hidden: true },
-		} );
-	}

-	( useShippingData as jest.Mock ).mockReturnValue( {
-		shippingRates: mockPackages,
+	act( () => {
+		dispatch( cartStore ).receiveCart( {
+			shipping_rates: [
+				generateShippingPackage( {
+					packageId: 0,
+					shippingRates: offers,
+				} ),
+			],
+		} );
+		if ( addressIncomplete ) {
+			dispatch( validationStore ).setValidationErrors( {
+				shipping_city: { message: 'Enter a city', hidden: true },
+			} );
+		}
 	} );

 	return render(
@@ -137,8 +110,7 @@ const renderWith = ( {
 };

 afterEach( () => {
-	mockShippingCostRequiresAddress = false;
-	dispatch( VALIDATION_STORE ).clearValidationErrors();
+	dispatch( validationStore ).clearValidationErrors();
 } );

 describe( 'Block', () => {
@@ -178,4 +150,21 @@ describe( 'Block', () => {
 			screen.queryByText( 'calculated with an address' )
 		).not.toBeInTheDocument();
 	} );
+
+	// Hiding costs until an address is entered must not change what the shopper reads here.
+	// With nothing deliverable there is no price to hide, only the prompt to enter an address.
+	it( 'keeps the address prompt for pickup-only rates even with costs hidden and the address incomplete', () => {
+		renderWith( {
+			costRequiresAddress: true,
+			addressIncomplete: true,
+			offers: [ collectionRate ],
+		} );
+
+		expect(
+			screen.getByRole( 'radio', {
+				name: ( name: string ) =>
+					name.startsWith( 'backup shipping text' ),
+			} )
+		).toHaveTextContent( 'calculated with an address' );
+	} );
 } );