Skip to content

🧪test-update: fix/auth-setup/authenticate-vendor #2814

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

dev-shahed
Copy link
Contributor

@dev-shahed dev-shahed commented Jul 25, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Tests
    • Improved reliability of Playwright test runner configuration for headless mode based on environment variable.
    • Enhanced vendor authentication setup in end-to-end tests for more robust nonce extraction.
    • Added a new selector for the "Add new product" button to improve test accuracy.

Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Walkthrough

The changes update Playwright test configurations to explicitly handle the headless mode based on the NON_HEADLESS environment variable, add a new product locator selector, and refactor the vendor authentication setup to directly extract a nonce from the product dashboard page using Playwright selectors instead of a class method. Error handling and logging were also improved.

Changes

File(s) Change Summary
tests/pw/e2e.config.ts,
tests/pw/playwright.config.ts
Updated Playwright config: headless option now explicitly checks if NON_HEADLESS !== 'false'.
tests/pw/pages/selectors.ts Added addNewProductHref selector for product page; reordered addNewProduct locator.
tests/pw/tests/e2e/_auth.setup.ts Refactored nonce extraction: removed ProductsPage, now fetches nonce via Playwright selectors; improved error handling.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐇✨
In Playwright’s warren, configs are clear,
Headless or not, the choice sincere.
A nonce is fetched with nimble paws,
Selectors added without a pause.
With every hop, our testing grows—
The garden’s safe, as every rabbit knows!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-25T10_44_18_843Z-debug-0.log

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a7e5d78 and ccc2ec4.

📒 Files selected for processing (4)
  • tests/pw/e2e.config.ts (1 hunks)
  • tests/pw/pages/selectors.ts (1 hunks)
  • tests/pw/playwright.config.ts (1 hunks)
  • tests/pw/tests/e2e/_auth.setup.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/pw/e2e.config.ts
  • tests/pw/tests/e2e/_auth.setup.ts
  • tests/pw/playwright.config.ts
  • tests/pw/pages/selectors.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (1, 3)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/auth-setup/authenticate-vendor

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 generate unit tests to generate unit tests for 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.

@dev-shahed dev-shahed changed the title Fix/auth setup/authenticate vendor testCase: fix.auth-setup/authenticate-vendor Jul 25, 2025
@dev-shahed dev-shahed changed the title testCase: fix.auth-setup/authenticate-vendor test_case: fix.auth-setup/authenticate-vendor Jul 25, 2025
@dev-shahed dev-shahed changed the title test_case: fix.auth-setup/authenticate-vendor test_case: fix/auth-setup/authenticate-vendor Jul 25, 2025
@dev-shahed dev-shahed changed the title test_case: fix/auth-setup/authenticate-vendor testCase: fix/auth-setup/authenticate-vendor Jul 25, 2025
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: 4

🧹 Nitpick comments (1)
tests/pw/tests/e2e/_auth.setup.ts (1)

90-102: Improve nonce extraction robustness.

The nonce extraction logic is good, but there are opportunities for improvement:

Consider these enhancements:

             let nonce = '';
             if (addProductHref) {
-                const match = addProductHref.match(/_dokan_edit_product_nonce=([a-zA-Z0-9]+)/);
+                const match = addProductHref.match(/_dokan_edit_product_nonce=([a-fA-F0-9]+)/);
                 if (match && match[1]) {
                     nonce = match[1];
                     console.log(`✅ Product edit nonce found: ${nonce}`);
+                } else {
+                    console.log(`⚠️ Nonce pattern not found in URL: ${addProductHref}`);
                 }
+            } else {
+                console.log('⚠️ Add product button href is null or empty');
             }

The regex change assumes nonces are hexadecimal (WordPress nonces typically are), which is more restrictive and accurate than [a-zA-Z0-9]+.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93c4270 and a7e5d78.

📒 Files selected for processing (5)
  • tests/pw/e2e.config.ts (1 hunks)
  • tests/pw/pages/selectors.ts (1 hunks)
  • tests/pw/playwright.config.ts (1 hunks)
  • tests/pw/tests/e2e/_auth.setup.ts (2 hunks)
  • tests/pw/types/environment.d.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/pw/tests/e2e/_auth.setup.ts (3)
tests/pw/utils/testData.ts (1)
  • data (63-2914)
