2021-03-21 12:17:37 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-10-22 21:35:29 +00:00
|
|
|
const { merchant, withRestApi } = require('@woocommerce/e2e-utils');
|
2021-04-04 08:26:27 +00:00
|
|
|
const { lorem, helpers } = require('faker');
|
2021-03-21 13:07:50 +00:00
|
|
|
|
2021-03-21 12:17:37 +00:00
|
|
|
const runAddShippingClassesTest = () => {
|
2021-03-23 16:56:39 +00:00
|
|
|
describe('Merchant can add shipping classes', () => {
|
2021-03-21 12:17:37 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
await merchant.login();
|
|
|
|
|
|
|
|
// Go to Shipping Classes page
|
|
|
|
await merchant.openSettings('shipping', 'classes');
|
|
|
|
});
|
|
|
|
|
2021-10-22 21:35:29 +00:00
|
|
|
afterAll(async () => {
|
2021-11-10 16:25:09 +00:00
|
|
|
await withRestApi.deleteAllShippingClasses( false );
|
2021-10-22 21:35:29 +00:00
|
|
|
});
|
|
|
|
|
2021-03-23 16:56:39 +00:00
|
|
|
it('can add shipping classes', async () => {
|
|
|
|
const shippingClassSlug = {
|
|
|
|
name: lorem.words(),
|
|
|
|
slug: lorem.slug(),
|
|
|
|
description: lorem.sentence()
|
2021-04-04 08:26:27 +00:00
|
|
|
};
|
2021-03-23 16:56:39 +00:00
|
|
|
const shippingClassNoSlug = {
|
|
|
|
name: lorem.words(3),
|
2021-03-21 13:07:50 +00:00
|
|
|
slug: '',
|
2021-03-23 16:56:39 +00:00
|
|
|
description: lorem.sentence()
|
2021-04-04 08:26:27 +00:00
|
|
|
};
|
|
|
|
const shippingClasses = [shippingClassSlug, shippingClassNoSlug];
|
2021-03-23 16:56:39 +00:00
|
|
|
|
|
|
|
// Add shipping classes
|
|
|
|
for (const { name, slug, description } of shippingClasses) {
|
2021-04-04 08:26:27 +00:00
|
|
|
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
|
|
|
|
);
|
2021-03-23 16:56:39 +00:00
|
|
|
}
|
2021-04-04 08:26:27 +00:00
|
|
|
await expect(page).toClick('.wc-shipping-class-save');
|
2021-03-23 16:56:39 +00:00
|
|
|
|
|
|
|
// Set the expected auto-generated slug
|
2021-04-04 08:26:27 +00:00
|
|
|
shippingClassNoSlug.slug = helpers.slugify(
|
|
|
|
shippingClassNoSlug.name
|
|
|
|
);
|
2021-03-23 16:56:39 +00:00
|
|
|
|
|
|
|
// Verify that the specified shipping classes were saved
|
|
|
|
for (const { name, slug, description } of shippingClasses) {
|
2021-04-04 08:26:27 +00:00
|
|
|
const row = await expect(
|
|
|
|
page
|
2021-08-26 01:00:22 +00:00
|
|
|
).toMatchElement('.wc-shipping-class-rows tr', { text: slug, timeout: 50000 });
|
2021-03-23 16:56:39 +00:00
|
|
|
|
2021-04-04 08:26:27 +00:00
|
|
|
await expect(row).toMatchElement(
|
|
|
|
'.wc-shipping-class-name',
|
|
|
|
name
|
|
|
|
);
|
|
|
|
await expect(row).toMatchElement(
|
|
|
|
'.wc-shipping-class-description',
|
|
|
|
description
|
|
|
|
);
|
2021-03-23 16:56:39 +00:00
|
|
|
}
|
2021-03-21 13:07:50 +00:00
|
|
|
});
|
2021-03-21 12:17:37 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = runAddShippingClassesTest;
|