woocommerce/packages/js/e2e-core-tests/specs/merchant/wp-admin-coupon-new.test.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-09-30 17:41:31 +00:00
/**
* Internal dependencies
*/
const {
merchant,
2020-09-30 17:41:31 +00:00
clickTab,
AdminEdit,
withRestApi,
2020-09-30 17:41:31 +00:00
} = require( '@woocommerce/e2e-utils' );
/**
* External dependencies
*/
const {
it,
describe,
beforeAll,
} = require( '@jest/globals' );
const runCreateCouponTest = () => {
describe('Add New Coupon Page', () => {
beforeAll(async () => {
await merchant.login();
2020-09-30 17:41:31 +00:00
});
it('can create new coupon', async () => {
// Go to "add coupon" page
await merchant.openNewCoupon();
2020-09-30 17:41:31 +00:00
// Make sure we're on the add coupon page
await expect(page.title()).resolves.toMatch('Add new coupon');
// Fill in coupon code and description
await expect(page).toFill('#title', 'code-' + new Date().getTime().toString());
await expect(page).toFill('#woocommerce-coupon-description', 'test coupon');
// Set general coupon data
await clickTab('General');
await expect(page).toSelect('#discount_type', 'Fixed cart discount');
await expect(page).toFill('#coupon_amount', '100');
// Publish coupon, verify that it was published.
2021-09-10 21:42:06 +00:00
const adminEdit = new AdminEdit();
await adminEdit.verifyPublish(
2020-09-30 17:41:31 +00:00
'#publish',
2020-10-27 19:44:42 +00:00
'.notice',
2020-09-30 17:41:31 +00:00
'Coupon updated.',
);
// Delete the coupon
2021-09-10 21:42:06 +00:00
const couponId = await adminEdit.getId();
if ( couponId ) {
await withRestApi.deleteCoupon( couponId );
}
2020-09-30 17:41:31 +00:00
});
});
}
module.exports = runCreateCouponTest;