Skip to content

All Products block: Add E2E test #58846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025
Merged

All Products block: Add E2E test #58846

merged 3 commits into from
Jun 18, 2025

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Jun 16, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR adds E2E test to catch future regression related to the strict dependency that there is between the All Products block and Mini Cart/Cart/Checkout blocks. For more details, check: #58741

Closes # .

(For Bug Fixes) Bug introduced in PR # .

Screenshots or screen recordings:

Before After

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Run pnpm --filter="@woocommerce/plugin-woocommerce" test:e2e:blocks plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts
  2. Ensure that the E2E tests don't fail.
  3. Revert the fix via the command: git revert fd9ca98
  4. Ensure that the E2E tests fail

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

Summary by CodeRabbit

  • Tests
    • Improved test coverage for the All Products block, including a new regression test to ensure correct rendering when the Mini Cart block is removed from the site editor's header template.

Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Walkthrough

The test suite for the WooCommerce "All Products" block was updated. The previous beforeEach setup was removed and replaced with two explicit test cases: one for standard block insertion and rendering, and another regression test verifying correct rendering when the Mini Cart block is absent from the header template. Imports were adjusted to support these changes.

Changes

Files Change Summary
plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts Removed beforeEach hook; added two explicit tests for block rendering, including a regression test for absence of Mini Cart block. Updated imports.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gigitux gigitux self-assigned this Jun 16, 2025
@github-actions github-actions bot added focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Jun 16, 2025
@gigitux gigitux marked this pull request as ready for review June 16, 2025 09:08
@gigitux gigitux requested a review from opr June 16, 2025 09:09
@woocommercebot woocommercebot requested review from a team and dinhtungdu and removed request for a team June 16, 2025 09:10
Copy link
Contributor

Testing Guidelines

Hi @dinhtungdu @opr ,

Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed.

Reminder: PR reviewers are required to document testing performed. This includes:

  • 🖼️ Screenshots or screen recordings.
  • 📝 List of functionality tested / steps followed.
  • 🌐 Site details (environment attributes such as hosting type, plugins, theme, store size, store age, and relevant settings).
  • 🔍 Any analysis performed, such as assessing potential impacts on environment attributes and other plugins, conducting performance profiling, or using LLM/AI-based analysis.

⚠️ Within the testing details you provide, please ensure that no sensitive information (such as API keys, passwords, user data, etc.) is included in this public issue.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts (3)

33-35: Fix typo in regression-comment URL

hhttps://…https://…

Purely cosmetic, but worth correcting to avoid broken links in the docs.


13-31: Extract shared publish-and-assert logic to a helper for clarity & DRYness

Both tests repeat the same three-step sequence:

  1. createNewPost
  2. insertBlock
  3. publishAndVisitPost + assertions

Moving this into a small utility (insertAndAssertAllProductsGrid()?) will:

  • Reduce duplication
  • Keep individual tests focused on their unique setup logic
  • Simplify future updates to the assertion criteria

No functional change—pure maintainability win.

Also applies to: 53-64


22-27: Reliance on the network response matcher can be brittle

page.waitForResponse() coupled with an includes( 'wp-json/wc/store/v1/products' ) check assumes:

  • Exactly one products API call
  • Stable request path

If the endpoint changes or extra calls are added (pagination, filters, etc.), the wait may resolve too early or never resolve.

A more resilient pattern is:

await page.waitForSelector(
	'.wc-block-grid__product.wc-block-layout >> nth=8', // 9th element (0-based)
	{ timeout: 30_000 }
);

This waits for DOM evidence of render completion without over-specifying the transport layer details.

Also applies to: 56-60

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b650e9a and d39d565.

📒 Files selected for processing (1)
  • plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: Assign reviewers
  • GitHub Check: Blocks e2e tests 1/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 8/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 4/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 10/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 6/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 3/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 5/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 7/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 4/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 2/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 1/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 9/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Blocks e2e tests 2/10 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Metrics - @woocommerce/plugin-woocommerce [performance]
  • GitHub Check: Core e2e tests 5/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 6/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Core e2e tests 3/6 - @woocommerce/plugin-woocommerce [e2e]
  • GitHub Check: Lint - @woocommerce/block-library

Comment on lines +41 to +52
const templatePath = 'header';
await admin.visitSiteEditor( {
postId: `${ BLOCK_THEME_SLUG }//${ templatePath }`,
postType: 'wp_template_part',
canvas: 'edit',
} );

await editor.setContent( '' );
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );

Copy link
Contributor

@coderabbitai coderabbitai bot Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

❓ Verification inconclusive

Blanking the global header template can break unrelated E2E suites – capture & restore it

This test empties the entire header template and never puts the content back.
Other specs that assume a non-empty header (navigation, branding, mini-cart, etc.) will now execute against a mutated site state, producing flakiness that is notoriously hard to debug.

