woocommerce/plugins/woocommerce-blocks/tests/e2e
Manish Menaria 861bc091d4
Product Collection - Add Editor UI for missing product reference (#51114)
* Initial implementation of the missing product state

- Changed `getProductCollectionUIStateInEditor` to a hook `useProductCollectionUIState`.
	- As we added logic to check if selected product reference is deleted which require making an API call. Therefore, I decided to use a hook.
- While making an API call to check if product reference is deleted, I decided to show spinner in the block.
- Introduced new UI state `DELETED_PRODUCT_REFERENCE` to handle the missing product state.
- Updated existing `ProductPicker` component to handle the new UI state.
	- It's better to use existing component for the missing product state, as it already has all the required UI.

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Use getEntityRecord to check if product exists and other improvements

* Remove console log

* Add E2E tests for deleted product reference in Product Collection block

This commit introduces new E2E tests to verify the behavior of the Product
Collection block when dealing with deleted product references. The changes
include:

1. New test suite in register-product-collection-tester.block_theme.spec.ts
2. Modification to product-collection.page.ts to support custom product selection
3. Minor update to utils.tsx to handle trashed products

These tests ensure that the Product Collection block correctly handles
scenarios where referenced products are deleted, trashed, or restored,
improving the overall reliability of the feature.

* Simplify product creation in Product Collection block test

* Refactor E2E test for delete product reference picker

1. Removing the unnecessary `test.describe` block for "Deleted product reference"
2. Eliminating the `beforeEach` hook that was creating a test product
3. Integrating the test product creation directly into the main test

This change simplifies the test structure and improves readability while
maintaining the same test coverage for the Product Collection block's
behavior when dealing with deleted or unavailable products.

* Simplify logic for product collection UI state

This commit simplifies the handling of the `usesReference` prop in the
Product Collection block:

1. In `edit/index.tsx`, directly pass `usesReference` to
   `useProductCollectionUIState` hook without conditional spreading.

2. In `utils.tsx`, update the type definition of `usesReference` in the
   `useProductCollectionUIState` hook to explicitly include `undefined`.

* Refactor Product Collection block to improve prop passing

- Introduce ProductCollectionContentProps type for better prop management
- Refactor Edit component to use a renderComponent function
- Update component prop types to use more specific props
- Remove unnecessary props from ProductCollectionEditComponentProps
- Simplify component rendering logic in Edit component
- Adjust ProductPicker to receive only required props
- Update imports and prop types in various files to use new types

This refactoring improves code organization and reduces prop drilling by
only passing necessary props to each component. It enhances maintainability
and readability of the Product Collection block and related components.

* Refactor Product Collection block editor UI state handling

This commit simplifies the rendering logic in the Product Collection block's
Edit component. It removes a redundant case for the VALID state, as both
VALID and VALID_WITH_PREVIEW states now render the same ProductCollectionContent
component. This change improves code maintainability and reduces duplication.

* Fix: isDeletedProductReference is not set correctly

* Use "page.reload" instead of "admin.page.reload"

* Separate PRODUCT_REFERENCE_PICKER and DELETED_PRODUCT_REFERENCE cases

This improves readability and maintainability of the switch statement.

---------

Co-authored-by: github-actions <github-actions@github.com>
2024-09-17 14:08:24 +05:30
..
bin Blocks E2E: Fix DB snapshot removal step in setup script (#49677) 2024-07-19 12:02:56 +02:00
content-templates [Experimental] Product Filters: New and improved blocks structure (#51096) 2024-09-14 00:04:06 +07:00
plugins Fix typos. (#50047) 2024-08-23 18:26:09 +01:00
rules Blocks E2E: Streamline E2E utils implementation (#47660) 2024-05-27 14:54:06 +00:00
test-data/data Refactor review blocks e2e tests to remove redundant html templates and add more scenarios (#44880) 2024-02-29 15:43:59 +13:00
tests Product Collection - Add Editor UI for missing product reference (#51114) 2024-09-17 14:08:24 +05:30
themes Initialize BlockTemplatesController for block themes only (#48905) 2024-07-03 11:31:41 +02:00
utils Blocks: Update wp-env config to use production WP (#49704) 2024-08-01 11:59:42 +02:00
.eslintrc.js Blocks E2E: Restore the no-hooks rule (#47500) 2024-05-15 13:05:52 +02:00
README.md Settings Save button disable/enable (#47444) 2024-06-25 13:12:14 +12:00
flaky-tests-reporter.ts Fix most of lint warnings (#50869) 2024-08-23 14:30:14 +02:00
global-setup.ts Blocks E2E: Streamline the usage of WP CLI (#47869) 2024-05-28 17:09:28 +02:00
playwright.config.ts [e2e tests] Add BuildKite reporter to Blocks e2e tests (#50642) 2024-08-15 13:48:44 +01:00
playwright.performance.config.ts Blocks: Isolate performance tests from e2e tests (#46773) 2024-04-23 13:11:46 +02:00
tsconfig.json Blocks E2E: Align ESLint and TS configs with Gutenberg (#47228) 2024-05-14 10:23:17 +02:00

README.md

WooCommerce Blocks End-to-End Tests

This document provides an overview of the WooCommerce Blocks end-to-end testing process. For detailed instructions and comprehensive guidelines, please refer to the contributor guidelines document.

Quick Start

Preparing the Environment

  1. Build the WooCommerce Plugin:

    pnpm --filter='@woocommerce/plugin-woocommerce' watch:build
    
  2. Go to the WooCommerce Blocks plugin folder:

    cd plugins/woocommerce-blocks/
    
  3. Start the environment:

    pnpm env:start
    

Running the Tests

  1. Run all tests:

    pnpm test:e2e
    
  2. Run a single test file:

    pnpm test:e2e path/to/the/file.spec.ts
    
  3. Run in UI mode:

    pnpm test:e2e --ui
    
  4. Run in debug mode:

pnpm test:e2e --debug