update order coupon test to use api, evalAndClick
This commit is contained in:
parent
6ece4bc82d
commit
c4074e7bf2
|
@ -28,29 +28,27 @@ const runOrderApplyCouponTest = () => {
|
||||||
describe('WooCommerce Orders > Apply coupon', () => {
|
describe('WooCommerce Orders > Apply coupon', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await merchant.login();
|
await merchant.login();
|
||||||
await Promise.all([
|
await createSimpleProduct();
|
||||||
await createSimpleProduct(),
|
couponCode = await createCoupon();
|
||||||
couponCode = await createCoupon(),
|
orderId = await createSimpleOrder('Pending payment', simpleProductName);
|
||||||
orderId = await createSimpleOrder('Pending payment', simpleProductName),
|
await addProductToOrder(orderId, simpleProductName);
|
||||||
await addProductToOrder(orderId, simpleProductName),
|
|
||||||
|
|
||||||
// We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below
|
// We need to remove any listeners on the `dialog` event otherwise we can't catch the dialog below
|
||||||
page.removeAllListeners('dialog'),
|
await page.removeAllListeners('dialog');
|
||||||
]);
|
|
||||||
|
|
||||||
// Make sure the simple product price is greater than the coupon amount
|
// Make sure the simple product price is greater than the coupon amount
|
||||||
await expect(Number(simpleProductPrice)).toBeGreaterThan(5.00);
|
await expect(Number(simpleProductPrice)).toBeGreaterThan(5.00);
|
||||||
} );
|
} );
|
||||||
|
|
||||||
it('can apply a coupon', async () => {
|
it('can apply a coupon', async () => {
|
||||||
|
await page.waitForSelector('button.add-coupon');
|
||||||
const couponDialog = await expect(page).toDisplayDialog(async () => {
|
const couponDialog = await expect(page).toDisplayDialog(async () => {
|
||||||
await expect(page).toClick('button.add-coupon');
|
await evalAndClick('button.add-coupon');
|
||||||
});
|
});
|
||||||
expect(couponDialog.message()).toMatch(couponDialogMessage);
|
expect(couponDialog.message()).toMatch(couponDialogMessage);
|
||||||
|
|
||||||
// Accept the dialog with the coupon code
|
// Accept the dialog with the coupon code
|
||||||
await couponDialog.accept(couponCode);
|
await couponDialog.accept(couponCode);
|
||||||
|
|
||||||
await uiUnblocked();
|
await uiUnblocked();
|
||||||
|
|
||||||
// Verify the coupon list is showing
|
// Verify the coupon list is showing
|
||||||
|
@ -64,12 +62,6 @@ const runOrderApplyCouponTest = () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can remove a coupon', async () => {
|
it('can remove a coupon', async () => {
|
||||||
// Temporarily add screenshot
|
|
||||||
const screenshot = await takeScreenshotFor( 'before removing a coupon' );
|
|
||||||
if ( screenshot.filePath ) {
|
|
||||||
await sendFailedTestScreenshotToSlack( screenshot.filePath );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we have a coupon on the page to use
|
// Make sure we have a coupon on the page to use
|
||||||
await page.waitForSelector('.wc-used-coupons');
|
await page.waitForSelector('.wc-used-coupons');
|
||||||
await expect(page).toMatchElement('.wc_coupon_list li.code.editable', { text: couponCode.toLowerCase() });
|
await expect(page).toMatchElement('.wc_coupon_list li.code.editable', { text: couponCode.toLowerCase() });
|
||||||
|
|
|
@ -17,7 +17,9 @@ import {
|
||||||
clearAndFillInput,
|
clearAndFillInput,
|
||||||
} from './page-utils';
|
} from './page-utils';
|
||||||
import factories from './factories';
|
import factories from './factories';
|
||||||
|
import { Coupon } from '@woocommerce/api';
|
||||||
|
|
||||||
|
const client = factories.api.withDefaultPermalinks;
|
||||||
const config = require( 'config' );
|
const config = require( 'config' );
|
||||||
const simpleProductName = config.get( 'products.simple.name' );
|
const simpleProductName = config.get( 'products.simple.name' );
|
||||||
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
const simpleProductPrice = config.has('products.simple.price') ? config.get('products.simple.price') : '9.99';
|
||||||
|
@ -452,23 +454,29 @@ const addProductToOrder = async ( orderId, productName ) => {
|
||||||
* @param discountType Type of a coupon. Defaults to Fixed cart discount.
|
* @param discountType Type of a coupon. Defaults to Fixed cart discount.
|
||||||
*/
|
*/
|
||||||
const createCoupon = async ( couponAmount = '5', discountType = 'Fixed cart discount' ) => {
|
const createCoupon = async ( couponAmount = '5', discountType = 'Fixed cart discount' ) => {
|
||||||
await merchant.openNewCoupon();
|
let couponType;
|
||||||
|
switch ( discountType ) {
|
||||||
|
case "Fixed cart discount":
|
||||||
|
couponType = 'fixed_cart';
|
||||||
|
break;
|
||||||
|
case "Fixed product discount":
|
||||||
|
couponType = 'fixed_product';
|
||||||
|
break;
|
||||||
|
case "Percentage discount":
|
||||||
|
couponType = 'percent';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
// Fill in coupon code
|
// Fill in coupon code
|
||||||
let couponCode = 'Code-' + discountType + new Date().getTime().toString();
|
let couponCode = 'code-' + couponType + new Date().getTime().toString();
|
||||||
await expect(page).toFill( '#title', couponCode );
|
const repository = Coupon.restRepository( client );
|
||||||
|
await repository.create( {
|
||||||
// Set general coupon data
|
code: couponCode,
|
||||||
await clickTab( 'General' );
|
discountType: couponType,
|
||||||
await expect(page).toSelect( '#discount_type', discountType );
|
amount: couponAmount,
|
||||||
await expect(page).toFill( '#coupon_amount', couponAmount );
|
});
|
||||||
|
|
||||||
// Publish coupon
|
|
||||||
await expect( page ).toClick( '#publish' );
|
|
||||||
await page.waitForSelector( '.updated.notice' );
|
|
||||||
|
|
||||||
// Verify
|
|
||||||
await expect( page ).toMatchElement( '.updated.notice', { text: 'Coupon updated.' } );
|
|
||||||
|
|
||||||
return couponCode;
|
return couponCode;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue