2020-09-30 17:41:31 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
const {
|
2020-12-22 13:59:16 +00:00
|
|
|
merchant,
|
2020-09-30 17:41:31 +00:00
|
|
|
clickTab,
|
2021-09-10 18:30:09 +00:00
|
|
|
AdminEdit,
|
2021-11-09 18:09:26 +00:00
|
|
|
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 () => {
|
2020-12-22 13:59:16 +00:00
|
|
|
await merchant.login();
|
2020-09-30 17:41:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can create new coupon', async () => {
|
|
|
|
// Go to "add coupon" page
|
2020-12-22 13:59:16 +00:00
|
|
|
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');
|
|
|
|
|
2021-09-10 18:30:09 +00:00
|
|
|
// 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.',
|
|
|
|
);
|
2021-09-10 18:30:09 +00:00
|
|
|
// Delete the coupon
|
2021-09-10 21:42:06 +00:00
|
|
|
const couponId = await adminEdit.getId();
|
2021-09-10 18:30:09 +00:00
|
|
|
if ( couponId ) {
|
2021-11-09 18:09:26 +00:00
|
|
|
await withRestApi.deleteCoupon( couponId );
|
2021-09-10 18:30:09 +00:00
|
|
|
}
|
2020-09-30 17:41:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = runCreateCouponTest;
|