Commit ca995f63b6 for woocommerce
commit ca995f63b64af29d5ff8a60a357fca47864f4787
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date: Thu Apr 17 08:25:30 2025 +0100
Create saveAdminPage E2E utility for waiting for admin settings save completion (#57316)
* Create saveAdminPage utility function to wait for the save action to complete by waiting for the button to become disabled
* Update JSDoc
* Add changelog
* Update other save button references in file to use util
diff --git a/plugins/woocommerce/changelog/fix-shopper-shipping-e2e-test b/plugins/woocommerce/changelog/fix-shopper-shipping-e2e-test
new file mode 100644
index 0000000000..5550e87835
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-shopper-shipping-e2e-test
@@ -0,0 +1,4 @@
+Significance: minor
+Type: dev
+
+Added saveAdminPage e2e util
diff --git a/plugins/woocommerce/client/blocks/tests/e2e/tests/cart/cart-checkout-block-shipping.block_theme.spec.ts b/plugins/woocommerce/client/blocks/tests/e2e/tests/cart/cart-checkout-block-shipping.block_theme.spec.ts
index c71e1dac3a..0942d69d90 100644
--- a/plugins/woocommerce/client/blocks/tests/e2e/tests/cart/cart-checkout-block-shipping.block_theme.spec.ts
+++ b/plugins/woocommerce/client/blocks/tests/e2e/tests/cart/cart-checkout-block-shipping.block_theme.spec.ts
@@ -50,9 +50,7 @@ test.describe( 'Shopper → Shipping', () => {
await admin.page
.getByLabel( 'Default customer location' )
.selectOption( 'No location by default' );
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await admin.visitAdminPage(
'admin.php?page=wc-settings&tab=shipping&zone_id=new'
@@ -64,9 +62,7 @@ test.describe( 'Shopper → Shipping', () => {
await admin.page
.getByRole( 'checkbox', { name: 'United Kingdom (UK)' } )
.click(); // .check() won't work here as the input disappears immediately after checking.
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await admin.page
.getByRole( 'button', { name: 'Add shipping method' } )
.click();
@@ -81,9 +77,7 @@ test.describe( 'Shopper → Shipping', () => {
.getByRole( 'button', { name: 'Save changes' } )
.isDisabled() )
) {
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
}
await expect(
admin.page.getByRole( 'button', { name: 'Save changes' } )
@@ -266,9 +260,7 @@ test.describe( 'Shopper → Shipping', () => {
await admin.page
.getByLabel( 'Default customer location' )
.selectOption( 'No location by default' );
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await admin.visitAdminPage( 'admin.php?page=wc-settings&tab=shipping' );
@@ -281,9 +273,7 @@ test.describe( 'Shopper → Shipping', () => {
// Then only one "name: yes" remains, making it the first, even though it's the second rate.
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await frontendUtils.goToShop();
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
@@ -364,9 +354,7 @@ test.describe( 'Shopper → Shipping', () => {
// Then only one "name: yes" remains, making it the first, even though it's the second rate.
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await frontendUtils.goToShop();
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
@@ -426,9 +414,7 @@ test.describe( 'Shopper → Shipping', () => {
// Then only one "name: yes" remains, making it the first, even though it's the second rate.
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await frontendUtils.goToShop();
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
@@ -573,9 +559,7 @@ test.describe( 'Shopper → Shipping', () => {
// Then only one "name: yes" remains, making it the first, even though it's the second rate.
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
await admin.page.getByRole( 'link', { name: 'Yes' } ).first().click();
- await admin.page
- .getByRole( 'button', { name: 'Save changes' } )
- .click();
+ await admin.saveAdminPage();
await frontendUtils.goToShop();
await frontendUtils.addToCart( REGULAR_PRICED_PRODUCT_NAME );
diff --git a/plugins/woocommerce/client/blocks/tests/e2e/utils/admin/index.ts b/plugins/woocommerce/client/blocks/tests/e2e/utils/admin/index.ts
index 0244e60943..febc25aabc 100644
--- a/plugins/woocommerce/client/blocks/tests/e2e/utils/admin/index.ts
+++ b/plugins/woocommerce/client/blocks/tests/e2e/utils/admin/index.ts
@@ -82,4 +82,15 @@ export class Admin extends CoreAdmin {
await Promise.any( [ welcomePopUp(), editorLoaded() ] );
}
+
+ /**
+ * Clicks the 'Save changes' button on an admin page and waits for it to become disabled to ensure the page is saved.
+ */
+ async saveAdminPage() {
+ const saveButton = this.page.getByRole( 'button', {
+ name: 'Save changes',
+ } );
+ await saveButton.click();
+ await saveButton.isDisabled();
+ }
}