From 1bafa98a66b41d1a9f7a2bc5a7ae85a34960a9fb Mon Sep 17 00:00:00 2001 From: Leif Singer Date: Fri, 22 Jan 2021 11:16:01 +0100 Subject: [PATCH] move registered customer checkout test to general checkout tests --- tests/e2e/core-tests/README.md | 1 - tests/e2e/core-tests/specs/index.js | 3 - .../front-end-checkout-registered.test.js | 130 ------------------ .../specs/shopper/front-end-checkout.test.js | 74 +++++++--- .../front-end/test-checkout-registered.js | 6 - 5 files changed, 55 insertions(+), 159 deletions(-) delete mode 100644 tests/e2e/core-tests/specs/shopper/front-end-checkout-registered.test.js delete mode 100644 tests/e2e/specs/front-end/test-checkout-registered.js diff --git a/tests/e2e/core-tests/README.md b/tests/e2e/core-tests/README.md index 135b8803a64..a75a039f18c 100644 --- a/tests/e2e/core-tests/README.md +++ b/tests/e2e/core-tests/README.md @@ -61,7 +61,6 @@ The functions to access the core tests are: - `runShopperTests` - Run all shopper tests - `runCartPageTest` - Shopper can view and update cart - `runCheckoutPageTest` - Shopper can complete checkout - - `runCheckoutRegisteredPageTest` - Registered shopper can complete checkout - `runMyAccountPageTest` - Shopper can access my account page - `runSingleProductPageTest` - Shopper can view single product page diff --git a/tests/e2e/core-tests/specs/index.js b/tests/e2e/core-tests/specs/index.js index 68175eaf46b..9012ab881aa 100644 --- a/tests/e2e/core-tests/specs/index.js +++ b/tests/e2e/core-tests/specs/index.js @@ -12,7 +12,6 @@ const runInitialStoreSettingsTest = require( './activate-and-setup/setup.test' ) const runCartPageTest = require( './shopper/front-end-cart.test' ); const runCheckoutApplyCouponsTest = require( './shopper/front-end-checkout-coupons.test'); const runCheckoutPageTest = require( './shopper/front-end-checkout.test' ); -const runCheckoutRegisteredPageTest = require( './shopper/front-end-checkout-registered.test' ); const runMyAccountPageTest = require( './shopper/front-end-my-account.test' ); const runSingleProductPageTest = require( './shopper/front-end-single-product.test' ); @@ -38,7 +37,6 @@ const runShopperTests = () => { runCartPageTest(); runCheckoutApplyCouponsTest(); runCheckoutPageTest(); - runCheckoutRegisteredPageTest(); runMyAccountPageTest(); runSingleProductPageTest(); }; @@ -65,7 +63,6 @@ module.exports = { runCartPageTest, runCheckoutApplyCouponsTest, runCheckoutPageTest, - runCheckoutRegisteredPageTest, runMyAccountPageTest, runSingleProductPageTest, runShopperTests, diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout-registered.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout-registered.test.js deleted file mode 100644 index 446d69120fb..00000000000 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout-registered.test.js +++ /dev/null @@ -1,130 +0,0 @@ -/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect, jest/no-standalone-expect */ -/** - * Internal dependencies - */ -const { - shopper, - merchant, - createSimpleProduct, - setCheckbox, - settingsPageSaveChanges, - uiUnblocked, - verifyCheckboxIsSet -} = require( '@woocommerce/e2e-utils' ); - -const config = require( 'config' ); -const simpleProductName = config.get( 'products.simple.name' ); -const singleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99'; - -let orderId; - -const runCheckoutRegisteredPageTest = () => { - describe('Checkout page', () => { - beforeAll(async () => { - await merchant.login(); - await createSimpleProduct(); - - // Go to general settings page - await merchant.openSettings('general'); - - // Set base location with state CA. - await expect(page).toSelect('select[name="woocommerce_default_country"]', 'United States (US) — California'); - // Sell to all countries - await expect(page).toSelect('#woocommerce_allowed_countries', 'Sell to all countries'); - // Set currency to USD - await expect(page).toSelect('#woocommerce_currency', 'United States (US) dollar ($)'); - // Tax calculation should have been enabled by another test - no-op - // Save - await settingsPageSaveChanges(); - - // Verify that settings have been saved - await Promise.all([ - expect(page).toMatchElement('#message', {text: 'Your settings have been saved.'}), - expect(page).toMatchElement('select[name="woocommerce_default_country"]', {text: 'United States (US) — California'}), - expect(page).toMatchElement('#woocommerce_allowed_countries', {text: 'Sell to all countries'}), - expect(page).toMatchElement('#woocommerce_currency', {text: 'United States (US) dollar ($)'}), - ]); - - // Enable BACS payment method - await merchant.openSettings('checkout', 'bacs'); - await setCheckbox('#woocommerce_bacs_enabled'); - await settingsPageSaveChanges(); - - // Verify that settings have been saved - await verifyCheckboxIsSet('#woocommerce_bacs_enabled'); - - // Enable COD payment method - await merchant.openSettings('checkout', 'cod'); - await setCheckbox('#woocommerce_cod_enabled'); - await settingsPageSaveChanges(); - - // Verify that settings have been saved - await verifyCheckboxIsSet('#woocommerce_cod_enabled'); - - // Enable PayPal payment method - await merchant.openSettings('checkout', 'paypal'); - await setCheckbox('#woocommerce_paypal_enabled'); - await settingsPageSaveChanges(); - - // Verify that settings have been saved - await verifyCheckboxIsSet('#woocommerce_paypal_enabled'); - - await merchant.logout(); - }); - - it('allows existing customer to place order', async () => { - await shopper.login(); - await shopper.goToShop(); - await shopper.addToCartFromShopPage(simpleProductName); - await shopper.goToCheckout(); - await shopper.productIsInCheckout(simpleProductName, `1`, singleProductPrice, singleProductPrice); - await shopper.fillBillingDetails(config.get('addresses.customer.billing')); - - await uiUnblocked(); - - await expect(page).toClick('.wc_payment_method label', {text: 'Cash on delivery'}); - await expect(page).toMatchElement('.payment_method_cod', {text: 'Pay with cash upon delivery.'}); - await uiUnblocked(); - await shopper.placeOrder(); - - await expect(page).toMatch('Order received'); - - // Get order ID from the order received html element on the page - let orderReceivedHtmlElement = await page.$('.woocommerce-order-overview__order.order'); - let orderReceivedText = await page.evaluate(element => element.textContent, orderReceivedHtmlElement); - return orderId = orderReceivedText.split(/(\s+)/)[6].toString(); - }); - - it('store owner can confirm the order was received', async () => { - await merchant.login(); - await merchant.openAllOrdersView(); - - // Click on the order which was placed in the previous step - await Promise.all([ - page.click('#post-' + orderId), - page.waitForNavigation({waitUntil: 'networkidle0'}), - ]); - - // Verify that the order page is indeed of the order that was placed - // Verify order number - await expect(page).toMatchElement('.woocommerce-order-data__heading', {text: 'Order #' + orderId + ' details'}); - - // Verify product name - await expect(page).toMatchElement('.wc-order-item-name', {text: simpleProductName}); - - // Verify product cost - await expect(page).toMatchElement('.woocommerce-Price-amount.amount', {text: singleProductPrice}); - - // Verify product quantity - await expect(page).toMatchElement('.quantity', {text: '1'}); - - // Verify total order amount without shipping - await expect(page).toMatchElement('.line_cost', {text: singleProductPrice}); - - // Verify customer profile link is present to verify order was placed by a registered customer, not a guest - await expect( page ).toMatchElement( 'label[for="customer_user"] a[href*=user-edit]', { text: 'Profile' } ); - }); - }); -}; - -module.exports = runCheckoutRegisteredPageTest; diff --git a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js index 2928b6e38ec..c7c9567ae80 100644 --- a/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js +++ b/tests/e2e/core-tests/specs/shopper/front-end-checkout.test.js @@ -20,7 +20,8 @@ const threeProductPrice = singleProductPrice * 3; const fourProductPrice = singleProductPrice * 4; const fiveProductPrice = singleProductPrice * 5; -let orderId; +let guestOrderId; +let customerOrderId; const runCheckoutPageTest = () => { describe('Checkout page', () => { @@ -136,34 +137,69 @@ const runCheckoutPageTest = () => { // Get order ID from the order received html element on the page let orderReceivedHtmlElement = await page.$('.woocommerce-order-overview__order.order'); let orderReceivedText = await page.evaluate(element => element.textContent, orderReceivedHtmlElement); - return orderId = orderReceivedText.split(/(\s+)/)[6].toString(); + return guestOrderId = orderReceivedText.split(/(\s+)/)[6].toString(); + }); + + it('allows existing customer to place order', async () => { + await shopper.login(); + await shopper.goToShop(); + await shopper.addToCartFromShopPage(simpleProductName); + await shopper.goToCheckout(); + await shopper.productIsInCheckout(simpleProductName, `1`, singleProductPrice, singleProductPrice); + await shopper.fillBillingDetails(config.get('addresses.customer.billing')); + + await uiUnblocked(); + + await expect(page).toClick('.wc_payment_method label', {text: 'Cash on delivery'}); + await expect(page).toMatchElement('.payment_method_cod', {text: 'Pay with cash upon delivery.'}); + await uiUnblocked(); + await shopper.placeOrder(); + + await expect(page).toMatch('Order received'); + + // Get order ID from the order received html element on the page + let orderReceivedHtmlElement = await page.$('.woocommerce-order-overview__order.order'); + let orderReceivedText = await page.evaluate(element => element.textContent, orderReceivedHtmlElement); + return customerOrderId = orderReceivedText.split(/(\s+)/)[6].toString(); }); it('store owner can confirm the order was received', async () => { await merchant.login(); - await merchant.openAllOrdersView(); + // await merchant.openAllOrdersView(); - // Click on the order which was placed in the previous step - await Promise.all([ - page.click('#post-' + orderId), - page.waitForNavigation({waitUntil: 'networkidle0'}), - ]); + const checkOrder = async function(orderId, productName, productPrice, quantity, orderTotal, ensureCustomerRegistered = false) { + await merchant.openAllOrdersView(); - // Verify that the order page is indeed of the order that was placed - // Verify order number - await expect(page).toMatchElement('.woocommerce-order-data__heading', {text: 'Order #' + orderId + ' details'}); + // Click on the order which was placed in the previous step + await Promise.all([ + page.click('#post-' + orderId), + page.waitForNavigation({waitUntil: 'networkidle0'}), + ]); - // Verify product name - await expect(page).toMatchElement('.wc-order-item-name', {text: simpleProductName}); + // Verify that the order page is indeed of the order that was placed + // Verify order number + await expect(page).toMatchElement('.woocommerce-order-data__heading', {text: 'Order #' + orderId + ' details'}); - // Verify product cost - await expect(page).toMatchElement('.woocommerce-Price-amount.amount', {text: singleProductPrice}); + // Verify product name + await expect(page).toMatchElement('.wc-order-item-name', {text: productName}); - // Verify product quantity - await expect(page).toMatchElement('.quantity', {text: '5'}); + // Verify product cost + await expect(page).toMatchElement('.woocommerce-Price-amount.amount', {text: productPrice}); - // Verify total order amount without shipping - await expect(page).toMatchElement('.line_cost', {text: fiveProductPrice}); + // Verify product quantity + await expect(page).toMatchElement('.quantity', {text: quantity.toString()}); + + // Verify total order amount without shipping + await expect(page).toMatchElement('.line_cost', {text: orderTotal}); + + if ( ensureCustomerRegistered ) { + // Verify customer profile link is present to verify order was placed by a registered customer, not a guest + await expect( page ).toMatchElement( 'label[for="customer_user"] a[href*=user-edit]', { text: 'Profile' } ); + } + }; + + await checkOrder(guestOrderId, simpleProductName, singleProductPrice, 5, fiveProductPrice); + await checkOrder(customerOrderId, simpleProductName, singleProductPrice, 1, singleProductPrice, true); }); }); }; diff --git a/tests/e2e/specs/front-end/test-checkout-registered.js b/tests/e2e/specs/front-end/test-checkout-registered.js deleted file mode 100644 index f87d0d4715c..00000000000 --- a/tests/e2e/specs/front-end/test-checkout-registered.js +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Internal dependencies - */ -const { runCheckoutRegisteredPageTest } = require( '@woocommerce/e2e-core-tests' ); - -runCheckoutRegisteredPageTest();