Skip to content

Update/tests manual order creation #2749

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 3 commits 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

  • Tests
    • Improved and expanded end-to-end tests for manual order configuration, including global settings and vendor profile scenarios.
    • Enhanced test reliability and maintainability with a more structured approach and clearer test flows.

@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

The manual order configuration end-to-end test suite was refactored to use a structured approach with a SettingsPage helper class and centralized selectors. Authentication is now handled via a dedicated browser context with admin credentials. Test flows and assertions were updated for improved maintainability and clarity.

Changes

File(s) Change Summary
tests/pw/tests/e2e/ManualOrder.spec.ts Refactored tests to use SettingsPage helper, centralized selectors, and improved authentication flow.

Suggested labels

Test Automation, Needs: Dev Review

Suggested reviewers

  • mrabbani

Poem

In the meadow of code where the test bunnies play,
Helpers and selectors now light up the way.
With contexts for login, and toggles anew,
The tests hop along—so robust and true!
🐇✨

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_45_528Z-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: 5

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

24-79: Consider test dependencies and state isolation

Both tests might have implicit dependencies on the application state (e.g., existence of active vendors, specific settings). Consider adding setup/teardown for test state isolation.

Consider:

  1. Adding a test fixture to create test vendors if none exist
  2. Resetting manual order settings to a known state before each test
  3. Using test-specific data attributes to avoid conflicts with real data
📜 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 9523645.

📒 Files selected for processing (1)
  • tests/pw/tests/e2e/ManualOrder.spec.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/pw/tests/e2e/ManualOrder.spec.ts (2)
tests/pw/pages/selectors.ts (1)
  • selector (3-8231)
tests/pw/pages/settingsPage.ts (1)
  • SettingsPage (12-725)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (3)
tests/pw/tests/e2e/ManualOrder.spec.ts (3)

1-4: LGTM: Clean import structure

The imports are well-organized and properly typed, importing necessary Playwright modules and the project's helper classes.


6-7: LGTM: Good selector centralization

Using centralized selectors from the selector object improves maintainability.


13-22: LGTM: Proper test lifecycle management

The beforeAll/afterAll setup correctly creates an authenticated browser context and cleans up resources afterward.

Comment on lines +49 to +55
const activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
const vendorNameCell = activeVendorRow.locator('td.store_name').nth(1);
await vendorNameCell.click();

// Navigate to vendor edit page
const editLink = vendorNameCell.getByRole('link').nth(1);
await editLink.click();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify complex vendor selection logic

The current vendor selection logic is complex and fragile. Consider abstracting this into a helper method for better maintainability.

Add this method to SettingsPage class:

async selectActiveVendorForEdit(): Promise<void> {
    const activeVendorRow = this.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)').first();
    await activeVendorRow.locator('td.store_name a').nth(1).click();
}

Then simplify the test:

-        // Select an active vendor
-        const activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
-        const vendorNameCell = activeVendorRow.locator('td.store_name').nth(1);
-        await vendorNameCell.click();
-
-        // Navigate to vendor edit page
-        const editLink = vendorNameCell.getByRole('link').nth(1);
-        await editLink.click();
+        // Select an active vendor and navigate to edit page
+        await admin.selectActiveVendorForEdit();
🤖 Prompt for AI Agents
In tests/pw/tests/e2e/ManualOrder.spec.ts around lines 49 to 55, the vendor
selection logic is complex and fragile. Refactor by moving this logic into a new
helper method named selectActiveVendorForEdit inside the SettingsPage class,
which locates the first active vendor row and clicks the second link in the
store_name cell. Then update the test code to call this new method instead of
manually locating and clicking elements, improving maintainability and
readability.

Comment on lines +58 to +60
const manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
await manualOrderToggle.click();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use more reliable selectors for vendor settings

The current selector is overly complex and could be simplified using better targeting strategies.

