2019-11-06 22:17:44 +00:00
|
|
|
import { clickTab } from "./index";
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
/**
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
|
|
|
const baseUrl = process.env.WP_BASE_URL;
|
|
|
|
|
2019-08-29 16:09:42 +00:00
|
|
|
const WP_ADMIN_NEW_COUPON = baseUrl + '/wp-admin/post-new.php?post_type=shop_coupon';
|
|
|
|
const WP_ADMIN_NEW_ORDER = baseUrl + '/wp-admin/post-new.php?post_type=shop_order';
|
2019-08-27 12:22:24 +00:00
|
|
|
const WP_ADMIN_NEW_PRODUCT = baseUrl + '/wp-admin/post-new.php?post_type=product';
|
2019-08-30 11:53:45 +00:00
|
|
|
const WP_ADMIN_WC_SETTINGS = baseUrl + '/wp-admin/admin.php?page=wc-settings&tab=';
|
2019-08-27 12:22:24 +00:00
|
|
|
|
2019-11-06 22:17:44 +00:00
|
|
|
const SHOP_PRODUCT = baseUrl + '/?p=';
|
2019-09-24 09:47:47 +00:00
|
|
|
const SHOP_CART_PAGE = baseUrl + '/cart/';
|
|
|
|
|
|
|
|
const getProductColumnExpression = ( productTitle ) => (
|
|
|
|
'td[@class="product-name" and ' +
|
|
|
|
`a[contains(text(), "${ productTitle }")]` +
|
|
|
|
']'
|
|
|
|
);
|
|
|
|
|
|
|
|
const getQtyColumnExpression = ( args ) => (
|
|
|
|
'td[@class="product-quantity" and ' +
|
|
|
|
'.//' + getQtyInputExpression( args ) +
|
|
|
|
']'
|
|
|
|
);
|
|
|
|
|
|
|
|
const getQtyInputExpression = ( args = {} ) => {
|
|
|
|
let qtyValue = '';
|
|
|
|
|
|
|
|
if ( args.checkQty ) {
|
|
|
|
qtyValue = ` and @value="${ args.qty }"`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'input[contains(@class, "input-text")' + qtyValue + ']';
|
|
|
|
};
|
|
|
|
|
|
|
|
const getCartItemExpression = ( productTitle, args ) => (
|
|
|
|
'//tr[contains(@class, "cart_item") and ' +
|
|
|
|
getProductColumnExpression( productTitle ) +
|
|
|
|
' and ' +
|
|
|
|
getQtyColumnExpression( args ) +
|
|
|
|
']'
|
|
|
|
);
|
|
|
|
|
|
|
|
const getRemoveExpression = () => (
|
|
|
|
'td[@class="product-remove"]//a[@class="remove"]'
|
|
|
|
);
|
|
|
|
|
|
|
|
const CustomerFlow = {
|
|
|
|
addToCart: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
page.click( '.single_add_to_cart_button' ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
|
|
|
removeFromCart: async ( productTitle ) => {
|
|
|
|
const cartItemXPath = getCartItemExpression( productTitle );
|
|
|
|
const removeItemXPath = cartItemXPath + '//' + getRemoveExpression();
|
|
|
|
|
|
|
|
const [ removeButton ] = await page.$x( removeItemXPath );
|
|
|
|
await removeButton.click();
|
|
|
|
},
|
|
|
|
|
2019-11-06 22:17:44 +00:00
|
|
|
goToProduct: async ( postID ) => {
|
|
|
|
await page.goto( SHOP_PRODUCT + postID, {
|
2019-09-24 09:47:47 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
goToCart: async () => {
|
|
|
|
await page.goto( SHOP_CART_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
productIsInCart: async ( productTitle, quantity = null ) => {
|
|
|
|
const cartItemArgs = quantity ? { qty: quantity } : {};
|
|
|
|
const cartItemXPath = getCartItemExpression( productTitle, cartItemArgs );
|
|
|
|
|
|
|
|
await expect( page.$x( cartItemXPath ) ).resolves.toHaveLength( 1 );
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
const StoreOwnerFlow = {
|
2019-09-24 10:39:24 +00:00
|
|
|
logout: async () => {
|
2019-11-06 17:00:48 +00:00
|
|
|
await page.goto(baseUrl + '/wp-login.php?action=logout', {
|
2019-09-24 10:39:24 +00:00
|
|
|
waitUntil: 'networkidle0',
|
2019-11-06 17:00:48 +00:00
|
|
|
});
|
2019-09-24 10:39:24 +00:00
|
|
|
|
2019-11-06 17:00:48 +00:00
|
|
|
await expect(page).toMatch('You are attempting to log out');
|
2019-09-24 10:39:24 +00:00
|
|
|
|
2019-11-06 17:00:48 +00:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForNavigation({ waitUntil: 'networkidle0' }),
|
|
|
|
page.click('a'),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2019-08-29 16:09:42 +00:00
|
|
|
openNewCoupon: async () => {
|
|
|
|
await page.goto( WP_ADMIN_NEW_COUPON, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
openNewOrder: async () => {
|
|
|
|
await page.goto( WP_ADMIN_NEW_ORDER, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
2019-09-24 10:39:24 +00:00
|
|
|
},
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
openNewProduct: async () => {
|
|
|
|
await page.goto( WP_ADMIN_NEW_PRODUCT, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2019-08-30 11:53:45 +00:00
|
|
|
|
|
|
|
openSettings: async ( tab, section = null ) => {
|
|
|
|
let settingsUrl = WP_ADMIN_WC_SETTINGS + tab;
|
|
|
|
|
|
|
|
if ( section ) {
|
|
|
|
settingsUrl += `§ion=${ section }`;
|
|
|
|
}
|
|
|
|
|
|
|
|
await page.goto( settingsUrl, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2019-08-27 12:22:24 +00:00
|
|
|
};
|
|
|
|
|
2019-09-24 09:47:47 +00:00
|
|
|
export { CustomerFlow, StoreOwnerFlow };
|