Skip to content
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

TESTING EXTERNAL SCRIPT: external merge request from Contributor #37185

Closed
wants to merge 4 commits into from

Conversation

jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Nov 1, 2024

Description

Fixes #

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced validation for phone number input to prevent invalid characters.
    • Improved tooltip functionality and visibility checks for various widget states.
    • Added tests for renaming, duplicating, and deleting the Phone Input widget.
    • Verified country code toggle and label text/position changes.
  • Bug Fixes

    • Addressed input validation logic to ensure proper formatting and error handling.
  • Tests

    • Expanded test suite for the Phone Input widget, covering functionality and edge cases.

@jacquesikot jacquesikot added the ok-to-test Required label for CI label Nov 1, 2024
Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

Walkthrough

The pull request introduces enhancements to the Phone Input widget tests within the Cypress framework, focusing on various functionalities such as property visibility, entity management, tooltip functionality, country code toggling, label adjustments, validation logic, widget state toggles, formatting, event handling, and styling properties. Additionally, it modifies the onValueChange method in the PhoneInputWidget class to include improved validation for phone number inputs, ensuring that only valid characters are processed.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts Enhanced tests for Phone Input widget covering visibility, entity management, tooltips, country code, label changes, validation, state toggles, formatting, events, and styling properties.
app/client/src/widgets/PhoneInputWidget/widget/index.tsx Modified onValueChange method to include regex validation for phone number input, preventing invalid characters from being processed.

Possibly related PRs

  • chore: refactor text and value to parsedText and rawText #33680: This PR involves refactoring the WDSPhoneInputWidget to rename properties related to text handling, which aligns with the validation logic changes in the main PR that enhance the Phone Input widget's functionality.
  • chore: fix validation in wds phoneinput widget #34177: This PR addresses validation issues in the WDSPhoneInputWidget, specifically correcting the validation mechanism, which is directly related to the validation logic enhancements made in the main PR.
  • test: fix tabs skipped test CE #37023: This PR fixes a previously skipped test related to the Tabs widget, which may share similar testing strategies or validation checks as the Phone Input widget tests in the main PR, indicating a broader focus on widget validation in tests.

Suggested labels

Test, Widgets Product

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • rahulbarwal

🎉 In the land of code where widgets play,
The Phone Input shines brighter today!
With tests that check each little part,
Validations ensure we’re smart!
So let’s celebrate this code delight,
Making our widgets work just right! 🎈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

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

🧹 Outside diff range and nitpick comments (3)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (3)

Line range hint 73-73: Class, let's avoid using agHelper.Sleep()!

I notice you're using agHelper.Sleep(2000) in your test. As per our coding guidelines, we should avoid using sleep commands. Instead, let's wait for specific conditions:

Replace the sleep commands with explicit wait conditions:

-agHelper.Sleep(2000);
+agHelper.WaitUntilAllToastsDisappear();
// or
+agHelper.WaitUntilEleAppear(locators._dropdownText);

Also applies to: 291-291


Line range hint 74-74: Let's improve our selector strategy, students!

I see we're using XPath selectors. According to our coding guidelines, we should avoid XPath and use data-* attributes instead.

Replace the XPath selector with a data attribute:

  1. First, add a data attribute to the span element in the component:
<span data-testid="country-option-india">India (+91)</span>
  1. Then update the test:
-agHelper.GetNClick("//span[text()='India (+91)']");
+agHelper.GetNClick("[data-testid='country-option-india']");

Also applies to: 291-291


295-297: Excellent work on the toast verification, class! ✨

The addition of toast message disappearance verification is a good practice. However, let's maintain consistency in our approach.

Consider using the helper method consistently throughout the test:

-cy.get(locators._toastMsg).should("not.exist");
+agHelper.AssertElementAbsence(locators._toastMsg);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6c13656 and 659af9d.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1 hunks)
  • app/client/src/widgets/PhoneInputWidget/widget/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.

Comment on lines +414 to +425
// This regular expression validates that the input:
// - Does not start with a whitespace character
// - Contains only digits, spaces, parentheses, plus, and minus symbols
if (/^(?!\s)[\d\s()+-]*$/.test(value)) {
this.props.updateWidgetMetaProperty("text", formattedValue, {
triggerPropertyName: "onTextChanged",
dynamicString: this.props.onTextChanged,
event: {
type: EventType.ON_TEXT_CHANGE,
},
});
}
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

⚠️ Potential issue

Class, let's improve our phone number validation! 📱