-        const manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
-        const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
+        const manualOrderToggle = admin.page.locator('input[value="enableManualOrder"]').locator('..').locator('.switch .slider');
📝 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 manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
await manualOrderToggle.click();
const manualOrderToggle = admin.page.locator('input[value="enableManualOrder"]').locator('..').locator('.switch .slider');
await manualOrderToggle.click();
🤖 Prompt for AI Agents
In tests/pw/tests/e2e/ManualOrder.spec.ts around lines 58 to 60, the current
selector for manualOrderCheckbox is too complex and fragile. Simplify the
selector by targeting a more specific and stable attribute or element unique to
the manual order setting, such as a data-testid or a unique class/id, to make
the selector more reliable and maintainable. Then update the manualOrderToggle
locator accordingly to use this simplified selector.

Comment on lines +30 to +34
const manualOrderOption = admin.page.getByRole('group').filter({
hasText: 'Allow Vendors to Create Orders Enable vendors to create orders manually from'
});
const toggleSwitch = manualOrderOption.locator('span').nth(1);
await toggleSwitch.click();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve selector reliability and maintainability

The current selector relies on hardcoded text content which is brittle and could break if the UI text changes. Consider using more reliable selectors.

-        const manualOrderOption = admin.page.getByRole('group').filter({
-            hasText: 'Allow Vendors to Create Orders Enable vendors to create orders manually from'
-        });
-        const toggleSwitch = manualOrderOption.locator('span').nth(1);
+        // Use data attributes or more specific CSS selectors
+        const manualOrderToggle = admin.page.locator('[data-testid="manual-order-toggle"]')
+            .or(admin.page.locator('.manual_order_create .switch'));

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In tests/pw/tests/e2e/ManualOrder.spec.ts around lines 30 to 34, the selector
uses hardcoded text which is fragile and prone to break if UI text changes.
Replace the text-based filter with more stable selectors such as data-testid
attributes, role with accessible names, or unique element IDs to improve
reliability and maintainability. Adjust the locator logic accordingly to avoid
dependence on exact text content.

Comment on lines +40 to +41
// await admin.reload();
// await admin.toBeChecked(manualOrderOption.locator('span').nth(1));
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

Re-enable test verification

The verification logic is commented out, which means the test doesn't actually verify that the setting was saved correctly. This reduces test reliability.

-        // Verify setting is saved correctly
-        // await admin.reload();
-        // await admin.toBeChecked(manualOrderOption.locator('span').nth(1));
+        // Verify setting is saved correctly
+        await admin.reload();
+        await admin.goToSingleDokanSettings(settingsAdmin.menus.sellingOptions, data.dokanSettings.selling.settingTitle);
+        const verifyToggle = admin.page.locator('.manual_order_create .switch input[type="checkbox"]');
+        await admin.toBeChecked(verifyToggle);

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In tests/pw/tests/e2e/ManualOrder.spec.ts around lines 40 to 41, the test
verification code is commented out, so the test does not confirm that the
setting was saved correctly. Uncomment the lines that reload the admin and check
the manualOrderOption locator to ensure the test properly verifies the expected
behavior.

Comment on lines +49 to 79
const activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
const vendorNameCell = activeVendorRow.locator('td.store_name').nth(1);
await vendorNameCell.click();

// Navigate to vendor edit page
const editLink = vendorNameCell.getByRole('link').nth(1);
await editLink.click();

// Enable manual order option for this vendor
const manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
await manualOrderToggle.click();

// Save vendor profile changes
const saveButton = admin.page.locator('.profile-banner.edit-mode .action-links.edit-mode .button.button-primary');
await saveButton.click();

// Confirm update dialog
const updateDialog = admin.page.getByRole('dialog', { name: 'Vendor Updated' });
await admin.toBeVisible(updateDialog);
await admin.page.getByRole('button', { name: 'OK' }).click();

// Verify settings by going to edit mode again
const editButton = admin.page.locator('.profile-banner .action-links .button.router-link-active');
await editButton.click();

