2019-08-27 12:22:24 +00:00
|
|
|
/**
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
2019-11-24 13:08:48 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { clearAndFillInput } from './index';
|
2019-08-27 12:22:24 +00:00
|
|
|
|
2019-11-24 13:08:48 +00:00
|
|
|
const config = require( 'config' );
|
|
|
|
const baseUrl = config.get( 'url' );
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2019-11-24 13:49:39 +00:00
|
|
|
const WP_ADMIN_LOGIN = baseUrl + 'wp-login.php';
|
|
|
|
const WP_ADMIN_DASHBOARD = baseUrl + 'wp-admin';
|
|
|
|
const WP_ADMIN_PLUGINS = baseUrl + 'wp-admin/plugins.php';
|
|
|
|
const WP_ADMIN_SETUP_WIZARD = baseUrl + 'wp-admin/admin.php?page=wc-setup';
|
2019-11-30 22:07:29 +00:00
|
|
|
const WP_ADMIN_ALL_ORDERS_VIEW = baseUrl + 'wp-admin/edit.php?post_type=shop_order';
|
2019-11-24 13:49:39 +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';
|
|
|
|
const WP_ADMIN_NEW_PRODUCT = baseUrl + 'wp-admin/post-new.php?post_type=product';
|
|
|
|
const WP_ADMIN_WC_SETTINGS = baseUrl + 'wp-admin/admin.php?page=wc-settings&tab=';
|
|
|
|
const WP_ADMIN_PERMALINK_SETTINGS = baseUrl + 'wp-admin/options-permalink.php';
|
|
|
|
|
2019-11-30 22:07:29 +00:00
|
|
|
const SHOP_PAGE = baseUrl + 'shop/';
|
|
|
|
const SHOP_PRODUCT_PAGE = baseUrl + '?p=';
|
2019-11-24 13:49:39 +00:00
|
|
|
const SHOP_CART_PAGE = baseUrl + 'cart/';
|
2019-11-30 22:07:29 +00:00
|
|
|
const SHOP_CHECKOUT_PAGE = baseUrl + 'checkout/';
|
2019-09-24 09:47:47 +00:00
|
|
|
|
2019-11-28 16:46:35 +00:00
|
|
|
|
2019-09-24 09:47:47 +00:00
|
|
|
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"]'
|
|
|
|
);
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
const CustomerFlow = {
|
2019-09-24 09:47:47 +00:00
|
|
|
addToCart: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
page.click( '.single_add_to_cart_button' ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
addToCartFromShopPage: async ( productTitle ) => {
|
|
|
|
const addToCartXPath = `//li[contains(@class, "type-product") and a/h2[contains(text(), "${ productTitle }")]]` +
|
|
|
|
'//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( addToCartXPath + ' and contains(@class, "added")]' );
|
|
|
|
},
|
|
|
|
|
|
|
|
goToCheckout: async () => {
|
|
|
|
await page.goto( SHOP_CHECKOUT_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-09-24 09:47:47 +00:00
|
|
|
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 ) => {
|
2019-11-30 22:07:29 +00:00
|
|
|
await page.goto( SHOP_PRODUCT_PAGE + postID, {
|
2019-09-24 09:47:47 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-11-21 17:21:58 +00:00
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
goToShop: async () => {
|
|
|
|
await page.goto(SHOP_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
placeOrder: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
expect( page ).toClick( '#place_order' ),
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
2019-11-22 12:33:08 +00:00
|
|
|
productIsInCheckout: async ( productTitle, quantity, total, cartSubtotal ) => {
|
|
|
|
await expect( page ).toMatchElement( '.product-name', { text: productTitle } );
|
|
|
|
await expect( page ).toMatchElement( '.product-quantity', { text: quantity } );
|
|
|
|
await expect( page ).toMatchElement( '.product-total .amount', { text: total } );
|
|
|
|
await expect( page ).toMatchElement( '.cart-subtotal .amount', { text: cartSubtotal } );
|
2019-09-24 14:44:10 +00:00
|
|
|
},
|
2019-11-21 17:21:58 +00:00
|
|
|
|
2019-09-24 09:47:47 +00:00
|
|
|
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-11-22 12:33:08 +00:00
|
|
|
fillBillingDetails: async (
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
company,
|
|
|
|
country,
|
|
|
|
addressFirst,
|
|
|
|
addressSecond,
|
|
|
|
city,
|
|
|
|
state,
|
|
|
|
postcode,
|
|
|
|
phone,
|
|
|
|
email
|
|
|
|
) => {
|
|
|
|
await expect( page ).toFill( '#billing_first_name', firstName );
|
|
|
|
await expect( page ).toFill( '#billing_last_name', lastName );
|
|
|
|
await expect( page ).toFill( '#billing_company', company );
|
|
|
|
await expect( page ).toSelect( '#billing_country', country );
|
|
|
|
await expect( page ).toFill( '#billing_address_1', addressFirst );
|
|
|
|
await expect( page ).toFill( '#billing_address_2', addressSecond );
|
|
|
|
await expect( page ).toFill( '#billing_city', city );
|
|
|
|
await expect( page ).toSelect( '#billing_state', state );
|
|
|
|
await expect( page ).toFill( '#billing_postcode', postcode );
|
|
|
|
await expect( page ).toFill( '#billing_phone', phone );
|
|
|
|
await expect( page ).toFill( '#billing_email', email );
|
|
|
|
},
|
|
|
|
|
|
|
|
fillShippingDetails: async (
|
|
|
|
firstName,
|
|
|
|
lastName,
|
|
|
|
company,
|
|
|
|
country,
|
|
|
|
addressFirst,
|
|
|
|
addressSecond,
|
|
|
|
city,
|
|
|
|
state,
|
|
|
|
postcode
|
|
|
|
) => {
|
|
|
|
await expect( page ).toFill( '#shipping_first_name', firstName );
|
|
|
|
await expect( page ).toFill( '#shipping_last_name', lastName );
|
|
|
|
await expect( page ).toFill( '#shipping_company', company );
|
|
|
|
await expect( page ).toSelect( '#shipping_country', country );
|
|
|
|
await expect( page ).toFill( '#shipping_address_1', addressFirst );
|
|
|
|
await expect( page ).toFill( '#shipping_address_2', addressSecond );
|
|
|
|
await expect( page ).toFill( '#shipping_city', city );
|
|
|
|
await expect( page ).toSelect( '#shipping_state', state );
|
|
|
|
await expect( page ).toFill( '#shipping_postcode', postcode );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
};
|
2019-08-27 12:22:24 +00:00
|
|
|
|
|
|
|
const StoreOwnerFlow = {
|
2019-11-23 17:40:29 +00:00
|
|
|
login: async () => {
|
|
|
|
await page.goto( WP_ADMIN_LOGIN, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
|
|
|
|
await expect( page.title() ).resolves.toMatch( 'Log In' );
|
|
|
|
|
2019-11-24 13:08:48 +00:00
|
|
|
await clearAndFillInput( '#user_login', ' ' );
|
|
|
|
|
|
|
|
await page.type( '#user_login', config.get( 'users.admin.username' ) );
|
|
|
|
await page.type( '#user_pass', config.get( 'users.admin.password' ) );
|
2019-11-23 17:40:29 +00:00
|
|
|
|
|
|
|
await Promise.all( [
|
|
|
|
page.click( 'input[type=submit]' ),
|
|
|
|
page.waitForNavigation( { waitUntil: 'networkidle0' } ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
logout: async () => {
|
2019-11-24 13:49:39 +00:00
|
|
|
await page.goto(baseUrl + 'wp-login.php?action=logout', {
|
2019-09-24 14:44:10 +00:00
|
|
|
waitUntil: 'networkidle0',
|
2019-11-06 17:00:48 +00:00
|
|
|
});
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2019-11-06 17:00:48 +00:00
|
|
|
await expect(page).toMatch('You are attempting to log out');
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2019-11-06 17:00:48 +00:00
|
|
|
await Promise.all([
|
|
|
|
page.waitForNavigation({ waitUntil: 'networkidle0' }),
|
|
|
|
page.click('a'),
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2019-11-30 22:07:29 +00:00
|
|
|
openAllOrdersView: async () => {
|
|
|
|
await page.goto( WP_ADMIN_ALL_ORDERS_VIEW, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-11-23 17:40:29 +00:00
|
|
|
openDashboard: async () => {
|
|
|
|
await page.goto( WP_ADMIN_DASHBOARD, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
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 14:44:10 +00:00
|
|
|
},
|
|
|
|
|
2019-08-27 12:22:24 +00:00
|
|
|
openNewProduct: async () => {
|
|
|
|
await page.goto( WP_ADMIN_NEW_PRODUCT, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2019-09-24 14:44:10 +00:00
|
|
|
|
2019-11-23 17:40:29 +00:00
|
|
|
openPermalinkSettings: async () => {
|
|
|
|
await page.goto( WP_ADMIN_PERMALINK_SETTINGS, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-11-24 13:49:39 +00:00
|
|
|
openPlugins: async () => {
|
|
|
|
await page.goto( WP_ADMIN_PLUGINS, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2019-09-24 14:44:10 +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-11-23 17:40:29 +00:00
|
|
|
|
|
|
|
runSetupWizard: async () => {
|
|
|
|
await page.goto( WP_ADMIN_SETUP_WIZARD, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2019-08-27 12:22:24 +00:00
|
|
|
};
|
|
|
|
|
2019-09-24 14:44:10 +00:00
|
|
|
export { CustomerFlow, StoreOwnerFlow };
|