woocommerce/tests/e2e/core-tests/specs/merchant/wp-admin-settings-shipping-...

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-03-23 16:56:39 +00:00
/* eslint-disable jest/no-export*/
/**
* Internal dependencies
*/
const { merchant } = require('@woocommerce/e2e-utils');
const { lorem, helpers } = require('faker');
2021-03-21 13:07:50 +00:00
const runAddShippingClassesTest = () => {
2021-03-23 16:56:39 +00:00
describe('Merchant can add shipping classes', () => {
beforeAll(async () => {
await merchant.login();
// Go to Shipping Classes page
await merchant.openSettings('shipping', 'classes');
});
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-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()
};
const shippingClasses = [shippingClassSlug, shippingClassNoSlug];
2021-03-23 16:56:39 +00:00
// 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
);
2021-03-23 16:56:39 +00:00
}
await expect(page).toClick('.wc-shipping-class-save');
2021-03-23 16:56:39 +00:00
// Set the expected auto-generated slug
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) {
const row = await expect(
page
).toMatchElement('.wc-shipping-class-rows tr', { text: slug });
2021-03-23 16:56:39 +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
});
});
};
module.exports = runAddShippingClassesTest;