Good work on adding input validation! However, let's make it even better with these educational improvements:

  1. Move the regex pattern to a named constant with documentation:
+// Validates phone number input:
+// - No leading whitespace
+// - Only allows digits, spaces, parentheses, plus, and minus symbols
+const PHONE_NUMBER_PATTERN = /^(?!\s)[\d\s()+-]*$/;
+
 onValueChange = (value: string) => {
   // ... existing code ...
-  if (/^(?!\s)[\d\s()+-]*$/.test(value)) {
+  if (PHONE_NUMBER_PATTERN.test(value)) {
  1. Consider providing user feedback when invalid characters are entered:
   if (PHONE_NUMBER_PATTERN.test(value)) {
     this.props.updateWidgetMetaProperty("text", formattedValue, {
       triggerPropertyName: "onTextChanged",
       dynamicString: this.props.onTextChanged,
       event: {
         type: EventType.ON_TEXT_CHANGE,
       },
     });
+  } else {
+    // Notify user about invalid input
+    this.props.updateWidgetMetaProperty("errorMessage", "Please enter a valid phone number");
   }
  1. For extra credit 🌟, consider enhancing the validation:
  • Add maximum length validation
  • Consider country-specific phone number formats
  • Add support for international number validation using libphonenumber-js

Would you like me to help implement any of these improvements?

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

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

🧹 Outside diff range and nitpick comments (10)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (10)

Line range hint 88-112: Clarify Tooltip Functionality Implementation

While your implementation of the tooltip functionality is commendable, consider the following to enhance clarity and efficiency:

  • Consistency in Test Steps: Ensure that each action is clearly defined. For instance, after updating the tooltip property, you immediately proceed to hover over the tooltip icon. Explicitly stating any waits or validations in between can prevent flaky tests.
  • Avoid Hardcoded Coordinates: Instead of using absolute positions like 550, 300, consider defining positions relative to the widget or page layout to enhance test reliability across different screen sizes.

Line range hint 114-124: Optimize Country Code Toggle Test

You've effectively tested the country code toggle functionality. However, to optimize the test:

  • Reduce Sleep Time: Instead of using agHelper.Sleep(2000);, wait for the specific element to be visible or interactable. This practice reduces test execution time and increases reliability.

Consider replacing it with:

 agHelper.GetNClick(propPane._countryCodeChangeDropDown);
 agHelper.TypeText(propPane._searchCountryPlaceHolder, "India");
- agHelper.Sleep(2000);
+ agHelper.WaitUntilElementVisible("//span[text()='India (+91)']");
 agHelper.GetNClick("//span[text()='India (+91)']");

Line range hint 126-144: Ensure Accurate Attribute Assertions

When verifying the label position attribute, ensure that the attribute you are asserting matches the actual implementation. For instance, the position attribute may not reflect the label's visual position in the DOM.

Consider using a CSS property or class that changes when the label position is updated. This approach provides a more accurate verification of the label's position.


Line range hint 173-187: Improve Toggle State Tests for Clarity

While testing the 'visible', 'disabled', and 'autofocus' properties, ensure that:

  • Attribute Checks Match Widget Behavior: For the 'visible' property, checking for the data-hidden attribute is correct. Additionally, you could verify the widget's presence or absence in the DOM.
  • Focus State Verification: After setting 'autofocus' to 'On' and refreshing the page, confirm that the input is indeed focused by checking the focus state explicitly.

Line range hint 189-199: Handle Country Selection Without Delays

Again, to reduce reliance on arbitrary sleep times:

  • Replace agHelper.Sleep(2000); with a more robust waiting mechanism.
  • Ensure that the test waits for the dropdown options to be populated before attempting to select a country.
 agHelper.TypeText(propPane._searchCountryPlaceHolder, "India");
- agHelper.Sleep(2000);
+ agHelper.WaitUntilElementVisible("//span[text()='India (+91)']");
 agHelper.GetNClick("//span[text()='India (+91)']");

Line range hint 201-207: Validate Input Formatting Thoroughly

When testing the 'Enable formatting' toggle:

  • Verify All Formatting Scenarios: Ensure that you're checking both enabling and disabling formatting and how it affects different types of input.
  • Edge Cases: Test with edge cases such as maximum length numbers or special characters to confirm that the formatting applies correctly.

Line range hint 209-217: Auto Height Limits Best Practices

Great job verifying the auto height with limits functionality. As a best practice:

  • Dynamic Content Testing: Consider adding tests where the content inside the widget changes dynamically to see if the auto-height adjusts within the specified limits.
  • Visual Confirmation: While asserting contains text like "Min-Height: 4 rows", you might also want to check the actual CSS properties to ensure they reflect the expected values.

Line range hint 219-237: Enhance Event Handling Tests with Negative Scenarios

Your tests for event handlers are comprehensive. To further strengthen them:

  • Negative Testing: Include scenarios where events should not trigger, ensuring that, for example, 'onTextChange' does not fire when the input value remains the same.
  • Event Order Verification: If the order of event triggers is important, add assertions to verify that events fire in the correct sequence.

Line range hint 239-272: Improve Style Property Assertions

When verifying style changes:

  • Use Specific CSS Assertions: Instead of asserting attributes like font-style as "ITALIC", check the actual CSS styles applied, such as font-style: italic; or font-weight: bold;.
  • Consistency in Emphasis: Ensure that toggling emphasis properties reflects consistently across editor, preview, and deploy modes.

Line range hint 274-294: Validate Border and Box Shadow Changes

For the border and box shadow assertions:

  • CSS Property Checks: Verify the exact CSS values applied after changing the border radius and box shadow settings.
  • Cross-Browser Compatibility: Be aware of how different browsers might render these styles and consider adding tests or notes if discrepancies are expected.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6c13656 and 659af9d.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1 hunks)
  • app/client/src/widgets/PhoneInputWidget/widget/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (4)
app/client/src/widgets/PhoneInputWidget/widget/index.tsx (1)

414-425: ⚠️ Potential issue

Class, let's examine this phone number validation implementation.

The added validation is a good step towards ensuring proper input format, but there are a few learning opportunities here:

  1. The regex pattern could be more restrictive to match real phone number patterns:

    • It currently allows multiple consecutive special characters like "((((" or "+++"
    • It permits numbers to start with special characters other than "+"
  2. The validation message isn't communicated to the user when invalid input is detected.

Here's your homework assignment to improve the implementation:

-    if (/^(?!\s)[\d\s()+-]*$/.test(value)) {
+    const isValidPhoneChar = /^[+]?[\d\s()-]*$/.test(value);
+    if (isValidPhoneChar) {
       this.props.updateWidgetMetaProperty("text", formattedValue, {
         triggerPropertyName: "onTextChanged",
         dynamicString: this.props.onTextChanged,
         event: {
           type: EventType.ON_TEXT_CHANGE,
         },
       });
+    } else if (value) {
+      // Notify user about invalid input
+      this.props.updateWidgetMetaProperty("errorMessage", "Please enter a valid phone number format");
     }

Extra credit: Consider using a more comprehensive phone number validation library like libphonenumber-js which is already imported in this file!

Let's check if the library is being used elsewhere in the codebase:

app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (3)

Line range hint 41-70: Excellent Work on Property Visibility Checks

You've done a splendid job verifying the visibility of the properties in different sections such as Data, Label, Validation, General, Events, Label Styles, and Border Shadows. Looping through the predefined arrays to assert each property's visibility is efficient and promotes maintainability.


Line range hint 72-86: Attention to Entity Management Functions

Great job implementing the renaming, duplication, and deletion functionalities. Ensuring that the widget can be manipulated correctly in both the entity explorer and the property pane is crucial for user experience.


Line range hint 146-171: Strengthen Validation Logic Tests

Your tests for regex validation and the 'Valid' property are well-structured. However, ensure that:

  • Error Messages Are Displayed Appropriately: Verify that the custom error message "Not valid value" appears when invalid input is provided.
  • Dependent Properties Are Handled Correctly: When the 'Valid' property depends on another widget's visibility, consider adding assertions to check the widget's state before and after changes.

Comment on lines +295 to +297
agHelper.WaitUntilToastDisappear("Value Changed");
agHelper.ClearNType(locators._input, "a");
cy.get(locators._toastMsg).should("not.exist");
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

Address Potential Flaky Test

In lines 295-297:

agHelper.WaitUntilToastDisappear("Value Changed");
agHelper.ClearNType(locators._input, "a");
cy.get(locators._toastMsg).should("not.exist");

To ensure the test is not flaky:

  • Explicit Waits for Toast Messages: Replace cy.get(locators._toastMsg).should("not.exist"); with a more robust wait that accounts for potential delays in toast disappearance.
  • Error Handling: Consider adding error handling for cases where the toast might not disappear as expected.

Copy link

github-actions bot commented Nov 8, 2024

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 8, 2024
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants