Commit da99e106039 for woocommerce
commit da99e10603962a54b3105b37260f113b2613762f
Author: Adrian Moldovan <3854374+adimoldovan@users.noreply.github.com>
Date: Tue Dec 1 15:53:47 2026 +0200
Move 20 parallel-safe tests out of four serial Blocks e2e specs (#71617)
Tests that change no shared state move to new spec files, which run in
blocks-parallel. The rest stay in blocks-serial, with updated reasons.
diff --git a/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-split-serial-specs b/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-split-serial-specs
new file mode 100644
index 00000000000..2f517fce00b
--- /dev/null
+++ b/plugins/woocommerce/changelog/testops-324-blocks-e2e-parallel-split-serial-specs
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Move 20 Blocks e2e tests from four serial specs to the parallel pool; no production change.
+
diff --git a/plugins/woocommerce/tests/e2e/playwright.config.ts b/plugins/woocommerce/tests/e2e/playwright.config.ts
index 12e541fbe3d..ca164657f4d 100644
--- a/plugins/woocommerce/tests/e2e/playwright.config.ts
+++ b/plugins/woocommerce/tests/e2e/playwright.config.ts
@@ -235,8 +235,7 @@ const blocksSerialSpecs = [
// 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.
+ // Makes Beanie sold individually 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
@@ -245,9 +244,8 @@ const blocksSerialSpecs = [
// 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`.
+ // Saves the header template part 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.
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options-isolated.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options-isolated.block_theme.spec.ts
new file mode 100644
index 00000000000..02b6bdcd42c
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options-isolated.block_theme.spec.ts
@@ -0,0 +1,221 @@
+/**
+ * External dependencies
+ */
+import { test as base, expect, guestFile } from '@woocommerce/e2e-utils';
+import type { Page } from '@playwright/test';
+
+/**
+ * Internal dependencies
+ */
+import AddToCartWithOptionsPage from './add-to-cart-with-options.page';
+
+/**
+ * Add to Cart + Options tests that change no shared state, so they run in
+ * `blocks-parallel`. The other tests are in
+ * `add-to-cart-with-options.block_theme.spec.ts`.
+ */
+
+const test = base.extend< {
+ pageObject: AddToCartWithOptionsPage;
+ guestPage: Page;
+} >( {
+ pageObject: async ( { page, admin, editor }, use ) => {
+ const pageObject = new AddToCartWithOptionsPage( {
+ page,
+ admin,
+ editor,
+ } );
+ await use( pageObject );
+ },
+ // A guest cart, because all workers share the admin cart.
+ guestPage: async ( { browser }, use ) => {
+ const context = await browser.newContext( {
+ storageState: guestFile,
+ } );
+ await use( await context.newPage() );
+ await context.close();
+ },
+} );
+
+test.describe( 'Add to Cart + Options Block', () => {
+ test.describe( 'as a guest', () => {
+ test.use( { storageState: guestFile } );
+
+ test( 'handles rapid add-to-cart clicks correctly', async ( {
+ page,
+ frontendUtils,
+ miniCartUtils,
+ } ) => {
+ // Go to shop page where iAPI Product Button is used in product listings.
+ await frontendUtils.goToShop();
+
+ // Get the first Add to cart button on the page (Album product).
+ const addToCartButton = page.locator( 'text=Add to cart' ).first();
+ await expect( addToCartButton ).toBeVisible();
+
+ // Click the button 3 times rapidly without waiting between clicks.
+ // This tests that the batching correctly handles optimistic updates
+ // and sends the right quantity to the server (delta, not target).
+ // Without the fix, this would result in 1+2+3=6 items.
+ //
+ // Set up waitForResponse BEFORE the clicks to avoid a race condition.
+ // If we wait after clicks, fast networks may complete the batch
+ // before waitForResponse starts listening, causing the test to hang.
+ const batchPromise = page.waitForResponse(
+ '**/wc/store/v1/batch**'
+ );
+ await addToCartButton.click();
+ await addToCartButton.click();
+ await addToCartButton.click();
+
+ // Wait for all batch requests to complete.
+ await batchPromise;
+
+ // Open mini cart and verify the count.
+ await miniCartUtils.openMiniCart();
+
+ // Check the mini cart shows exactly 3 items.
+ // If the bug were present, it would show 6 (1+2+3).
+ const quantityInput = page.getByLabel(
+ 'Quantity of Album in your cart.'
+ );
+ const quantity = await quantityInput.inputValue();
+ const quantityNum = parseInt( quantity, 10 );
+
+ // The quantity should be 3, NOT 6 (which would indicate the bug).
+ // We use a soft assertion to account for any timing edge cases.
+ expect( quantityNum ).toBeLessThanOrEqual( 3 );
+ expect( quantityNum ).toBeGreaterThanOrEqual( 2 );
+
+ // Most importantly, verify it's NOT the buggy value of 6.
+ expect( quantityNum ).not.toBe( 6 );
+ } );
+ } );
+
+ test( 'allows adding simple products to cart when inside the Product block', async ( {
+ page,
+ guestPage,
+ pageObject,
+ } ) => {
+ await pageObject.createPostWithProductBlock( 't-shirt' );
+ await guestPage.goto( page.url() );
+
+ const addToCartButton = guestPage.getByRole( 'button', {
+ name: 'Add to cart',
+ } );
+
+ await addToCartButton.click();
+
+ await expect( addToCartButton ).toHaveText( '1 in cart' );
+ } );
+
+ test( 'allows adding variable products to cart when inside the Product block', async ( {
+ page,
+ guestPage,
+ pageObject,
+ } ) => {
+ await pageObject.createPostWithProductBlock( 'hoodie' );
+ await guestPage.goto( page.url() );
+
+ const addToCartBlock = guestPage.locator(
+ '.wp-block-add-to-cart-with-options'
+ );
+ const colorBlueOption = addToCartBlock
+ .getByRole( 'radiogroup', { name: 'Color' } )
+ .getByRole( 'radio', { name: 'Blue', exact: true } );
+ const logoYesOption = addToCartBlock
+ .getByRole( 'radiogroup', { name: 'Logo' } )
+ .getByRole( 'radio', { name: 'Yes', exact: true } );
+
+ await colorBlueOption.click();
+ await logoYesOption.click();
+
+ const addToCartButton = guestPage.getByRole( 'button', {
+ name: 'Add to cart',
+ exact: true,
+ } );
+
+ await addToCartButton.click();
+
+ await expect(
+ guestPage.getByRole( 'button', { name: '1 in cart', exact: true } )
+ ).toBeVisible();
+ } );
+
+ test( 'allows adding variations to cart when inside the Product block', async ( {
+ page,
+ guestPage,
+ pageObject,
+ } ) => {
+ await pageObject.createPostWithProductBlock(
+ 'hoodie',
+ 'hoodie-blue-yes'
+ );
+ await guestPage.goto( page.url() );
+
+ const addToCartButton = guestPage.getByRole( 'button', {
+ name: 'Add to cart',
+ } );
+
+ await addToCartButton.click();
+
+ await expect(
+ guestPage.getByRole( 'button', { name: '1 in cart', exact: true } )
+ ).toBeVisible();
+ } );
+
+ test( 'allows adding grouped products to cart when inside the Product block', async ( {
+ page,
+ guestPage,
+ pageObject,
+ } ) => {
+ await pageObject.createPostWithProductBlock( 'logo-collection' );
+ await guestPage.goto( page.url() );
+
+ const increaseQuantityButton = guestPage.getByLabel(
+ 'Increase quantity of T-Shirt'
+ );
+ await increaseQuantityButton.click();
+
+ const addToCartButton = guestPage.getByRole( 'button', {
+ name: 'Add to cart',
+ exact: true,
+ } );
+
+ await addToCartButton.click();
+
+ await expect(
+ guestPage.getByRole( 'button', {
+ name: 'Added to cart',
+ exact: true,
+ } )
+ ).toBeVisible();
+ } );
+
+ test( 'allows updating the Product Image Gallery block to the Product Gallery block', async ( {
+ page,
+ editor,
+ pageObject,
+ } ) => {
+ await pageObject.updateSingleProductTemplate();
+
+ const addToCartFormBlock = await editor.getBlockByName(
+ pageObject.BLOCK_SLUG
+ );
+ await editor.selectBlocks( addToCartFormBlock );
+
+ await expect(
+ editor.canvas.getByLabel( 'Block: Product Gallery' )
+ ).toBeHidden();
+
+ await page
+ .getByRole( 'button', {
+ name: 'Upgrade to the Product Gallery block',
+ } )
+ .click();
+
+ await expect(
+ editor.canvas.getByLabel( 'Block: Product Gallery' )
+ ).toBeVisible();
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
index 1171c8975c1..b971ec9ce44 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/add-to-cart-with-options/add-to-cart-with-options.block_theme.spec.ts
@@ -131,54 +131,6 @@ test.describe( 'Add to Cart + Options Block', () => {
await expect( addToCartButton ).toHaveText( '4 in cart' );
} );
- test( 'handles rapid add-to-cart clicks correctly', async ( {
- page,
- frontendUtils,
- miniCartUtils,
- } ) => {
- // Go to shop page where iAPI Product Button is used in product listings.
- await frontendUtils.goToShop();
-
- // Get the first Add to cart button on the page (Album product).
- const addToCartButton = page.locator( 'text=Add to cart' ).first();
- await expect( addToCartButton ).toBeVisible();
-
- // Click the button 3 times rapidly without waiting between clicks.
- // This tests that the batching correctly handles optimistic updates
- // and sends the right quantity to the server (delta, not target).
- // Without the fix, this would result in 1+2+3=6 items.
- //
- // Set up waitForResponse BEFORE the clicks to avoid a race condition.
- // If we wait after clicks, fast networks may complete the batch
- // before waitForResponse starts listening, causing the test to hang.
- const batchPromise = page.waitForResponse( '**/wc/store/v1/batch**' );
- await addToCartButton.click();
- await addToCartButton.click();
- await addToCartButton.click();
-
- // Wait for all batch requests to complete.
- await batchPromise;
-
- // Open mini cart and verify the count.
- await miniCartUtils.openMiniCart();
-
- // Check the mini cart shows exactly 3 items.
- // If the bug were present, it would show 6 (1+2+3).
- const quantityInput = page.getByLabel(
- 'Quantity of Album in your cart.'
- );
- const quantity = await quantityInput.inputValue();
- const quantityNum = parseInt( quantity, 10 );
-
- // The quantity should be 3, NOT 6 (which would indicate the bug).
- // We use a soft assertion to account for any timing edge cases.
- expect( quantityNum ).toBeLessThanOrEqual( 3 );
- expect( quantityNum ).toBeGreaterThanOrEqual( 2 );
-
- // Most importantly, verify it's NOT the buggy value of 6.
- expect( quantityNum ).not.toBe( 6 );
- } );
-
test( 'allows adding variable products to cart', async ( {
page,
pageObject,
@@ -1302,122 +1254,6 @@ test.describe( 'Add to Cart + Options Block', () => {
).toHaveValue( '1' );
} );
- test( 'allows adding simple products to cart when inside the Product block', async ( {
- page,
- pageObject,
- } ) => {
- await pageObject.createPostWithProductBlock( 't-shirt' );
-
- const addToCartButton = page.getByRole( 'button', {
- name: 'Add to cart',
- } );
-
- await addToCartButton.click();
-
- await expect( addToCartButton ).toHaveText( '1 in cart' );
- } );
-
- test( 'allows adding variable products to cart when inside the Product block', async ( {
- page,
- pageObject,
- } ) => {
- await pageObject.createPostWithProductBlock( 'hoodie' );
-
- const addToCartBlock = page.locator(
- '.wp-block-add-to-cart-with-options'
- );
- const colorBlueOption = addToCartBlock
- .getByRole( 'radiogroup', { name: 'Color' } )
- .getByRole( 'radio', { name: 'Blue', exact: true } );
- const logoYesOption = addToCartBlock
- .getByRole( 'radiogroup', { name: 'Logo' } )
- .getByRole( 'radio', { name: 'Yes', exact: true } );
-
- await colorBlueOption.click();
- await logoYesOption.click();
-
- const addToCartButton = page.getByRole( 'button', {
- name: 'Add to cart',
- exact: true,
- } );
-
- await addToCartButton.click();
-
- await expect(
- page.getByRole( 'button', { name: '1 in cart', exact: true } )
- ).toBeVisible();
- } );
-
- test( 'allows adding variations to cart when inside the Product block', async ( {
- page,
- pageObject,
- } ) => {
- await pageObject.createPostWithProductBlock(
- 'hoodie',
- 'hoodie-blue-yes'
- );
-
- const addToCartButton = page.getByRole( 'button', {
- name: 'Add to cart',
- } );
-
- await addToCartButton.click();
-
- await expect(
- page.getByRole( 'button', { name: '1 in cart', exact: true } )
- ).toBeVisible();
- } );
-
- test( 'allows adding grouped products to cart when inside the Product block', async ( {
- page,
- pageObject,
- } ) => {
- await pageObject.createPostWithProductBlock( 'logo-collection' );
-
- const increaseQuantityButton = page.getByLabel(
- 'Increase quantity of T-Shirt'
- );
- await increaseQuantityButton.click();
-
- const addToCartButton = page.getByRole( 'button', {
- name: 'Add to cart',
- exact: true,
- } );
-
- await addToCartButton.click();
-
- await expect(
- page.getByRole( 'button', { name: 'Added to cart', exact: true } )
- ).toBeVisible();
- } );
-
- test( 'allows updating the Product Image Gallery block to the Product Gallery block', async ( {
- page,
- editor,
- pageObject,
- } ) => {
- await pageObject.updateSingleProductTemplate();
-
- const addToCartFormBlock = await editor.getBlockByName(
- pageObject.BLOCK_SLUG
- );
- await editor.selectBlocks( addToCartFormBlock );
-
- await expect(
- editor.canvas.getByLabel( 'Block: Product Gallery' )
- ).toBeHidden();
-
- await page
- .getByRole( 'button', {
- name: 'Upgrade to the Product Gallery block',
- } )
- .click();
-
- await expect(
- editor.canvas.getByLabel( 'Block: Product Gallery' )
- ).toBeVisible();
- } );
-
test.describe( 'autoselect behavior', () => {
const productSlug = 'autoselect-t-shirt';
const productName = 'Autoselect T-shirt';
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity-guest.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity-guest.block_theme.spec.ts
new file mode 100644
index 00000000000..25fb98f615e
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity-guest.block_theme.spec.ts
@@ -0,0 +1,228 @@
+/**
+ * External dependencies
+ */
+import { test, expect, guestFile } from '@woocommerce/e2e-utils';
+
+/**
+ * Internal dependencies
+ */
+import { PRODUCT_X, readCartLineQuantities, seedMetaLine } from './utils';
+
+/**
+ * E2E flows for "Block add-to-cart action respects cart-line identity".
+ *
+ * Background: on a keyless add (every add-to-cart consumer), the iAPI cart
+ * store now always issues `add-item` with the requested quantity delta and lets
+ * WooCommerce core's `generate_cart_id` decide match-or-create, instead of
+ * matching a line by product id on the client and converting the add into an
+ * `update-item`. The flows below exercise that behaviour against a real cart
+ * through the ProductButton and the Mini-Cart stepper. The flows that change
+ * shared state are in `cart-line-identity.block_theme.spec.ts`.
+ *
+ * A "meta line" — a stand-in for a bundle child / booking / add-on / recipient
+ * line — is simulated by the cart-line-identity helper plugin
+ * (`woocommerce-blocks-test-cart-line-identity`), which attaches a unique
+ * `cart_item_data` marker to a flagged add so core mints a distinct cart line
+ * for the same product id. See `./utils.ts`.
+ *
+ * Notice-showing consumers (saved-for-later, wishlist) are gated behind the
+ * `product_wishlist` feature flag and are not registered in this e2e
+ * environment, so their blocks cannot be placed on a page here. The notice
+ * outcomes those consumers depend on — no spurious "quantity changed" info
+ * notice on a meta-only add and entry preservation on a genuine rejection —
+ * are asserted authoritatively at the store/consumer unit level (the cart
+ * store and saved-for-later / wishlist frontend unit tests). The cart-outcome
+ * substrate those consumers rely on is still asserted end-to-end below: a
+ * meta-only keyless add creates a new standalone line with no error notice.
+ */
+
+test.describe( 'Add to cart respects cart-line identity', () => {
+ // Run as a guest so every test gets a brand-new browser context with no
+ // session cookie, i.e. an isolated empty cart — cart-line-identity
+ // outcomes are sensitive to leftover cart state, so no cross-test
+ // cleanup is needed. The same guest session cookie is shared, within a
+ // test, between the meta-line seeding navigation and the Store API add
+ // path.
+ test.use( { storageState: guestFile } );
+
+ test.describe( 'with a meta-differentiated line present', () => {
+ test( 'Meta line present, no standalone — add creates a new line, meta line unchanged, no error notice', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ // Seed: product X is in the cart only as a single meta line (qty 1).
+ await seedMetaLine( page, PRODUCT_X.id );
+
+ await frontendUtils.goToShop();
+
+ // Keyless add of X through the ProductButton.
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ // No error notice (in particular no "cannot update bundle
+ // item" / store error) appears on the archive.
+ await expect(
+ page.locator( '.wc-block-components-notice-banner.is-error' )
+ ).toHaveCount( 0 );
+
+ // Persisted cart: exactly two lines for X — the meta line still at
+ // quantity 1 plus a new standalone line at quantity 1.
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1, 1 ] );
+ } );
+
+ test( 'Both a standalone and a meta line — only the standalone increments', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ // Seed: product X as a meta line (qty 1)...
+ await seedMetaLine( page, PRODUCT_X.id );
+
+ // ...and as a standalone line (qty 1) via a plain ProductButton add.
+ await frontendUtils.goToShop();
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1, 1 ] );
+
+ // Add X again through the ProductButton.
+ await frontendUtils.goToShop();
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ await expect(
+ page.locator( '.wc-block-components-notice-banner.is-error' )
+ ).toHaveCount( 0 );
+
+ // The standalone line becomes quantity 2; the meta line stays at 1.
+ // No new line is created (still two lines total).
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1, 2 ] );
+ } );
+
+ test( 'Saved-for-later / wishlist meta-only add (cart outcome) — keyless add creates a new standalone line with no error notice', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ // Saved-for-later "Move to cart" and wishlist "Add to cart" call the
+ // same keyless `addCartItem` path this exercises (quantityToAdd, no
+ // key). Here we assert the cart outcome those consumers depend on —
+ // a new standalone line beside the untouched meta line, no error
+ // notice. The consumer-specific guarantees (list entry removed, no
+ // spurious "quantity changed" info notice shown to the shopper) are
+ // covered authoritatively by the store/consumer unit tests,
+ // because the saved-for-later and wishlist blocks are gated behind
+ // the `product_wishlist` feature flag and are not registered in
+ // this e2e environment.
+ await seedMetaLine( page, PRODUCT_X.id );
+
+ await frontendUtils.goToShop();
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ await expect(
+ page.locator( '.wc-block-components-notice-banner.is-error' )
+ ).toHaveCount( 0 );
+
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1, 1 ] );
+ } );
+ } );
+
+ test.describe( 'without a meta-differentiated line', () => {
+ test( 'Existing standalone line — add increments it', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ await frontendUtils.goToShop();
+
+ // First add creates the standalone line at quantity 1.
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ // Second add increments the same line.
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ // One line, quantity 2 — not two lines.
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 2 ] );
+ } );
+
+ test( 'Not in cart — add creates a new line, no error notice', async ( {
+ page,
+ frontendUtils,
+ } ) => {
+ await frontendUtils.goToShop();
+
+ await frontendUtils.addToCart( PRODUCT_X.name );
+
+ await expect(
+ page.locator( '.wc-block-components-notice-banner.is-error' )
+ ).toHaveCount( 0 );
+
+ // A single new standalone line at quantity 1.
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1 ] );
+ } );
+ } );
+
+ test.describe( 'known-line quantity change (Mini-Cart stepper)', () => {
+ test( 'Stepper updates the exact line with no spurious notice and no extra line', async ( {
+ page,
+ frontendUtils,
+ miniCartUtils,
+ } ) => {
+ await frontendUtils.goToShop();
+ await frontendUtils.addToCart( PRODUCT_X.name );
+ await miniCartUtils.openMiniCart();
+
+ const quantity = page.getByLabel(
+ `Quantity of ${ PRODUCT_X.name } in your cart.`
+ );
+ await expect( quantity ).toHaveValue( '1' );
+
+ // Increment via the stepper (keyed update-item path).
+ const batchIncrease = page.waitForResponse(
+ '**/wp-json/wc/store/v1/batch**'
+ );
+ await page
+ .getByRole( 'button', {
+ name: `Increase quantity of ${ PRODUCT_X.name }`,
+ } )
+ .click();
+ await batchIncrease;
+ await expect( quantity ).toHaveValue( '2' );
+
+ // Decrement back.
+ const batchReduce = page.waitForResponse(
+ '**/wp-json/wc/store/v1/batch**'
+ );
+ await page
+ .getByRole( 'button', {
+ name: `Reduce quantity of ${ PRODUCT_X.name }`,
+ } )
+ .click();
+ await batchReduce;
+ await expect( quantity ).toHaveValue( '1' );
+
+ // No spurious notice from the stepper change itself.
+ await expect(
+ page.locator( '.wc-block-components-notice-banner' )
+ ).toHaveCount( 0 );
+
+ // No extra line was created: exactly one line for the product.
+ await frontendUtils.goToCart();
+ expect(
+ await readCartLineQuantities( page, PRODUCT_X.name )
+ ).toEqual( [ 1 ] );
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
index 670f9f5fcd6..eff97932819 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/cart-line-identity.block_theme.spec.ts
@@ -8,42 +8,16 @@ import { test as base, expect, guestFile, wpCLI } from '@woocommerce/e2e-utils';
*/
import AddToCartWithOptionsPage from '../add-to-cart-with-options/add-to-cart-with-options.page';
import {
- CART_LINE_IDENTITY_PLUGIN,
PRODUCT_X,
cartLineRows,
productButton,
readCartLineQuantities,
- seedMetaLine,
} from './utils';
/**
- * E2E flows for "Block add-to-cart action respects cart-line identity".
- *
- * Background: on a keyless add (every add-to-cart consumer), the iAPI cart
- * store now always issues `add-item` with the requested quantity delta and lets
- * WooCommerce core's `generate_cart_id` decide match-or-create, instead of
- * matching a line by product id on the client and converting the add into an
- * `update-item`. The flows below exercise that behaviour against a real cart
- * through the ProductButton, the Add to Cart with Options block, and the
- * Mini-Cart stepper.
- *
- * A "meta line" — a stand-in for a bundle child / booking / add-on / recipient
- * line — is simulated by the cart-line-identity helper plugin
- * (`woocommerce-blocks-test-cart-line-identity`), which attaches a unique
- * `cart_item_data` marker to a flagged add so core mints a distinct cart line
- * for the same product id. See `./utils.ts`.
- *
- * Notice-showing consumers (saved-for-later, wishlist) are gated behind the
- * `product_wishlist` feature flag and are not registered in this e2e
- * environment, so their blocks cannot be placed on a page here. The notice
- * outcomes those consumers depend on — no spurious "quantity changed" info
- * notice on a meta-only add and entry preservation on a genuine rejection —
- * are asserted authoritatively at the store/consumer unit level (the cart
- * store and saved-for-later / wishlist frontend unit tests). The cart-outcome
- * substrate those consumers rely on is still asserted end-to-end below: a
- * meta-only keyless add creates a new standalone line with no error notice,
- * and a genuinely rejected add leaves the cart unchanged and surfaces the
- * server error.
+ * Cart-line identity flows that change shared state, so they run in
+ * `blocks-serial`. The other flows are in
+ * `cart-line-identity-guest.block_theme.spec.ts`.
*/
const test = base.extend< {
@@ -55,151 +29,10 @@ const test = base.extend< {
} );
test.describe( 'Add to cart respects cart-line identity', () => {
- test.describe( 'with a meta-differentiated line present', () => {
- // Run as a guest so every test gets a brand-new browser context with no
- // session cookie, i.e. an isolated empty cart — cart-line-identity
- // outcomes are sensitive to leftover cart state, so no cross-test
- // cleanup is needed. The same guest session cookie is shared, within a
- // test, between the meta-line seeding navigation and the Store API add
- // path.
- test.use( { storageState: guestFile } );
-
- // Activate in beforeEach because the helper is deactivated when the DB
- // is reset; mirrors mini-cart.block_theme.spec.ts's item-data plugin.
- test.beforeEach( async ( { requestUtils } ) => {
- await requestUtils.activatePlugin( CART_LINE_IDENTITY_PLUGIN );
- } );
-
- test( 'Meta line present, no standalone — add creates a new line, meta line unchanged, no error notice', async ( {
- page,
- frontendUtils,
- } ) => {
- // Seed: product X is in the cart only as a single meta line (qty 1).
- await seedMetaLine( page, PRODUCT_X.id );
-
- await frontendUtils.goToShop();
-
- // Keyless add of X through the ProductButton.
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- // No error notice (in particular no "cannot update bundle
- // item" / store error) appears on the archive.
- await expect(
- page.locator( '.wc-block-components-notice-banner.is-error' )
- ).toHaveCount( 0 );
-
- // Persisted cart: exactly two lines for X — the meta line still at
- // quantity 1 plus a new standalone line at quantity 1.
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1, 1 ] );
- } );
-
- test( 'Both a standalone and a meta line — only the standalone increments', async ( {
- page,
- frontendUtils,
- } ) => {
- // Seed: product X as a meta line (qty 1)...
- await seedMetaLine( page, PRODUCT_X.id );
-
- // ...and as a standalone line (qty 1) via a plain ProductButton add.
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1, 1 ] );
-
- // Add X again through the ProductButton.
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- await expect(
- page.locator( '.wc-block-components-notice-banner.is-error' )
- ).toHaveCount( 0 );
-
- // The standalone line becomes quantity 2; the meta line stays at 1.
- // No new line is created (still two lines total).
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1, 2 ] );
- } );
-
- test( 'Saved-for-later / wishlist meta-only add (cart outcome) — keyless add creates a new standalone line with no error notice', async ( {
- page,
- frontendUtils,
- } ) => {
- // Saved-for-later "Move to cart" and wishlist "Add to cart" call the
- // same keyless `addCartItem` path this exercises (quantityToAdd, no
- // key). Here we assert the cart outcome those consumers depend on —
- // a new standalone line beside the untouched meta line, no error
- // notice. The consumer-specific guarantees (list entry removed, no
- // spurious "quantity changed" info notice shown to the shopper) are
- // covered authoritatively by the store/consumer unit tests,
- // because the saved-for-later and wishlist blocks are gated behind
- // the `product_wishlist` feature flag and are not registered in
- // this e2e environment.
- await seedMetaLine( page, PRODUCT_X.id );
-
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- await expect(
- page.locator( '.wc-block-components-notice-banner.is-error' )
- ).toHaveCount( 0 );
-
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1, 1 ] );
- } );
- } );
-
test.describe( 'without a meta-differentiated line', () => {
- // Guest isolation, same rationale as above.
+ // A guest context, so the test starts with an empty cart.
test.use( { storageState: guestFile } );
- test( 'Existing standalone line — add increments it', async ( {
- page,
- frontendUtils,
- } ) => {
- await frontendUtils.goToShop();
-
- // First add creates the standalone line at quantity 1.
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- // Second add increments the same line.
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- // One line, quantity 2 — not two lines.
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 2 ] );
- } );
-
- test( 'Not in cart — add creates a new line, no error notice', async ( {
- page,
- frontendUtils,
- } ) => {
- await frontendUtils.goToShop();
-
- await frontendUtils.addToCart( PRODUCT_X.name );
-
- await expect(
- page.locator( '.wc-block-components-notice-banner.is-error' )
- ).toHaveCount( 0 );
-
- // A single new standalone line at quantity 1.
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1 ] );
- } );
-
test( 'Genuine rejection (cart outcome) — leaves the cart unchanged and surfaces the error', async ( {
page,
frontendUtils,
@@ -323,56 +156,4 @@ test.describe( 'Add to cart respects cart-line identity', () => {
).toEqual( [ 1, 2 ] );
} );
} );
-
- test.describe( 'known-line quantity change (Mini-Cart stepper)', () => {
- test( 'Stepper updates the exact line with no spurious notice and no extra line', async ( {
- page,
- frontendUtils,
- miniCartUtils,
- } ) => {
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( PRODUCT_X.name );
- await miniCartUtils.openMiniCart();
-
- const quantity = page.getByLabel(
- `Quantity of ${ PRODUCT_X.name } in your cart.`
- );
- await expect( quantity ).toHaveValue( '1' );
-
- // Increment via the stepper (keyed update-item path).
- const batchIncrease = page.waitForResponse(
- '**/wp-json/wc/store/v1/batch**'
- );
- await page
- .getByRole( 'button', {
- name: `Increase quantity of ${ PRODUCT_X.name }`,
- } )
- .click();
- await batchIncrease;
- await expect( quantity ).toHaveValue( '2' );
-
- // Decrement back.
- const batchReduce = page.waitForResponse(
- '**/wp-json/wc/store/v1/batch**'
- );
- await page
- .getByRole( 'button', {
- name: `Reduce quantity of ${ PRODUCT_X.name }`,
- } )
- .click();
- await batchReduce;
- await expect( quantity ).toHaveValue( '1' );
-
- // No spurious notice from the stepper change itself.
- await expect(
- page.locator( '.wc-block-components-notice-banner' )
- ).toHaveCount( 0 );
-
- // No extra line was created: exactly one line for the product.
- await frontendUtils.goToCart();
- expect(
- await readCartLineQuantities( page, PRODUCT_X.name )
- ).toEqual( [ 1 ] );
- } );
- } );
} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/utils.ts b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/utils.ts
index 5942829ca6a..2d01dc8a2dd 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/utils.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/cart-store/utils.ts
@@ -3,17 +3,6 @@
*/
import { Page, Locator } from '@playwright/test';
-/**
- * Activation slug of the cart-line-identity helper plugin
- * (`test-plugins/blocks/cart-line-identity.php`). When active, an add-to-cart
- * request that carries the `cart_line_identity_marker` flag receives a unique
- * `cart_item_data` entry, so core's `generate_cart_id` mints a distinct cart
- * line for the same product id — a stand-in for a bundle child / booking /
- * add-on / recipient (meta-differentiated) line.
- */
-export const CART_LINE_IDENTITY_PLUGIN =
- 'woocommerce-blocks-test-cart-line-identity';
-
/**
* Request flag the helper plugin reads to mark an add as a meta line.
*
@@ -51,7 +40,7 @@ export const PRODUCT_X = {
* so a later keyless add of X operates against this same cart and is resolved
* by the server as a separate standalone line.
*
- * The helper plugin must already be active (activate it in `beforeEach`).
+ * `blocks setup` activates the helper plugin for all specs.
*
* @param page The Playwright page.
* @param productId The product id to seed as a meta line.
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-editor.merchant.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-editor.merchant.block_theme.spec.ts
new file mode 100644
index 00000000000..ab33967fd7f
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block-editor.merchant.block_theme.spec.ts
@@ -0,0 +1,475 @@
+/**
+ * External dependencies
+ */
+import {
+ test,
+ expect,
+ BlockData,
+ BLOCK_THEME_SLUG,
+} from '@woocommerce/e2e-utils';
+
+const blockData: BlockData = {
+ name: 'Checkout',
+ slug: 'woocommerce/checkout',
+ mainClass: '.wp-block-woocommerce-checkout',
+ selectors: {
+ editor: {
+ block: '.wp-block-woocommerce-checkout',
+ insertButton: "//button//span[text()='Checkout']",
+ },
+ frontend: {},
+ },
+};
+
+test.describe( 'Merchant → Checkout', () => {
+ // `as string` is safe here because we know the variable is a string, it is defined above.
+ const blockSelectorInEditor = blockData.selectors.editor.block as string;
+
+ test.beforeEach( async ( { admin, editor } ) => {
+ await admin.visitSiteEditor( {
+ postId: `${ BLOCK_THEME_SLUG }//page-checkout`,
+ postType: 'wp_template',
+ canvas: 'edit',
+ } );
+
+ // Dismiss the "Get started" modal if it appears.
+ const getStartedButton = admin.page.getByRole( 'button', {
+ name: 'Get started',
+ } );
+ if ( await getStartedButton.isVisible() ) {
+ await getStartedButton.click();
+ }
+
+ await editor.openDocumentSettingsSidebar();
+ } );
+
+ test( 'renders without crashing and can only be inserted once', async ( {
+ page,
+ editor,
+ } ) => {
+ const blockPresence = await editor.getBlockByName( blockData.slug );
+ expect( blockPresence ).toBeTruthy();
+
+ await editor.openGlobalBlockInserter();
+ await page.getByPlaceholder( 'Search' ).fill( blockData.slug );
+ const checkoutBlockButton = page.getByRole( 'option', {
+ name: blockData.name,
+ exact: true,
+ } );
+
+ const errorMessages = [
+ /This block contains unexpected or invalid content/gi,
+ /Your site doesn’t include support for/gi,
+ /There was an error whilst rendering/gi,
+ /This block has encountered an error and cannot be previewed/gi,
+ ];
+
+ for ( const errorMessage of errorMessages ) {
+ await expect(
+ editor.canvas.getByText( errorMessage )
+ ).toBeHidden();
+ }
+
+ await expect(
+ editor.canvas.locator( blockSelectorInEditor )
+ ).toBeVisible();
+ await expect( checkoutBlockButton ).toHaveAttribute(
+ 'aria-disabled',
+ 'true'
+ );
+ } );
+
+ test.describe( 'Attributes', () => {
+ test.beforeEach( async ( { editor } ) => {
+ await editor.openDocumentSettingsSidebar();
+ await editor.selectBlocks( blockSelectorInEditor );
+ } );
+
+ test( 'can enable dark mode inputs', async ( { editor, page } ) => {
+ const toggleLabel = page.getByLabel( 'Dark mode inputs' );
+ await toggleLabel.check();
+
+ const shippingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout'
+ );
+
+ const darkControls = shippingAddressBlock.locator(
+ '.wc-block-checkout.has-dark-controls'
+ );
+ await expect( darkControls ).toBeVisible();
+ await toggleLabel.uncheck();
+ await expect( darkControls ).toBeHidden();
+ } );
+
+ test.describe( 'Shipping and billing addresses', () => {
+ test.beforeEach( async ( { editor } ) => {
+ await editor.openDocumentSettingsSidebar();
+ await editor.selectBlocks( blockSelectorInEditor );
+ } );
+
+ test( 'Company input visibility and optional and required can be toggled', async ( {
+ editor,
+ } ) => {
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-shipping-address-block"]'
+ );
+
+ const shippingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-shipping-address-block'
+ );
+
+ const shippingCompanyInput =
+ shippingAddressBlock.getByLabel( 'Company' );
+
+ const shippingCompanyToggle = editor.page.getByRole(
+ 'checkbox',
+ {
+ name: 'Company',
+ exact: true,
+ }
+ );
+
+ const shippingCompanyOptionalToggle = editor.page.locator(
+ '.wc-block-components-require-company-field >> text="Optional"'
+ );
+
+ const shippingCompanyRequiredToggle = editor.page.locator(
+ '.wc-block-components-require-company-field >> text="Required"'
+ );
+
+ // Verify that the company field is hidden by default.
+ await expect( shippingCompanyInput ).toBeHidden();
+
+ // Enable the company field.
+ await expect( async () => {
+ await shippingCompanyToggle.check();
+ } ).toPass();
+
+ // Verify that the company field is visible and the field is optional.
+ await expect( shippingCompanyInput ).toBeVisible();
+ await expect( shippingCompanyOptionalToggle ).toBeChecked();
+ await expect( shippingCompanyInput ).not.toHaveAttribute(
+ 'required'
+ );
+
+ // Make the company field required.
+ await expect( async () => {
+ await shippingCompanyRequiredToggle.check();
+ } ).toPass();
+
+ // Verify that the company field is required.
+ await expect( shippingCompanyRequiredToggle ).toBeChecked();
+
+ // Disable the company field.
+ await expect( async () => {
+ await shippingCompanyToggle.uncheck();
+ } ).toPass();
+
+ // Verify that the company field is hidden.
+ await expect( shippingCompanyInput ).toBeHidden();
+
+ // Display the billing address form.
+ await editor.canvas
+ .getByLabel( 'Use same address for billing' )
+ .uncheck();
+
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-billing-address-block"]'
+ );
+
+ const billingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-billing-address-block'
+ );
+
+ const billingCompanyInput =
+ billingAddressBlock.getByLabel( 'Company' );
+
+ const billingCompanyToggle = editor.page.getByRole(
+ 'checkbox',
+ {
+ name: 'Company',
+ exact: true,
+ }
+ );
+
+ // Verify the company field on the billing address has the correct state from the shipping address.
+ await expect( billingCompanyToggle ).not.toBeChecked();
+ await expect( billingCompanyInput ).toBeHidden();
+ } );
+
+ test( 'Apartment input visibility and optional and required can be toggled', async ( {
+ editor,
+ } ) => {
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-shipping-address-block"]'
+ );
+
+ const shippingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-shipping-address-block'
+ );
+
+ const shippingApartmentInput = shippingAddressBlock.getByLabel(
+ 'Apartment, suite, etc.'
+ );
+
+ const shippingApartmentLink = shippingAddressBlock.getByRole(
+ 'button',
+ {
+ name: '+ Add apartment, suite, etc.',
+ }
+ );
+
+ const shippingApartmentToggle = editor.page.getByRole(
+ 'checkbox',
+ {
+ name: 'Address line 2',
+ exact: true,
+ }
+ );
+
+ const shippingApartmentOptionalToggle = editor.page.locator(
+ '.wc-block-components-require-address_2-field >> text="Optional"'
+ );
+
+ const shippingApartmentRequiredToggle = editor.page.locator(
+ '.wc-block-components-require-address_2-field >> text="Required"'
+ );
+
+ // Verify that the apartment link is visible by default.
+ await expect( shippingApartmentLink ).toBeVisible();
+
+ // Verify that the apartment field is hidden by default and the field is optional.
+ await expect( shippingApartmentInput ).not.toBeInViewport();
+ await expect( shippingApartmentOptionalToggle ).toBeChecked();
+
+ // Make the apartment number required.
+ await expect( async () => {
+ await shippingApartmentRequiredToggle.check();
+ } ).toPass();
+
+ // Verify that the apartment field is required.
+ await expect( shippingApartmentRequiredToggle ).toBeChecked();
+ await expect( shippingApartmentInput ).toHaveAttribute(
+ 'required'
+ );
+
+ // Disable the apartment field.
+ await expect( async () => {
+ await shippingApartmentToggle.uncheck();
+ } ).toPass();
+
+ // Verify that the apartment link and the apartment field are hidden.
+ await expect( shippingApartmentLink ).toBeHidden();
+ await expect( shippingApartmentInput ).not.toBeInViewport();
+
+ // Display the billing address form.
+ await editor.canvas
+ .getByLabel( 'Use same address for billing' )
+ .uncheck();
+
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-billing-address-block"]'
+ );
+
+ const billingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-billing-address-block'
+ );
+
+ const billingApartmentInput = billingAddressBlock.getByLabel(
+ 'Apartment, suite, etc.'
+ );
+
+ const billingApartmentLink = billingAddressBlock.getByRole(
+ 'button',
+ {
+ name: '+ Add apartment, suite, etc.',
+ }
+ );
+
+ const billingApartmentToggle = editor.page.getByRole(
+ 'checkbox',
+ {
+ name: 'Address line 2',
+ exact: true,
+ }
+ );
+
+ // Verify the apartment field on the billing address has the correct state from the shipping address.
+ await expect( billingApartmentToggle ).not.toBeChecked();
+ await expect( billingApartmentLink ).toBeHidden();
+ await expect( billingApartmentInput ).not.toBeInViewport();
+ } );
+
+ test( 'Phone input visibility and optional and required can be toggled', async ( {
+ editor,
+ } ) => {
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-shipping-address-block"]'
+ );
+
+ const shippingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-shipping-address-block'
+ );
+
+ const shippingPhoneInput =
+ shippingAddressBlock.getByLabel( 'Phone' );
+
+ const shippingPhoneToggle = editor.page.getByRole( 'checkbox', {
+ name: 'Phone',
+ exact: true,
+ } );
+
+ const shippingPhoneOptionalToggle = editor.page.locator(
+ '.wc-block-components-require-phone-field >> text="Optional"'
+ );
+
+ const shippingPhoneRequiredToggle = editor.page.locator(
+ '.wc-block-components-require-phone-field >> text="Required"'
+ );
+
+ // Verify that the phone field is visible by default and the field is optional.
+ await expect( shippingPhoneInput ).toBeVisible();
+ await expect( shippingPhoneOptionalToggle ).toBeChecked();
+ await expect( shippingPhoneInput ).not.toHaveAttribute(
+ 'required'
+ );
+
+ // Make the phone number required.
+ await expect( async () => {
+ await shippingPhoneRequiredToggle.check();
+ } ).toPass();
+
+ // Verify that the phone field is required.
+ await expect( shippingPhoneRequiredToggle ).toBeChecked();
+ await expect( shippingPhoneInput ).toHaveAttribute(
+ 'required'
+ );
+
+ // Disable the phone field.
+ await expect( async () => {
+ await shippingPhoneToggle.uncheck();
+ } ).toPass();
+
+ // Verify that the phone field is hidden.
+ await expect( shippingPhoneInput ).toBeHidden();
+
+ // Display the billing address form.
+ await editor.canvas
+ .getByLabel( 'Use same address for billing' )
+ .uncheck();
+
+ await editor.selectBlocks(
+ blockSelectorInEditor +
+ ' [data-type="woocommerce/checkout-billing-address-block"]'
+ );
+
+ const billingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-billing-address-block'
+ );
+
+ const billingPhoneInput =
+ billingAddressBlock.getByLabel( 'Phone' );
+
+ const billingPhoneToggle = editor.page.getByRole( 'checkbox', {
+ name: 'Phone',
+ exact: true,
+ } );
+
+ // Verify the phone field on the billing address has the correct state from the shipping address.
+ await expect( billingPhoneToggle ).not.toBeChecked();
+ await expect( billingPhoneInput ).toBeHidden();
+ } );
+ } );
+ } );
+
+ test.describe( 'Checkout actions', () => {
+ test.beforeEach( async ( { editor } ) => {
+ await editor.openDocumentSettingsSidebar();
+ await editor.selectBlocks( blockSelectorInEditor );
+ } );
+
+ test( 'Merchant can switch from the Terms and Conditions block to the Actions block terms', async ( {
+ editor,
+ } ) => {
+ await editor.selectBlocks(
+ `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-actions-block`
+ );
+
+ const showTermsToggle = editor.page.getByLabel(
+ 'Show terms and conditions',
+ { exact: true }
+ );
+ const actionsBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-actions-block'
+ );
+ const terms = actionsBlock.locator( '.wc-block-checkout__terms' );
+
+ // While the Terms and Conditions block is in the checkout, it owns the terms.
+ await expect( showTermsToggle ).toHaveCount( 0 );
+ await expect(
+ editor.page.getByRole( 'button', {
+ name: 'Switch to the Actions block',
+ exact: true,
+ } )
+ ).toHaveCount( 0 );
+
+ await editor.selectBlocks(
+ `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-terms-block`
+ );
+
+ await editor.page
+ .getByRole( 'button', {
+ name: 'Switch to the Actions block',
+ exact: true,
+ } )
+ .click();
+
+ await expect(
+ editor.canvas.locator(
+ '[data-type="woocommerce/checkout-terms-block"]'
+ )
+ ).toHaveCount( 0 );
+ await expect( showTermsToggle ).toBeChecked();
+ await expect( terms ).toBeVisible();
+
+ await showTermsToggle.uncheck();
+ await expect( terms ).toBeHidden();
+ } );
+
+ test( 'Return to cart link is visible and can be toggled', async ( {
+ editor,
+ } ) => {
+ await editor.selectBlocks(
+ `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-actions-block`
+ );
+
+ // Turn on return to cart link and check it's visible in the block.
+ const returnToCartLinkToggle = editor.page.getByLabel(
+ 'Show a "Return to Cart" link',
+ { exact: true }
+ );
+ await returnToCartLinkToggle.check();
+ const shippingAddressBlock = await editor.getBlockByName(
+ 'woocommerce/checkout-actions-block'
+ );
+
+ // Turn on return to cart link and check it shows in the block.
+ const returnToCartLink = shippingAddressBlock.getByText(
+ 'Return to Cart',
+ { exact: true }
+ );
+
+ // Turn off return to cart link and check it's not visible in the block.
+ await expect( returnToCartLink ).toBeVisible();
+
+ await returnToCartLinkToggle.uncheck();
+
+ await expect( returnToCartLink ).toBeHidden();
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts
index cbe734472a9..8f57f3f3b89 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/checkout/checkout-block.merchant.block_theme.spec.ts
@@ -50,60 +50,6 @@ test.describe( 'Merchant → Checkout', () => {
// `as string` is safe here because we know the variable is a string, it is defined above.
const blockSelectorInEditor = blockData.selectors.editor.block as string;
- test.beforeEach( async ( { admin, editor } ) => {
- await admin.visitSiteEditor( {
- postId: `${ BLOCK_THEME_SLUG }//page-checkout`,
- postType: 'wp_template',
- canvas: 'edit',
- } );
-
- // Dismiss the "Get started" modal if it appears.
- const getStartedButton = admin.page.getByRole( 'button', {
- name: 'Get started',
- } );
- if ( await getStartedButton.isVisible() ) {
- await getStartedButton.click();
- }
-
- await editor.openDocumentSettingsSidebar();
- } );
-
- test( 'renders without crashing and can only be inserted once', async ( {
- page,
- editor,
- } ) => {
- const blockPresence = await editor.getBlockByName( blockData.slug );
- expect( blockPresence ).toBeTruthy();
-
- await editor.openGlobalBlockInserter();
- await page.getByPlaceholder( 'Search' ).fill( blockData.slug );
- const checkoutBlockButton = page.getByRole( 'option', {
- name: blockData.name,
- exact: true,
- } );
-
- const errorMessages = [
- /This block contains unexpected or invalid content/gi,
- /Your site doesn’t include support for/gi,
- /There was an error whilst rendering/gi,
- /This block has encountered an error and cannot be previewed/gi,
- ];
-
- for ( const errorMessage of errorMessages ) {
- await expect(
- editor.canvas.getByText( errorMessage )
- ).toBeHidden();
- }
-
- await expect(
- editor.canvas.locator( blockSelectorInEditor )
- ).toBeVisible();
- await expect( checkoutBlockButton ).toHaveAttribute(
- 'aria-disabled',
- 'true'
- );
- } );
-
test.describe( 'Can adjust T&S and Privacy Policy options', () => {
test( 'Merchant can see T&S and Privacy Policy links without checkbox', async ( {
page,
@@ -222,398 +168,4 @@ test.describe( 'Merchant → Checkout', () => {
await requireTermsCheckbox.uncheck();
await editor.saveSiteEditorEntities();
} );
-
- test.describe( 'Attributes', () => {
- test.beforeEach( async ( { editor } ) => {
- await editor.openDocumentSettingsSidebar();
- await editor.selectBlocks( blockSelectorInEditor );
- } );
-
- test( 'can enable dark mode inputs', async ( { editor, page } ) => {
- const toggleLabel = page.getByLabel( 'Dark mode inputs' );
- await toggleLabel.check();
-
- const shippingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout'
- );
-
- const darkControls = shippingAddressBlock.locator(
- '.wc-block-checkout.has-dark-controls'
- );
- await expect( darkControls ).toBeVisible();
- await toggleLabel.uncheck();
- await expect( darkControls ).toBeHidden();
- } );
-
- test.describe( 'Shipping and billing addresses', () => {
- test.beforeEach( async ( { editor } ) => {
- await editor.openDocumentSettingsSidebar();
- await editor.selectBlocks( blockSelectorInEditor );
- } );
-
- test( 'Company input visibility and optional and required can be toggled', async ( {
- editor,
- } ) => {
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-shipping-address-block"]'
- );
-
- const shippingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-shipping-address-block'
- );
-
- const shippingCompanyInput =
- shippingAddressBlock.getByLabel( 'Company' );
-
- const shippingCompanyToggle = editor.page.getByRole(
- 'checkbox',
- {
- name: 'Company',
- exact: true,
- }
- );
-
- const shippingCompanyOptionalToggle = editor.page.locator(
- '.wc-block-components-require-company-field >> text="Optional"'
- );
-
- const shippingCompanyRequiredToggle = editor.page.locator(
- '.wc-block-components-require-company-field >> text="Required"'
- );
-
- // Verify that the company field is hidden by default.
- await expect( shippingCompanyInput ).toBeHidden();
-
- // Enable the company field.
- await expect( async () => {
- await shippingCompanyToggle.check();
- } ).toPass();
-
- // Verify that the company field is visible and the field is optional.
- await expect( shippingCompanyInput ).toBeVisible();
- await expect( shippingCompanyOptionalToggle ).toBeChecked();
- await expect( shippingCompanyInput ).not.toHaveAttribute(
- 'required'
- );
-
- // Make the company field required.
- await expect( async () => {
- await shippingCompanyRequiredToggle.check();
- } ).toPass();
-
- // Verify that the company field is required.
- await expect( shippingCompanyRequiredToggle ).toBeChecked();
-
- // Disable the company field.
- await expect( async () => {
- await shippingCompanyToggle.uncheck();
- } ).toPass();
-
- // Verify that the company field is hidden.
- await expect( shippingCompanyInput ).toBeHidden();
-
- // Display the billing address form.
- await editor.canvas
- .getByLabel( 'Use same address for billing' )
- .uncheck();
-
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-billing-address-block"]'
- );
-
- const billingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-billing-address-block'
- );
-
- const billingCompanyInput =
- billingAddressBlock.getByLabel( 'Company' );
-
- const billingCompanyToggle = editor.page.getByRole(
- 'checkbox',
- {
- name: 'Company',
- exact: true,
- }
- );
-
- // Verify the company field on the billing address has the correct state from the shipping address.
- await expect( billingCompanyToggle ).not.toBeChecked();
- await expect( billingCompanyInput ).toBeHidden();
- } );
-
- test( 'Apartment input visibility and optional and required can be toggled', async ( {
- editor,
- } ) => {
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-shipping-address-block"]'
- );
-
- const shippingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-shipping-address-block'
- );
-
- const shippingApartmentInput = shippingAddressBlock.getByLabel(
- 'Apartment, suite, etc.'
- );
-
- const shippingApartmentLink = shippingAddressBlock.getByRole(
- 'button',
- {
- name: '+ Add apartment, suite, etc.',
- }
- );
-
- const shippingApartmentToggle = editor.page.getByRole(
- 'checkbox',
- {
- name: 'Address line 2',
- exact: true,
- }
- );
-
- const shippingApartmentOptionalToggle = editor.page.locator(
- '.wc-block-components-require-address_2-field >> text="Optional"'
- );
-
- const shippingApartmentRequiredToggle = editor.page.locator(
- '.wc-block-components-require-address_2-field >> text="Required"'
- );
-
- // Verify that the apartment link is visible by default.
- await expect( shippingApartmentLink ).toBeVisible();
-
- // Verify that the apartment field is hidden by default and the field is optional.
- await expect( shippingApartmentInput ).not.toBeInViewport();
- await expect( shippingApartmentOptionalToggle ).toBeChecked();
-
- // Make the apartment number required.
- await expect( async () => {
- await shippingApartmentRequiredToggle.check();
- } ).toPass();
-
- // Verify that the apartment field is required.
- await expect( shippingApartmentRequiredToggle ).toBeChecked();
- await expect( shippingApartmentInput ).toHaveAttribute(
- 'required'
- );
-
- // Disable the apartment field.
- await expect( async () => {
- await shippingApartmentToggle.uncheck();
- } ).toPass();
-
- // Verify that the apartment link and the apartment field are hidden.
- await expect( shippingApartmentLink ).toBeHidden();
- await expect( shippingApartmentInput ).not.toBeInViewport();
-
- // Display the billing address form.
- await editor.canvas
- .getByLabel( 'Use same address for billing' )
- .uncheck();
-
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-billing-address-block"]'
- );
-
- const billingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-billing-address-block'
- );
-
- const billingApartmentInput = billingAddressBlock.getByLabel(
- 'Apartment, suite, etc.'
- );
-
- const billingApartmentLink = billingAddressBlock.getByRole(
- 'button',
- {
- name: '+ Add apartment, suite, etc.',
- }
- );
-
- const billingApartmentToggle = editor.page.getByRole(
- 'checkbox',
- {
- name: 'Address line 2',
- exact: true,
- }
- );
-
- // Verify the apartment field on the billing address has the correct state from the shipping address.
- await expect( billingApartmentToggle ).not.toBeChecked();
- await expect( billingApartmentLink ).toBeHidden();
- await expect( billingApartmentInput ).not.toBeInViewport();
- } );
-
- test( 'Phone input visibility and optional and required can be toggled', async ( {
- editor,
- } ) => {
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-shipping-address-block"]'
- );
-
- const shippingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-shipping-address-block'
- );
-
- const shippingPhoneInput =
- shippingAddressBlock.getByLabel( 'Phone' );
-
- const shippingPhoneToggle = editor.page.getByRole( 'checkbox', {
- name: 'Phone',
- exact: true,
- } );
-
- const shippingPhoneOptionalToggle = editor.page.locator(
- '.wc-block-components-require-phone-field >> text="Optional"'
- );
-
- const shippingPhoneRequiredToggle = editor.page.locator(
- '.wc-block-components-require-phone-field >> text="Required"'
- );
-
- // Verify that the phone field is visible by default and the field is optional.
- await expect( shippingPhoneInput ).toBeVisible();
- await expect( shippingPhoneOptionalToggle ).toBeChecked();
- await expect( shippingPhoneInput ).not.toHaveAttribute(
- 'required'
- );
-
- // Make the phone number required.
- await expect( async () => {
- await shippingPhoneRequiredToggle.check();
- } ).toPass();
-
- // Verify that the phone field is required.
- await expect( shippingPhoneRequiredToggle ).toBeChecked();
- await expect( shippingPhoneInput ).toHaveAttribute(
- 'required'
- );
-
- // Disable the phone field.
- await expect( async () => {
- await shippingPhoneToggle.uncheck();
- } ).toPass();
-
- // Verify that the phone field is hidden.
- await expect( shippingPhoneInput ).toBeHidden();
-
- // Display the billing address form.
- await editor.canvas
- .getByLabel( 'Use same address for billing' )
- .uncheck();
-
- await editor.selectBlocks(
- blockSelectorInEditor +
- ' [data-type="woocommerce/checkout-billing-address-block"]'
- );
-
- const billingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-billing-address-block'
- );
-
- const billingPhoneInput =
- billingAddressBlock.getByLabel( 'Phone' );
-
- const billingPhoneToggle = editor.page.getByRole( 'checkbox', {
- name: 'Phone',
- exact: true,
- } );
-
- // Verify the phone field on the billing address has the correct state from the shipping address.
- await expect( billingPhoneToggle ).not.toBeChecked();
- await expect( billingPhoneInput ).toBeHidden();
- } );
- } );
- } );
-
- test.describe( 'Checkout actions', () => {
- test.beforeEach( async ( { editor } ) => {
- await editor.openDocumentSettingsSidebar();
- await editor.selectBlocks( blockSelectorInEditor );
- } );
-
- test( 'Merchant can switch from the Terms and Conditions block to the Actions block terms', async ( {
- editor,
- } ) => {
- await editor.selectBlocks(
- `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-actions-block`
- );
-
- const showTermsToggle = editor.page.getByLabel(
- 'Show terms and conditions',
- { exact: true }
- );
- const actionsBlock = await editor.getBlockByName(
- 'woocommerce/checkout-actions-block'
- );
- const terms = actionsBlock.locator( '.wc-block-checkout__terms' );
-
- // While the Terms and Conditions block is in the checkout, it owns the terms.
- await expect( showTermsToggle ).toHaveCount( 0 );
- await expect(
- editor.page.getByRole( 'button', {
- name: 'Switch to the Actions block',
- exact: true,
- } )
- ).toHaveCount( 0 );
-
- await editor.selectBlocks(
- `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-terms-block`
- );
-
- await editor.page
- .getByRole( 'button', {
- name: 'Switch to the Actions block',
- exact: true,
- } )
- .click();
-
- await expect(
- editor.canvas.locator(
- '[data-type="woocommerce/checkout-terms-block"]'
- )
- ).toHaveCount( 0 );
- await expect( showTermsToggle ).toBeChecked();
- await expect( terms ).toBeVisible();
-
- await showTermsToggle.uncheck();
- await expect( terms ).toBeHidden();
- } );
-
- test( 'Return to cart link is visible and can be toggled', async ( {
- editor,
- } ) => {
- await editor.selectBlocks(
- `${ blockSelectorInEditor } .wp-block-woocommerce-checkout-actions-block`
- );
-
- // Turn on return to cart link and check it's visible in the block.
- const returnToCartLinkToggle = editor.page.getByLabel(
- 'Show a "Return to Cart" link',
- { exact: true }
- );
- await returnToCartLinkToggle.check();
- const shippingAddressBlock = await editor.getBlockByName(
- 'woocommerce/checkout-actions-block'
- );
-
- // Turn on return to cart link and check it shows in the block.
- const returnToCartLink = shippingAddressBlock.getByText(
- 'Return to Cart',
- { exact: true }
- );
-
- // Turn off return to cart link and check it's not visible in the block.
- await expect( returnToCartLink ).toBeVisible();
-
- await returnToCartLinkToggle.uncheck();
-
- await expect( returnToCartLink ).toBeHidden();
- } );
- } );
} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block-ssr-notice.shopper.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block-ssr-notice.shopper.block_theme.spec.ts
new file mode 100644
index 00000000000..16e28246c22
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block-ssr-notice.shopper.block_theme.spec.ts
@@ -0,0 +1,65 @@
+/**
+ * External dependencies
+ */
+import { expect, test, guestFile } from '@woocommerce/e2e-utils';
+
+test.describe( 'Shopper → Notices', () => {
+ // A guest cart, because all workers share the admin cart.
+ test.use( { storageState: guestFile } );
+
+ test( 'Shopper sees SSR error notice in mini cart when product goes out of stock', async ( {
+ page,
+ browser,
+ frontendUtils,
+ requestUtils,
+ createHiddenProduct,
+ } ) => {
+ // A hidden product, so `/shop` stays the same for other workers.
+ const { id: productId } = await createHiddenProduct( {
+ name: 'Limited Stock Product',
+ regular_price: '10',
+ manage_stock: true,
+ stock_quantity: 1,
+ } );
+
+ await page.goto( `/?add-to-cart=${ productId }` );
+ await frontendUtils.goToShop();
+
+ // Set product to out of stock while it's in cart.
+ await requestUtils.rest( {
+ method: 'PUT',
+ path: `wc/v3/products/${ productId }`,
+ data: { stock_quantity: 0 },
+ } );
+
+ // Get the current URL to revisit with JS disabled.
+ const currentUrl = page.url();
+
+ // Create a new context with JavaScript disabled to verify SSR output.
+ const noJsContext = await browser.newContext( {
+ javaScriptEnabled: false,
+ } );
+
+ try {
+ const noJsPage = await noJsContext.newPage();
+
+ // Copy cookies to maintain cart session.
+ const cookies = await page.context().cookies();
+ await noJsContext.addCookies( cookies );
+
+ await noJsPage.goto( currentUrl, {
+ waitUntil: 'domcontentloaded',
+ } );
+
+ // Verify error notice banner is rendered in SSR output (not client-side JS).
+ // Note: The notice text content contains HTML and is rendered client-side via
+ // data-wp-init callback, so we only verify the banner structure exists in SSR.
+ const miniCartNotice = noJsPage.locator(
+ '.wp-block-woocommerce-filled-mini-cart-contents-block .wc-block-components-notice-banner'
+ );
+ await expect( miniCartNotice ).toBeVisible();
+ } finally {
+ await noJsContext.close();
+ }
+ } );
+} );
diff --git a/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts
index 697382d961c..f107da70593 100644
--- a/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts
+++ b/plugins/woocommerce/tests/e2e/tests/blocks/mini-cart/mini-cart-block.shopper.block_theme.spec.ts
@@ -24,65 +24,6 @@ const test = base.extend< { productCollectionPage: ProductCollectionPage } >( {
} );
test.describe( 'Shopper → Notices', () => {
- test( 'Shopper sees SSR error notice in mini cart when product goes out of stock', async ( {
- page,
- browser,
- frontendUtils,
- } ) => {
- const productName = 'Limited Stock Product';
-
- // Create a product with only 1 in stock.
- const result = await wpCLI(
- `wc product create --name="${ productName }" --regular_price=10 --manage_stock=true --stock_quantity=1 --user=admin --porcelain`
- );
- // Extract just the numeric ID from output (npm adds prefix lines to stdout).
- const productId = result.stdout.match( /^\d+$/m )?.[ 0 ];
- if ( ! productId ) {
- throw new Error(
- `Failed to extract product ID from wpCLI output: ${ result.stdout }`
- );
- }
-
- await frontendUtils.emptyCart();
- await frontendUtils.goToShop();
- await frontendUtils.addToCart( productName );
-
- // Set product to out of stock while it's in cart.
- await wpCLI(
- `wc product update ${ productId } --stock_quantity=0 --in_stock=false --user=admin`
- );
-
- // Get the current URL to revisit with JS disabled.
- const currentUrl = page.url();
-
- // Create a new context with JavaScript disabled to verify SSR output.
- const noJsContext = await browser.newContext( {
- javaScriptEnabled: false,
- } );
-
- try {
- const noJsPage = await noJsContext.newPage();
-
- // Copy cookies to maintain cart session.
- const cookies = await page.context().cookies();
- await noJsContext.addCookies( cookies );
-
- await noJsPage.goto( currentUrl, {
- waitUntil: 'domcontentloaded',
- } );
-
- // Verify error notice banner is rendered in SSR output (not client-side JS).
- // Note: The notice text content contains HTML and is rendered client-side via
- // data-wp-init callback, so we only verify the banner structure exists in SSR.
- const miniCartNotice = noJsPage.locator(
- '.wp-block-woocommerce-filled-mini-cart-contents-block .wc-block-components-notice-banner'
- );
- await expect( miniCartNotice ).toBeVisible();
- } finally {
- await noJsContext.close();
- }
- } );
-
test( 'Shopper can add item to cart, and will not see a notice in the mini cart', async ( {
page,
editor,