Add new e2e test shopper cart redirection
This commit is contained in:
parent
b4a9560358
commit
45fdc3451c
|
@ -5,6 +5,7 @@
|
|||
## Added
|
||||
|
||||
- Shopper My Account Create Account
|
||||
- Shopper Cart Redirection
|
||||
|
||||
## Fixed
|
||||
|
||||
|
|
|
@ -78,6 +78,7 @@ The functions to access the core tests are:
|
|||
- `runVariableProductUpdateTest` - Shopper can view and update variations on a variable product
|
||||
- `runCheckoutCreateAccountTest` - Shopper can create an account during checkout
|
||||
- `runMyAccountCreateAccountTest` - Shopper can create an account via my account page
|
||||
- `runCartRedirectionTest` - Shopper is redirected to the cart page after adding to cart
|
||||
|
||||
### REST API
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ const runMyAccountCreateAccountTest = require( './shopper/front-end-my-account-c
|
|||
const runSingleProductPageTest = require( './shopper/front-end-single-product.test' );
|
||||
const runVariableProductUpdateTest = require( './shopper/front-end-variable-product-updates.test' );
|
||||
const runCheckoutCreateAccountTest = require( './shopper/front-end-checkout-create-account.test' );
|
||||
const runCartRedirectionTest = require( './shopper/front-end-cart-redirection.test' );
|
||||
|
||||
// Merchant tests
|
||||
const runAddNewShippingZoneTest = require ( './merchant/wp-admin-settings-shipping-zones.test' );
|
||||
|
@ -65,6 +66,7 @@ const runShopperTests = () => {
|
|||
runSingleProductPageTest();
|
||||
runVariableProductUpdateTest();
|
||||
runCheckoutCreateAccountTest();
|
||||
runCartRedirectionTest();
|
||||
};
|
||||
|
||||
const runMerchantTests = () => {
|
||||
|
@ -136,4 +138,5 @@ module.exports = {
|
|||
runAnalyticsPageLoadsTest,
|
||||
runCheckoutCreateAccountTest,
|
||||
runMyAccountCreateAccountTest,
|
||||
runCartRedirectionTest,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/* eslint-disable jest/no-export, jest/no-disabled-tests, jest/expect-expect */
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
const {
|
||||
shopper,
|
||||
merchant,
|
||||
createSimpleProduct,
|
||||
setCheckbox,
|
||||
unsetCheckbox,
|
||||
settingsPageSaveChanges,
|
||||
} = require( '@woocommerce/e2e-utils' );
|
||||
|
||||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
const {
|
||||
it,
|
||||
describe,
|
||||
beforeAll,
|
||||
afterAll,
|
||||
} = require( '@jest/globals' );
|
||||
|
||||
const config = require( 'config' );
|
||||
const simpleProductName = config.get( 'products.simple.name' );
|
||||
|
||||
const runCartRedirectionTest = () => {
|
||||
describe('Cart > Redirect to cart from shop', () => {
|
||||
let simplePostIdValue;
|
||||
beforeAll(async () => {
|
||||
await merchant.login();
|
||||
simplePostIdValue = await createSimpleProduct();
|
||||
|
||||
// Set checkbox in settings to enable cart redirection
|
||||
await merchant.openSettings('products');
|
||||
await setCheckbox('#woocommerce_cart_redirect_after_add');
|
||||
await settingsPageSaveChanges();
|
||||
|
||||
await merchant.logout();
|
||||
});
|
||||
|
||||
it('can redirect user to cart from shop page', async () => {
|
||||
await shopper.goToShop();
|
||||
|
||||
// Add to cart from shop page
|
||||
const addToCartXPath = `//li[contains(@class, "type-product") and a/h2[contains(text(), "${ simpleProductName }")]]` +
|
||||
'//a[contains(@class, "add_to_cart_button") and contains(@class, "ajax_add_to_cart")';
|
||||
const [ addToCartButton ] = await page.$x( addToCartXPath + ']' );
|
||||
addToCartButton.click();
|
||||
await page.waitFor(1000); // to avoid flakiness
|
||||
|
||||
await shopper.productIsInCart(simpleProductName);
|
||||
await shopper.removeFromCart(simpleProductName);
|
||||
});
|
||||
|
||||
it('can redirect user to cart from detail page', async () => {
|
||||
await shopper.goToProduct(simplePostIdValue);
|
||||
|
||||
// Add to cart from detail page
|
||||
await shopper.addToCart();
|
||||
await page.waitFor(1000); // to avoid flakiness
|
||||
|
||||
await shopper.productIsInCart(simpleProductName);
|
||||
await shopper.removeFromCart(simpleProductName);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await merchant.login();
|
||||
await merchant.openSettings('products');
|
||||
await unsetCheckbox('#woocommerce_cart_redirect_after_add');
|
||||
await settingsPageSaveChanges();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = runCartRedirectionTest;
|
|
@ -0,0 +1,6 @@
|
|||
/*
|
||||
* Internal dependencies
|
||||
*/
|
||||
const { runCartRedirectionTest } = require( '@woocommerce/e2e-core-tests' );
|
||||
|
||||
runCartRedirectionTest();
|
Loading…
Reference in New Issue