A minimal safeguard is to capture the original markup and restore it in a finally block:

 		const templatePath = 'header';
@@
 		await admin.visitSiteEditor( {
 			postId: `${ BLOCK_THEME_SLUG }//${ templatePath }`,
 			postType: 'wp_template_part',
 			canvas: 'edit',
 		} );
 
-		await editor.setContent( '' );
-		await editor.saveSiteEditorEntities( {
-			isOnlyCurrentEntityDirty: true,
-		} );
+		const originalHeader = await editor.getContent();
+		await editor.setContent( '' );
+		await editor.saveSiteEditorEntities( { isOnlyCurrentEntityDirty: true } );
+
+		try {
+			/* … remainder of the test … */
+		} finally {
+			// Restore header so subsequent tests see the expected theme state.
+			await editor.setContent( originalHeader );
+			await editor.saveSiteEditorEntities( { isOnlyCurrentEntityDirty: true } );
+		}

This keeps the regression test self-contained and prevents cross-suite bleed-through.


Prevent E2E Flakiness by Restoring Header Template

This test empties the global header template and never restores it, causing subsequent E2E specs (navigation, branding, mini-cart, etc.) to run against a mutated site state. Capture the original markup and restore it in a finally block to keep this test self-contained:

• File: plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts
• Lines: ~41–52

   const templatePath = 'header';
@@
   await admin.visitSiteEditor({
     postId: `${ BLOCK_THEME_SLUG }//${ templatePath }`,
     postType: 'wp_template_part',
     canvas: 'edit',
   });

-  await editor.setContent( '' );
-  await editor.saveSiteEditorEntities({ isOnlyCurrentEntityDirty: true });
+  const originalHeader = await editor.getContent();
+  await editor.setContent('');
+  await editor.saveSiteEditorEntities({ isOnlyCurrentEntityDirty: true });
+
+  try {
+    /* … remainder of the test … */
+  } finally {
+    // Restore header so subsequent tests see the expected theme state.
+    await editor.setContent(originalHeader);
+    await editor.saveSiteEditorEntities({ isOnlyCurrentEntityDirty: true });
+  }

This change ensures the header is reset after the test and prevents bleed-through into other suites.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const templatePath = 'header';
await admin.visitSiteEditor( {
postId: `${ BLOCK_THEME_SLUG }//${ templatePath }`,
postType: 'wp_template_part',
canvas: 'edit',
} );
await editor.setContent( '' );
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );
const templatePath = 'header';
await admin.visitSiteEditor( {
postId: `${ BLOCK_THEME_SLUG }//${ templatePath }`,
postType: 'wp_template_part',
canvas: 'edit',
} );
+ // Capture the original header so we can restore it later
+ const originalHeader = await editor.getContent();
+
await editor.setContent( '' );
await editor.saveSiteEditorEntities( {
isOnlyCurrentEntityDirty: true,
} );
+
+ try {
+ /* … remainder of the test … */
+ } finally {
+ // Restore header so subsequent tests see the expected theme state.
+ await editor.setContent( originalHeader );
+ await editor.saveSiteEditorEntities( {
+ isOnlyCurrentEntityDirty: true,
+ } );
+ }
🤖 Prompt for AI Agents
In
plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts
around lines 41 to 52, the test empties the global header template but does not
restore it, causing other E2E tests to run with a mutated site state. Fix this
by capturing the original header content before clearing it, then use a finally
block to restore the original content after the test completes, ensuring the
test is self-contained and does not affect other suites.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a false positive. For each test, we reset the database to the initial state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gigitux You're absolutely right, thank you for the clarification! If the database is reset to the initial state for each test, then my concern about needing to manually restore the header template is indeed a false positive. The test infrastructure handles the cleanup automatically, so there's no risk of cross-suite contamination.

I appreciate you pointing this out - it helps me better understand the E2E test setup.


✏️ Learnings added
Learnt from: gigitux
PR: woocommerce/woocommerce#58846
File: plugins/woocommerce/client/blocks/tests/e2e/tests/all-products/all-products.block_theme.spec.ts:41-52
Timestamp: 2025-06-16T09:20:22.948Z
Learning: In WooCommerce E2E tests, the database is reset to the initial state for each test, so there's no need to manually restore global template changes (like clearing the header template) as the test infrastructure handles cleanup automatically.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested well! LGTM!

@gigitux gigitux merged commit 7f4d6ab into trunk Jun 18, 2025
42 of 45 checks passed
@gigitux gigitux deleted the fix/e2e-all-products branch June 18, 2025 07:19
@github-actions github-actions bot added this to the 10.1.0 milestone Jun 18, 2025
Kallyan01 pushed a commit to Kallyan01/woocommerce that referenced this pull request Jun 23, 2025
* Enhance e2e tests for All Products block by adding checks for rendering without the Mini Cart block

* remove only

* update link
This was referenced Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: e2e tests Issues related to e2e tests plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants