Merge pull request #28661 from woocommerce/e2e-shopper-cart-apply-coupon
Add new e2e test shopper cart apply coupon
This commit is contained in:
commit
d882433db4
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
- Shopper Checkout Apply Coupon
|
- Shopper Checkout Apply Coupon
|
||||||
|
|
||||||
|
|
||||||
|
- Shopper Cart Apply Coupon
|
||||||
|
|
||||||
## Fixed
|
## Fixed
|
||||||
|
|
||||||
- Flaky Create Product, Coupon, and Order tests
|
- Flaky Create Product, Coupon, and Order tests
|
||||||
|
|
|
@ -9,6 +9,7 @@ const { runOnboardingFlowTest, runTaskListTest } = require( './activate-and-setu
|
||||||
const runInitialStoreSettingsTest = require( './activate-and-setup/setup.test' );
|
const runInitialStoreSettingsTest = require( './activate-and-setup/setup.test' );
|
||||||
|
|
||||||
// Shopper tests
|
// Shopper tests
|
||||||
|
const runCartApplyCouponsTest = require( './shopper/front-end-cart-coupons.test');
|
||||||
const runCartPageTest = require( './shopper/front-end-cart.test' );
|
const runCartPageTest = require( './shopper/front-end-cart.test' );
|
||||||
const runCheckoutApplyCouponsTest = require( './shopper/front-end-checkout-coupons.test');
|
const runCheckoutApplyCouponsTest = require( './shopper/front-end-checkout-coupons.test');
|
||||||
const runCheckoutPageTest = require( './shopper/front-end-checkout.test' );
|
const runCheckoutPageTest = require( './shopper/front-end-checkout.test' );
|
||||||
|
@ -34,6 +35,7 @@ const runSetupOnboardingTests = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const runShopperTests = () => {
|
const runShopperTests = () => {
|
||||||
|
runCartApplyCouponsTest();
|
||||||
runCartPageTest();
|
runCartPageTest();
|
||||||
runCheckoutApplyCouponsTest();
|
runCheckoutApplyCouponsTest();
|
||||||
runCheckoutPageTest();
|
runCheckoutPageTest();
|
||||||
|
@ -60,6 +62,7 @@ module.exports = {
|
||||||
runTaskListTest,
|
runTaskListTest,
|
||||||
runInitialStoreSettingsTest,
|
runInitialStoreSettingsTest,
|
||||||
runSetupOnboardingTests,
|
runSetupOnboardingTests,
|
||||||
|
runCartApplyCouponsTest,
|
||||||
runCartPageTest,
|
runCartPageTest,
|
||||||
runCheckoutApplyCouponsTest,
|
runCheckoutApplyCouponsTest,
|
||||||
runCheckoutPageTest,
|
runCheckoutPageTest,
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
|
||||||
|
/**
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
shopper,
|
||||||
|
merchant,
|
||||||
|
createCoupon,
|
||||||
|
createSimpleProduct,
|
||||||
|
uiUnblocked
|
||||||
|
} = require( '@woocommerce/e2e-utils' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External dependencies
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
it,
|
||||||
|
describe,
|
||||||
|
beforeAll,
|
||||||
|
} = require( '@jest/globals' );
|
||||||
|
|
||||||
|
const runCartApplyCouponsTest = () => {
|
||||||
|
describe('Cart applying coupons', () => {
|
||||||
|
let couponFixedCart;
|
||||||
|
let couponPercentage;
|
||||||
|
let couponFixedProduct;
|
||||||
|
beforeAll(async () => {
|
||||||
|
await merchant.login();
|
||||||
|
await createSimpleProduct();
|
||||||
|
couponFixedCart = await createCoupon();
|
||||||
|
couponPercentage = await createCoupon('50', 'Percentage discount');
|
||||||
|
couponFixedProduct = await createCoupon('5', 'Fixed product discount');
|
||||||
|
await merchant.logout();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows customer to apply coupons in the cart', async () => {
|
||||||
|
await shopper.goToShop();
|
||||||
|
await shopper.addToCartFromShopPage('Simple product');
|
||||||
|
await shopper.goToCart();
|
||||||
|
await shopper.productIsInCart('Simple product');
|
||||||
|
|
||||||
|
// Apply Fixed cart discount coupon
|
||||||
|
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
|
||||||
|
await page.waitForSelector('.order-total');
|
||||||
|
|
||||||
|
// Verify discount applied and order total
|
||||||
|
await page.waitForSelector('.cart-discount .amount', {text: '$5.00'});
|
||||||
|
await page.waitForSelector('.order-total .amount', {text: '$4.99'});
|
||||||
|
|
||||||
|
// Remove coupon
|
||||||
|
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
||||||
|
await uiUnblocked();
|
||||||
|
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
||||||
|
|
||||||
|
// Apply Percentage discount coupon
|
||||||
|
await expect(page).toFill('#coupon_code', couponPercentage);
|
||||||
|
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
|
||||||
|
await expect(page).toClick('.woocommerce-remove-coupon', {text: '[Remove]'});
|
||||||
|
await uiUnblocked();
|
||||||
|
await page.waitForSelector('.woocommerce-message', {text: 'Coupon has been removed.'});
|
||||||
|
|
||||||
|
// Apply Fixed product discount coupon
|
||||||
|
await expect(page).toFill('#coupon_code', couponFixedProduct);
|
||||||
|
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: '$5.00'});
|
||||||
|
await page.waitForSelector('.order-total .amount', {text: '$4.99'});
|
||||||
|
|
||||||
|
// Try to apply the same coupon
|
||||||
|
await expect(page).toFill('#coupon_code', couponFixedProduct);
|
||||||
|
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
|
||||||
|
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.'});
|
||||||
|
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'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = runCartApplyCouponsTest;
|
|
@ -0,0 +1,6 @@
|
||||||
|
/*
|
||||||
|
* Internal dependencies
|
||||||
|
*/
|
||||||
|
const { runCartApplyCouponsTest } = require( '@woocommerce/e2e-core-tests' );
|
||||||
|
|
||||||
|
runCartApplyCouponsTest();
|
Loading…
Reference in New Issue