From a7fc9afa8e09ed6a1e1be49b69fdc9a6342932e2 Mon Sep 17 00:00:00 2001 From: Veljko V Date: Thu, 13 Jun 2024 21:47:45 +0200 Subject: [PATCH] Improve cart util and update relevant e2e tests (#48475) * Improve cart util and update relevant tests * Add changelog * Remove focused test --- .../woocommerce/changelog/e2e-improve-cart-util | 4 ++++ .../cart-checkout-block-calculate-tax.spec.js | 3 +-- .../cart-checkout-restricted-coupons.spec.js | 10 ++++------ .../e2e-pw/tests/shopper/checkout-block.spec.js | 17 ++++++++--------- plugins/woocommerce/tests/e2e-pw/utils/cart.js | 15 +++++++++------ 5 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 plugins/woocommerce/changelog/e2e-improve-cart-util diff --git a/plugins/woocommerce/changelog/e2e-improve-cart-util b/plugins/woocommerce/changelog/e2e-improve-cart-util new file mode 100644 index 00000000000..4c97596f611 --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-improve-cart-util @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +E2E tests: improving cart util and updating relevant tests diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js index 97974bb16ef..03bc60ffc26 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js @@ -293,8 +293,7 @@ test.describe( 'Shopper Cart & Checkout Block Tax Rounding', () => { // all tests use the same products await addAProductToCart( page, productId ); - await addAProductToCart( page, productId2 ); - await addAProductToCart( page, productId2 ); + await addAProductToCart( page, productId2, 2 ); } ); test.afterAll( async ( { baseURL } ) => { diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-restricted-coupons.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-restricted-coupons.spec.js index e80a49762ce..3214de6fb70 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-restricted-coupons.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-restricted-coupons.spec.js @@ -235,9 +235,8 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => { ).toBeVisible(); // add a couple more in order to hit minimum spend - for ( let i = 0; i < 2; i++ ) { - await addAProductToCart( page, firstProductId ); - } + await addAProductToCart( page, firstProductId, 2 ); + // passed because we're between 50 and 200 dollars await page.goto( '/cart/' ); await page @@ -280,9 +279,8 @@ test.describe( 'Cart & Checkout Restricted Coupons', () => { ).toBeVisible(); // add a couple more in order to hit minimum spend - for ( let i = 0; i < 2; i++ ) { - await addAProductToCart( page, firstProductId ); - } + await addAProductToCart( page, firstProductId, 2 ); + // passed because we're between 50 and 200 dollars await page.goto( '/checkout/' ); await page diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js index 83ce606b8ef..f64acb7ea35 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/checkout-block.spec.js @@ -57,6 +57,10 @@ test.describe( 'Checkout Block page', () => { consumerSecret: process.env.CONSUMER_SECRET, version: 'wc/v3', } ); + // make sure the currency is USD + await api.put( 'settings/general/woocommerce_currency', { + value: 'USD', + } ); // add product await api .post( 'products', { @@ -287,8 +291,7 @@ test.describe( 'Checkout Block page', () => { testPage, } ) => { // this time we're going to add two products to the cart - await addAProductToCart( page, productId ); - await addAProductToCart( page, productId ); + await addAProductToCart( page, productId, 2 ); await page.goto( testPage.slug ); await expect( @@ -325,9 +328,7 @@ test.describe( 'Checkout Block page', () => { testPage, } ) => { // this time we're going to add three products to the cart - await addAProductToCart( page, productId ); - await addAProductToCart( page, productId ); - await addAProductToCart( page, productId ); + await addAProductToCart( page, productId, 3 ); await page.goto( testPage.slug ); await expect( @@ -601,8 +602,7 @@ test.describe( 'Checkout Block page', () => { testPage, } ) => { // adding 2 products to the cart - await addAProductToCart( page, productId ); - await addAProductToCart( page, productId ); + await addAProductToCart( page, productId, 2 ); await page.goto( testPage.slug ); await expect( @@ -727,8 +727,7 @@ test.describe( 'Checkout Block page', () => { page, testPage, } ) => { - await addAProductToCart( page, productId ); - await addAProductToCart( page, productId ); + await addAProductToCart( page, productId, 2 ); await page.goto( testPage.slug ); await expect( diff --git a/plugins/woocommerce/tests/e2e-pw/utils/cart.js b/plugins/woocommerce/tests/e2e-pw/utils/cart.js index 19d05b04863..7392e3200dc 100644 --- a/plugins/woocommerce/tests/e2e-pw/utils/cart.js +++ b/plugins/woocommerce/tests/e2e-pw/utils/cart.js @@ -1,9 +1,12 @@ -const addAProductToCart = async ( page, productId ) => { - const responsePromise = page.waitForResponse( - '**/wp-json/wc/store/v1/cart?**' - ); - await page.goto( `/shop/?add-to-cart=${ productId }` ); - await responsePromise; +const addAProductToCart = async ( page, productId, quantity = 1 ) => { + for ( let i = 0; i < quantity; i++ ) { + const responsePromise = page.waitForResponse( + '**/wp-json/wc/store/v1/cart?**' + ); + await page.goto( `/shop/?add-to-cart=${ productId }` ); + await responsePromise; + await page.getByRole( 'alert' ).waitFor( { state: 'visible' } ); + } }; module.exports = {