2021-04-14 14:50:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-03-01 11:25:13 +00:00
|
|
|
import {
|
|
|
|
shopper as wcShopper,
|
|
|
|
uiUnblocked,
|
|
|
|
SHOP_CART_PAGE,
|
|
|
|
} from '@woocommerce/e2e-utils';
|
2021-04-14 14:50:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getBlockPagePermalink } from './get-block-page-permalink';
|
2022-02-25 09:44:16 +00:00
|
|
|
import { SHOP_CART_BLOCK_PAGE, SHOP_CHECKOUT_BLOCK_PAGE } from './constants';
|
2021-04-14 14:50:27 +00:00
|
|
|
|
|
|
|
export const shopper = {
|
|
|
|
...wcShopper,
|
|
|
|
|
|
|
|
goToCheckoutBlock: async () => {
|
2022-02-25 09:44:16 +00:00
|
|
|
await page.goto( SHOP_CHECKOUT_BLOCK_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2021-04-14 14:50:27 +00:00
|
|
|
|
2022-02-25 09:44:16 +00:00
|
|
|
goToCartBlock: async () => {
|
|
|
|
await page.goto( SHOP_CART_BLOCK_PAGE, {
|
2021-04-14 14:50:27 +00:00
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
productIsInCheckoutBlock: async ( productTitle, quantity, total ) => {
|
2021-05-18 13:09:30 +00:00
|
|
|
// Make sure Order summary is expanded
|
|
|
|
const [ button ] = await page.$x(
|
|
|
|
`//button[contains(@aria-expanded, 'false')]//span[contains(text(), 'Order summary')]`
|
2021-04-14 14:50:27 +00:00
|
|
|
);
|
2021-05-18 13:09:30 +00:00
|
|
|
if ( button ) {
|
|
|
|
await button.click();
|
|
|
|
}
|
2022-02-24 11:31:26 +00:00
|
|
|
await expect( page ).toMatchElement( 'span', {
|
2021-05-18 13:09:30 +00:00
|
|
|
text: productTitle,
|
|
|
|
} );
|
2022-02-24 11:31:26 +00:00
|
|
|
await expect( page ).toMatchElement(
|
2021-05-18 13:09:30 +00:00
|
|
|
'div.wc-block-components-order-summary-item__quantity',
|
2021-04-14 14:50:27 +00:00
|
|
|
{
|
|
|
|
text: quantity,
|
|
|
|
}
|
|
|
|
);
|
2022-02-24 11:31:26 +00:00
|
|
|
await expect( page ).toMatchElement(
|
2021-05-18 13:09:30 +00:00
|
|
|
'span.wc-block-components-product-price__value',
|
2021-04-14 14:50:27 +00:00
|
|
|
{
|
|
|
|
text: total,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2022-02-22 02:50:59 +00:00
|
|
|
|
|
|
|
goToBlockPage: async ( title ) => {
|
2022-02-22 04:34:51 +00:00
|
|
|
await page.goto( await getBlockPagePermalink( title ), {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
2022-02-22 02:50:59 +00:00
|
|
|
|
|
|
|
await expect( page ).toMatchElement( 'h1', { text: title } );
|
|
|
|
},
|
2022-03-01 11:25:13 +00:00
|
|
|
|
2022-03-07 15:23:31 +00:00
|
|
|
block: {
|
|
|
|
goToCart: async () => {
|
|
|
|
await page.goto( SHOP_CART_BLOCK_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
2022-03-01 11:25:13 +00:00
|
|
|
|
2022-03-08 13:52:40 +00:00
|
|
|
goToCheckout: async () => {
|
|
|
|
await page.goto( SHOP_CHECKOUT_BLOCK_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
2022-03-07 15:23:31 +00:00
|
|
|
/**
|
|
|
|
* For some reason "wcShopper.emptyCart" sometimes result in an error, but using the same
|
|
|
|
* implementation here fixes the problem.
|
|
|
|
*/
|
|
|
|
emptyCart: async () => {
|
|
|
|
await page.goto( SHOP_CART_PAGE, {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Remove products if they exist
|
|
|
|
if ( ( await page.$( '.remove' ) ) !== null ) {
|
|
|
|
let products = await page.$$( '.remove' );
|
|
|
|
while ( products && products.length > 0 ) {
|
|
|
|
await page.click( '.remove' );
|
|
|
|
await uiUnblocked();
|
|
|
|
products = await page.$$( '.remove' );
|
|
|
|
}
|
2022-03-01 11:25:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 15:23:31 +00:00
|
|
|
// Remove coupons if they exist
|
|
|
|
if ( ( await page.$( '.woocommerce-remove-coupon' ) ) !== null ) {
|
|
|
|
await page.click( '.woocommerce-remove-coupon' );
|
|
|
|
await uiUnblocked();
|
|
|
|
}
|
2022-03-01 11:25:13 +00:00
|
|
|
|
2022-03-07 15:23:31 +00:00
|
|
|
await page.waitForSelector( '.woocommerce-info' );
|
|
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
|
|
|
await expect( page ).toMatchElement( '.woocommerce-info', {
|
|
|
|
text: 'Your cart is currently empty.',
|
|
|
|
} );
|
|
|
|
},
|
2022-03-08 13:52:40 +00:00
|
|
|
|
|
|
|
placeOrder: async () => {
|
|
|
|
await Promise.all( [
|
|
|
|
page.waitForNavigation( {
|
|
|
|
waitUntil: 'networkidle0',
|
|
|
|
} ),
|
|
|
|
expect( page ).toClick( '.wc-block-components-button__text', {
|
|
|
|
text: 'Place Order',
|
|
|
|
} ),
|
|
|
|
] );
|
|
|
|
},
|
|
|
|
|
|
|
|
fillBillingDetails: async ( customerBillingDetails ) => {
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-first_name',
|
|
|
|
customerBillingDetails.firstname
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-last_name',
|
|
|
|
customerBillingDetails.lastname
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#components-form-token-input-0',
|
|
|
|
customerBillingDetails.country
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-address_1',
|
|
|
|
customerBillingDetails.addressfirstline
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-address_2',
|
|
|
|
customerBillingDetails.addresssecondline
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-city',
|
|
|
|
customerBillingDetails.city
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#components-form-token-input-2',
|
|
|
|
customerBillingDetails.state
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#billing-postcode',
|
|
|
|
customerBillingDetails.postcode
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#phone',
|
|
|
|
customerBillingDetails.phone
|
|
|
|
);
|
|
|
|
await expect( page ).toFill(
|
|
|
|
'#email',
|
|
|
|
customerBillingDetails.email
|
|
|
|
);
|
|
|
|
},
|
2022-03-01 11:25:13 +00:00
|
|
|
},
|
2021-04-14 14:50:27 +00:00
|
|
|
};
|