Commit ed478d6841f for woocommerce
commit ed478d6841fb4d1b2f5beb5d157c7f909efa9186
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Tue Nov 24 21:26:00 2026 +0200
Run 5 Blocks e2e filter specs in parallel (#71374)
* Run 5 Blocks e2e filter specs in parallel
These specs saved the Product Catalog template, which changes /shop for
all workers, so they ran serially. Each test now publishes its own post
with a local Product Collection and deletes the post after the test.
The classic template tests set a global option, so they move to their
own serial files. A new serial spec keeps Product Filters coverage on
/shop.
diff --git a/plugins/woocommerce/changelog/testops-308-blocks-e2e-move-filter-specs-that-save-the-shop b/plugins/woocommerce/changelog/testops-308-blocks-e2e-move-filter-specs-that-save-the-shop
new file mode 100644
index 00000000000..6f6760bb4e1
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-308-blocks-e2e-move-filter-specs-that-save-the-shop
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Run 5 Blocks e2e filter specs in parallel; tests only, no production change.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/price-filter/test/edit.tsx b/plugins/woocommerce/client/blocks/assets/js/blocks/price-filter/test/edit.tsx
new file mode 100644
index 00000000000..54385a40eb7
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/price-filter/test/edit.tsx
@@ -0,0 +1,76 @@
+/**
+ * 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 PriceFilterEdit 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( 'Price Filter Edit', () => {
+ it( "sets showFilterButton from the Show 'Apply filters' button toggle", async () => {
+ const setAttributes = jest.fn();
+ const Edit = PriceFilterEdit as unknown as React.ComponentType<
+ Record< string, unknown >
+ >;
+
+ render(
+ <Edit
+ attributes={ {
+ heading: '',
+ headingLevel: 3,
+ inlineInput: false,
+ showFilterButton: false,
+ showInputFields: true,
+ } }
+ clientId="price-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-308-price-filter-apply-toggle-test b/plugins/woocommerce/client/blocks/changelog/testops-308-price-filter-apply-toggle-test
new file mode 100644
index 00000000000..835ba654f1d
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/changelog/testops-308-price-filter-apply-toggle-test
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Add a unit test for the Filter by Price Apply button toggle; tests only, no production change.
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_active-filters.handlebars
similarity index 68%
rename from plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars
rename to plugins/woocommerce/tests/e2e/content-templates/blocks/post_active-filters.handlebars
index 651a0eda658..22a4bdf24fb 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_active-filters.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_active-filters.handlebars
@@ -1,3 +1,5 @@
+<!-- wp:woocommerce/product-collection {"queryId":1,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":false,"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-filters -->
<div
class='wp-block-woocommerce-product-filters wc-block-product-filters'
@@ -15,10 +17,7 @@
<!-- /wp:woocommerce/product-filter-active -->
</div>
<!-- /wp:woocommerce/product-filters -->
-
-<!-- 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-template -->
<!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
<!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/post_attribute-filter.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_attribute-filter.handlebars
new file mode 100644
index 00000000000..f5387465e14
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_attribute-filter.handlebars
@@ -0,0 +1,52 @@
+<!-- wp:woocommerce/product-collection {"queryId":1,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":false,"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-filters -->
+<div class="wp-block-woocommerce-product-filters wc-block-product-filters" style="--wc-product-filters-text-color:#111;--wc-product-filters-background-color:#fff">
+<!-- wp:woocommerce/product-filter-active -->
+<div class="wp-block-woocommerce-product-filter-active">
+
+<!-- wp:woocommerce/product-filter-clear-button -->
+<!-- wp:buttons {"style":{"spacing":{"margin":{"top":"var:preset|spacing|10"}}},"layout":{"type":"flex","verticalAlignment":"stretched"}} -->
+<div class="wp-block-buttons" style="margin-top:var(--wp--preset--spacing--10)"><!-- wp:button {"textAlign":"center","width":100,"className":"wc-block-product-filter-clear-button is-style-outline","style":{"border":{"width":"1px"},"typography":{"textDecoration":"none"},"outline":"none","fontSize":"medium","spacing":{"padding":{"left":"8px","right":"8px","top":"5px","bottom":"5px"}}}} -->
+<div class="wp-block-button has-custom-width wp-block-button__width-100 wc-block-product-filter-clear-button is-style-outline"><a class="wp-block-button__link has-text-align-center wp-element-button" style="border-width:1px;padding-top:5px;padding-right:8px;padding-bottom:5px;padding-left:8px;text-decoration:none">Clear filters</a></div>
+<!-- /wp:button --></div>
+<!-- /wp:buttons -->
+<!-- /wp:woocommerce/product-filter-clear-button --></div>
+<!-- /wp:woocommerce/product-filter-active -->
+{{#> wp-block blockName='woocommerce/product-filter-attribute' attributes=attributes }}
+<div class="wp-block-woocommerce-product-filter-attribute"><!-- wp:group {"metadata":{"name":"Header"},"style":{"spacing":{"blockGap":"0"}},"layout":{"type":"flex","flexWrap":"nowrap"}} -->
+<div class="wp-block-group"><!-- wp:heading {"level":3} -->
+<h3 class="wp-block-heading">Attribute</h3>
+<!-- /wp:heading --></div>
+<!-- /wp:group -->
+
+{{#if dropdown}}
+{{#> wp-block blockName='woocommerce/dropdown' attributes=dropdownAttributes }}{{/ wp-block }}
+{{else}}
+<!-- wp:woocommerce/product-filter-checkbox-list {"lock":{"remove":true}} -->
+<div class="wp-block-woocommerce-product-filter-checkbox-list wc-block-product-filter-checkbox-list"></div>
+<!-- /wp:woocommerce/product-filter-checkbox-list -->
+{{/if}}
+</div>
+{{/ wp-block }}
+
+{{#if taxonomy}}
+<!-- wp:woocommerce/product-filter-taxonomy {"taxonomy":"product_cat","displayStyle":"woocommerce/dropdown"} -->
+<div class="wp-block-woocommerce-product-filter-taxonomy"><!-- wp:woocommerce/dropdown /--></div>
+<!-- /wp:woocommerce/product-filter-taxonomy -->
+{{/if}}
+
+</div>
+<!-- /wp:woocommerce/product-filters -->
+<!-- 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/post_filters-with-product-collection.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars
new file mode 100644
index 00000000000..37c9caa980e
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_filters-with-product-collection.handlebars
@@ -0,0 +1,83 @@
+<!-- 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":"",{{#if showFilterButton}}"showFilterButton":true,{{/if}}"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":"",{{#if showFilterButton}}"showFilterButton":true,{{/if}}"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":false,"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_multiple-product-filters.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_multiple-product-filters.handlebars
similarity index 80%
rename from plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars
rename to plugins/woocommerce/tests/e2e/content-templates/blocks/post_multiple-product-filters.handlebars
index fb7a67bf479..1fc33b5d7f0 100644
--- a/plugins/woocommerce/tests/e2e/content-templates/blocks/template_archive-product_multiple-product-filters.handlebars
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_multiple-product-filters.handlebars
@@ -1,3 +1,5 @@
+<!-- wp:woocommerce/product-collection {"queryId":1,"query":{"perPage":9,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","search":"","exclude":[],"inherit":false,"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-filters -->
<div class="wp-block-woocommerce-product-filters wc-block-product-filters" style="--wc-product-filters-text-color:#111;--wc-product-filters-background-color:#fff">
<!-- wp:woocommerce/product-filter-active -->
@@ -25,10 +27,7 @@
{{/ wp-block }}
</div>
<!-- /wp:woocommerce/product-filters -->
-
-<!-- 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-template -->
<!-- wp:woocommerce/product-image {"showSaleBadge":false,"imageSizing":"thumbnail"} -->
<!-- wp:woocommerce/product-sale-badge {"align":"right"} /-->
<!-- /wp:woocommerce/product-image -->
diff --git a/plugins/woocommerce/tests/e2e/content-templates/blocks/post_price-filter-with-all-products.handlebars b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_price-filter-with-all-products.handlebars
new file mode 100644
index 00000000000..9617789e919
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/content-templates/blocks/post_price-filter-with-all-products.handlebars
@@ -0,0 +1,27 @@
+<!-- wp:woocommerce/all-products {"columns":3,"rows":3,"alignButtons":false,"contentVisibility":{"orderBy":true},"orderby":"date","layoutConfig":[["woocommerce/product-image",{"imageSizing":"cropped"}],["woocommerce/product-title"],["woocommerce/product-price"],["woocommerce/product-rating"],["woocommerce/product-button"]]} -->
+<div
+ class='wp-block-woocommerce-all-products wc-block-all-products'
+ data-attributes='{"alignButtons":false,"columns":3,"contentVisibility":{"orderBy":true},"isPreview":false,"layoutConfig":[["woocommerce/product-image",{"imageSizing":"cropped"}],["woocommerce/product-title"],["woocommerce/product-price"],["woocommerce/product-rating"],["woocommerce/product-button"]],"orderby":"date","rows":3}'
+></div>
+<!-- /wp:woocommerce/all-products -->
+
+<!-- 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'
+ data-showinputfields='true'
+ data-showfilterbutton='false'
+ data-heading=''
+ data-heading-level='3'
+ ><span
+ aria-hidden='true'
+ class='wc-block-product-categories__placeholder'
+ ></span></div>
+ <!-- /wp:woocommerce/price-filter --></div>
+<!-- /wp:woocommerce/filter-wrapper -->
diff --git a/plugins/woocommerce/tests/e2e/playwright.config.ts b/plugins/woocommerce/tests/e2e/playwright.config.ts
index 2ff3ec41672..d3ed957d54f 100644
--- a/plugins/woocommerce/tests/e2e/playwright.config.ts
+++ b/plugins/woocommerce/tests/e2e/playwright.config.ts
@@ -226,18 +226,16 @@ const blocksSerialSpecs = [
// `wc_blocks_use_blockified_product_grid_block_as_template` option. Every
// spec that visits those pages reads them.
'**/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts',
- '**/tests/blocks/attributes-filter/attribute-filter.block_theme.spec.ts',
+ '**/tests/blocks/attributes-filter/attribute-filter-classic-template.block_theme.spec.ts',
'**/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts',
'**/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts',
'**/tests/blocks/classic-template/classic-template-blockified-option.block_theme.spec.ts',
'**/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts',
'**/tests/blocks/mini-cart/mini-cart-header-colors.block_theme.spec.ts',
'**/tests/blocks/page-content-wrapper/page-content-wrapper-page-edit.block_theme.spec.ts',
- '**/tests/blocks/price-filter/price-filter.block_theme.spec.ts',
+ '**/tests/blocks/price-filter/price-filter-classic-template.block_theme.spec.ts',
'**/tests/blocks/product-collection/product-collection-site-templates.block_theme.spec.ts',
- '**/tests/blocks/product-filters/active-filter-frontend.block_theme.spec.ts',
- '**/tests/blocks/product-filters/attribute-filter-frontend.block_theme.spec.ts',
- '**/tests/blocks/product-filters/product-filters-frontend.block_theme.spec.ts',
+ '**/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',
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter-classic-template.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter-classic-template.block_theme.spec.ts
new file mode 100644
index 00000000000..c80eba67a88
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter-classic-template.block_theme.spec.ts
@@ -0,0 +1,66 @@
+/**
+ * External dependencies
+ */
+import { test, expect, wpCLI, BLOCK_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+const blockData = {
+ name: 'Filter by Attribute',
+ slug: 'woocommerce/attribute-filter',
+ urlSearchParamWhenFilterIsApplied: 'filter_size=small&query_type_size=or',
+};
+
+const blockifiedTemplateOption =
+ 'wc_blocks_use_blockified_product_grid_block_as_template';
+
+test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
+ test( 'filters the PHP classic template by attribute', async ( {
+ admin,
+ editor,
+ frontendUtils,
+ page,
+ } ) => {
+ await wpCLI( `option update ${ blockifiedTemplateOption } false` );
+ await admin.visitSiteEditor( {
+ postId: `${ BLOCK_THEME_SLUG }//archive-product`,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+
+ await editor.insertBlock( {
+ name: 'woocommerce/filter-wrapper',
+ attributes: {
+ filterType: 'attribute-filter',
+ heading: 'Filter By Attribute',
+ },
+ } );
+ const attributeFilter = await editor.getBlockByName( blockData.slug );
+
+ await attributeFilter.getByText( 'Size' ).click();
+ await attributeFilter.getByText( 'Done' ).click();
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+ await page.goto( '/shop' );
+
+ const legacyTemplate = await frontendUtils.getBlockByName(
+ 'woocommerce/legacy-template'
+ );
+ const productTitles = legacyTemplate.locator(
+ '.woocommerce-loop-product__title'
+ );
+
+ await expect( productTitles.first() ).toBeVisible();
+ expect( await productTitles.allTextContents() ).not.toHaveLength( 0 );
+ for ( const name of [ 'Small', 'Medium', 'Large' ] ) {
+ await expect(
+ page.getByRole( 'checkbox', { name } )
+ ).toBeVisible();
+ }
+
+ await page.getByRole( 'checkbox', { name: 'Small' } ).click();
+ await expect( page ).toHaveURL(
+ new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
+ );
+ await expect( productTitles ).toHaveText( [ 'V-Neck T-Shirt' ] );
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter.block_theme.spec.ts
index 7847a366b5f..d59e2573b52 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/attributes-filter/attribute-filter.block_theme.spec.ts
@@ -1,14 +1,7 @@
/**
* External dependencies
*/
-import {
- test as base,
- expect,
- wpCLI,
- TemplateCompiler,
- BLOCK_THEME_SLUG,
- getProductAttributeIds,
-} from '@woocommerce/e2e-utils';
+import { test, expect, getProductAttributeIds } from '@woocommerce/e2e-utils';
import type { Page } from '@playwright/test';
const blockData = {
@@ -17,18 +10,6 @@ const blockData = {
urlSearchParamWhenFilterIsApplied: 'filter_size=small&query_type_size=or',
};
-const blockifiedTemplateOption =
- 'wc_blocks_use_blockified_product_grid_block_as_template';
-
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, provideTemplateCompiler ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_filters-with-product-collection'
- );
- await provideTemplateCompiler( compiler );
- },
-} );
-
const getProductCollectionTitles = ( page: Page ) =>
page.locator(
'.wp-block-woocommerce-product-template .wp-block-post-title'
@@ -86,74 +67,19 @@ test.describe( `${ blockData.name } Block`, () => {
} );
} );
-test.describe( `${ blockData.name } Block - with PHP classic template`, () => {
- test( 'filters the PHP classic template by attribute', async ( {
- admin,
- editor,
- frontendUtils,
- page,
- } ) => {
- await wpCLI( `option update ${ blockifiedTemplateOption } false` );
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//archive-product`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
-
- await editor.insertBlock( {
- name: 'woocommerce/filter-wrapper',
- attributes: {
- filterType: 'attribute-filter',
- heading: 'Filter By Attribute',
- },
- } );
- const attributeFilter = await editor.getBlockByName( blockData.slug );
-
- await attributeFilter.getByText( 'Size' ).click();
- await attributeFilter.getByText( 'Done' ).click();
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
- await page.goto( '/shop' );
-
- const legacyTemplate = await frontendUtils.getBlockByName(
- 'woocommerce/legacy-template'
- );
- const productTitles = legacyTemplate.locator(
- '.woocommerce-loop-product__title'
- );
-
- await expect( productTitles.first() ).toBeVisible();
- expect( await productTitles.allTextContents() ).not.toHaveLength( 0 );
- for ( const name of [ 'Small', 'Medium', 'Large' ] ) {
- await expect(
- page.getByRole( 'checkbox', { name } )
- ).toBeVisible();
- }
-
- await page.getByRole( 'checkbox', { name: 'Small' } ).click();
- await expect( page ).toHaveURL(
- new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
- );
- await expect( productTitles ).toHaveText( [ 'V-Neck T-Shirt' ] );
- } );
-} );
-
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 { sizeAttributeId } = await getProductAttributeIds();
- const template = await templateCompiler.compile( {
+ const post = await createPost( 'filters-with-product-collection', {
attributeId: sizeAttributeId,
} );
const productTitles = getProductCollectionTitles( page );
- await page.goto( '/shop' );
+ await page.goto( post.link );
await expect( productTitles.first() ).toBeVisible();
const automaticBaseline = ( await productTitles.allTextContents() ).map(
( title ) => title.trim()
@@ -169,22 +95,11 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
);
await expect( productTitles ).toHaveText( [ 'V-Neck T-Shirt' ] );
- await admin.visitSiteEditor( {
- postId: template.id,
- postType: template.type,
- canvas: 'edit',
- } );
-
- const attributeFilter = await editor.getBlockByName( blockData.slug );
- await expect( attributeFilter ).toBeVisible();
- await editor.selectBlocks( attributeFilter );
- await editor.openDocumentSettingsSidebar();
- await page.getByText( "Show 'Apply filters' button" ).click();
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
-
- await page.goto( '/shop' );
+ const deferredPost = await createPost(
+ 'filters-with-product-collection',
+ { attributeId: sizeAttributeId, showFilterButton: true }
+ );
+ await page.goto( deferredPost.link );
await expect( productTitles.first() ).toBeVisible();
const smallCheckbox = page.getByRole( 'checkbox', { name: 'Small' } );
await expect( smallCheckbox ).toBeVisible();
@@ -217,7 +132,9 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
} )
);
await expect( smallCheckbox ).toBeChecked();
- const applyButton = page.getByRole( 'button', { name: 'Apply' } );
+ const applyButton = page.getByRole( 'button', {
+ name: 'Apply attribute filter',
+ } );
await expect( applyButton ).toBeVisible();
await expect( applyButton ).toBeEnabled();
await expect( page ).toHaveURL( deferredUrl );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter-classic-template.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter-classic-template.block_theme.spec.ts
new file mode 100644
index 00000000000..5d2a68b3fcb
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter-classic-template.block_theme.spec.ts
@@ -0,0 +1,67 @@
+/**
+ * External dependencies
+ */
+import { test, expect, wpCLI, BLOCK_THEME_SLUG } from '@woocommerce/e2e-utils';
+
+const blockData = {
+ name: 'Filter by Price',
+ urlSearchParamWhenFilterIsApplied: 'max_price=5',
+};
+
+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: 'price-filter',
+ heading: 'Filter By Price',
+ },
+ } );
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+ await page.goto( '/shop' );
+ } );
+
+ test( 'filters the classic product template by maximum price', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ const legacyTemplate = await frontendUtils.getBlockByName(
+ 'woocommerce/legacy-template'
+ );
+ const productTitles = legacyTemplate.locator(
+ '.woocommerce-loop-product__title'
+ );
+
+ await expect( productTitles.first() ).toBeVisible();
+ // More than one product, so the test cannot pass against a shop page that
+ // was already filtered.
+ expect(
+ ( await productTitles.allTextContents() ).length
+ ).toBeGreaterThan( 1 );
+
+ const maxPriceInput = page.getByRole( 'textbox', {
+ name: 'Filter products by maximum price',
+ } );
+
+ await frontendUtils.selectTextInput( maxPriceInput );
+ await maxPriceInput.fill( '$5' );
+ await maxPriceInput.press( 'Tab' );
+ await expect( page ).toHaveURL(
+ new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
+ );
+
+ await expect( productTitles ).toHaveText( [ 'Single' ] );
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter.block_theme.spec.ts
index 601ef739f96..4f259e48ed6 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/price-filter/price-filter.block_theme.spec.ts
@@ -1,15 +1,7 @@
/**
* External dependencies
*/
-import {
- test as base,
- expect,
- TemplateCompiler,
- BASE_URL,
- wpCLI,
- BLOCK_THEME_SLUG,
- flushMacrotask,
-} from '@woocommerce/e2e-utils';
+import { test, expect, BASE_URL, flushMacrotask } from '@woocommerce/e2e-utils';
const blockData = {
slug: 'woocommerce/price-filter',
@@ -24,53 +16,6 @@ const blockData = {
placeholderUrl: `${ BASE_URL }/wp-content/plugins/woocommerce/assets/images/placeholder.webp`,
};
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, provideFixture ) => {
- // Retry the template creation to handle socket hang up errors
- const maxRetries = 3;
- let retryCount = 0;
- let compiler;
- let lastError;
-
- while ( retryCount < maxRetries ) {
- try {
- compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_filters-with-product-collection'
- );
- break; // Success, exit retry loop
- } catch ( error ) {
- lastError = error;
- const errorMessage = error?.message || '';
-
- // Only retry on network-related errors that are likely transient
- const isRetriableError =
- errorMessage.includes( 'socket hang up' ) ||
- errorMessage.includes( 'ECONNRESET' ) ||
- errorMessage.includes( 'ETIMEDOUT' ) ||
- errorMessage.includes( 'ENOTFOUND' );
-
- retryCount++;
-
- if ( ! isRetriableError || retryCount >= maxRetries ) {
- throw error;
- }
-
- // Exponential backoff: 200ms, 400ms, 800ms
- const backoffDelay = Math.pow( 2, retryCount - 1 ) * 200;
- await new Promise( ( resolve ) =>
- setTimeout( resolve, backoffDelay )
- );
- }
- }
-
- if ( ! compiler ) {
- throw lastError;
- }
-
- await provideFixture( compiler );
- },
-} );
-
test.describe( `${ blockData.name } Block - editor side`, () => {
test.beforeEach( async ( { admin, editor } ) => {
await admin.createNewPost();
@@ -148,19 +93,9 @@ test.describe( `${ blockData.name } Block - editor side`, () => {
} );
test.describe( `${ blockData.name } Block - with All products Block`, () => {
- test.beforeEach( async ( { admin, page, editor } ) => {
- await admin.createNewPost();
- await editor.insertBlock( { name: 'woocommerce/all-products' } );
- await editor.insertBlock( {
- name: 'woocommerce/filter-wrapper',
- attributes: {
- filterType: 'price-filter',
- heading: 'Filter By Price',
- },
- } );
-
- const postId = await editor.publishPost();
- await page.goto( `/?p=${ postId }` );
+ test.beforeEach( async ( { page, createPost } ) => {
+ const post = await createPost( 'price-filter-with-all-products' );
+ await page.goto( post.link );
await page
.waitForResponse(
@@ -200,8 +135,8 @@ test.describe( `${ blockData.name } Block - with All products Block`, () => {
);
await expect( productTitles.first() ).toBeVisible();
- // See the note on the other baselines: more than one product, so the test
- // cannot pass against a shop page that was already filtered.
+ // More than one product, so the test cannot pass against a page that was
+ // already filtered.
expect(
( await productTitles.allTextContents() ).length
).toBeGreaterThan( 1 );
@@ -265,86 +200,26 @@ test.describe( `${ blockData.name } Block - with All products Block`, () => {
} );
} );
-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: 'price-filter',
- heading: 'Filter By Price',
- },
- } );
- await editor.saveSiteEditorEntities( {
- isOnlyCurrentEntityDirty: true,
- } );
- await page.goto( '/shop' );
- } );
-
- test( 'filters the classic product template by maximum price', async ( {
- page,
- frontendUtils,
- } ) => {
- const legacyTemplate = await frontendUtils.getBlockByName(
- 'woocommerce/legacy-template'
- );
- const productTitles = legacyTemplate.locator(
- '.woocommerce-loop-product__title'
- );
-
- await expect( productTitles.first() ).toBeVisible();
- // See the note on the other baselines: more than one product, so the test
- // cannot pass against a shop page that was already filtered.
- expect(
- ( await productTitles.allTextContents() ).length
- ).toBeGreaterThan( 1 );
-
- const maxPriceInput = page.getByRole( 'textbox', {
- name: 'Filter products by maximum price',
- } );
-
- await frontendUtils.selectTextInput( maxPriceInput );
- await maxPriceInput.fill( '$5' );
- await maxPriceInput.press( 'Tab' );
- await expect( page ).toHaveURL(
- new RegExp( blockData.urlSearchParamWhenFilterIsApplied )
- );
-
- await expect( productTitles ).toHaveText( [ 'Single' ] );
- } );
-} );
-
test.describe( `${ blockData.name } Block - with Product Collection`, () => {
test( 'filters Product Collection automatically and defers changes until Apply when configured', async ( {
page,
- admin,
- editor,
frontendUtils,
- 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 );
@@ -360,24 +235,11 @@ test.describe( `${ blockData.name } Block - with Product Collection`, () => {
);
await expect( productTitles ).toHaveText( [ 'Single' ] );
- await admin.visitSiteEditor( {
- postId: template.id,
- postType: template.type,
- canvas: 'edit',
- } );
-
- const priceFilterControls = await editor.getBlockByName(
- blockData.slug
+ const deferredPost = await createPost(
+ 'filters-with-product-collection',
+ { showFilterButton: true }
);
- await expect( priceFilterControls ).toBeVisible();
- await editor.selectBlocks( priceFilterControls );
- 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 deferredMaxPriceInput = page.getByRole( 'textbox', {
name: 'Filter products by maximum price',
@@ -389,9 +251,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();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/active-filter-frontend.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/active-filter-frontend.block_theme.spec.ts
index f6d280130fb..5b87718b237 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/active-filter-frontend.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/active-filter-frontend.block_theme.spec.ts
@@ -1,20 +1,23 @@
/**
* External dependencies
*/
-import { TemplateCompiler, test as base, expect } from '@woocommerce/e2e-utils';
+import { test, expect } from '@woocommerce/e2e-utils';
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, use ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_active-filters'
- );
- await use( compiler );
- },
-} );
+// The post's Product Collection has `queryId: 1`, so its filters read
+// `wcp-1-` prefixed URL params.
+const withFilters = ( link: string, params: Record< string, string > ) => {
+ const url = new URL( link );
+ for ( const [ key, value ] of Object.entries( params ) ) {
+ url.searchParams.set( `wcp-1-${ key }`, value );
+ }
+ return url.href;
+};
test.describe( 'woocommerce/product-filter-active - Frontend', () => {
- test.beforeEach( async ( { page, templateCompiler } ) => {
- await templateCompiler.compile();
+ let postLink: string;
+
+ test.beforeEach( async ( { page, createPost } ) => {
+ ( { link: postLink } = await createPost( 'active-filters' ) );
await page.addInitScript( () => {
// Mock the wc global variable.
@@ -33,7 +36,7 @@ test.describe( 'woocommerce/product-filter-active - Frontend', () => {
test( 'Without any filters selected, active block should not be rendered', async ( {
page,
} ) => {
- await page.goto( '/shop' );
+ await page.goto( postLink );
const chips = page.locator(
'.wp-block-woocommerce-product-filter-active'
@@ -45,7 +48,7 @@ test.describe( 'woocommerce/product-filter-active - Frontend', () => {
test( 'With rating filters applied it shows the correct active filters', async ( {
page,
} ) => {
- await page.goto( `${ '/shop' }?rating_filter=1,2,5` );
+ await page.goto( withFilters( postLink, { rating_filter: '1,2,5' } ) );
await expect(
page.getByText( 'Rating: Rated 1 out of 5' ).first()
@@ -62,7 +65,9 @@ test.describe( 'woocommerce/product-filter-active - Frontend', () => {
page,
} ) => {
await page.goto(
- `${ '/shop' }?filter_stock_status=instock,onbackorder`
+ withFilters( postLink, {
+ filter_stock_status: 'instock,onbackorder',
+ } )
);
await expect(
@@ -77,7 +82,10 @@ test.describe( 'woocommerce/product-filter-active - Frontend', () => {
page,
} ) => {
await page.goto(
- `${ '/shop' }?filter_color=blue,gray&query_type_color=or`
+ withFilters( postLink, {
+ filter_color: 'blue,gray',
+ query_type_color: 'or',
+ } )
);
await expect( page.getByText( 'Color: Blue' ).first() ).toBeVisible();
@@ -87,7 +95,9 @@ test.describe( 'woocommerce/product-filter-active - Frontend', () => {
test( 'With price filters applied it shows the correct active filters', async ( {
page,
} ) => {
- await page.goto( `${ '/shop' }?min_price=17&max_price=71` );
+ await page.goto(
+ withFilters( postLink, { min_price: '17', max_price: '71' } )
+ );
await expect(
page.getByText( 'Price: $17 - $71' ).first()
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/attribute-filter-frontend.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/attribute-filter-frontend.block_theme.spec.ts
index 0e4c08fa996..80816bce125 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/attribute-filter-frontend.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/attribute-filter-frontend.block_theme.spec.ts
@@ -1,40 +1,30 @@
/**
* External dependencies
*/
-import {
- TemplateCompiler,
- test as base,
- expect,
- getProductAttributeIds,
-} from '@woocommerce/e2e-utils';
+import { test, expect, getProductAttributeIds } from '@woocommerce/e2e-utils';
const GRAY_PRODUCT_TITLES = [ 'T-Shirt', 'T-Shirt with Logo' ];
+// Tests that depend on option order use `name-asc`: the default `count-desc`
+// sorts by site-wide term counts, which hidden products from other workers change.
const COLOR_ATTRIBUTES_WITH_COUNTS = [
'Blue (4)',
- 'Red (4)',
- 'Green (3)',
'Gray (2)',
+ 'Green (3)',
+ 'Red (4)',
'Yellow (1)',
];
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, use ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_attribute-filter'
- );
- await use( compiler );
- },
-} );
-
test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
test.describe( 'With default display style', () => {
- test.beforeEach( async ( { templateCompiler, page } ) => {
+ let postLink: string;
+
+ test.beforeEach( async ( { createPost, page } ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ ( { link: postLink } = await createPost( 'attribute-filter', {
attributes: {
attributeId: colorAttributeId,
},
- } );
+ } ) );
await page.addInitScript( () => {
// Mock the wc global variable.
@@ -53,7 +43,7 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
test( 'selects and clears an attribute while keeping URL, products, and controls in sync', async ( {
page,
} ) => {
- await page.goto( '/shop' );
+ await page.goto( postLink );
const grayCheckbox = page.getByRole( 'checkbox', { name: 'Gray' } );
const clearButton = page.getByRole( 'button', {
@@ -73,8 +63,10 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
.poll( () => {
const params = new URL( page.url() ).searchParams;
return {
- filterColor: params.get( 'filter_color' ),
- queryTypeColor: params.get( 'query_type_color' ),
+ filterColor: params.get( 'wcp-1-filter_color' ),
+ queryTypeColor: params.get(
+ 'wcp-1-query_type_color'
+ ),
};
} )
.toEqual( {
@@ -116,11 +108,11 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test( 'Dropdown updates results on each checkbox selection and supports keyboard dismissal', async ( {
- templateCompiler,
+ createPost,
page,
} ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ const { link } = await createPost( 'attribute-filter', {
dropdown: true,
attributes: {
attributeId: colorAttributeId,
@@ -129,7 +121,7 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
sortOrder: 'name-asc',
},
} );
- await page.goto( '/shop' );
+ await page.goto( link );
const trigger = page.getByRole( 'button', {
name: 'Color: Choose options',
} );
@@ -173,8 +165,9 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
);
await page.waitForURL(
( url ) =>
- url.searchParams.get( 'filter_color' )?.includes( 'gray' ) ??
- false
+ url.searchParams
+ .get( 'wcp-1-filter_color' )
+ ?.includes( 'gray' ) ?? false
);
await page.reload();
await expect( selectedTrigger ).toBeVisible();
@@ -193,19 +186,20 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test( 'Escape dismisses the Dropdown before the filter overlay', async ( {
- templateCompiler,
+ createPost,
page,
} ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ const { link } = await createPost( 'attribute-filter', {
dropdown: true,
attributes: {
attributeId: colorAttributeId,
displayStyle: 'woocommerce/dropdown',
+ sortOrder: 'name-asc',
},
} );
await page.setViewportSize( { width: 390, height: 844 } );
- await page.goto( '/shop' );
+ await page.goto( link );
await page.getByRole( 'button', { name: 'Filter products' } ).click();
const overlay = page.getByRole( 'dialog', { name: 'Product Filters' } );
const trigger = overlay.getByRole( 'button', {
@@ -237,21 +231,22 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test( 'Dropdown summary retains active selections hidden by another filter', async ( {
- templateCompiler,
+ createPost,
page,
browser,
} ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ const { link } = await createPost( 'attribute-filter', {
dropdown: true,
taxonomy: true,
attributes: {
attributeId: colorAttributeId,
displayStyle: 'woocommerce/dropdown',
hideEmpty: true,
+ sortOrder: 'name-asc',
},
} );
- await page.goto( '/shop' );
+ await page.goto( link );
const color = page.locator(
'.wp-block-woocommerce-product-filter-attribute'
);
@@ -289,8 +284,9 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
await expect( trigger ).toHaveText( 'Color: Blue, Green +1' );
await page.waitForURL(
( url ) =>
- url.searchParams.get( 'filter_color' )?.includes( 'green' ) ??
- false
+ url.searchParams
+ .get( 'wcp-1-filter_color' )
+ ?.includes( 'green' ) ?? false
);
const noScript = await browser.newContext( {
javaScriptEnabled: false,
@@ -310,7 +306,7 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test( 'Dropdown defaults allow theme CSS overrides in either load order', async ( {
- templateCompiler,
+ createPost,
page,
} ) => {
const { colorAttributeId } = await getProductAttributeIds();
@@ -318,8 +314,11 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
attributeId: colorAttributeId,
displayStyle: 'woocommerce/dropdown',
};
- await templateCompiler.compile( { dropdown: true, attributes } );
- await page.goto( '/shop' );
+ const { link } = await createPost( 'attribute-filter', {
+ dropdown: true,
+ attributes,
+ } );
+ await page.goto( link );
const trigger = page.getByRole( 'button', {
name: 'Color: Choose options',
} );
@@ -348,11 +347,11 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test( 'Dropdown Core colors and borders override theme CSS and preserve separate corners', async ( {
- templateCompiler,
+ createPost,
page,
} ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ const { link } = await createPost( 'attribute-filter', {
dropdown: true,
attributes: {
attributeId: colorAttributeId,
@@ -375,7 +374,7 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
},
},
} );
- await page.goto( '/shop' );
+ await page.goto( link );
const trigger = page.getByRole( 'button', {
name: /^Color:/,
} );
@@ -449,20 +448,23 @@ test.describe( 'woocommerce/product-filter-attribute - Frontend', () => {
} );
test.describe( 'With show counts enabled', () => {
- test.beforeEach( async ( { templateCompiler } ) => {
+ let postLink: string;
+
+ test.beforeEach( async ( { createPost } ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ ( { link: postLink } = await createPost( 'attribute-filter', {
attributes: {
attributeId: colorAttributeId,
showCounts: true,
+ sortOrder: 'name-asc',
},
- } );
+ } ) );
} );
test( 'renders current product counts for every attribute', async ( {
page,
} ) => {
- await page.goto( '/shop' );
+ await page.goto( postLink );
const listItems = page
.getByRole( 'heading', {
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-frontend.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-frontend.block_theme.spec.ts
index ee9da66e587..49c2a91ff47 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-frontend.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-frontend.block_theme.spec.ts
@@ -1,31 +1,19 @@
/**
* External dependencies
*/
-import {
- TemplateCompiler,
- getProductAttributeIds,
- test as base,
- expect,
-} from '@woocommerce/e2e-utils';
-
-const test = base.extend< { templateCompiler: TemplateCompiler } >( {
- templateCompiler: async ( { requestUtils }, provideTemplate ) => {
- const compiler = await requestUtils.createTemplateFromFile(
- 'archive-product_attribute-filter'
- );
- await provideTemplate( compiler );
- },
-} );
+import { getProductAttributeIds, test, expect } from '@woocommerce/e2e-utils';
test.describe( 'woocommerce/product-filters - Frontend', () => {
test.describe( 'Overlay', () => {
- test.beforeEach( async ( { templateCompiler, page } ) => {
+ let postLink: string;
+
+ test.beforeEach( async ( { createPost, page } ) => {
const { colorAttributeId } = await getProductAttributeIds();
- await templateCompiler.compile( {
+ ( { link: postLink } = await createPost( 'attribute-filter', {
attributes: {
attributeId: colorAttributeId,
},
- } );
+ } ) );
await page.addInitScript( () => {
// Mock the wc global variable.
@@ -45,7 +33,7 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
page,
} ) => {
await page.setViewportSize( { width: 400, height: 600 } );
- await page.goto( '/shop' );
+ await page.goto( postLink );
const openOverlayButton = page.getByRole( 'button', {
name: 'Filter products',
@@ -137,7 +125,7 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
test.skip( 'filter is working inside overlay', async ( { page } ) => {
await page.setViewportSize( { width: 400, height: 600 } );
- await page.goto( '/shop' );
+ await page.goto( postLink );
await page
.getByRole( 'button', {
@@ -154,7 +142,7 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
.click();
// wait for navigation
- await page.waitForURL( /.*filter_color=gray.*/ );
+ await page.waitForURL( /.*wcp-1-filter_color=gray.*/ );
const products = page.locator( '.wc-block-product' );
@@ -165,7 +153,7 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
test.describe( 'Multiple instances', () => {
test( 'syncs active filters between Product Filters blocks', async ( {
page,
- requestUtils,
+ createPost,
} ) => {
await page.addInitScript( () => {
// Mock the wc global variable.
@@ -180,18 +168,14 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
}
} );
- const templateCompiler = await requestUtils.createTemplateFromFile(
- 'archive-product_multiple-product-filters'
- );
const { colorAttributeId } = await getProductAttributeIds();
-
- await templateCompiler.compile( {
+ const { link } = await createPost( 'multiple-product-filters', {
attributes: {
attributeId: colorAttributeId,
},
} );
- await page.goto( '/shop' );
+ await page.goto( link );
const productFilters = page.locator(
'.wp-block-woocommerce-product-filters'
@@ -212,7 +196,8 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
await grayCheckbox.click();
await page.waitForURL(
- ( url ) => url.searchParams.get( 'filter_color' ) === 'gray'
+ ( url ) =>
+ url.searchParams.get( 'wcp-1-filter_color' ) === 'gray'
);
await expect( grayActiveFilter ).toBeVisible();
@@ -224,7 +209,7 @@ test.describe( 'woocommerce/product-filters - Frontend', () => {
} )
.click();
await page.waitForURL(
- ( url ) => ! url.searchParams.has( 'filter_color' )
+ ( url ) => ! url.searchParams.has( 'wcp-1-filter_color' )
);
await expect( grayActiveFilter ).toBeHidden();
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-shop.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-shop.block_theme.spec.ts
new file mode 100644
index 00000000000..ff7e6491d96
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/product-filters/product-filters-shop.block_theme.spec.ts
@@ -0,0 +1,74 @@
+/**
+ * External dependencies
+ */
+import {
+ TemplateCompiler,
+ test as base,
+ expect,
+ getProductAttributeIds,
+} from '@woocommerce/e2e-utils';
+
+const GRAY_PRODUCT_TITLES = [ 'T-Shirt', 'T-Shirt with Logo' ];
+// Default `count-desc` order. Only serial runs keep the term counts stable.
+const COLOR_ATTRIBUTES_WITH_COUNTS = [
+ 'Blue (4)',
+ 'Red (4)',
+ 'Green (3)',
+ 'Gray (2)',
+ 'Yellow (1)',
+];
+
+// Filters outside an inherit Product Collection use the main query and plain params.
+const test = base.extend< { templateCompiler: TemplateCompiler } >( {
+ templateCompiler: async ( { requestUtils }, use ) => {
+ const compiler = await requestUtils.createTemplateFromFile(
+ 'archive-product_attribute-filter'
+ );
+ await use( compiler );
+ },
+} );
+
+test( 'Product Filters filter the shop page and clear the filters', async ( {
+ templateCompiler,
+ page,
+} ) => {
+ const { colorAttributeId } = await getProductAttributeIds();
+ await templateCompiler.compile( {
+ attributes: { attributeId: colorAttributeId, showCounts: true },
+ } );
+
+ await page.goto( '/shop' );
+
+ const grayCheckbox = page.getByRole( 'checkbox', { name: 'Gray' } );
+ const clearButton = page.getByRole( 'button', { name: 'Clear filters' } );
+ const attributeLabels = page
+ .locator( '.wp-block-woocommerce-product-filter-attribute' )
+ .locator( 'label' );
+ const productTitles = page.locator(
+ '.wp-block-woocommerce-product-template .wp-block-post-title'
+ );
+ const expectFilterParams = ( expected: string | null ) =>
+ expect
+ .poll( () => {
+ const params = new URL( page.url() ).searchParams;
+ return [
+ params.get( 'filter_color' ),
+ params.get( 'query_type_color' ),
+ ];
+ } )
+ .toEqual( [ expected, expected ? 'or' : null ] );
+
+ await expect( attributeLabels ).toHaveText( COLOR_ATTRIBUTES_WITH_COUNTS );
+ const initialProductTitles = await productTitles.allInnerTexts();
+
+ await grayCheckbox.click();
+ await expectFilterParams( 'gray' );
+ await expect( productTitles ).toHaveText( GRAY_PRODUCT_TITLES );
+ // The counts of an OR filter leave out its own selection.
+ await expect( attributeLabels ).toHaveText( COLOR_ATTRIBUTES_WITH_COUNTS );
+
+ await clearButton.click();
+ await expectFilterParams( null );
+ await expect( productTitles ).toHaveText( initialProductTitles );
+ await expect( grayCheckbox ).not.toBeChecked();
+} );
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/request-utils/posts.ts b/plugins/woocommerce/tests/e2e/utils/blocks/request-utils/posts.ts
index b375cb7df41..ec4cc5c6157 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/request-utils/posts.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/request-utils/posts.ts
@@ -2,6 +2,7 @@
* External dependencies
*/
import path from 'path';
+import { randomUUID } from 'crypto';
import { readFile } from 'fs/promises';
import Handlebars from 'handlebars';
import { Post } from '@wordpress/e2e-test-utils-playwright/build-types/request-utils/posts';
@@ -60,6 +61,10 @@ export async function createPostFromFile( this: RequestUtils, name: string ) {
date_gmt: new Date().toISOString(),
content,
title: name,
+ // WordPress does not lock the slug check, so posts that parallel
+ // workers publish at the same time can share a slug, and
+ // `post.link` then opens the wrong post.
+ slug: `${ name }-${ randomUUID() }`,
},
} );
},
diff --git a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
index 9215a48578f..2422b587c14 100644
--- a/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
+++ b/plugins/woocommerce/tests/e2e/utils/blocks/test.ts
@@ -15,6 +15,7 @@ import {
MiniCartUtils,
PageUtils,
PerformanceUtils,
+ PostCompiler,
RequestUtils,
ShippingUtils,
WPTemplate,
@@ -142,6 +143,10 @@ const test = base.extend<
createHiddenProduct: (
data: Record< string, unknown >
) => Promise< { id: number } >;
+ createPost: (
+ name: string,
+ data?: unknown
+ ) => ReturnType< PostCompiler[ 'compile' ] >;
},
{
requestUtils: RequestUtils;
@@ -421,6 +426,22 @@ const test = base.extend<
}
}
},
+ // Publishes a post from `content-templates/blocks/post_<name>.handlebars`
+ // and deletes it after the test.
+ createPost: async ( { requestUtils, cleanup }, use ) => {
+ await use( async ( name, data ) => {
+ const compiler = await requestUtils.createPostFromFile( name );
+ const post = await compiler.compile( data );
+ cleanup( () =>
+ requestUtils.rest( {
+ method: 'DELETE',
+ path: `/wp/v2/posts/${ post.id }`,
+ params: { force: true },
+ } )
+ );
+ return post;
+ } );
+ },
requestUtils: [
async ( {}, use, workerInfo ) => {
const requestUtils = await RequestUtils.setup( {