woocommerce/plugins/woocommerce-blocks/tests/e2e/utils/frontend/frontend-utils.page.ts

193 lines
4.5 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { Page, Locator } from '@playwright/test';
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
import { RequestUtils } from '@wordpress/e2e-test-utils-playwright';
export class FrontendUtils {
page: Page;
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
requestUtils: RequestUtils;
constructor( page: Page, requestUtils: RequestUtils ) {
this.page = page;
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
this.requestUtils = requestUtils;
}
async getBlockByName( name: string ) {
return this.page.locator( `[data-block-name="${ name }"]` );
}
E2E: Product Gallery Thumbnails block tests (https://github.com/woocommerce/woocommerce-blocks/pull/10370) * WIP Product Gallery: Add the Thumbnails block * Product Gallery Thumbnails: Add block settings * Add template for the Product Gallery block * Add template for the Product Gallery block. Add the rest of the files. * Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block. * Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block. * Product Gallery Thumbnails: Move the static template ouside of the component * Make sure the context is set before accesing the array values * Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc * Product Gallery Thumbnails: Fix TS error * Product Gallery Thumbnails: Remove unused stylesheet * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend. * Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically * E2E: Add tests for the Product Gallery Thumbnails block * Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down * Product Gallery Thumbnails: Add failure handling * Product Gallery Thumbnails: Fix the eslint dependency error * Product Gallery Thumbnails: Add inner blocks to the sideEffects array * Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file * Product Gallery Thumbnails: Update the utils file * Product Gallery Thumbnails: Update the utils file. Fix comment indentation * Product Gallery Thumbnails: Fix failing tests * Revert unrelated package.json changes * Product Gallery Thumbnails: Further package.json reverts * Product Gallery Thumbnails: Rename the test screenshots * Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set * Product Gallery: Rename clientId to productGalleryClientId * Product Gallery Thumbnails: Combine the useEffect code having the same dependencies * Product Gallery Thumbnails: Combine all useEffect code together * Product Gallery Thumbnails: Add a ThumbnailsPosition enum * Product Gallery Thumbnails: Update the thumbnailsPosition to an enum * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Add missing dependency * Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block * Product Gallery Thumbnails: Fix E2E tests * Product Gallery Thumbnails: Remove unused function from frontend utils * Product Gallery Thumbnails: Remove unused screenshots and config amendment * Product Gallery Thumbnails: Add check for the order of block on the frontend * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Revert back to ts-ignore * Revert "Product Gallery: Add crop, zoom and full-screen settings" This reverts commit 840654197619e2611029b81990493387ae0b543d. * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery: Remove the redundant React Fragment * Product Gallery E2E: Simplify and combine the tests
2023-08-04 11:07:31 +00:00
async getBlockByClassWithParent( blockClass: string, parentName: string ) {
const parentBlock = await this.getBlockByName( parentName );
if ( ! parentBlock ) {
throw new Error( `Parent block "${ parentName }" not found.` );
}
const block = parentBlock.locator( `.${ blockClass }` );
E2E: Product Gallery Thumbnails block tests (https://github.com/woocommerce/woocommerce-blocks/pull/10370) * WIP Product Gallery: Add the Thumbnails block * Product Gallery Thumbnails: Add block settings * Add template for the Product Gallery block * Add template for the Product Gallery block. Add the rest of the files. * Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block. * Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block. * Product Gallery Thumbnails: Move the static template ouside of the component * Make sure the context is set before accesing the array values * Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc * Product Gallery Thumbnails: Fix TS error * Product Gallery Thumbnails: Remove unused stylesheet * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend. * Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically * E2E: Add tests for the Product Gallery Thumbnails block * Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down * Product Gallery Thumbnails: Add failure handling * Product Gallery Thumbnails: Fix the eslint dependency error * Product Gallery Thumbnails: Add inner blocks to the sideEffects array * Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file * Product Gallery Thumbnails: Update the utils file * Product Gallery Thumbnails: Update the utils file. Fix comment indentation * Product Gallery Thumbnails: Fix failing tests * Revert unrelated package.json changes * Product Gallery Thumbnails: Further package.json reverts * Product Gallery Thumbnails: Rename the test screenshots * Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set * Product Gallery: Rename clientId to productGalleryClientId * Product Gallery Thumbnails: Combine the useEffect code having the same dependencies * Product Gallery Thumbnails: Combine all useEffect code together * Product Gallery Thumbnails: Add a ThumbnailsPosition enum * Product Gallery Thumbnails: Update the thumbnailsPosition to an enum * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Add missing dependency * Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block * Product Gallery Thumbnails: Fix E2E tests * Product Gallery Thumbnails: Remove unused function from frontend utils * Product Gallery Thumbnails: Remove unused screenshots and config amendment * Product Gallery Thumbnails: Add check for the order of block on the frontend * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Revert back to ts-ignore * Revert "Product Gallery: Add crop, zoom and full-screen settings" This reverts commit 840654197619e2611029b81990493387ae0b543d. * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery: Remove the redundant React Fragment * Product Gallery E2E: Simplify and combine the tests
2023-08-04 11:07:31 +00:00
return block;
}
async addToCart( itemName = '' ) {
await this.page.waitForLoadState( 'domcontentloaded' );
if ( itemName !== '' ) {
// We can't use `getByRole()` here because the Add to Cart button
// might be a button (in blocks) or a link (in the legacy template).
await this.page
.getByLabel( `Add to cart: “${ itemName }` )
.click();
Refactor Cart and Checkout Page Templates (https://github.com/woocommerce/woocommerce-blocks/pull/10773) * Rename checkout template slug * Remove redirect and custom title * Classic shortcode block for checkout * Empty title * WIP placeholder * Change blockified template * Prefix cart and checkout templates with "Page: " * Template migration routine * Apply same treatment to cart template * Notices * Update placeholder text * Classic shortcodes block * Page content wrapper for templates * Update default * Do not save attributes * Update templates * Remove cart classic template * Reverted endpoints for Cart & Checkout templates. This reverts PR 9406 * Migrate page content wrapper. * Removed useless method arg. Minor tweaks. * Skip migration if the theme has a template file for this page. * Removed impossible condition. * Migrate page content wrapper. * Remove TemplateNotice in favour of DefaultNotice * Documentation links in shortcode placeholder * Hide cart and checkout page selector when using block themes * Unused var * Add tests for template changes * Revert changes to classic-template * Allow frontend redirect * Unused file * Bump version for updater * Support x template naming as well as page-x * Need to add item to cart to test checkout * Fix header test by fixing utility for adding to cart * Remove permalink tests * Click body * Wait for content to finish loading * Wait for add to cart response when adding to cart without item name * Wait for save before visiting frontend * Set content instead of inserting block * Perform test in site editor rather than page editor * Prevent notice to set the default cart/checkout page from showing on the site editor. --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2023-09-19 09:58:18 +00:00
} else {
await this.page.click( 'text=Add to cart' );
}
Refactor Cart and Checkout Page Templates (https://github.com/woocommerce/woocommerce-blocks/pull/10773) * Rename checkout template slug * Remove redirect and custom title * Classic shortcode block for checkout * Empty title * WIP placeholder * Change blockified template * Prefix cart and checkout templates with "Page: " * Template migration routine * Apply same treatment to cart template * Notices * Update placeholder text * Classic shortcodes block * Page content wrapper for templates * Update default * Do not save attributes * Update templates * Remove cart classic template * Reverted endpoints for Cart & Checkout templates. This reverts PR 9406 * Migrate page content wrapper. * Removed useless method arg. Minor tweaks. * Skip migration if the theme has a template file for this page. * Removed impossible condition. * Migrate page content wrapper. * Remove TemplateNotice in favour of DefaultNotice * Documentation links in shortcode placeholder * Hide cart and checkout page selector when using block themes * Unused var * Add tests for template changes * Revert changes to classic-template * Allow frontend redirect * Unused file * Bump version for updater * Support x template naming as well as page-x * Need to add item to cart to test checkout * Fix header test by fixing utility for adding to cart * Remove permalink tests * Click body * Wait for content to finish loading * Wait for add to cart response when adding to cart without item name * Wait for save before visiting frontend * Set content instead of inserting block * Perform test in site editor rather than page editor * Prevent notice to set the default cart/checkout page from showing on the site editor. --------- Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2023-09-19 09:58:18 +00:00
await this.page.waitForResponse( ( request ) => {
const url = request.url();
return url.includes( 'add_to_cart' ) || url.includes( 'batch' );
} );
}
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
async goToCheckout() {
await this.page.goto( '/checkout', {
waitUntil: 'domcontentloaded',
} );
}
E2E: Product Gallery Thumbnails block tests (https://github.com/woocommerce/woocommerce-blocks/pull/10370) * WIP Product Gallery: Add the Thumbnails block * Product Gallery Thumbnails: Add block settings * Add template for the Product Gallery block * Add template for the Product Gallery block. Add the rest of the files. * Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block. * Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block. * Product Gallery Thumbnails: Move the static template ouside of the component * Make sure the context is set before accesing the array values * Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc * Product Gallery Thumbnails: Fix TS error * Product Gallery Thumbnails: Remove unused stylesheet * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend. * Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically * E2E: Add tests for the Product Gallery Thumbnails block * Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down * Product Gallery Thumbnails: Add failure handling * Product Gallery Thumbnails: Fix the eslint dependency error * Product Gallery Thumbnails: Add inner blocks to the sideEffects array * Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file * Product Gallery Thumbnails: Update the utils file * Product Gallery Thumbnails: Update the utils file. Fix comment indentation * Product Gallery Thumbnails: Fix failing tests * Revert unrelated package.json changes * Product Gallery Thumbnails: Further package.json reverts * Product Gallery Thumbnails: Rename the test screenshots * Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set * Product Gallery: Rename clientId to productGalleryClientId * Product Gallery Thumbnails: Combine the useEffect code having the same dependencies * Product Gallery Thumbnails: Combine all useEffect code together * Product Gallery Thumbnails: Add a ThumbnailsPosition enum * Product Gallery Thumbnails: Update the thumbnailsPosition to an enum * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Add missing dependency * Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block * Product Gallery Thumbnails: Fix E2E tests * Product Gallery Thumbnails: Remove unused function from frontend utils * Product Gallery Thumbnails: Remove unused screenshots and config amendment * Product Gallery Thumbnails: Add check for the order of block on the frontend * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Revert back to ts-ignore * Revert "Product Gallery: Add crop, zoom and full-screen settings" This reverts commit 840654197619e2611029b81990493387ae0b543d. * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery: Remove the redundant React Fragment * Product Gallery E2E: Simplify and combine the tests
2023-08-04 11:07:31 +00:00
async goToCart() {
await this.page.goto( '/cart', {
waitUntil: 'commit',
} );
}
async goToMiniCart() {
await this.page.goto( '/mini-cart', {
waitUntil: 'domcontentloaded',
} );
}
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
async goToShop() {
await this.page.goto( '/shop', {
Interactivity API and Product Button (https://github.com/woocommerce/woocommerce-blocks/pull/10006) * Update Interactivity API JS files * Disable TS checks in the Interactivity API for now * Add new SSR files * Replace wp_ prefixes with wc_ ones * Replace wp- prefix with wc- * Replace guternberg_ prefix with woocommerce_ * Remove file comments from Gutenberg * Rename files with `wp` prefix * Fix code to load Interactivity API php files * Remove TODO comments * Replace @wordpress with @woocommerce * Update Webpack configuration * Fix directive prefix * Remove interactivity folder from tsconfig exclude * Add client-side navigation meta tag code * Remove unneeded blocks.php file * Fix store tag id * Register Interactivity API runtime script * Fix Interactivity API runtime registering * Remove all files related to directive processing in PHP * Move json_encode to Store's render method * WIP * WIP * WIP * WIP * Preserve previous context * Ignore Minicart block on client-side navigation * Refresh page on store updatRefresh page on store updatee * Refactor logic * Add console error when a path is missing * fix PHP lint error * WIP store * use store approach * update jest configuration * restore Mini Cart changes * move cart store subscription to interactivity package * move interactivity flag * format HTML * move addToCartText to the context * Load product-query stylesheet when rendering the Products block * update sideEffects array * fix catch * rename moreThanOneItem to isThereMoreThanOneItem * improve how scripts are enqueued * update default value for the filter woocommerce_blocks_enable_interactivity_api * Update assets/js/atomic/blocks/product-elements/button/block.json Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * Update assets/js/interactivity/cart/cart-store.ts Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> * fix block.json * remove updateStore function * restore interactivity api changes * import cart store * show notice when there is an error * add logic to dequeue script on classic themes and block themes * imrpove logic about notice * Interactivity API: add `afterLoad` callbacks to `store()` function (https://github.com/woocommerce/woocommerce-blocks/pull/10338) * show notice when there is an error * Add initial implementation for store callbacks * Run `afterLoad` callbacks after `init` * Move cart state subscription to Product button * Remove cart-store from Interactivity API internals * Change callbacks with options and save only afterLoad callbacks * ProductButton: Add animation (https://github.com/woocommerce/woocommerce-blocks/pull/10351) * implement animation * improve logic * refactor logic * refactor code * address feedback about code style * add support for woocommerce_add_to_cart_quantity * Fix animation flickering * Introduce wp-effect, reduce the amount of numberOfItem variables to 2 and consolidate animation status * add support for added class * Remove unnecessary selector * Don't fetch cart if it was already fetched * remove added class --------- Co-authored-by: Luis Herranz <luisherranz@gmail.com> --------- Co-authored-by: Luigi <gigitux@gmail.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> * update deepsignal * remove added class * update deepsignal * Interactivity API and Product Button: Add E2E tests (https://github.com/woocommerce/woocommerce-blocks/pull/10036) * Add FrontendUtils class * fix conflicts * use locator * restore click usage * Product Button: Add E2E test * fix util * fix E2E tests * remove comment * Add E2E test to ensure that woocommerce_product_add_to_cart_text works * update sideEffects array * add zip and unzip as package * fix wp-env configuration * fix E2E test * add report * try now * try now * try now * fix E2E test * E2E: Add documentation for testing actions and filters. Fixes woocommerce/woocommerce-blocks#10135 (https://github.com/woocommerce/woocommerce-blocks/pull/10206) * update description * fix label * rename files * make requestUtils private * remove page.goto * use toHaveCount * use productsToDisplay variable * fix E2E tests * rename class utils --------- Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com> --------- Co-authored-by: David Arenas <david.arenas@automattic.com> Co-authored-by: Luis Herranz <luisherranz@gmail.com> Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com> Co-authored-by: Daniel Dudzic <daniel.dudzic@automattic.com>
2023-08-10 14:02:33 +00:00
waitUntil: 'commit',
} );
}
Convert shipping selection Checkout tests to playwright (https://github.com/woocommerce/woocommerce-blocks/pull/10532) * Create selectAndVerifyShippingOption method * Add goToCheckout util * Add emptyCart util * Add selectAndVerifyShippingOption to FrontendUtils class * Add initial checkout shopper test file and a shipping options test * Remove selectAndVerifyShippingOptions from frontendUtils * Re-add selectAndVerifyShippingOption to checkout block test * Move cart and checkout blocks into their own directories * Create CheckoutPage class to keep utils for checkout * Use CheckoutPage class in Checkout tests * Update name of test suite * Remove nested describe * Move to correct folder, make selectAndVerifyShippingOption return * Remove networkidle and goToCheckout from frontendutils * Add placeOrder util * Add fillBilingDetails util to checkout page * Add fillShippingDetails util to checkout page * Add fillInCheckoutWithTestData util to checkout page * Add checkCustomerPushCompleted util to checkout page * Change test to focus on free shipping and flat rate in separate tests * Instead of waiting for selector, just wait for the shipping name * Check element visibility instead of count * Use postcode id rather than autocomplete value * Don't instantiate FrontendUtils * Delete tests that have been moved to playwright * Add test to side effects project because it adds items to cart * Remove unused method * Go to cart page before removing items This is to ensure the cart data store is loaded * Empty cart before proceeding with tests * Re-implement goToCheckout to frontendUtils * Remove check for whether customer data has been pushed Rely instead on order complete page to check for address details. * Ensure request to set shipping option is complete * Get email address from page not billing form (its not there) * Move testData to class property * Add verifyAddressDetails util * Make test check for setting different addresses and shipping in same run * Remove User can have different shipping and billing addresses from jest * Pass in playwright's request to the frontend utils file * Update emptyCart function to use API requests to empty the cart * Pass request utils to frontendUtils class * Update frontendUtils to use requestUtils for API requests
2023-08-15 10:42:29 +00:00
async emptyCart() {
const cartResponse = await this.requestUtils.request.get(
'/wp-json/wc/store/cart'
);
const nonce = cartResponse.headers()?.nonce;
if ( ! nonce ) {
throw new Error( 'Could not get cart nonce.' );
}
const res = await this.requestUtils.request.delete(
'/wp-json/wc/store/v1/cart/items',
{ headers: { nonce } }
);
if ( ! res.ok() ) {
throw new Error(
`Got an error response when trying to empty cart. Status code: ${ res.status() }`
);
}
}
E2E: Product Gallery Thumbnails block tests (https://github.com/woocommerce/woocommerce-blocks/pull/10370) * WIP Product Gallery: Add the Thumbnails block * Product Gallery Thumbnails: Add block settings * Add template for the Product Gallery block * Add template for the Product Gallery block. Add the rest of the files. * Product Gallery Thumbnails: Add context settings sharing between the Product Gallery and Thumbnails block. * Product Gallery Thumbnails: Add UI functionality and frontend functionality. Add settings for the Thumbnails in both places - Product Gallery and the Thumbnails block. * Product Gallery Thumbnails: Move the static template ouside of the component * Make sure the context is set before accesing the array values * Product Gallery Thumbnails: Move the setGroupAttributes() function outside of the component * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Update the Features Flags and Experimental Interfaces doc * Product Gallery Thumbnails: Fix TS error * Product Gallery Thumbnails: Remove unused stylesheet * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Remove unused context and fix the thumbnails bottom position styling on the frontend. * Product Gallery Thumbnails: Allow the user to move the horizontal thumbnails above the large image and don't overwrite that automatically * E2E: Add tests for the Product Gallery Thumbnails block * Product Gallery Thumbnails: Add code comments and remove the incorrect conditional check when moving thumbnails up and down * Product Gallery Thumbnails: Add failure handling * Product Gallery Thumbnails: Fix the eslint dependency error * Product Gallery Thumbnails: Add inner blocks to the sideEffects array * Product Gallery Thumbnails: Refactor Product Gallery edit code and move the logic to a utils file * Product Gallery Thumbnails: Update the utils file * Product Gallery Thumbnails: Update the utils file. Fix comment indentation * Product Gallery Thumbnails: Fix failing tests * Revert unrelated package.json changes * Product Gallery Thumbnails: Further package.json reverts * Product Gallery Thumbnails: Rename the test screenshots * Product Gallery Thumbnails: Fix undefined variable html when only 1 product image is set * Product Gallery: Rename clientId to productGalleryClientId * Product Gallery Thumbnails: Combine the useEffect code having the same dependencies * Product Gallery Thumbnails: Combine all useEffect code together * Product Gallery Thumbnails: Add a ThumbnailsPosition enum * Product Gallery Thumbnails: Update the thumbnailsPosition to an enum * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Fix TS errors * Product Gallery Thumbnails: Add missing dependency * Product Gallery Thumbnails: Uppercase the enum and fix the thumbnails position bug when initially adding the Product Gallery block * Product Gallery Thumbnails: Fix E2E tests * Product Gallery Thumbnails: Remove unused function from frontend utils * Product Gallery Thumbnails: Remove unused screenshots and config amendment * Product Gallery Thumbnails: Add check for the order of block on the frontend * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Replace ts-ignore with ts-expect-error * Product Gallery Thumbnails: Revert back to ts-ignore * Revert "Product Gallery: Add crop, zoom and full-screen settings" This reverts commit 840654197619e2611029b81990493387ae0b543d. * Product Gallery: Add crop, zoom and full-screen settings * Product Gallery: Remove the redundant React Fragment * Product Gallery E2E: Simplify and combine the tests
2023-08-04 11:07:31 +00:00
async isBlockEarlierThan< T >(
containerBlock: T,
firstBlock: string,
secondBlock: string
) {
const container =
containerBlock instanceof Function
? await containerBlock()
: containerBlock;
if ( ! container ) {
throw new Error( 'Container block not found.' );
}
const childBlocks = container.locator( '[data-block-name]' );
let firstBlockIndex = -1;
let secondBlockIndex = -1;
for ( let i = 0; i < ( await childBlocks.count() ); i++ ) {
const blockName = await childBlocks
.nth( i )
.getAttribute( 'data-block-name' );
if ( blockName === firstBlock ) {
firstBlockIndex = i;
}
if ( blockName === secondBlock ) {
secondBlockIndex = i;
}
if ( firstBlockIndex !== -1 && secondBlockIndex !== -1 ) {
break;
}
}
if ( firstBlockIndex === -1 || secondBlockIndex === -1 ) {
throw new Error( 'Both blocks must exist within the editor' );
}
return firstBlockIndex < secondBlockIndex;
}
async isBlockEarlierThanGroupBlock(
containerBlock: Locator,
firstBlock: string
) {
if ( ! containerBlock ) {
throw new Error( 'Container block not found.' );
}
const childBlocks: Locator = containerBlock.locator( '> div' );
let firstBlockIndex = -1;
let secondBlockIndex = -1;
for ( let i = 0; i < ( await childBlocks.count() ); i++ ) {
const blockName = await childBlocks
.nth( i )
.getAttribute( 'data-block-name' );
const isGroupBlock = await childBlocks
.nth( i )
.evaluate( ( node ) =>
node.classList.contains( 'wp-block-group' )
);
if ( blockName === firstBlock ) {
firstBlockIndex = i;
}
if ( isGroupBlock ) {
secondBlockIndex = i;
}
if ( firstBlockIndex !== -1 && secondBlockIndex !== -1 ) {
break;
}
}
if ( firstBlockIndex === -1 || secondBlockIndex === -1 ) {
throw new Error( 'Both blocks must exist within the editor' );
}
return firstBlockIndex < secondBlockIndex;
}
/**
* Playwright selectText causes flaky tests when running on local
* development machine. This method is more reliable on both environments.
*/
async selectTextInput( locator: Locator ) {
await locator.click();
await locator.press( 'End' );
await locator.press( 'Shift+Home' );
}
Playwright E2E tests: Multiple signed in roles (https://github.com/woocommerce/woocommerce-blocks/pull/10561) * Convert checkout place order E2E tests to Playwright * Add "gotoMyAccount" method * Create login/logout utility functions * Use the existing "customer" test data * Complete the place order test cases * Fix "My Account" page title * Fix rebase * Reset My account page title * Check for heading instead of the page title * Check for heading in login/logout functions * Fix all failing tests * Add guest/customer/admin roles * Update the auth setup * Register the auth setup within Playwright * Update testing cases * Add generated auth files to .gitignore * Tidy up comments Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Remove unnecessary comment Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update comments Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Remove unnecessary comment Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update comment for Guest case Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Remove confusing comment * Remove another unnecessary comment * Remove unnecessary Playwright project dependency * Tidy up the file structure and constants * Fix mixed up test descriptions * Remove commented code Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Remove unnecessary function from frontend-utils * Refactor testing cases * Rename testing file * Delete unused testing file * Ensure we're logged out before trying to log in as a user * Log out before each authentication setup step * Ensure tests requiring admin are logged in * Log in as admin during block theme setup * Fix Playwright strict mode violation * Run Multiple sign-in roles to the global-setup phase In this step of the Playwright's setup, we can add the multiple sign-in roles and keeping the admin logged by default. This fixes the issue of failing tests `logged out` error. * Remove unnecessary login as admin * Remove "auth.setup" dependency since the logic lives in the global setup instead * Remove unnecessary login as admin from test files The admin profile is set by default --------- Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
2023-12-08 16:44:59 +00:00
async gotoMyAccount() {
await this.page.goto( '/my-account', {
waitUntil: 'commit',
} );
}
}