Commit 7ee0e4610b8 for woocommerce
commit 7ee0e4610b8bd8157194e89741b174c1cfae0a9c
Author: Ann <annchichi@users.noreply.github.com>
Date: Fri Jul 31 14:58:27 2026 +0800
Clean up shipping method title test coverage (#67006)
* Simplify shipping method title synchronization
* Add changelog entry for shipping method title tests
* Consolidate shipping method E2E coverage
diff --git a/plugins/woocommerce/changelog/66887-clean-up-shipping-method-title-test b/plugins/woocommerce/changelog/66887-clean-up-shipping-method-title-test
new file mode 100644
index 00000000000..0bb748fe930
--- /dev/null
+++ b/plugins/woocommerce/changelog/66887-clean-up-shipping-method-title-test
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Clean up shipping method title test-only exports and add end-to-end coverage.
diff --git a/plugins/woocommerce/client/legacy/js/admin/meta-boxes-order.js b/plugins/woocommerce/client/legacy/js/admin/meta-boxes-order.js
index d2d7ee740f1..c3454033e2d 100644
--- a/plugins/woocommerce/client/legacy/js/admin/meta-boxes-order.js
+++ b/plugins/woocommerce/client/legacy/js/admin/meta-boxes-order.js
@@ -1,34 +1,5 @@
// eslint-disable-next-line max-len
-/*global woocommerce_admin_meta_boxes, woocommerce_admin, accounting, woocommerce_admin_meta_boxes_order, wcSetClipboard, wcClearClipboard, wc_enhanced_select_params, module */
-
-/**
- * Get the shipping method title to use after a method selection changes.
- *
- * @param {Object} args Shipping title data.
- * @param {string} args.currentTitle Current shipping title.
- * @param {string} args.defaultTitle Default shipping title.
- * @param {string} args.previousTitle Previously selected method title.
- * @param {string} args.methodValue Selected shipping method value.
- * @param {string} args.methodTitle Selected shipping method title.
- * @return {string} The shipping title to use.
- */
-function getShippingMethodTitle( args ) {
- if (
- args.currentTitle
- && args.currentTitle !== args.defaultTitle
- && args.currentTitle !== args.previousTitle
- ) {
- return args.currentTitle;
- }
-
- return args.methodValue && 'other' !== args.methodValue
- ? args.methodTitle
- : args.defaultTitle;
-}
-
-if ( typeof module !== 'undefined' && module.exports ) {
- module.exports = { getShippingMethodTitle };
-}
+/*global woocommerce_admin_meta_boxes, woocommerce_admin, accounting, woocommerce_admin_meta_boxes_order, wcSetClipboard, wcClearClipboard, wc_enhanced_select_params */
jQuery( function ( $ ) {
@@ -416,13 +387,17 @@ jQuery( function ( $ ) {
} ).text();
var currentTitle = $name.val();
var defaultTitle = $name.data( 'default-shipping-title' );
- var nextTitle = getShippingMethodTitle( {
- currentTitle: currentTitle,
- defaultTitle: defaultTitle,
- previousTitle: previousTitle,
- methodValue: $select.val(),
- methodTitle: title
- } );
+ var nextTitle = defaultTitle;
+
+ if (
+ currentTitle
+ && currentTitle !== defaultTitle
+ && currentTitle !== previousTitle
+ ) {
+ nextTitle = currentTitle;
+ } else if ( $select.val() && 'other' !== $select.val() ) {
+ nextTitle = title;
+ }
$select.data( 'selected-title', title );
diff --git a/plugins/woocommerce/client/legacy/js/admin/test/meta-boxes-order.test.js b/plugins/woocommerce/client/legacy/js/admin/test/meta-boxes-order.test.js
deleted file mode 100644
index 7bd51d99ef2..00000000000
--- a/plugins/woocommerce/client/legacy/js/admin/test/meta-boxes-order.test.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Tests for the order meta box shipping method name synchronization.
- */
-
-global.jQuery = jest.fn();
-
-const { getShippingMethodTitle } = require( '../meta-boxes-order' );
-
-describe( 'Order meta box shipping method names', () => {
- test( 'uses the selected method title for the default shipping name', () => {
- expect( getShippingMethodTitle( {
- currentTitle: 'Shipping',
- defaultTitle: 'Shipping',
- previousTitle: 'N/A',
- methodValue: 'free_shipping',
- methodTitle: 'Free shipping',
- } ) ).toBe( 'Free shipping' );
- } );
-
- test.each( [
- [ 'N/A', '', 'N/A' ],
- [ 'Other', 'other', 'Other' ],
- ] )( 'resets an auto-synced name when selecting %s', ( label, methodValue, methodTitle ) => {
- expect( getShippingMethodTitle( {
- currentTitle: 'Free shipping',
- defaultTitle: 'Shipping',
- previousTitle: 'Free shipping',
- methodValue,
- methodTitle,
- } ) ).toBe( 'Shipping' );
- } );
-
- test( 'preserves a custom name when selecting N/A', () => {
- expect( getShippingMethodTitle( {
- currentTitle: 'Local courier',
- defaultTitle: 'Shipping',
- previousTitle: 'Free shipping',
- methodValue: '',
- methodTitle: 'N/A',
- } ) ).toBe( 'Local courier' );
- } );
-} );
diff --git a/plugins/woocommerce/tests/e2e/tests/order/order-edit.spec.ts b/plugins/woocommerce/tests/e2e/tests/order/order-edit.spec.ts
index a41e2f7f1ce..58d5dd90c28 100644
--- a/plugins/woocommerce/tests/e2e/tests/order/order-edit.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/order/order-edit.spec.ts
@@ -31,7 +31,7 @@ test.describe( 'Edit order', { tag: [ tags.SERVICES, tags.HPOS ] }, () => {
} );
await restApi
.post( `${ WC_API_PATH }/orders`, {
- status: 'processing',
+ status: 'pending',
} )
.then( ( response: { data: { id: number } } ) => {
secondOrderId = response.data.id;
@@ -43,7 +43,6 @@ test.describe( 'Edit order', { tag: [ tags.SERVICES, tags.HPOS ] }, () => {
.then( ( response: { data: { id: number } } ) => {
orderToCancel = response.data.id;
} );
-
await restApi
.post( `${ WC_API_PATH }/customers`, {
email: `${ username }@email.addr`,
@@ -374,6 +373,39 @@ test.describe( 'Edit order', { tag: [ tags.SERVICES, tags.HPOS ] }, () => {
await page.locator( 'li.select2-results__option' ).click();
} );
+ await test.step( 'Update the shipping method name', async () => {
+ await page.getByRole( 'button', { name: 'Add item(s)' } ).click();
+ await page.getByRole( 'button', { name: 'Add shipping' } ).click();
+
+ const shippingRow = page.locator( 'tr.shipping' ).last();
+ await expect( shippingRow ).toBeVisible();
+ await shippingRow
+ .getByRole( 'link', { name: 'Edit shipping' } )
+ .click();
+
+ const method = shippingRow.locator( 'select.shipping_method' );
+ const name = shippingRow.locator( 'input.shipping_method_name' );
+
+ await method.selectOption( 'free_shipping' );
+ await expect( name ).toHaveValue( 'Free shipping' );
+
+ await method.selectOption( '' );
+ await expect( name ).toHaveValue( 'Shipping' );
+
+ await method.selectOption( 'free_shipping' );
+ await expect( name ).toHaveValue( 'Free shipping' );
+ await method.selectOption( 'other' );
+ await expect( name ).toHaveValue( 'Shipping' );
+
+ await method.selectOption( 'free_shipping' );
+ await expect( name ).toHaveValue( 'Free shipping' );
+ await name.fill( 'Local courier' );
+ await method.selectOption( '' );
+ await expect( name ).toHaveValue( 'Local courier' );
+
+ await page.locator( 'button.save-action' ).click();
+ } );
+
await test.step( 'Load the billing address and then copy it to the shipping address', async () => {
// Click the load billing address button
await page