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

fix: add regex check on phone number change #34715

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

SaiCharanChetpelly31
Copy link
Contributor

@SaiCharanChetpelly31 SaiCharanChetpelly31 commented Jul 4, 2024

Fixes - 25911

Summary by CodeRabbit

  • New Features

    • Added validation for phone input to ensure only numeric values are accepted.
  • Tests

    • Enhanced test scenario to validate the lifecycle of the toast message after user input, ensuring it disappears appropriately.

Copy link
Contributor

coderabbitai bot commented Jul 4, 2024

Walkthrough

The latest changes enhance the phone input widget by adding a validation step that checks against a regex pattern before updating the text property. Additionally, test modifications ensure that the system waits for a toast message to disappear before clearing non-numeric values from the phone input field, thereby improving the robustness of the input handling.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/... Added functionality to wait for a toast message to disappear before clearing non-numeric input.
app/client/src/widgets/PhoneInputWidget/widget/index.tsx Introduced regex pattern validation before updating the text property in PhoneInputWidget

Poem

🌟 Within the widget, checks now run,
Regex dances, validation begun.
In the test, we wait, for a toast to fade,
Cleaning numbers in a thoughtful cascade.
Progress shines, the app now bright,
With every change, it reaches new height.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b0963bb and 631facf.

📒 Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (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 (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1)

295-297: Well done, class! These changes are a step in the right direction.

I'm pleased to see the improvements you've made to the test case. Let's break down what you've done:

  1. You've added a wait for the toast message to disappear, which is a good practice. This ensures that the test doesn't proceed until the UI is in a stable state.
  2. You've included an additional test step to verify that non-numeric input doesn't trigger the toast message. This is an excellent way to cover edge cases.

These changes make the test more robust and reliable. Keep up the good work!


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

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

295-297: Avoid using cy.wait in Cypress tests.

Using cy.wait can lead to flaky tests. Instead, use dynamic waits to ensure the toast message disappears before proceeding.

Consider using cy.get() with should('not.exist') to wait for the toast message to disappear.

-  agHelper.Sleep(2000);
+  cy.get(locators._toastMsg).should('not.exist');
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6c48a39 and b0963bb.

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/**/*.*: Follow best practices for Cypress code and e2e automation.
Avoid using cy.wait.
Use variables for locators, not strings.
Use data-* attributes for selectors; avoid Xpaths and CSS attributes.
Avoid selectors like .btn.submit or button[type=submit].
Perform logins via API with LoginFromAPI.
Only interact with controlled sites/servers.
Ensure tests can run with it.only and are independent.
Use before, beforeEach, after, afterEach correctly; clean state before tests.
Check new specs for flakiness by running them 10 times on CI.
Use multiple assertions; don't treat Cypress as unit tests.
Use constants for strings.
Include datasource operations in before hooks.

Learnings (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/PhoneInput/PhoneInput_Part2_spec.ts (1)
Learnt from: Aishwarya-U-R
PR: appsmithorg/appsmith#29405
File: app/client/cypress/e2e/Regression/ClientSide/Widgets/Radio/Radio2_spec.ts:404-407
Timestamp: 2023-12-08T09:01:51.841Z
Learning: The `Radio2_spec.ts` file is not part of the initial phase for the removal of static waits in the pull request titled "test: Cypress | Replace static with Dynamic waits - Part 1".
Additional comments not posted (1)
app/client/src/widgets/PhoneInputWidget/widget/index.tsx (1)

411-419: Ensure the regex pattern is appropriate for phone number validation.

The regex pattern /^(?!\s)[\d\s()+-]*$/ allows digits, spaces, parentheses, plus signs, and hyphens. Ensure this pattern meets the validation requirements for phone numbers.

@SaiCharanChetpelly31
Copy link
Contributor Author

HI @ApekshaBhosale

I hope this message finds you well.
As I am at the initial stage of contributing to the project, I am eager to receive your feedback and make any necessary adjustments to align with the project's standards.

Your review is highly valued, and I am committed to ensuring this contribution meets our collective goals. I would greatly appreciate it if you could take some time to review the PR at your earliest convenience.

Thank you for your attention to this matter, and I look forward to your feedback.

@jsartisan jsartisan self-requested a review July 15, 2024 11:05
type: EventType.ON_TEXT_CHANGE,
},
});
if (/^(?!\s)[\d\s()+-]*$/.test(value)) {
Copy link
Contributor

@jsartisan jsartisan Jul 17, 2024

Choose a reason for hiding this comment

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

@SaiCharanChetpelly31 can you write a comment here what this regex actually means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsartisan I added a comment explaining regex i used.

@SaiCharanChetpelly31
Copy link
Contributor Author

Hi @jsartisan Gentle Remainder: Thanks for reviewing.I have addressed review comment. Can you please review it?
Thanks in Advance.

@ramsaptami
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10041082887.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34715.
recreate: .

@ramsaptami
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10061534208.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34715.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-34715.dp.appsmith.com

@ramsaptami ramsaptami self-requested a review July 23, 2024 15:30
@SaiCharanChetpelly31
Copy link
Contributor Author

Hi @ramsaptami Could you please merge this PR if everything is ok?

@ramsaptami
Copy link
Contributor

@jsartisan please review and merge if everything is ok

@sagar-qa007
Copy link
Contributor

@rahulbarwal Can you please check this ?

@SaiCharanChetpelly31 SaiCharanChetpelly31 force-pushed the fix/Issue_25911_onTextChanged_phone_input_widget branch from 6eb0a71 to 631facf Compare September 27, 2024 05:48
@ankitakinger ankitakinger removed their request for review September 27, 2024 06:08
@KelvinOm KelvinOm removed request for KelvinOm and a team September 27, 2024 11:01
@ayushpahwa ayushpahwa removed their request for review September 30, 2024 05:55
@nidhi-nair nidhi-nair removed the request for review from a team November 4, 2024 13:04
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.

4 participants