tests/pw/pages/selectors.ts (1)
  • selector (3-8231)
tests/pw/utils/helpers.ts (1)
  • helpers (7-547)
🔇 Additional comments (4)
tests/pw/types/environment.d.ts (1)

59-59: Good type system improvement!

Changing NON_HEADLESS from string to boolean aligns with its actual usage pattern and creates consistency with other boolean environment variables in the interface like LOCAL, CI, and DOKAN_PRO.

tests/pw/tests/e2e/_auth.setup.ts (3)

8-8: LGTM - Clean import change.

The import change from ProductsPage to selector aligns well with the refactored approach of using direct selectors instead of page object methods.


103-107: LGTM - Good error handling approach.

The try-catch block with fallback nonce handling is well-implemented. Using different fallback values ('fallback_nonce' vs 'error_fallback_nonce') is helpful for debugging.


80-84: Validation Completed: Navigation Timing & URL Consistency

  • The data.subUrls.frontend.vDashboard.products endpoint is used uniformly across all E2E tests and page-object methods.
  • Each navigation (page.goto) is immediately followed by await page.waitForLoadState('networkidle'), ensuring the dashboard is fully loaded before further actions.
  • The existing try { … } wrapper covers unexpected navigation failures—no additional error-handling changes are required at this location.

No further action needed.

@@ -81,7 +81,7 @@ export default defineConfig({
/* Emulates 'prefers-colors-scheme' media feature, supported values are 'light', 'dark', 'no-preference' */
// colorScheme: 'dark' ,
/* Whether to run tests on headless or non-headless mode */
headless: !NON_HEADLESS,
headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical logic error: headless behavior is inverted and comment is outdated.

The change from !NON_HEADLESS to Boolean(NON_HEADLESS) inverts the intended behavior:

  • Previous behavior: headless = false when NON_HEADLESS is truthy (correct)
  • Current behavior: headless = true when NON_HEADLESS is true (incorrect)

The variable name NON_HEADLESS suggests it should enable non-headless mode, but now it directly enables headless mode.

Apply this diff to fix the logic and update the comment:

-        headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
+        headless: !NON_HEADLESS, // NON_HEADLESS=true means run in non-headless mode, so headless should be false
📝 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
headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
headless: !NON_HEADLESS, // NON_HEADLESS=true means run in non-headless mode, so headless should be false
🤖 Prompt for AI Agents
In tests/pw/e2e.config.ts at line 84, the headless flag logic is inverted and
the comment is outdated. Change the assignment to headless:
!Boolean(NON_HEADLESS) to ensure headless mode is false when NON_HEADLESS is
truthy, matching the intended behavior. Also update the comment to clearly
explain that NON_HEADLESS enables non-headless mode, so headless is the negation
of NON_HEADLESS.

@@ -74,7 +74,8 @@ export default defineConfig({
/* Emulates 'prefers-colors-scheme' media feature, supported values are 'light', 'dark', 'no-preference' */
// colorScheme: 'dark' ,
/* Whether to run tests on headless or non-headless mode */
headless: !NON_HEADLESS,

headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the headless mode logic - current implementation is incorrect.

The current logic Boolean(NON_HEADLESS) will always return true for any non-empty string, including "false". This means setting NON_HEADLESS="false" would still result in headless=true, which is counterintuitive.

Apply this fix to correctly handle the NON_HEADLESS environment variable:

-        headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
+        headless: !NON_HEADLESS || NON_HEADLESS.toLowerCase() === 'false',

Or alternatively, use a more explicit approach:

-        headless: Boolean(NON_HEADLESS), // Because NON_HEADLESS is a string, we convert it to boolean
+        headless: NON_HEADLESS !== 'true',
🤖 Prompt for AI Agents
In tests/pw/playwright.config.ts at line 78, the headless mode is incorrectly
set using Boolean(NON_HEADLESS), which treats any non-empty string as true. To
fix this, update the logic to explicitly check if NON_HEADLESS equals the string
"true" or "1" (case-insensitive) and set headless to the inverse of that, so
that setting NON_HEADLESS="false" correctly results in headless=true. Replace
the current Boolean conversion with this explicit string comparison to properly
handle the environment variable.

@dev-shahed dev-shahed changed the title testCase: fix/auth-setup/authenticate-vendor 🧪test-update: fix/auth-setup/authenticate-vendor Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant