From f19f39aabbb7c94876df721e8468ed6951caf999 Mon Sep 17 00:00:00 2001 From: rodel Date: Sun, 21 Mar 2021 05:17:37 -0700 Subject: [PATCH] wip: first test in add shipping classes --- tests/e2e/core-tests/specs/index.js | 35 +++++----- ...wp-admin-settings-shipping-classes.test.js | 68 +++++++++++++++++++ 2 files changed, 87 insertions(+), 16 deletions(-) create mode 100644 tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-classes.test.js diff --git a/tests/e2e/core-tests/specs/index.js b/tests/e2e/core-tests/specs/index.js index 68b6ceac201..ed17a3382c1 100644 --- a/tests/e2e/core-tests/specs/index.js +++ b/tests/e2e/core-tests/specs/index.js @@ -21,6 +21,7 @@ const runVariableProductUpdateTest = require( './shopper/front-end-variable-prod // Merchant tests const runAddNewShippingZoneTest = require ( './merchant/wp-admin-settings-shipping-zones.test' ); +const runAddShippingClassesTest = require('./merchant/wp-admin-settings-shipping-classes.test') const runCreateCouponTest = require( './merchant/wp-admin-coupon-new.test' ); const runCreateOrderTest = require( './merchant/wp-admin-order-new.test' ); const runEditOrderTest = require( './merchant/wp-admin-order-edit.test' ); @@ -63,22 +64,24 @@ const runShopperTests = () => { }; const runMerchantTests = () => { - runOrderSearchingTest(); - runAddNewShippingZoneTest(); - runCreateCouponTest(); - runCreateOrderTest(); - runEditOrderTest(); - runAddSimpleProductTest(); - runAddVariableProductTest(); - runUpdateGeneralSettingsTest(); - runProductSettingsTest(); - runTaxSettingsTest(); - runOrderStatusFiltersTest(); - runOrderRefundTest(); - runOrderApplyCouponTest(); - runProductEditDetailsTest(); - runProductSearchTest(); - runMerchantOrdersCustomerPaymentPage(); + runAddShippingClassesTest() + // todo re-enable + // runOrderSearchingTest(); + // runAddNewShippingZoneTest(); + // runCreateCouponTest(); + // runCreateOrderTest(); + // runEditOrderTest(); + // runAddSimpleProductTest(); + // runAddVariableProductTest(); + // runUpdateGeneralSettingsTest(); + // runProductSettingsTest(); + // runTaxSettingsTest(); + // runOrderStatusFiltersTest(); + // runOrderRefundTest(); + // runOrderApplyCouponTest(); + // runProductEditDetailsTest(); + // runProductSearchTest(); + // runMerchantOrdersCustomerPaymentPage(); } const runApiTests = () => { diff --git a/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-classes.test.js b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-classes.test.js new file mode 100644 index 00000000000..b39e46b7dd7 --- /dev/null +++ b/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-classes.test.js @@ -0,0 +1,68 @@ +/* eslint-disable jest/no-export, jest/no-disabled-tests */ + +import faker from 'faker' + +/** + * Internal dependencies + */ +const { merchant } = require('@woocommerce/e2e-utils'); + +/** + * Add shipping class(es) by filling up and submitting the 'Add shipping class' form + */ +const addShippingClasses = async (...shippingClasses) => { + for (const { name, slug, description } of shippingClasses) { + await expect(page).toClick('.wc-shipping-class-add') + await expect(page).toFill('.editing [data-attribute="name"]', name) + await expect(page).toFill('.editing [data-attribute="slug"]', slug) + await expect(page).toFill('.editing [data-attribute="description"]', description) + } + + await expect(page).toClick('.wc-shipping-class-save') +} + +/** + * Verify that the specified shipping classes were saved + */ +const verifyThatShippingClassWasSaved = async (...savedShippingClasses) => { + for (const { name, slug, description } of savedShippingClasses) { + const savedClass = await expect(page).toMatchElement('.wc-shipping-class-rows tr', { text: slug }) + + await expect(savedClass).toMatchElement('.wc-shipping-class-name', name) + await expect(savedClass).toMatchElement('.wc-shipping-class-slug', slug) + await expect(savedClass).toMatchElement('.wc-shipping-class-description', description) + } +} + +const runAddShippingClassesTest = () => { + describe('Merchant can add a shipping class', () => { + beforeAll(async () => { + await merchant.login(); + + // Go to Shipping Classes page + await merchant.openSettings('shipping', 'classes'); + }); + + // wip + it('can add a new shipping class', async () => { + const expectedShippingClasses = { + name: faker.lorem.words(), + slug: faker.lorem.slug(), + description: faker.lorem.sentence() + } + + await addShippingClasses(expectedShippingClasses) + await verifyThatShippingClassWasSaved(expectedShippingClasses) + }); + + // it('can add multiple shipping classes at once', async () => { + // // todo + // }); + + // it('can automatically generate slug', async () => { + // // todo + // }); + }); +}; + +module.exports = runAddShippingClassesTest;