Skip to content

refactor: update selectors and tests for vendor return request functionality #2748

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 1 commit into
base: develop
Choose a base branch
from

Conversation

mralaminahamed
Copy link
Member

@mralaminahamed mralaminahamed commented May 26, 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

  • Bug Fixes

    • Improved reliability of vendor return request menu and table detection in tests by updating selectors.
    • Added checks for new menu items "Rejected" and "Reviewing" in the vendor return request menu.
  • Tests

    • Enhanced vendor return request tests with more explicit navigation and UI element visibility checks.
    • Updated test routes to reflect changes in the vendor dashboard URL structure.

@mralaminahamed mralaminahamed self-assigned this May 26, 2025
@mralaminahamed mralaminahamed added the In Progress The issues is being worked on label May 26, 2025
Copy link
Contributor

coderabbitai bot commented May 26, 2025

Walkthrough

Selectors for vendor return request menus and tables were updated from XPath to CSS, with new menu items added. Test cases were refactored to use direct navigation and explicit selector checks instead of helper methods. The return request dashboard URL was updated to a new path in test data.

Changes

Files/Paths Change Summary
tests/pw/pages/selectors.ts Updated vendor return request selectors to use CSS; added new menu items; updated table selectors; added a comment.
tests/pw/tests/e2e/vendorReturnRequest.spec.ts Refactored tests to use explicit navigation and selector checks; replaced helper methods; improved UI assertions.
tests/pw/utils/testData.ts Changed vendor return request dashboard URL path in test data.

Sequence Diagram(s)

sequenceDiagram
    participant Vendor
    participant Browser
    participant Selectors
    participant TestData

    Vendor->>Browser: Navigate to new return request URL (from TestData)
    Browser->>Selectors: Use updated CSS selectors for menu/table
    Browser->>Vendor: Display return request UI
    Vendor->>Browser: Perform UI checks (menu, table, details)
Loading

Suggested labels

QA approved, Test Automation

Suggested reviewers

  • mrabbani
  • shohag121

Poem

A bunny hopped through code so neat,
Swapped XPaths out for CSS sweet.
New menus found, old helpers gone,
The dashboard path now marches on.
With tests more clear and checks in place,
This patch brings smiles to every face! 🐇✨

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 warn config production Use --omit=dev instead.
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-05-26T03_23_26_061Z-debug-0.log

✨ 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.

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: 2

🧹 Nitpick comments (2)
tests/pw/tests/e2e/vendorReturnRequest.spec.ts (1)

107-107: Remove debug console.log statement.

This console.log appears to be debug code and should be removed before merging.

-        console.log('data.subUrls.frontend.vDashboard.returnRequest', data.subUrls.frontend.vDashboard.returnRequest)
tests/pw/pages/selectors.ts (1)