// Assertions to verify enabling was successful
await admin.toBeVisible(manualOrderCheckbox);
const checkboxInput = admin.page.locator('.payment-info.edit-mode .checkbox-left input[type="checkbox"][value="enableManualOrder"]');
await admin.toBeChecked(checkboxInput);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for missing elements

The test assumes that active vendors exist and that navigation succeeds. Add error handling to make the test more robust.

+        // Verify active vendors exist before proceeding
+        const activeVendorCount = await admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)').count();
+        if (activeVendorCount === 0) {
+            throw new Error('No active vendors found for testing');
+        }
+
         // Select an active vendor
         const activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
📝 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 activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
const vendorNameCell = activeVendorRow.locator('td.store_name').nth(1);
await vendorNameCell.click();
// Navigate to vendor edit page
const editLink = vendorNameCell.getByRole('link').nth(1);
await editLink.click();
// Enable manual order option for this vendor
const manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
await manualOrderToggle.click();
// Save vendor profile changes
const saveButton = admin.page.locator('.profile-banner.edit-mode .action-links.edit-mode .button.button-primary');
await saveButton.click();
// Confirm update dialog
const updateDialog = admin.page.getByRole('dialog', { name: 'Vendor Updated' });
await admin.toBeVisible(updateDialog);
await admin.page.getByRole('button', { name: 'OK' }).click();
// Verify settings by going to edit mode again
const editButton = admin.page.locator('.profile-banner .action-links .button.router-link-active');
await editButton.click();
// Assertions to verify enabling was successful
await admin.toBeVisible(manualOrderCheckbox);
const checkboxInput = admin.page.locator('.payment-info.edit-mode .checkbox-left input[type="checkbox"][value="enableManualOrder"]');
await admin.toBeChecked(checkboxInput);
});
// Verify active vendors exist before proceeding
const activeVendorCount = await admin.page
.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)')
.count();
if (activeVendorCount === 0) {
throw new Error('No active vendors found for testing');
}
// Select an active vendor
const activeVendorRow = admin.page.locator('.wp-list-table tr:has(.enabled [type="checkbox"]:checked)');
const vendorNameCell = activeVendorRow.locator('td.store_name').nth(1);
await vendorNameCell.click();
// Navigate to vendor edit page
const editLink = vendorNameCell.getByRole('link').nth(1);
await editLink.click();
// Enable manual order option for this vendor
const manualOrderCheckbox = admin.page.locator('.payment-info.edit-mode .checkbox-left:has(input[type="checkbox"][value="enableManualOrder"])');
const manualOrderToggle = manualOrderCheckbox.locator('.switch > .slider');
await manualOrderToggle.click();
// Save vendor profile changes
const saveButton = admin.page.locator('.profile-banner.edit-mode .action-links.edit-mode .button.button-primary');
await saveButton.click();
// Confirm update dialog
const updateDialog = admin.page.getByRole('dialog', { name: 'Vendor Updated' });
await admin.toBeVisible(updateDialog);
await admin.page.getByRole('button', { name: 'OK' }).click();
// Verify settings by going to edit mode again
const editButton = admin.page.locator('.profile-banner .action-links .button.router-link-active');
await editButton.click();
// Assertions to verify enabling was successful
await admin.toBeVisible(manualOrderCheckbox);
const checkboxInput = admin.page.locator('.payment-info.edit-mode .checkbox-left input[type="checkbox"][value="enableManualOrder"]');
await admin.toBeChecked(checkboxInput);
});
🤖 Prompt for AI Agents
In tests/pw/tests/e2e/ManualOrder.spec.ts around lines 49 to 79, the test
assumes the presence of active vendors and successful navigation without checks.
Add error handling by verifying the existence of elements like activeVendorRow,
vendorNameCell, and editLink before interacting with them. Use conditional
checks or try-catch blocks to handle cases where elements are missing, and fail
the test gracefully with informative error messages to improve robustness.

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