From f19f39aabbb7c94876df721e8468ed6951caf999 Mon Sep 17 00:00:00 2001 From: rodel Date: Sun, 21 Mar 2021 05:17:37 -0700 Subject: [PATCH 1/8] 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; From 2c3bec842908e70ed270315ebdca82bcd43280fe Mon Sep 17 00:00:00 2001 From: rodel Date: Sun, 21 Mar 2021 06:07:50 -0700 Subject: [PATCH 2/8] Tests for "Add shipping classes" --- ...wp-admin-settings-shipping-classes.test.js | 75 +++++++++++++------ 1 file changed, 51 insertions(+), 24 deletions(-) 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 index b39e46b7dd7..cc14307ad0e 100644 --- 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 @@ -1,6 +1,6 @@ /* eslint-disable jest/no-export, jest/no-disabled-tests */ -import faker from 'faker' +const faker = require("faker"); /** * Internal dependencies @@ -10,12 +10,12 @@ const { merchant } = require('@woocommerce/e2e-utils'); /** * Add shipping class(es) by filling up and submitting the 'Add shipping class' form */ -const addShippingClasses = async (...shippingClasses) => { +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).toFill('.editing:last-child [data-attribute="name"]', name) + await expect(page).toFill('.editing:last-child [data-attribute="slug"]', slug) + await expect(page).toFill('.editing:last-child [data-attribute="description"]', description) } await expect(page).toClick('.wc-shipping-class-save') @@ -24,16 +24,33 @@ const addShippingClasses = async (...shippingClasses) => { /** * Verify that the specified shipping classes were saved */ -const verifyThatShippingClassWasSaved = async (...savedShippingClasses) => { +const verifySavedShippingClasses = async (savedShippingClasses) => { for (const { name, slug, description } of savedShippingClasses) { - const savedClass = await expect(page).toMatchElement('.wc-shipping-class-rows tr', { text: slug }) + const row = 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) + await expect(row).toMatchElement('.wc-shipping-class-name', name) + await expect(row).toMatchElement('.wc-shipping-class-slug', slug) + await expect(row).toMatchElement('.wc-shipping-class-description', description) } } +/** + * Generate an array of shipping class objects to be used as test data. + */ +const generateShippingClassesTestData = (count = 1) => { + const shippingClasses = [] + + while (count--) { + shippingClasses.push({ + name: faker.lorem.words(), + slug: faker.lorem.slug(), + description: faker.lorem.sentence() + }) + } + + return shippingClasses +} + const runAddShippingClassesTest = () => { describe('Merchant can add a shipping class', () => { beforeAll(async () => { @@ -43,25 +60,35 @@ const runAddShippingClassesTest = () => { 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() - } + const shippingClass = generateShippingClassesTestData() - await addShippingClasses(expectedShippingClasses) - await verifyThatShippingClassWasSaved(expectedShippingClasses) + await addShippingClasses(shippingClass) + await verifySavedShippingClasses(shippingClass) }); - // it('can add multiple shipping classes at once', async () => { - // // todo - // }); + it('can add multiple shipping classes at once', async () => { + const shippingClasses = generateShippingClassesTestData(2) - // it('can automatically generate slug', async () => { - // // todo - // }); + await addShippingClasses(shippingClasses) + await verifySavedShippingClasses(shippingClasses) + }); + + it('can automatically generate slug', async () => { + const input = [{ + name: faker.lorem.words(3), + slug: '', + description: '' + }] + const expectedShippingClass = [{ + name: input.name, + slug: faker.helpers.slugify(input.name), + description: '' + }] + + await addShippingClasses(input) + await verifySavedShippingClasses(expectedShippingClass) + }); }); }; From a17a629f3fd6a891768c4144885c0f6cae3f07b4 Mon Sep 17 00:00:00 2001 From: rodel Date: Sun, 21 Mar 2021 06:09:12 -0700 Subject: [PATCH 3/8] re-enabled merchant tests --- tests/e2e/core-tests/specs/index.js | 33 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/e2e/core-tests/specs/index.js b/tests/e2e/core-tests/specs/index.js index ed17a3382c1..294d35435ce 100644 --- a/tests/e2e/core-tests/specs/index.js +++ b/tests/e2e/core-tests/specs/index.js @@ -65,23 +65,22 @@ const runShopperTests = () => { const runMerchantTests = () => { runAddShippingClassesTest() - // todo re-enable - // runOrderSearchingTest(); - // runAddNewShippingZoneTest(); - // runCreateCouponTest(); - // runCreateOrderTest(); - // runEditOrderTest(); - // runAddSimpleProductTest(); - // runAddVariableProductTest(); - // runUpdateGeneralSettingsTest(); - // runProductSettingsTest(); - // runTaxSettingsTest(); - // runOrderStatusFiltersTest(); - // runOrderRefundTest(); - // runOrderApplyCouponTest(); - // runProductEditDetailsTest(); - // runProductSearchTest(); - // runMerchantOrdersCustomerPaymentPage(); + runOrderSearchingTest(); + runAddNewShippingZoneTest(); + runCreateCouponTest(); + runCreateOrderTest(); + runEditOrderTest(); + runAddSimpleProductTest(); + runAddVariableProductTest(); + runUpdateGeneralSettingsTest(); + runProductSettingsTest(); + runTaxSettingsTest(); + runOrderStatusFiltersTest(); + runOrderRefundTest(); + runOrderApplyCouponTest(); + runProductEditDetailsTest(); + runProductSearchTest(); + runMerchantOrdersCustomerPaymentPage(); } const runApiTests = () => { From 1d9194795327096eaa5fc57015566c8d0c3c48c3 Mon Sep 17 00:00:00 2001 From: rodel Date: Tue, 23 Mar 2021 09:56:39 -0700 Subject: [PATCH 4/8] simplified steps and functions --- ...wp-admin-settings-shipping-classes.test.js | 107 ++++++------------ 1 file changed, 33 insertions(+), 74 deletions(-) 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 index cc14307ad0e..0b1cc56d427 100644 --- 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 @@ -1,58 +1,13 @@ -/* eslint-disable jest/no-export, jest/no-disabled-tests */ - -const faker = require("faker"); +/* eslint-disable jest/no-export*/ /** * 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:last-child [data-attribute="name"]', name) - await expect(page).toFill('.editing:last-child [data-attribute="slug"]', slug) - await expect(page).toFill('.editing:last-child [data-attribute="description"]', description) - } - - await expect(page).toClick('.wc-shipping-class-save') -} - -/** - * Verify that the specified shipping classes were saved - */ -const verifySavedShippingClasses = async (savedShippingClasses) => { - for (const { name, slug, description } of savedShippingClasses) { - const row = await expect(page).toMatchElement('.wc-shipping-class-rows tr', { text: slug }) - - await expect(row).toMatchElement('.wc-shipping-class-name', name) - await expect(row).toMatchElement('.wc-shipping-class-slug', slug) - await expect(row).toMatchElement('.wc-shipping-class-description', description) - } -} - -/** - * Generate an array of shipping class objects to be used as test data. - */ -const generateShippingClassesTestData = (count = 1) => { - const shippingClasses = [] - - while (count--) { - shippingClasses.push({ - name: faker.lorem.words(), - slug: faker.lorem.slug(), - description: faker.lorem.sentence() - }) - } - - return shippingClasses -} +const { lorem, helpers } = require("faker"); const runAddShippingClassesTest = () => { - describe('Merchant can add a shipping class', () => { + describe('Merchant can add shipping classes', () => { beforeAll(async () => { await merchant.login(); @@ -60,34 +15,38 @@ const runAddShippingClassesTest = () => { await merchant.openSettings('shipping', 'classes'); }); - it('can add a new shipping class', async () => { - const shippingClass = generateShippingClassesTestData() - - await addShippingClasses(shippingClass) - await verifySavedShippingClasses(shippingClass) - }); - - it('can add multiple shipping classes at once', async () => { - const shippingClasses = generateShippingClassesTestData(2) - - await addShippingClasses(shippingClasses) - await verifySavedShippingClasses(shippingClasses) - }); - - it('can automatically generate slug', async () => { - const input = [{ - name: faker.lorem.words(3), + it('can add shipping classes', async () => { + const shippingClassSlug = { + name: lorem.words(), + slug: lorem.slug(), + description: lorem.sentence() + } + const shippingClassNoSlug = { + name: lorem.words(3), slug: '', - description: '' - }] - const expectedShippingClass = [{ - name: input.name, - slug: faker.helpers.slugify(input.name), - description: '' - }] + description: lorem.sentence() + } + const shippingClasses = [shippingClassSlug, shippingClassNoSlug] - await addShippingClasses(input) - await verifySavedShippingClasses(expectedShippingClass) + // Add shipping classes + for (const { name, slug, description } of shippingClasses) { + await expect(page).toClick('.wc-shipping-class-add') + await expect(page).toFill('.editing:last-child [data-attribute="name"]', name) + await expect(page).toFill('.editing:last-child [data-attribute="slug"]', slug) + await expect(page).toFill('.editing:last-child [data-attribute="description"]', description) + } + await expect(page).toClick('.wc-shipping-class-save') + + // Set the expected auto-generated slug + shippingClassNoSlug.slug = helpers.slugify(shippingClassNoSlug.name) + + // Verify that the specified shipping classes were saved + for (const { name, slug, description } of shippingClasses) { + const row = await expect(page).toMatchElement('.wc-shipping-class-rows tr', { text: slug }) + + await expect(row).toMatchElement('.wc-shipping-class-name', name) + await expect(row).toMatchElement('.wc-shipping-class-description', description) + } }); }); }; From 8d4ebb935e7807defbf6770e8d7705a6c755275b Mon Sep 17 00:00:00 2001 From: rodel-calasagsag Date: Sun, 4 Apr 2021 01:20:59 -0700 Subject: [PATCH 5/8] Add missing exports for this test --- tests/e2e/core-tests/specs/index.js | 3 ++- tests/e2e/specs/wp-admin/test-add-shipping-classes.js | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/specs/wp-admin/test-add-shipping-classes.js diff --git a/tests/e2e/core-tests/specs/index.js b/tests/e2e/core-tests/specs/index.js index 294d35435ce..b9b0f1381e3 100644 --- a/tests/e2e/core-tests/specs/index.js +++ b/tests/e2e/core-tests/specs/index.js @@ -64,7 +64,7 @@ const runShopperTests = () => { }; const runMerchantTests = () => { - runAddShippingClassesTest() + runAddShippingClassesTest(); runOrderSearchingTest(); runAddNewShippingZoneTest(); runCreateCouponTest(); @@ -129,4 +129,5 @@ module.exports = { runAddNewShippingZoneTest, runProductBrowseSearchSortTest, runApiTests, + runAddShippingClassesTest }; diff --git a/tests/e2e/specs/wp-admin/test-add-shipping-classes.js b/tests/e2e/specs/wp-admin/test-add-shipping-classes.js new file mode 100644 index 00000000000..5b51054cb7d --- /dev/null +++ b/tests/e2e/specs/wp-admin/test-add-shipping-classes.js @@ -0,0 +1,6 @@ +/* + * Internal dependencies + */ +const { runAddShippingClassesTest } = require( '@woocommerce/e2e-core-tests' ); + +runAddShippingClassesTest(); From e39badbcf71494870e06619a3c37b6e883a80fcb Mon Sep 17 00:00:00 2001 From: rodel-calasagsag Date: Sun, 4 Apr 2021 01:26:27 -0700 Subject: [PATCH 6/8] Fixed missing semi-colons and other styling issues --- ...wp-admin-settings-shipping-classes.test.js | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) 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 index 0b1cc56d427..1d35bfbe679 100644 --- 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 @@ -4,7 +4,7 @@ * Internal dependencies */ const { merchant } = require('@woocommerce/e2e-utils'); -const { lorem, helpers } = require("faker"); +const { lorem, helpers } = require('faker'); const runAddShippingClassesTest = () => { describe('Merchant can add shipping classes', () => { @@ -20,32 +20,51 @@ const runAddShippingClassesTest = () => { name: lorem.words(), slug: lorem.slug(), description: lorem.sentence() - } + }; const shippingClassNoSlug = { name: lorem.words(3), slug: '', description: lorem.sentence() - } - const shippingClasses = [shippingClassSlug, shippingClassNoSlug] + }; + const shippingClasses = [shippingClassSlug, shippingClassNoSlug]; // Add shipping classes for (const { name, slug, description } of shippingClasses) { - await expect(page).toClick('.wc-shipping-class-add') - await expect(page).toFill('.editing:last-child [data-attribute="name"]', name) - await expect(page).toFill('.editing:last-child [data-attribute="slug"]', slug) - await expect(page).toFill('.editing:last-child [data-attribute="description"]', description) + await expect(page).toClick('.wc-shipping-class-add'); + await expect(page).toFill( + '.editing:last-child [data-attribute="name"]', + name + ); + await expect(page).toFill( + '.editing:last-child [data-attribute="slug"]', + slug + ); + await expect(page).toFill( + '.editing:last-child [data-attribute="description"]', + description + ); } - await expect(page).toClick('.wc-shipping-class-save') + await expect(page).toClick('.wc-shipping-class-save'); // Set the expected auto-generated slug - shippingClassNoSlug.slug = helpers.slugify(shippingClassNoSlug.name) + shippingClassNoSlug.slug = helpers.slugify( + shippingClassNoSlug.name + ); // Verify that the specified shipping classes were saved for (const { name, slug, description } of shippingClasses) { - const row = await expect(page).toMatchElement('.wc-shipping-class-rows tr', { text: slug }) + const row = await expect( + page + ).toMatchElement('.wc-shipping-class-rows tr', { text: slug }); - await expect(row).toMatchElement('.wc-shipping-class-name', name) - await expect(row).toMatchElement('.wc-shipping-class-description', description) + await expect(row).toMatchElement( + '.wc-shipping-class-name', + name + ); + await expect(row).toMatchElement( + '.wc-shipping-class-description', + description + ); } }); }); From 68df2796a92b971c69c01718ba74ca423036ea52 Mon Sep 17 00:00:00 2001 From: rodel-calasagsag Date: Sun, 4 Apr 2021 01:39:57 -0700 Subject: [PATCH 7/8] Added 'faker' dependency --- tests/e2e/core-tests/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/e2e/core-tests/package.json b/tests/e2e/core-tests/package.json index edc537d927b..f94e1081d3c 100644 --- a/tests/e2e/core-tests/package.json +++ b/tests/e2e/core-tests/package.json @@ -11,7 +11,8 @@ "main": "index.js", "dependencies": { "@jest/globals": "^26.4.2", - "config": "3.3.3" + "config": "3.3.3", + "faker": "^5.5.2" }, "peerDependencies": { "@woocommerce/api": "^0.1.1", From fb5ccc14a1427819970e676eef55e20e42aa0203 Mon Sep 17 00:00:00 2001 From: rodel-calasagsag Date: Tue, 6 Apr 2021 02:26:58 -0700 Subject: [PATCH 8/8] Consistent faker version --- tests/e2e/core-tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/core-tests/package.json b/tests/e2e/core-tests/package.json index 04dacc5d626..06c0628b776 100644 --- a/tests/e2e/core-tests/package.json +++ b/tests/e2e/core-tests/package.json @@ -12,7 +12,7 @@ "dependencies": { "@jest/globals": "^26.4.2", "config": "3.3.3", - "faker": "^5.5.2" + "faker": "^5.1.0" }, "peerDependencies": { "@woocommerce/api": "^0.1.2",