5101-5104: Consider unifying selector styles for table headers
You’ve added a CSS selector for the table root (#dokan-rma-requests-data-view), which is great. For consistency and maintainability, consider migrating the header selectors (detailsColumn, productsColumn, typeColumn) from XPath to CSS as well.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d3441c1 and 8f2e2a3.

📒 Files selected for processing (3)
  • tests/pw/pages/selectors.ts (3 hunks)
  • tests/pw/tests/e2e/vendorReturnRequest.spec.ts (3 hunks)
  • tests/pw/utils/testData.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/pw/tests/e2e/vendorReturnRequest.spec.ts (2)
tests/pw/pages/selectors.ts (1)
  • selector (3-8233)
tests/pw/utils/testData.ts (1)
  • data (63-2914)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (7)
tests/pw/utils/testData.ts (1)

1193-1193: LGTM! URL path updated to support hash-based navigation.

The update to the vendor return request URL from 'dashboard/return-request' to 'dashboard/new/#/return-request' correctly reflects the migration to client-side hash-based navigation. This change aligns well with the broader refactoring effort for vendor return request functionality mentioned in the PR objectives.

tests/pw/tests/e2e/vendorReturnRequest.spec.ts (4)

8-13: LGTM! Good refactoring to centralize selectors.

This change properly imports selectors from the centralized module and creates well-named variables for reuse throughout the test file. This improves maintainability and follows good testing practices.


68-82: Excellent refactoring to explicit test steps.

The test is now much more readable and explicit about what it's verifying. The conditional logic properly handles both scenarios (with and without return requests), and the selector usage is consistent with the centralized selectors.


86-102: Well-structured explicit test implementation.

The test now clearly verifies all the important elements of the RMA settings page with proper selector usage. The explicit assertions make it easy to understand what functionality is being tested.


109-125: Verify orderId availability and good refactoring pattern.

The explicit test steps and proper destructuring to exclude sendRefund from status checks are well implemented. However, orderId may be undefined due to the commented order creation code in beforeAll.

Ensure that orderId is properly initialized before this test runs, either through the commented setup code or via API-based order creation.

tests/pw/pages/selectors.ts (2)

5092-5096: Updated menu selectors look solid
Switching from XPath to CSS with :has-text improves readability and robustness.


5109-5111: Verify the row count selector accuracy
Ensure that #dokan-rma-requests-data-view tbody tr correctly captures all rows in the table (e.g., including cases like grouped rows or nested <tbody>).

Comment on lines +41 to +45
// await customer1.addProductToCartFromSingleProductPage(data.predefined.simpleProduct.product1.name);
// await customer1.goToCheckout();
// orderId = await customer1.paymentOrder();
// await vendor1.updateOrderStatusOnTable(orderId, 'processing');
// await customer.customerRequestWarranty(orderId, data.predefined.simpleProduct.product1.name, data.rma.requestWarranty);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Flag potential dependency issue with commented order creation.

The commented order creation code may cause orderId to be undefined, which is used in later tests (lines 109, 129, 133, 137, 142, 147). This could lead to test failures.

Consider either:

  1. Uncommenting this code if tests depend on it
  2. Implementing API-based order creation as suggested by the todo comment
  3. Adding proper setup for orderId in tests that require it

🏁 Script executed:

#!/bin/bash
# Check if orderId is used elsewhere in the test file without proper initialization
rg -n "orderId" tests/pw/tests/e2e/vendorReturnRequest.spec.ts

Length of output: 1637


Ensure orderId is initialized before use in vendorReturnRequest tests

In tests/pw/tests/e2e/vendorReturnRequest.spec.ts, the top-level declaration

let orderId: string;

never receives a value because both the UI-based setup (lines 43–45) and the API-based setup (lines 49–50) are commented out. Meanwhile, orderId is referenced later at lines 109, 129, 134, 138, 142, and 147, which will lead to runtime errors.

Locations needing attention:

  • Line 23: let orderId: string; (declared but unassigned)
  • Lines 43–45: commented UI-based setup
  • Lines 49–50: commented API-based setup
  • Lines 109, 129, 134, 138, 142, 147: usages of orderId without initialization

Recommended fixes:

  • Uncomment one of the existing setup blocks (UI or API) so orderId is assigned before use
  • Or implement a new API-based order creation in a beforeAll/beforeEach
  • Or initialize orderId directly within each test before it’s referenced
🤖 Prompt for AI Agents
In tests/pw/tests/e2e/vendorReturnRequest.spec.ts around lines 41 to 45, the
variable orderId is declared but never assigned because both the UI-based and
API-based order creation code blocks are commented out. Since orderId is used
later in the test file at lines 109, 129, 134, 138, 142, and 147, this will
cause runtime errors. To fix this, uncomment one of the existing order creation
setups (either the UI-based code at lines 41-45 or the API-based code at lines
49-50) to ensure orderId is properly initialized before use, or implement a new
API-based order creation in a beforeAll or beforeEach hook, or assign orderId
directly within each test before it is referenced.

Comment on lines +7276 to 7278
// “p1_v1-simple” has been added to your cart.
productAddedSuccessMessage: (productName: string) => `//div[@class="woocommerce-message" and contains(.,"“${productName}” has been added to your cart.")]`,
productWithQuantityAddedSuccessMessage: (productName: string, quantity: string) => `//div[@class="woocommerce-message" and contains(.,"${quantity} × “${productName}” have been added to your cart.")]`,
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 smart quotes in success message selectors
Using curly quotes (/) in the XPath may not match the actual DOM text if the UI uses straight quotes. Replace them with standard quotes or adjust to match the exact markup.

Proposed fix:

- // “p1_v1-simple” has been added to your cart.
+ // "{productName}" has been added to your cart.
- productAddedSuccessMessage: (productName: string) => `//div[@class="woocommerce-message" and contains(.,"“${productName}” has been added to your cart.")]`,
+ productAddedSuccessMessage: (productName: string) => `//div[@class="woocommerce-message" and contains(.,"\"${productName}\" has been added to your cart.")]`,
- productWithQuantityAddedSuccessMessage: (productName: string, quantity: string) => `//div[@class="woocommerce-message" and contains(.,"${quantity} × “${productName}” have been added to your cart.")]`,
+ productWithQuantityAddedSuccessMessage: (productName: string, quantity: string) => `//div[@class="woocommerce-message" and contains(.,"${quantity} × \"${productName}\" have been added to your cart.")]`,
📝 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
// “p1_v1-simple” has been added to your cart.
productAddedSuccessMessage: (productName: string) => `//div[@class="woocommerce-message" and contains(.,"${productName} has been added to your cart.")]`,
productWithQuantityAddedSuccessMessage: (productName: string, quantity: string) => `//div[@class="woocommerce-message" and contains(.,"${quantity} × ${productName} have been added to your cart.")]`,
// "{productName}" has been added to your cart.
productAddedSuccessMessage: (productName: string) => `//div[@class="woocommerce-message" and contains(.,"\"${productName}\" has been added to your cart.")]`,
productWithQuantityAddedSuccessMessage: (productName: string, quantity: string) => `//div[@class="woocommerce-message" and contains(.,"${quantity} × \"${productName}\" have been added to your cart.")]`,
🤖 Prompt for AI Agents
In tests/pw/pages/selectors.ts around lines 7276 to 7278, the XPath selectors
use curly smart quotes around product names, which may not match the actual DOM
text if the UI uses straight quotes. Replace the curly quotes with standard
straight quotes in the XPath strings to ensure correct matching of the success
message elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Progress The issues is being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant