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

chore: external merge request from Contributor #36575

Draft
wants to merge 9 commits into
base: release
Choose a base branch
from

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Sep 27, 2024

Description

Issue: #26696
Original PR: #34812
EE PR:

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=

🔍 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

    • Introduced a new test suite for the Select widget to validate event handling and alert displays.
  • Bug Fixes

    • Improved the popover visibility toggle logic to prevent redundant calls and ensure proper functionality when triggered by a button click.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

This pull request introduces enhancements to the Select widget in the application. It adds a new test suite to validate event handling for dropdown interactions, ensuring alerts are displayed correctly. Additionally, modifications to the SelectComponent class improve the logic for toggling the visibility of the popover, preventing redundant actions when triggered by button clicks.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/Select/Select4_spec.ts New test suite for Select widget validating onDropdownClose, onDropdownOpen, and onOptionChange events.
app/client/src/widgets/SelectWidget/component/index.tsx Added togglePopoverVisibilityFromButton method and updated togglePopoverVisibility method to prevent redundant calls.

Assessment against linked issues

Objective Addressed Explanation
Ensure alert message triggers only once when onDropdownClose (Issue #34812)

Possibly related PRs

  • chore: fix select1 spec #36228: Changes in Select1_spec.ts involve testing functionality related to selecting options, similar to the event handling tests for the Select widget in Select4_spec.ts.

Suggested labels

skip-changelog

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007

🎉 In the land of dropdowns, where options reside,
Alerts now ring true, no more double-tide!
With tests in the mix, and popovers refined,
The Select widget shines, perfectly aligned!
So let’s celebrate this code, with joy and cheer,
For every click and toggle, brings us all near! 🎈


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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 27, 2024
@rahulbarwal rahulbarwal marked this pull request as draft September 27, 2024 05:45
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 (1)
app/client/src/widgets/SelectWidget/component/index.tsx (1)

82-89: Attention, students! Let's analyze this method update.

The modifications to togglePopoverVisibility show great problem-solving skills. By adding the isButtonClick parameter and the conditional check, we've addressed an edge case where the method could be called twice when closing via button click. This is a prime example of defensive programming.

However, let's consider a small enhancement:

Consider adding a comment explaining the edge case. This will help future developers understand the reasoning behind this check. Here's a suggested addition:

 togglePopoverVisibility = (isButtonClick = false) => {
+  // Edge case: Prevent double-triggering when closing via button click
   if (isButtonClick && this.state.isOpen) return;

   // ... rest of the method
 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fc9a594 and 8edc030.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/Select/Select4_spec.ts (1 hunks)
  • app/client/src/widgets/SelectWidget/component/index.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/Select/Select4_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/cypress/e2e/Regression/ClientSide/Widgets/Select/Select4_spec.ts (1)

1-18: Well done on the imports and file structure, class!

The imports are neatly organized, and you've used tags for better test categorization. Good job linking the related issue too! This sets a great foundation for our test.

app/client/src/widgets/SelectWidget/component/index.tsx (3)

78-80: Well done, class! Let's examine this new method.

The addition of togglePopoverVisibilityFromButton is a smart move. It acts as a specialized wrapper for togglePopoverVisibility, allowing us to distinguish button-triggered toggles. This is an excellent example of the Single Responsibility Principle in action.


466-466: Class, observe this subtle yet important change in the render method.

Excellent work on updating the togglePopoverVisibility prop to use the new togglePopoverVisibilityFromButton method. This change ensures that button clicks are handled with the new logic we just reviewed. It's a perfect example of how small changes can have a big impact on the overall functionality of our code.


Line range hint 1-524: Class dismissed! Let's recap our code review lesson.

Today, we've examined some excellent improvements to our SelectComponent. The changes we've reviewed effectively address the issue of multiple alert displays when closing the dropdown, as outlined in our PR objectives.

Here's a summary of what we've learned:

  1. We added a new method togglePopoverVisibilityFromButton to handle button-specific toggle events.
  2. We updated togglePopoverVisibility to prevent redundant calls in edge cases.
  3. We modified the render method to use our new button-specific toggle method.

These changes demonstrate good problem-solving skills and adherence to solid programming principles. Remember, students, even small, focused changes can significantly improve the functionality and user experience of our applications.

Keep up the good work, and always strive for clear, efficient, and well-documented code!

Comment on lines +19 to +51
it("Validate OnDropdownClose events are rendering show alert only once", () => {
propPane.EnterJSContext(
"onDropdownClose",
"{{showAlert('Dropdown closed!','success')}}",
true,
);
propPane.ToggleJSMode("onDropdownClose", false);
propPane.EnterJSContext(
"onDropdownOpen",
"{{showAlert('Dropdown opened!','success')}}",
true,
);
propPane.ToggleJSMode("onDropdownOpen", false);
propPane.EnterJSContext(
"onOptionChange",
"{{showAlert('Option changed!','success')}}",
true,
);
propPane.ToggleJSMode("onOptionChange", false);
deployMode.DeployApp(locators._widgetInDeployed(draggableWidgets.SELECT));
agHelper.GetNClick(locators._widgetInDeployed(draggableWidgets.SELECT));
agHelper.ValidateToastMessage("Dropdown opened!");
agHelper.AssertElementVisibility(
locators._selectOptionValue("Red"),
true,
);
agHelper.GetNClick(locators._selectOptionValue("Red"));
agHelper.ValidateToastMessage("Option changed!");
agHelper.ValidateToastMessage("Dropdown closed!");
cy.get("#ToastId12 > .Toastify__toast-body")
.contains("Dropdown closed!")
.should("have.length", 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

Good effort on the test case, but let's make some improvements!

Your test case does a great job of covering the main functionality of the Select widget. However, there are a few areas where we can make it even better:

  1. Instead of using cy.get('#ToastId12'), let's use a more robust selector. Remember, we want to avoid direct element selection and use data attributes instead.

  2. We should use locator variables for all our selectors to make the test more maintainable.

  3. The toast ID (#ToastId12) might change, making our test brittle. Let's find a more stable way to assert the toast message.

Here's how we can improve it:

it("Validate OnDropdownClose events are rendering show alert only once", () => {
  // ... (previous code remains the same)

  // Use a data attribute for the toast
  agHelper.AssertElementVisibility(locators._toastMsg, true);
  agHelper.ValidateToastMessage("Dropdown closed!");

  // Use a more robust way to check for a single occurrence of the message
  cy.get(locators._toastMsg)
    .contains("Dropdown closed!")
    .should("have.length", 1);
});

Remember, class, using data attributes and locator variables makes our tests more robust and easier to maintain. Keep up the good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants