Merge branch 'master' into packages/env/clean-up-console
This commit is contained in:
commit
e1a9fa0dc6
|
@ -21,7 +21,7 @@
|
||||||
"pelago/emogrifier": "3.1.0",
|
"pelago/emogrifier": "3.1.0",
|
||||||
"psr/container": "1.0.0",
|
"psr/container": "1.0.0",
|
||||||
"woocommerce/action-scheduler": "3.1.6",
|
"woocommerce/action-scheduler": "3.1.6",
|
||||||
"woocommerce/woocommerce-admin": "1.9.0-rc.3",
|
"woocommerce/woocommerce-admin": "1.9.0",
|
||||||
"woocommerce/woocommerce-blocks": "4.0.0"
|
"woocommerce/woocommerce-blocks": "4.0.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
|
@ -364,9 +364,11 @@ class WC_Tracker {
|
||||||
);
|
);
|
||||||
|
|
||||||
$first = time();
|
$first = time();
|
||||||
|
$processing_first = $first;
|
||||||
|
$first_time = $first;
|
||||||
$last = 0;
|
$last = 0;
|
||||||
$processing_first = time();
|
|
||||||
$processing_last = 0;
|
$processing_last = 0;
|
||||||
|
$order_data = array();
|
||||||
|
|
||||||
$orders = wc_get_orders( $args );
|
$orders = wc_get_orders( $args );
|
||||||
$orders_count = count( $orders );
|
$orders_count = count( $orders );
|
||||||
|
@ -445,10 +447,25 @@ class WC_Tracker {
|
||||||
$orders_count = count( $orders );
|
$orders_count = count( $orders );
|
||||||
}
|
}
|
||||||
|
|
||||||
$order_data['first'] = gmdate( 'Y-m-d H:i:s', $first );
|
if ( $first !== $first_time ) {
|
||||||
$order_data['last'] = gmdate( 'Y-m-d H:i:s', $last );
|
$order_data['first'] = gmdate( 'Y-m-d H:i:s', $first );
|
||||||
$order_data['processing_first'] = gmdate( 'Y-m-d H:i:s', $processing_first );
|
}
|
||||||
$order_data['processing_last'] = gmdate( 'Y-m-d H:i:s', $processing_last );
|
|
||||||
|
if ( $processing_first !== $first_time ) {
|
||||||
|
$order_data['processing_first'] = gmdate( 'Y-m-d H:i:s', $processing_first );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $last ) {
|
||||||
|
$order_data['last'] = gmdate( 'Y-m-d H:i:s', $last );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $processing_last ) {
|
||||||
|
$order_data['processing_last'] = gmdate( 'Y-m-d H:i:s', $processing_last );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $order_data as $key => $value ) {
|
||||||
|
$order_data[ $key ] = (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
return $order_data;
|
return $order_data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@ const {
|
||||||
merchant,
|
merchant,
|
||||||
createCoupon,
|
createCoupon,
|
||||||
createSimpleProduct,
|
createSimpleProduct,
|
||||||
uiUnblocked
|
uiUnblocked,
|
||||||
|
clearAndFillInput,
|
||||||
} = require( '@woocommerce/e2e-utils' );
|
} = require( '@woocommerce/e2e-utils' );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,11 +20,36 @@ const {
|
||||||
beforeAll,
|
beforeAll,
|
||||||
} = require( '@jest/globals' );
|
} = require( '@jest/globals' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply a coupon code to the cart.
|
||||||
|
*
|
||||||
|
* @param couponCode string
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const applyCouponToCart = async ( couponCode ) => {
|
||||||
|
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
||||||
|
await uiUnblocked();
|
||||||
|
await clearAndFillInput('#coupon_code', couponCode);
|
||||||
|
await expect(page).toClick('button', {text: 'Apply coupon'});
|
||||||
|
await uiUnblocked();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove one coupon from the cart.
|
||||||
|
*
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const removeCouponFromCart = async () => {
|
||||||
|
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
||||||
|
await uiUnblocked();
|
||||||
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon has been removed.'});
|
||||||
|
}
|
||||||
const runCheckoutApplyCouponsTest = () => {
|
const runCheckoutApplyCouponsTest = () => {
|
||||||
describe('Checkout applying coupons', () => {
|
describe('Checkout coupons', () => {
|
||||||
let couponFixedCart;
|
let couponFixedCart;
|
||||||
let couponPercentage;
|
let couponPercentage;
|
||||||
let couponFixedProduct;
|
let couponFixedProduct;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await merchant.login();
|
await merchant.login();
|
||||||
await createSimpleProduct();
|
await createSimpleProduct();
|
||||||
|
@ -31,86 +57,63 @@ const runCheckoutApplyCouponsTest = () => {
|
||||||
couponPercentage = await createCoupon('50', 'Percentage discount');
|
couponPercentage = await createCoupon('50', 'Percentage discount');
|
||||||
couponFixedProduct = await createCoupon('5', 'Fixed product discount');
|
couponFixedProduct = await createCoupon('5', 'Fixed product discount');
|
||||||
await merchant.logout();
|
await merchant.logout();
|
||||||
});
|
|
||||||
|
|
||||||
it('allows customer to apply coupons in the checkout', async () => {
|
|
||||||
await shopper.goToShop();
|
await shopper.goToShop();
|
||||||
await shopper.addToCartFromShopPage('Simple product');
|
await shopper.addToCartFromShopPage('Simple product');
|
||||||
await uiUnblocked();
|
await uiUnblocked();
|
||||||
await shopper.goToCheckout();
|
await shopper.goToCheckout();
|
||||||
|
});
|
||||||
|
|
||||||
// Apply Fixed cart discount coupon
|
it('allows customer to apply fixed cart coupon', async () => {
|
||||||
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
await applyCouponToCart( couponFixedCart );
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
||||||
await expect(page).toFill('#coupon_code', couponFixedCart);
|
|
||||||
await expect(page).toClick('button', {text: 'Apply coupon'});
|
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
|
||||||
|
|
||||||
// Wait for page to expand total calculations to avoid flakyness
|
// Wait for page to expand total calculations to avoid flakyness
|
||||||
await page.waitForSelector('.order-total');
|
await page.waitForSelector('.order-total');
|
||||||
|
|
||||||
// Verify discount applied and order total
|
// Verify discount applied and order total
|
||||||
await page.waitForSelector('.cart-discount .amount', {text: '$5.00'});
|
await expect(page).toMatchElement('.cart-discount .amount', {text: '$5.00'});
|
||||||
await page.waitForSelector('.order-total .amount', {text: '$4.99'});
|
await expect(page).toMatchElement('.order-total .amount', {text: '$4.99'});
|
||||||
|
await removeCouponFromCart();
|
||||||
|
});
|
||||||
|
|
||||||
// Remove coupon
|
it('allows customer to apply percentage coupon', async () => {
|
||||||
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
await applyCouponToCart( couponPercentage );
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
|
||||||
|
|
||||||
// Apply Percentage discount coupon
|
// Verify discount applied and order total
|
||||||
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
await expect(page).toMatchElement('.cart-discount .amount', {text: '$4.99'});
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.order-total .amount', {text: '$5.00'});
|
||||||
await expect(page).toFill('#coupon_code', couponPercentage);
|
await removeCouponFromCart();
|
||||||
await expect(page).toClick('button', {text: 'Apply coupon'});
|
});
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
|
||||||
await page.waitForSelector('.cart-discount .amount', {text: '$4.99'});
|
|
||||||
await page.waitForSelector('.order-total .amount', {text: '$5.00'});
|
|
||||||
|
|
||||||
// Remove coupon
|
it('allows customer to apply fixed product coupon', async () => {
|
||||||
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
await applyCouponToCart( couponFixedProduct );
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
await expect(page).toMatchElement('.cart-discount .amount', {text: '$5.00'});
|
||||||
|
await expect(page).toMatchElement('.order-total .amount', {text: '$4.99'});
|
||||||
|
await removeCouponFromCart();
|
||||||
|
});
|
||||||
|
|
||||||
// Apply Fixed product discount coupon
|
it('prevents customer applying same coupon twice', async () => {
|
||||||
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
await applyCouponToCart( couponFixedCart );
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
||||||
await expect(page).toFill('#coupon_code', couponFixedProduct);
|
await applyCouponToCart( couponFixedCart );
|
||||||
await expect(page).toClick('button', {text: 'Apply coupon'});
|
// Verify only one discount applied
|
||||||
await uiUnblocked();
|
// This is a work around for Puppeteer inconsistently finding 'Coupon code already applied'
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
await expect(page).toMatchElement('.cart-discount .amount', {text: '$5.00'});
|
||||||
await page.waitForSelector('.cart-discount .amount', {text: '$5.00'});
|
await expect(page).toMatchElement('.order-total .amount', {text: '$4.99'});
|
||||||
await page.waitForSelector('.order-total .amount', {text: '$4.99'});
|
});
|
||||||
|
|
||||||
// Try to apply the same coupon
|
it('allows customer to apply multiple coupons', async () => {
|
||||||
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
await applyCouponToCart( couponFixedProduct );
|
||||||
await uiUnblocked();
|
await expect(page).toMatchElement('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
||||||
await expect(page).toFill('#coupon_code', couponFixedProduct);
|
await expect(page).toMatchElement('.order-total .amount', {text: '$0.00'});
|
||||||
await expect(page).toClick('button', {text: 'Apply coupon'});
|
});
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-error', { text: 'Coupon code already applied!' });
|
|
||||||
|
|
||||||
// Try to apply multiple coupons
|
it('restores cart total when coupons are removed', async () => {
|
||||||
await expect(page).toClick('a', {text: 'Click here to enter your code'});
|
await removeCouponFromCart();
|
||||||
await uiUnblocked();
|
await removeCouponFromCart();
|
||||||
await expect(page).toFill('#coupon_code', couponFixedCart);
|
await expect(page).toMatchElement('.order-total .amount', {text: '$9.99'});
|
||||||
await expect(page).toClick('button', {text: 'Apply coupon'});
|
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon code applied successfully.'});
|
|
||||||
await page.waitForSelector('.order-total .amount', {text: '$0.00'});
|
|
||||||
|
|
||||||
// Remove coupon
|
|
||||||
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
|
||||||
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
|
||||||
await uiUnblocked();
|
|
||||||
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
|
||||||
|
|
||||||
// Verify the total amount after all coupons removal
|
|
||||||
await page.waitForSelector('.order-total .amount', {text: '$9.99'});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue