diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js index e7da3ffe377..6e5b8fb51c9 100644 --- a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-zones.test.js @@ -10,8 +10,7 @@ const { addShippingZoneAndMethod, clearAndFillInput, selectOptionInSelect2, - evalAndClick, - uiUnblocked, + deleteAllShippingZones, } = require( '@woocommerce/e2e-utils' ); const config = require( 'config' ); @@ -28,27 +27,7 @@ const runAddNewShippingZoneTest = () => { beforeAll(async () => { await merchant.login(); await createSimpleProduct(); - await merchant.openSettings('shipping'); - - // Delete existing shipping zones. - try { - let zone = await page.$( '.wc-shipping-zone-delete' ); - if ( zone ) { - // WP action links aren't clickable because they are hidden with a left=-9999 style. - await page.evaluate(() => { - document.querySelector('.wc-shipping-zone-name .row-actions') - .style - .left = '0'; - }); - while ( zone ) { - await evalAndClick( '.wc-shipping-zone-delete' ); - await uiUnblocked(); - zone = await page.$( '.wc-shipping-zone-delete' ); - } - } - } catch (error) { - // Prevent an error here causing the test to fail. - } + await deleteAllShippingZones(); }); it('add shipping zone for San Francisco with free Local pickup', async () => { diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js index f5fe1fcff2d..aa9baaee694 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-calculate-shipping.test.js @@ -8,7 +8,7 @@ const { createSimpleProduct, addShippingZoneAndMethod, clearAndFillInput, - evalAndClick, + deleteAllShippingZones, uiUnblocked, selectOptionInSelect2, } = require( '@woocommerce/e2e-utils' ); @@ -33,33 +33,9 @@ const runCartCalculateShippingTest = () => { beforeAll(async () => { await merchant.login(); await createSimpleProduct(firstProductName); - await merchant.openSettings('general'); await createSimpleProduct(secondProductName, secondProductPrice); - await merchant.openSettings('shipping'); + await deleteAllShippingZones(); }); - - it('can remove the existing shippings if they are present', async () => { - // Delete existing shipping zones. - try { - let zone = await page.$( '.wc-shipping-zone-delete' ); - if ( zone ) { - // WP action links aren't clickable because they are hidden with a left=-9999 style. - await page.evaluate(() => { - document.querySelector('.wc-shipping-zone-name .row-actions') - .style - .left = '0'; - }); - while ( zone ) { - await evalAndClick( '.wc-shipping-zone-delete' ); - await uiUnblocked(); - zone = await page.$( '.wc-shipping-zone-delete' ); - } - } - } catch (error) { - // Prevent an error here causing the test to fail. - } - }); - it('can prepare the shipping zones for the test', async () => { // Add a new shipping zone Germany with Free shipping await addShippingZoneAndMethod(shippingZoneNameDE, shippingCountryDE, ' ', 'free_shipping'); diff --git a/tests/e2e/utils/CHANGELOG.md b/tests/e2e/utils/CHANGELOG.md index 07e70e130fe..561ee7f4105 100644 --- a/tests/e2e/utils/CHANGELOG.md +++ b/tests/e2e/utils/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - `emptyCart()` Shopper flow helper that empties the cart +- `deleteAllShippingZones` Delete all the existing shipping zones # 0.1.4 diff --git a/tests/e2e/utils/README.md b/tests/e2e/utils/README.md index f6b5c662e4f..bffe722c41c 100644 --- a/tests/e2e/utils/README.md +++ b/tests/e2e/utils/README.md @@ -124,6 +124,7 @@ describe( 'Cart page', () => { | `removeCoupon` | | helper method that removes a single coupon within cart or checkout | | `selectOrderAction` | `action` | Helper method to select an order action in the `Order Actions` postbox | | `clickUpdateOrder` | `noticeText`, `waitForSave` | Helper method to click the Update button on the order details page | +| `deleteAllShippingZones` | | Delete all the existing shipping zones | ### Test Utilities diff --git a/tests/e2e/utils/src/components.js b/tests/e2e/utils/src/components.js index c449622937b..addeed491ff 100644 --- a/tests/e2e/utils/src/components.js +++ b/tests/e2e/utils/src/components.js @@ -12,7 +12,8 @@ import { verifyCheckboxIsUnset, selectOptionInSelect2, setCheckbox, - unsetCheckbox + unsetCheckbox, + evalAndClick, } from './page-utils'; import factories from './factories'; @@ -538,6 +539,32 @@ const deleteAllEmailLogs = async () => { } }; +/** + * Delete all the existing shipping zones. + */ +const deleteAllShippingZones = async () => { + await merchant.openSettings('shipping'); + // Delete existing shipping zones. + try { + let zone = await page.$( '.wc-shipping-zone-delete' ); + if ( zone ) { + // WP action links aren't clickable because they are hidden with a left=-9999 style. + await page.evaluate(() => { + document.querySelector('.wc-shipping-zone-name .row-actions') + .style + .left = '0'; + }); + while ( zone ) { + await evalAndClick( '.wc-shipping-zone-delete' ); + await uiUnblocked(); + zone = await page.$( '.wc-shipping-zone-delete' ); + }; + }; + } catch (error) { + // Prevent an error here causing the test to fail. + }; +}; + export { completeOnboardingWizard, createSimpleProduct, @@ -551,4 +578,5 @@ export { createSimpleProductWithCategory, clickUpdateOrder, deleteAllEmailLogs, + deleteAllShippingZones, };