Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ describe(

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


// onFocus
propPane.SelectPlatformFunction("onFocus", "Show alert");
Expand Down
19 changes: 12 additions & 7 deletions app/client/src/widgets/PhoneInputWidget/widget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,18 @@ class PhoneInputWidget extends BaseInputWidget<
"value",
parseIncompletePhoneNumber(formattedValue),
);
this.props.updateWidgetMetaProperty("text", formattedValue, {
triggerPropertyName: "onTextChanged",
dynamicString: this.props.onTextChanged,
event: {
type: EventType.ON_TEXT_CHANGE,
},
});
// 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,
},
});
}
Comment on lines +414 to +425
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.

if (!this.props.isDirty) {
this.props.updateWidgetMetaProperty("isDirty", true);
}
Expand Down