Commit 57738f1fb35 for woocommerce
commit 57738f1fb356d162fdb6a31a751b998214d74ef3
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Thu Nov 26 12:49:33 2026 +0200
Run Products, rating and stock filter Blocks e2e specs in parallel (#71485)
diff --git a/plugins/woocommerce/changelog/testops-310-blocks-e2e-document-or-move-the-last-template b/plugins/woocommerce/changelog/testops-310-blocks-e2e-document-or-move-the-last-template
new file mode 100644
index 00000000000..457b7adbe33
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-310-blocks-e2e-document-or-move-the-last-template
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Move 3 more Blocks e2e specs to the parallel project and document the serial ones; no production change.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/rating-filter/test/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/rating-filter/test/edit.tsx
new file mode 100644
index 00000000000..b22c6543bac
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/rating-filter/test/edit.tsx
@@ -0,0 +1,75 @@
+/**
+ * External dependencies
+ */
+import type React from '@wordpress/element';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+/**
+ * Internal dependencies
+ */
+import RatingFilterEdit from '../edit';
+
+jest.mock( '@woocommerce/block-settings', () => ( {
+ ...jest.requireActual( '@woocommerce/block-settings' ),
+ blocksConfig: { productCount: 1 },
+} ) );
+
+jest.mock( '@wordpress/block-editor', () => ( {
+ ...jest.requireActual( '@wordpress/block-editor' ),
+ useBlockProps: jest.fn( ( props = {} ) => props ),
+ InspectorControls: jest.fn( ( { children } ) => <div>{ children }</div> ),
+} ) );
+
+jest.mock( '@wordpress/components', () => ( {
+ ...jest.requireActual( '@wordpress/components' ),
+ ToggleControl: jest.fn( ( { label, checked, onChange } ) => (
+ <label htmlFor={ String( label ) }>
+ <input
+ id={ String( label ) }
+ type="checkbox"
+ checked={ checked }
+ onChange={ ( event ) => onChange( event.target.checked ) }
+ />
+ { label }
+ </label>
+ ) ),
+ __experimentalToggleGroupControl: jest.fn( () => null ),
+} ) );
+
+jest.mock( '../block', () => jest.fn( () => null ) );
+jest.mock( '../../filter-wrapper/upgrade', () => ( {
+ UpgradeNotice: jest.fn( () => null ),
+} ) );
+
+describe( 'Rating Filter Edit', () => {
+ it( "sets showFilterButton from the Show 'Apply filters' button toggle", async () => {
+ const setAttributes = jest.fn();
+ const Edit = RatingFilterEdit as unknown as React.ComponentType<
+ Record< string, unknown >
+ >;
+
+ render(
+ <Edit
+ attributes={ {
+ displayStyle: 'list',
+ selectType: 'multiple',
+ showCounts: false,
+ showFilterButton: false,
+ } }
+ clientId="rating-filter-client-id"
+ setAttributes={ setAttributes }
+ />
+ );
+
+ await userEvent.click(
+ screen.getByRole( 'checkbox', {
+ name: "Show 'Apply filters' button",
+ } )
+ );
+
+ expect( setAttributes ).toHaveBeenCalledWith( {
+ showFilterButton: true,
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/stock-filter/test/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/stock-filter/test/edit.tsx
new file mode 100644
index 00000000000..ce8f15fcc08
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/stock-filter/test/edit.tsx
@@ -0,0 +1,83 @@
+/**
+ * External dependencies
+ */
+import type React from '@wordpress/element';
+import { render, screen } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+
+/**
+ * Internal dependencies
+ */
+import StockFilterEdit from '../edit';
+
+jest.mock( '@woocommerce/block-settings', () => ( {
+ ...jest.requireActual( '@woocommerce/block-settings' ),
+ blocksConfig: { productCount: 1 },
+} ) );
+
+jest.mock( '@wordpress/block-editor', () => ( {
+ ...jest.requireActual( '@wordpress/block-editor' ),
+ useBlockProps: jest.fn( ( props = {} ) => props ),
+ InspectorControls: jest.fn( ( { children } ) => <div>{ children }</div> ),
+} ) );
+
+jest.mock( '@wordpress/components', () => ( {
+ ...jest.requireActual( '@wordpress/components' ),
+ ToggleControl: jest.fn( ( { label, checked, onChange } ) => (
+ <label htmlFor={ String( label ) }>
+ <input
+ id={ String( label ) }
+ type="checkbox"
+ checked={ checked }
+ onChange={ ( event ) => onChange( event.target.checked ) }
+ />
+ { label }
+ </label>
+ ) ),
+ __experimentalToggleGroupControl: jest.fn( () => null ),
+ __experimentalToolsPanel: jest.fn( ( { children } ) => (
+ <div>{ children }</div>
+ ) ),
+ __experimentalToolsPanelItem: jest.fn( ( { children } ) => (
+ <div>{ children }</div>
+ ) ),
+} ) );
+
+jest.mock( '../block', () => jest.fn( () => null ) );
+jest.mock( '../../filter-wrapper/upgrade', () => ( {
+ UpgradeNotice: jest.fn( () => null ),
+} ) );
+
+describe( 'Stock Filter Edit', () => {
+ it( "sets showFilterButton from the Show 'Apply filters' button toggle", async () => {
+ const setAttributes = jest.fn();
+ const Edit = StockFilterEdit as unknown as React.ComponentType<
+ Record< string, unknown >
+ >;
+
+ render(
+ <Edit
+ attributes={ {
+ displayStyle: 'list',
+ heading: '',
+ headingLevel: 3,
+ selectType: 'multiple',
+ showCounts: false,
+ showFilterButton: false,
+ } }
+ clientId="stock-filter-client-id"
+ setAttributes={ setAttributes }
+ />
+ );
+
+ await userEvent.click(
+ screen.getByRole( 'checkbox', {
+ name: "Show 'Apply filters' button",
+ } )
+ );
+
+ expect( setAttributes ).toHaveBeenCalledWith( {
+ showFilterButton: true,
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/client/blocks/changelog/testops-310-rating-stock-filter-apply-toggle-tests b/plugins/woocommerce/client/blocks/changelog/testops-310-rating-stock-filter-apply-toggle-tests
new file mode 100644
index 00000000000..5c8b8cb9126
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/changelog/testops-310-rating-stock-filter-apply-toggle-tests
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Add unit tests for the Filter by Rating and Filter by Stock Apply button toggles; tests only, no production change.
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars
index 37c9caa980e..e907685df94 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars
@@ -30,7 +30,7 @@
<h3 class='wp-block-heading'>Filter by stock status</h3>
<!-- /wp:heading -->
- <!-- wp:woocommerce/stock-filter {"heading":"","lock":{"remove":true}} -->
+ <!-- wp:woocommerce/stock-filter {"heading":"",{{#if showFilterButton}}"showFilterButton":true,{{/if}}"lock":{"remove":true}} -->
<div class="wp-block-woocommerce-stock-filter is-loading"></div>
<!-- /wp:woocommerce/stock-filter -->
</div>
@@ -42,7 +42,7 @@
<h3 class='wp-block-heading'>Filter by rating</h3>
<!-- /wp:heading -->
- <!-- wp:woocommerce/rating-filter {"lock":{"remove":true}} -->
+ <!-- wp:woocommerce/rating-filter { {{#if showFilterButton}}"showFilterButton":true,{{/if}}"lock":{"remove":true}} -->
<div class="wp-block-woocommerce-rating-filter is-loading"></div>
<!-- /wp:woocommerce/rating-filter -->
</div>
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars
deleted file mode 100644
index e67bed2ac34..00000000000
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_filters-with-product-collection.handlebars
+++ /dev/null
@@ -1,83 +0,0 @@
-<!-- wp:columns -->
-<div class='wp-block-columns'>
- <!-- wp:column {"width":"33.33%"} -->
- <div class='wp-block-column' style='flex-basis:33.33%'>
- <!-- wp:woocommerce/filter-wrapper {"filterType":"active-filters","heading":"Active filters"} -->
- <div class='wp-block-woocommerce-filter-wrapper'>
- <!-- wp:heading {"level":3} -->
- <h3 class='wp-block-heading'>Active filters</h3>
- <!-- /wp:heading -->
-
- <!-- wp:woocommerce/active-filters {"heading":"","lock":{"remove":true}} -->
- <div class="wp-block-woocommerce-active-filters is-loading"><span aria-hidden="true" class="wc-block-active-filters__placeholder"></span></div>
- <!-- /wp:woocommerce/active-filters -->
- </div>
- <!-- /wp:woocommerce/filter-wrapper -->
-
- <!-- wp:woocommerce/filter-wrapper {"filterType":"price-filter","heading":"Filter by price"} -->
- <div class='wp-block-woocommerce-filter-wrapper'><!-- wp:heading {"level":3} -->
- <h3 class='wp-block-heading'>Filter by price</h3>
- <!-- /wp:heading -->
-
- <!-- wp:woocommerce/price-filter {"heading":"","lock":{"remove":true}} -->
- <div class="wp-block-woocommerce-price-filter is-loading"><span aria-hidden="true" class="wc-block-product-categories__placeholder"></span></div>
- <!-- /wp:woocommerce/price-filter -->
- </div>
- <!-- /wp:woocommerce/filter-wrapper -->
-
- <!-- wp:woocommerce/filter-wrapper {"filterType":"stock-filter","heading":"Filter by stock status"} -->
- <div class='wp-block-woocommerce-filter-wrapper'><!-- wp:heading {"level":3} -->
- <h3 class='wp-block-heading'>Filter by stock status</h3>
- <!-- /wp:heading -->
-
- <!-- wp:woocommerce/stock-filter {"heading":"","lock":{"remove":true}} -->
- <div class="wp-block-woocommerce-stock-filter is-loading"></div>
- <!-- /wp:woocommerce/stock-filter -->
- </div>
- <!-- /wp:woocommerce/filter-wrapper -->
-
- <!-- wp:woocommerce/filter-wrapper {"filterType":"rating-filter","heading":"Filter by rating"} -->
- <div class='wp-block-woocommerce-filter-wrapper'>
- <!-- wp:heading {"level":3} -->
- <h3 class='wp-block-heading'>Filter by rating</h3>
- <!-- /wp:heading -->
-
- <!-- wp:woocommerce/rating-filter {"lock":{"remove":true}} -->
- <div class="wp-block-woocommerce-rating-filter is-loading"></div>
- <!-- /wp:woocommerce/rating-filter -->
- </div>
- <!-- /wp:woocommerce/filter-wrapper -->
- <!-- wp:woocommerce/filter-wrapper {"filterType":"attribute-filter","heading":"Filter by attribute"} -->
- <div class='wp-block-woocommerce-filter-wrapper'>
- <!-- wp:heading {"level":3} -->
- <h3 class='wp-block-heading'>Filter by attribute</h3>
- <!-- /wp:heading -->
-
- <!-- wp:woocommerce/attribute-filter {"attributeId":{{#if attributeId}}{{attributeId}}{{else}}2{{/if}},"heading":"","lock":{"remove":true}} -->
- <div class="wp-block-woocommerce-attribute-filter is-loading"></div>
- <!-- /wp:woocommerce/attribute-filter -->
- </div>
- <!-- /wp:woocommerce/filter-wrapper -->
- </div>
- <!-- /wp:column -->
-
- <!-- wp:column {"width":"66.66%"} -->
- <div class='wp-block-column' style='flex-basis:66.66%'>
- <!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
- <div class="wp-block-woocommerce-product-collection">
- <!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
- <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
- <!-- /wp:woocommerce/product-image -->
- <!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
-
- <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
-
- <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
- <!-- /wp:woocommerce/product-template -->
- </div>
- <!-- /wp:woocommerce/product-collection -->
- </div>
- <!-- /wp:column -->
-</div>
-<!-- /wp:columns -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars
deleted file mode 100644
index 6fec612dc86..00000000000
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_price-filter.handlebars
+++ /dev/null
@@ -1,22 +0,0 @@
-<!-- wp:woocommerce/product-filter {"filterType":"price-filter","heading":"Filter by Price"} -->
-<!-- wp:heading {"level":3} -->
-<h3 class='wp-block-heading'>Filter by Price</h3>
-<!-- /wp:heading -->
-
-{{#> wp-block blockName='woocommerce/product-filter-price' attributes=attributes }}
-{{/ wp-block }}
-
-<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
-<div class='wp-block-woocommerce-product-collection'>
- <!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
- <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
- <!-- /wp:woocommerce/product-image -->
- <!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
-
- <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
-
- <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
- <!-- /wp:woocommerce/product-template -->
-</div>
-<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars
deleted file mode 100644
index f83b269c82b..00000000000
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_rating-filter.handlebars
+++ /dev/null
@@ -1,22 +0,0 @@
-<!-- wp:woocommerce/product-filter {"filterType":"rating-filter","heading":"Filter by Rating"} -->
-<!-- wp:heading {"level":3} -->
-<h3 class="wp-block-heading">Filter by Rating</h3>
-<!-- /wp:heading -->
-
-{{#> wp-block blockName='woocommerce/product-filter-rating' attributes=attributes }}
-{{/ wp-block }}
-
-<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
-<div class="wp-block-woocommerce-product-collection">
- <!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
- <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
- <!-- /wp:woocommerce/product-image -->
- <!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
-
- <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
-
- <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
- <!-- /wp:woocommerce/product-template -->
-</div>
-<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars
deleted file mode 100644
index b91a9d97b91..00000000000
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_stock-status.handlebars
+++ /dev/null
@@ -1,23 +0,0 @@
-<!-- wp:woocommerce/product-filter {"filterType":"stock-filter","heading":"Filter by Stock Status"} -->
-<!-- wp:heading {"level":3} -->
-<h3 class='wp-block-heading'>Filter by Stock Status</h3>
-<!-- /wp:heading -->
-
-{{#> wp-block blockName='woocommerce/product-filter-status' attributes=attributes }}
-{{/ wp-block }}
-
-<!-- wp:woocommerce/product-collection {"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":true,"taxQuery":[],"isProductCollectionBlock":true,"featured":false,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":3,"shrinkColumns":true},"queryContextIncludes":["collection"]} -->
-<div class='wp-block-woocommerce-product-collection'>
- <!-- wp:woocommerce/product-template -->
- <!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
- <!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
- <!-- /wp:woocommerce/product-image -->
-
- <!-- wp:post-title {"textAlign":"center","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
-
- <!-- wp:woocommerce/product-price {"textAlign":"center","fontSize":"small"} /-->
-
- <!-- wp:woocommerce/product-button {"textAlign":"center","fontSize":"small"} /-->
- <!-- /wp:woocommerce/product-template -->
-</div>
-<!-- /wp:woocommerce/product-collection -->
diff --git a/plugins/woocommerce/tests/e2e/fixtures/fixtures.ts b/plugins/woocommerce/tests/e2e/fixtures/fixtures.ts
index 2e943836bc6..d2ede6b693f 100644
--- a/plugins/woocommerce/tests/e2e/fixtures/fixtures.ts
+++ b/plugins/woocommerce/tests/e2e/fixtures/fixtures.ts
@@ -128,4 +128,7 @@ export const locks = {
// `taxonomy-product_brand` templates. The Site Editor offers to add one only
// while it does not exist.
TAXONOMY_TEMPLATES: 'taxonomy-templates',
+ // The `taxonomy-product_cat-tshirts` template. Each test creates it and
+ // deletes it.
+ TSHIRTS_CATEGORY_TEMPLATE: 'tshirts-category-template',
} as const;
diff --git a/plugins/woocommerce/tests/e2e/playwright.config.ts b/plugins/woocommerce/tests/e2e/playwright.config.ts
index d3ed957d54f..78a30c88c8a 100644
--- a/plugins/woocommerce/tests/e2e/playwright.config.ts
+++ b/plugins/woocommerce/tests/e2e/playwright.config.ts
@@ -225,20 +225,56 @@ const blocksSerialSpecs = [
// archive, header, cart, checkout), or the
// `wc_blocks_use_blockified_product_grid_block_as_template` option. Every
// spec that visits those pages reads them.
+
+ // Saves the Single Product template and the Add to Cart + Options template
+ // part for variable products, creates and changes visible products,
+ // activates two test plugins, and turns off AJAX add to cart and turns on
+ // the redirect to the cart.
'**/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts',
+ // Sets the option to false and saves the Product Catalog template, to check
+ // the Filter by Attribute block with the classic template on `/shop`.
'**/tests/blocks/attributes-filter/attribute-filter-classic-template.block_theme.spec.ts',
+ // Makes Beanie sold individually, activates a test plugin, and saves the
+ // Single Product template.
'**/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts',
+ // Saves the Checkout page template. A post with a Checkout block is not the
+ // checkout page, so it cannot replace this template. Also places orders for
+ // Polo.
'**/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts',
+ // Sets the option to false, to check that the Product Catalog template
+ // then has the classic template block.
'**/tests/blocks/classic-template/classic-template-blockified-option.block_theme.spec.ts',
+ // Saves the header template part, creates a visible $10 product, and
+ // changes the tax settings `woocommerce_prices_include_tax` and
+ // `woocommerce_tax_display_cart`.
'**/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts',
+ // Saves the header template part, which every frontend page shows. Its
+ // only test is skipped.
'**/tests/blocks/mini-cart/mini-cart-header-colors.block_theme.spec.ts',
+ // Edits the content of the Cart and Checkout pages.
'**/tests/blocks/page-content-wrapper/page-content-wrapper-page-edit.block_theme.spec.ts',
+ // Sets the option to false and saves the Product Catalog template, to check
+ // the Filter by Price block with the classic template on `/shop`.
'**/tests/blocks/price-filter/price-filter-classic-template.block_theme.spec.ts',
+ // Saves the Product Catalog and Product Search Results templates and the
+ // templates for all categories and all tags, and changes the default
+ // catalog order and the number of products per page.
'**/tests/blocks/product-collection/product-collection-site-templates.block_theme.spec.ts',
+ // Saves the Product Catalog template and checks term counts on `/shop`,
+ // which only stay the same in a serial run.
'**/tests/blocks/product-filters/product-filters-shop.block_theme.spec.ts',
- '**/tests/blocks/products/products.block_theme.spec.ts',
- '**/tests/blocks/rating-filter/rating-filter.block_theme.spec.ts',
- '**/tests/blocks/stock-filter/stock-filter.block_theme.spec.ts',
+ // Saves the Product Catalog and Product Search Results templates. No
+ // narrower template can change only one of these pages.
+ '**/tests/blocks/products/products-site-templates.block_theme.spec.ts',
+ // Sets the option to false and saves the Product Catalog template, to check
+ // the Filter by Rating block with the classic template on `/shop`.
+ '**/tests/blocks/rating-filter/rating-filter-classic-template.block_theme.spec.ts',
+ // Sets the option to false and saves the Product Catalog template, to check
+ // the Filter by Stock block with the classic template on `/shop`.
+ '**/tests/blocks/stock-filter/stock-filter-classic-template.block_theme.spec.ts',
+ // Saves the Single Product template under the plugin template ID and
+ // renames the `wp_theme` term of the plugin. Only a site-wide template has
+ // this ID.
'**/tests/blocks/templates/legacy-templates.block_theme.spec.ts',
// Turn off AJAX add to cart, which every Product Button reads.
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/products/products-site-templates.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/products/products-site-templates.block_theme.spec.ts
new file mode 100644
index 00000000000..3f1e8a25929
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/products/products-site-templates.block_theme.spec.ts
@@ -0,0 +1,63 @@
+/**
+ * External dependencies
+ */
+import { test, expect, BLOCK_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+/**
+ * Internal dependencies
+ */
+import {
+ getProductsNameFromClassicTemplate,
+ getProductsNameFromProductQuery,
+ insertProductsQuery,
+} from './utils';
+
+const routes = [
+ {
+ testTitle:
+ 'Products block matches the classic template block on the shop page',
+ templateTitle: 'Product Catalog',
+ slug: 'archive-product',
+ frontendPage: '/shop/',
+ },
+ {
+ testTitle:
+ 'Products block matches the classic template block on product search results',
+ templateTitle: 'Product Search Results',
+ slug: 'product-search-results',
+ frontendPage: '/?s=shirt&post_type=product',
+ },
+];
+
+for ( const { testTitle, templateTitle, slug, frontendPage } of routes ) {
+ test.describe( `${ templateTitle } template, Products block`, () => {
+ test( testTitle, async ( { admin, editor, page } ) => {
+ await admin.visitSiteEditor( {
+ postId: `${ BLOCK_THEME_SLUG }//${ slug }`,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+ await editor.setContent( '' );
+ await insertProductsQuery( editor );
+ await editor.insertBlock( { name: 'woocommerce/legacy-template' } );
+ await editor.canvas.locator( 'body' ).click();
+
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+
+ await page.goto( frontendPage );
+ await expect(
+ page.locator( '.woocommerce-loop-product__title' ).first()
+ ).toBeVisible();
+
+ const classicProducts =
+ await getProductsNameFromClassicTemplate( page );
+ const productQueryProducts =
+ await getProductsNameFromProductQuery( page );
+
+ expect( classicProducts.length ).toBeGreaterThan( 1 );
+ expect( classicProducts ).toEqual( productQueryProducts );
+ } );
+ } );
+}
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/products/products.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/products/products.block_theme.spec.ts
index b41b62a50ff..210b484da09 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/products/products.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/products/products.block_theme.spec.ts
@@ -2,12 +2,12 @@
* External dependencies
*/
import {
- test,
+ test as base,
expect,
- Admin,
+ guestFile,
BlockData,
BLOCK_THEME_SLUG,
- RequestUtils,
+ WPTemplate,
} from '@woocommerce/e2e-utils';
/**
@@ -20,6 +20,7 @@ import {
getProductsNameFromProductQuery,
insertProductsQuery,
} from './utils';
+import { locks } from '../../../fixtures/fixtures';
const blockData: BlockData = {
name: 'core/query',
@@ -31,44 +32,34 @@ const blockData: BlockData = {
},
};
-const templates = {
- 'archive-product': {
- templateTitle: 'Product Catalog',
- slug: 'archive-product',
- frontendPage: '/shop/',
- legacyBlockName: 'woocommerce/legacy-template',
- },
-};
-
-const classicTemplateComparisonRoutes = {
- 'archive-product': {
- testTitle:
- 'Products block matches the classic template block on the shop page',
- templateTitle: 'Product Catalog',
- slug: 'archive-product',
- frontendPage: '/shop/',
- legacyBlockName: 'woocommerce/legacy-template',
- needsCreation: false,
- },
- 'taxonomy-product_cat': {
- testTitle:
- 'Products block matches the classic template block on a product category archive',
- templateTitle: 'Products by Category',
- slug: 'taxonomy-product_cat',
- frontendPage: '/product-category/tshirts/',
- legacyBlockName: 'woocommerce/legacy-template',
- needsCreation: true,
- },
- 'product-search-results': {
- testTitle:
- 'Products block matches the classic template block on product search results',
- templateTitle: 'Product Search Results',
- slug: 'product-search-results',
- frontendPage: '/?s=shirt&post_type=product',
- legacyBlockName: 'woocommerce/legacy-template',
- needsCreation: false,
+const CATEGORY_PAGE = '/product-category/clothing/tshirts/';
+const LEGACY_BLOCK_NAME = 'woocommerce/legacy-template';
+
+const test = base.extend< { categoryTemplate: WPTemplate } >( {
+ // A template for the Tshirts category only, so no other page changes.
+ categoryTemplate: async ( { requestUtils }, use ) => {
+ // A stopped run can leave the template, and a second one gets a
+ // different slug, which the Tshirts page does not use.
+ await requestUtils
+ .rest( {
+ method: 'DELETE',
+ path: `/wp/v2/templates/${ BLOCK_THEME_SLUG }//taxonomy-product_cat-tshirts`,
+ params: { force: true },
+ } )
+ .catch( ( error ) => {
+ if ( error?.code !== 'rest_template_not_found' ) {
+ throw error;
+ }
+ } );
+ const template = ( await requestUtils.createTemplate( 'wp_template', {
+ slug: 'taxonomy-product_cat-tshirts',
+ title: 'Products by Category: Tshirts',
+ content: '',
+ } ) ) as WPTemplate;
+ await use( template );
+ await requestUtils.revertTemplate( 'wp_template', template.id );
},
-};
+} );
test.describe( `${ blockData.name } Block `, () => {
test( 'when Inherits Query From Template other options are hidden, show up otherwise', async ( {
@@ -76,6 +67,7 @@ test.describe( `${ blockData.name } Block `, () => {
editor,
page,
} ) => {
+ // This test does not save the template.
await admin.visitSiteEditor( {
postId: `${ BLOCK_THEME_SLUG }//archive-product`,
postType: 'wp_template',
@@ -101,54 +93,52 @@ test.describe( `${ blockData.name } Block `, () => {
await expect( advancedFilterOption ).toBeVisible();
await expect( inheritQueryFromTemplateOption ).toBeVisible();
} );
+} );
- test( 'product button should add product to the cart when inheriting query from template', async ( {
- admin,
- editor,
- page,
- frontendUtils,
- } ) => {
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//archive-product`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
- await editor.setContent( '' );
- await insertProductsQuery( editor );
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
+test.describe(
+ 'Tshirts category template',
+ { lock: locks.TSHIRTS_CATEGORY_TEMPLATE },
+ () => {
+ test.beforeEach( async ( { admin, editor, categoryTemplate } ) => {
+ await admin.visitSiteEditor( {
+ postId: categoryTemplate.id,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+ await insertProductsQuery( editor );
} );
- await frontendUtils.goToShop();
- const addToCartButton = page.getByRole( 'button', {
- name: 'Add to cart: “Single”',
+ test( 'product button should add product to the cart when inheriting query from template', async ( {
+ editor,
+ browser,
+ } ) => {
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+
+ // A guest cart, because all workers share the admin cart.
+ const guestContext = await browser.newContext( {
+ storageState: guestFile,
+ } );
+ const guestPage = await guestContext.newPage();
+ await guestPage.goto( CATEGORY_PAGE );
+
+ const addToCartButton = guestPage.getByRole( 'button', {
+ name: 'Add to cart: “Polo”',
+ } );
+ await addToCartButton.click();
+ await expect( addToCartButton ).toHaveText( '1 in cart' );
+ const cartLink = guestPage.getByRole( 'link', {
+ name: 'View cart',
+ } );
+ await expect( cartLink ).toBeVisible();
+ await guestContext.close();
} );
- await addToCartButton.click();
- await expect( addToCartButton ).toHaveText( '1 in cart' );
- const cartLink = page.getByRole( 'link', { name: 'View cart' } );
- await expect( cartLink ).toBeVisible();
- } );
-} );
-for ( const {
- templateTitle,
- slug,
- frontendPage,
- legacyBlockName,
-} of Object.values( templates ) ) {
- test.describe( `${ templateTitle } template`, () => {
test( 'Product Collection matches with classic template block', async ( {
- admin,
editor,
page,
} ) => {
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//${ slug }`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
- await editor.setContent( '' );
- await insertProductsQuery( editor );
await page
.getByRole( 'button', {
name: 'Upgrade to Product Collection',
@@ -171,7 +161,7 @@ for ( const {
};
await expectProductCollectionQuery();
- await editor.insertBlock( { name: legacyBlockName } );
+ await editor.insertBlock( { name: LEGACY_BLOCK_NAME } );
await editor.canvas.locator( 'body' ).click();
await editor.saveSiteEditorEntities( {
@@ -181,7 +171,7 @@ for ( const {
await editor.canvas.locator( 'body' ).waitFor();
await expectProductCollectionQuery();
- await page.goto( frontendPage );
+ await page.goto( CATEGORY_PAGE );
const classicProducts =
await getProductsNameFromClassicTemplate( page );
@@ -192,65 +182,19 @@ for ( const {
expect( productCollectionProducts.length ).toBeGreaterThan( 1 );
expect( classicProducts ).toEqual( productCollectionProducts );
} );
- } );
-}
-
-const openRouteTemplateForEditing = async (
- admin: Admin,
- requestUtils: RequestUtils,
- {
- templateTitle,
- slug,
- needsCreation,
- }: { templateTitle: string; slug: string; needsCreation: boolean }
-) => {
- if ( needsCreation ) {
- const template = await requestUtils.createTemplate( 'wp_template', {
- slug,
- title: templateTitle,
- content: '',
- } );
- await admin.visitSiteEditor( {
- postId: template.id,
- postType: 'wp_template',
- canvas: 'edit',
- } );
- return;
- }
-
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//${ slug }`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
-};
-
-for ( const {
- testTitle,
- templateTitle,
- slug,
- frontendPage,
- legacyBlockName,
- needsCreation,
-} of Object.values( classicTemplateComparisonRoutes ) ) {
- test.describe( `${ templateTitle } template, Products block`, () => {
- test( testTitle, async ( { admin, editor, page, requestUtils } ) => {
- await openRouteTemplateForEditing( admin, requestUtils, {
- templateTitle,
- slug,
- needsCreation,
- } );
- await editor.setContent( '' );
- await insertProductsQuery( editor );
- await editor.insertBlock( { name: legacyBlockName } );
+ test( 'Products block matches the classic template block on a product category archive', async ( {
+ editor,
+ page,
+ } ) => {
+ await editor.insertBlock( { name: LEGACY_BLOCK_NAME } );
await editor.canvas.locator( 'body' ).click();
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );
- await page.goto( frontendPage );
+ await page.goto( CATEGORY_PAGE );
await expect(
page.locator( '.woocommerce-loop-product__title' ).first()
).toBeVisible();
@@ -263,5 +207,5 @@ for ( const {
expect( classicProducts.length ).toBeGreaterThan( 1 );
expect( classicProducts ).toEqual( productQueryProducts );
} );
- } );
-}
+ }
+);
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter-classic-template.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter-classic-template.block_theme.spec.ts
new file mode 100644
index 00000000000..a5cd26b20ce
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter-classic-template.block_theme.spec.ts
@@ -0,0 +1,65 @@
+/**
+ * External dependencies
+ */
+import { test, expect, wpCLI, BLOCK_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+// The Cap is the only seeded product in this bucket: its reviews are rated 1
+// and 2, averaging 1.5.
+const blockData = {
+ name: 'Filter by Rating',
+ urlSearchParamWhenFilterIsApplied: 'rating_filter=2',
+};
+
+test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
+ test.beforeEach( async ( { admin, page, editor } ) => {
+ await wpCLI(
+ 'option update wc_blocks_use_blockified_product_grid_block_as_template false'
+ );
+
+ await admin.visitSiteEditor( {
+ postId: `${ BLOCK_THEME_SLUG }//archive-product`,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+
+ await editor.insertBlock( {
+ name: 'woocommerce/filter-wrapper',
+ attributes: {
+ filterType: 'rating-filter',
+ heading: 'Filter By Rating',
+ },
+ } );
+
+ await page.keyboard.press( 'Escape' );
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+
+ await page.goto( '/shop' );
+ } );
+
+ test( 'filters the classic product template by rating', async ( {
+ frontendUtils,
+ page,
+ } ) => {
+ await page
+ .getByRole( 'checkbox', { name: 'Rated 2 out of 5' } )
+ .click();
+
+ await expect( page ).toHaveURL(
+ new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
+ );
+
+ const legacyTemplate = await frontendUtils.getBlockByName(
+ 'woocommerce/legacy-template'
+ );
+ const products = legacyTemplate
+ .getByRole( 'list' )
+ .locator( '.product' );
+
+ await expect( products ).toHaveCount( 1 );
+ await expect(
+ products.getByRole( 'heading', { name: 'Cap' } )
+ ).toBeVisible();
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter.block_theme.spec.ts
index 6bb473062f6..93ee15ba777 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/rating-filter/rating-filter.block_theme.spec.ts
@@ -1,107 +1,34 @@
/**
* External dependencies
*/
-import {
- test as base,
- expect,
- wpCLI,
- TemplateCompiler,
- BLOCK_THEME_SLUG,
- flushMacrotask,
-} from '@woocommerce/e2e-utils';
+import { test, expect, flushMacrotask } from '@woocommerce/e2e-utils';
// The Cap is the only seeded product in this bucket: its reviews are rated 1
// and 2, averaging 1.5.
const blockData = {
name: 'Filter by Rating',
- slug: 'woocommerce/rating-filter',
urlSearchParamWhenFilterIsApplied: 'rating_filter=2',
};
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, use ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_filters-with-product-collection'
- );
- await use( compiler );
- },
-} );
-
-test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
- test.beforeEach( async ( { admin, page, editor } ) => {
- await wpCLI(
- 'option update wc_blocks_use_blockified_product_grid_block_as_template false'
- );
-
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//archive-product`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
-
- await editor.insertBlock( {
- name: 'woocommerce/filter-wrapper',
- attributes: {
- filterType: 'rating-filter',
- heading: 'Filter By Rating',
- },
- } );
-
- await page.keyboard.press( 'Escape' );
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
-
- await page.goto( '/shop' );
- } );
-
- test( 'filters the classic product template by rating', async ( {
- frontendUtils,
- page,
- } ) => {
- await page
- .getByRole( 'checkbox', { name: 'Rated 2 out of 5' } )
- .click();
-
- await expect( page ).toHaveURL(
- new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
- );
-
- const legacyTemplate = await frontendUtils.getBlockByName(
- 'woocommerce/legacy-template'
- );
- const products = legacyTemplate
- .getByRole( 'list' )
- .locator( '.product' );
-
- await expect( products ).toHaveCount( 1 );
- await expect(
- products.getByRole( 'heading', { name: 'Cap' } )
- ).toBeVisible();
- } );
-} );
-
test.describe( `${ blockData.name } Block - with Product Collection`, () => {
test( 'filters Product Collection automatically and defers changes until Apply when configured', async ( {
page,
- admin,
- editor,
- templateCompiler,
+ createPost,
} ) => {
await page.clock.install();
- const template = await templateCompiler.compile();
+ const post = await createPost( 'filters-with-product-collection' );
const productTitles = page.locator(
'.wp-block-woocommerce-product-template .wp-block-post-title'
);
- await page.goto( '/shop' );
+ await page.goto( post.link );
await expect( productTitles.first() ).toBeVisible();
const automaticBaseline = ( await productTitles.allTextContents() ).map(
( title ) => title.trim()
);
- // Greater than one, not merely non-empty: an unfiltered /shop must show more
+ // Greater than one, not merely non-empty: the unfiltered post must show more
// than the single product the filter is about to leave behind. Asserting only
- // that it is non-empty passes on a shop page that arrived already filtered,
+ // that it is non-empty passes on a page that arrived already filtered,
// and then the post-filter assertion passes too, for the wrong reason.
expect( automaticBaseline.length ).toBeGreaterThan( 1 );
@@ -114,24 +41,11 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
);
await expect( productTitles ).toHaveText( [ 'Cap' ] );
- await admin.visitSiteEditor( {
- postId: template.id,
- postType: template.type,
- canvas: 'edit',
- } );
-
- const ratingFilterControls = await editor.getBlockByName(
- blockData.slug
+ const deferredPost = await createPost(
+ 'filters-with-product-collection',
+ { showFilterButton: true }
);
- await expect( ratingFilterControls ).toBeVisible();
- await editor.selectBlocks( ratingFilterControls );
- await editor.openDocumentSettingsSidebar();
- await page.getByText( "Show 'Apply filters' button" ).click();
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
-
- await page.goto( '/shop' );
+ await page.goto( deferredPost.link );
await expect( productTitles.first() ).toBeVisible();
const ratingFilterCheckbox = page.getByRole( 'checkbox', {
name: 'Rated 2 out of 5',
@@ -143,9 +57,9 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
const deferredBaseline = ( await productTitles.allTextContents() ).map(
( title ) => title.trim()
);
- // Greater than one, not merely non-empty: an unfiltered /shop must show more
+ // Greater than one, not merely non-empty: the unfiltered post must show more
// than the single product the filter is about to leave behind. Asserting only
- // that it is non-empty passes on a shop page that arrived already filtered,
+ // that it is non-empty passes on a page that arrived already filtered,
// and then the post-filter assertion passes too, for the wrong reason.
expect( deferredBaseline.length ).toBeGreaterThan( 1 );
const deferredUrl = page.url();
@@ -154,7 +68,9 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
await page.clock.runFor( 501 );
await flushMacrotask( page );
await expect( ratingFilterCheckbox ).toBeChecked();
- const applyButton = page.getByRole( 'button', { name: 'Apply' } );
+ const applyButton = page.getByRole( 'button', {
+ name: 'Apply rating filter',
+ } );
await expect( applyButton ).toBeVisible();
await expect( applyButton ).toBeEnabled();
await expect( page ).toHaveURL( deferredUrl );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter-classic-template.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter-classic-template.block_theme.spec.ts
new file mode 100644
index 00000000000..af92b8b892b
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter-classic-template.block_theme.spec.ts
@@ -0,0 +1,63 @@
+/**
+ * External dependencies
+ */
+import { test, expect, wpCLI, BLOCK_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+const blockData = {
+ name: 'Filter by Stock',
+ urlSearchParamWhenFilterIsApplied: 'filter_stock_status=outofstock',
+};
+
+test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
+ test.beforeEach( async ( { admin, page, editor } ) => {
+ await wpCLI(
+ 'option update wc_blocks_use_blockified_product_grid_block_as_template false'
+ );
+
+ await page.reload();
+
+ await admin.visitSiteEditor( {
+ postId: `${ BLOCK_THEME_SLUG }//archive-product`,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+
+ await editor.insertBlock( {
+ name: 'woocommerce/filter-wrapper',
+ attributes: {
+ filterType: 'stock-filter',
+ heading: 'Filter By Stock',
+ },
+ } );
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+ await page.goto( '/shop' );
+ } );
+
+ test( 'filters the classic product template by stock status', async ( {
+ frontendUtils,
+ page,
+ } ) => {
+ const stockFilter = await frontendUtils.getBlockByName(
+ 'woocommerce/filter-wrapper'
+ );
+ await stockFilter.getByText( 'Out of Stock' ).click();
+
+ await expect( page ).toHaveURL(
+ new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
+ );
+
+ const legacyTemplate = await frontendUtils.getBlockByName(
+ 'woocommerce/legacy-template'
+ );
+ const products = legacyTemplate
+ .getByRole( 'list' )
+ .locator( '.product' );
+
+ await expect( products ).toHaveCount( 1 );
+ await expect(
+ products.getByRole( 'heading', { name: 'T-Shirt with Logo' } )
+ ).toBeVisible();
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter.block_theme.spec.ts
index 912b140d8d6..f28f96ea9c1 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/stock-filter/stock-filter.block_theme.spec.ts
@@ -1,105 +1,32 @@
/**
* External dependencies
*/
-import {
- test as base,
- expect,
- TemplateCompiler,
- wpCLI,
- BLOCK_THEME_SLUG,
- flushMacrotask,
-} from '@woocommerce/e2e-utils';
+import { test, expect, flushMacrotask } from '@woocommerce/e2e-utils';
-export const blockData = {
+const blockData = {
name: 'Filter by Stock',
- slug: 'woocommerce/stock-filter',
urlSearchParamWhenFilterIsApplied: 'filter_stock_status=outofstock',
};
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, use ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_filters-with-product-collection'
- );
- await use( compiler );
- },
-} );
-
-test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
- test.beforeEach( async ( { admin, page, editor } ) => {
- await wpCLI(
- 'option update wc_blocks_use_blockified_product_grid_block_as_template false'
- );
-
- await page.reload();
-
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//archive-product`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
-
- await editor.insertBlock( {
- name: 'woocommerce/filter-wrapper',
- attributes: {
- filterType: 'stock-filter',
- heading: 'Filter By Stock',
- },
- } );
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
- await page.goto( '/shop' );
- } );
-
- test( 'filters the classic product template by stock status', async ( {
- frontendUtils,
- page,
- } ) => {
- const stockFilter = await frontendUtils.getBlockByName(
- 'woocommerce/filter-wrapper'
- );
- await stockFilter.getByText( 'Out of Stock' ).click();
-
- await expect( page ).toHaveURL(
- new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
- );
-
- const legacyTemplate = await frontendUtils.getBlockByName(
- 'woocommerce/legacy-template'
- );
- const products = legacyTemplate
- .getByRole( 'list' )
- .locator( '.product' );
-
- await expect( products ).toHaveCount( 1 );
- await expect(
- products.getByRole( 'heading', { name: 'T-Shirt with Logo' } )
- ).toBeVisible();
- } );
-} );
-
test.describe( `${ blockData.name } Block - with Product Collection`, () => {
test( 'filters Product Collection automatically and defers changes until Apply when configured', async ( {
page,
- admin,
- editor,
- templateCompiler,
+ createPost,
} ) => {
await page.clock.install();
- const template = await templateCompiler.compile();
+ const post = await createPost( 'filters-with-product-collection' );
const productTitles = page.locator(
'.wp-block-woocommerce-product-template .wp-block-post-title'
);
- await page.goto( '/shop' );
+ await page.goto( post.link );
await expect( productTitles.first() ).toBeVisible();
const automaticBaseline = ( await productTitles.allTextContents() ).map(
( title ) => title.trim()
);
- // Greater than one, not merely non-empty: an unfiltered /shop must show more
+ // Greater than one, not merely non-empty: the unfiltered post must show more
// than the single product the filter is about to leave behind. Asserting only
- // that it is non-empty passes on a shop page that arrived already filtered,
+ // that it is non-empty passes on a page that arrived already filtered,
// and then the post-filter assertion passes too, for the wrong reason.
expect( automaticBaseline.length ).toBeGreaterThan( 1 );
@@ -109,24 +36,11 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
);
await expect( productTitles ).toHaveText( [ 'T-Shirt with Logo' ] );
- await admin.visitSiteEditor( {
- postId: template.id,
- postType: template.type,
- canvas: 'edit',
- } );
-
- const stockFilterControls = await editor.getBlockByName(
- blockData.slug
+ const deferredPost = await createPost(
+ 'filters-with-product-collection',
+ { showFilterButton: true }
);
- await expect( stockFilterControls ).toBeVisible();
- await editor.selectBlocks( stockFilterControls );
- await editor.openDocumentSettingsSidebar();
- await page.getByText( "Show 'Apply filters' button" ).click();
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
-
- await page.goto( '/shop' );
+ await page.goto( deferredPost.link );
await expect( productTitles.first() ).toBeVisible();
const outOfStockFilter = page.getByRole( 'checkbox', {
name: 'Out of Stock',
@@ -138,9 +52,9 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
const deferredBaseline = ( await productTitles.allTextContents() ).map(
( title ) => title.trim()
);
- // Greater than one, not merely non-empty: an unfiltered /shop must show more
+ // Greater than one, not merely non-empty: the unfiltered post must show more
// than the single product the filter is about to leave behind. Asserting only
- // that it is non-empty passes on a shop page that arrived already filtered,
+ // that it is non-empty passes on a page that arrived already filtered,
// and then the post-filter assertion passes too, for the wrong reason.
expect( deferredBaseline.length ).toBeGreaterThan( 1 );
const deferredUrl = page.url();
@@ -149,7 +63,9 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
await page.clock.runFor( 501 );
await flushMacrotask( page );
await expect( outOfStockFilter ).toBeChecked();
- const applyButton = page.getByRole( 'button', { name: 'Apply' } );
+ const applyButton = page.getByRole( 'button', {
+ name: 'Apply stock filter',
+ } );
await expect( applyButton ).toBeVisible();
await expect( applyButton ).toBeEnabled();
await expect( page ).toHaveURL( deferredUrl );