From 60b5b183da2ac2571242c4327e525663f9325cd9 Mon Sep 17 00:00:00 2001 From: Rodel Calasagsag Date: Thu, 1 Jul 2021 20:02:59 +0800 Subject: [PATCH] Use switch-case to get coupons --- .../shopper/front-end-cart-coupons.test.js | 22 +++++++++--------- .../front-end-checkout-coupons.test.js | 23 +++++++++---------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js b/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js index 1e2586d5d7d..4899d048aa1 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-cart-coupons.test.js @@ -26,29 +26,29 @@ const couponsTable = [ ['fixed product', { text: '$5.00' }, { text: '$4.99' }] ]; -let coupons; +let couponFixedCart; +let couponPercentage; +let couponFixedProduct; const getCoupon = (couponType) => { - const coupon = coupons.find((pair) => pair.includes(couponType))[1]; - return coupon; + switch (couponType) { + case 'fixed cart': + return couponFixedCart; + case 'percentage': + return couponPercentage; + case 'fixed product': + return couponFixedProduct; + } }; const runCartApplyCouponsTest = () => { describe('Cart applying coupons', () => { - let couponFixedCart; - let couponPercentage; - let couponFixedProduct; beforeAll(async () => { await createSimpleProduct(); couponFixedCart = await createCoupon(); couponPercentage = await createCoupon('50', 'Percentage discount'); couponFixedProduct = await createCoupon('5', 'Fixed product discount'); - coupons = [ - ['fixed cart', couponFixedCart], - ['percentage', couponPercentage], - ['fixed product', couponFixedProduct] - ]; await shopper.emptyCart(); await shopper.goToShop(); await shopper.addToCartFromShopPage('Simple product'); diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js index abf13f2b84e..bd5fa06fa7e 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout-coupons.test.js @@ -27,29 +27,28 @@ const couponsTable = [ ['fixed product', { text: '$5.00' }, { text: '$4.99' }] ]; -let coupons; +let couponFixedCart; +let couponPercentage; +let couponFixedProduct; const getCoupon = (couponType) => { - const coupon = coupons.find((pair) => pair.includes(couponType))[1]; - return coupon; + switch (couponType) { + case 'fixed cart': + return couponFixedCart; + case 'percentage': + return couponPercentage; + case 'fixed product': + return couponFixedProduct; + } }; const runCheckoutApplyCouponsTest = () => { describe('Checkout coupons', () => { - let couponFixedCart; - let couponPercentage; - let couponFixedProduct; - beforeAll(async () => { await createSimpleProduct(); couponFixedCart = await createCoupon(); couponPercentage = await createCoupon('50', 'Percentage discount'); couponFixedProduct = await createCoupon('5', 'Fixed product discount'); - coupons = [ - ['fixed cart', couponFixedCart], - ['percentage', couponPercentage], - ['fixed product', couponFixedProduct] - ]; await shopper.emptyCart(); await shopper.goToShop(); await waitForSelectorWithoutThrow( '.add_to_cart_button' );