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:Ensure alert message triggers only once when onDropdownClose in select widget #34812

Merged
Show file tree
Hide file tree
Changes from 8 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
@@ -0,0 +1,53 @@
import {
agHelper,
draggableWidgets,
deployMode,
entityExplorer,
locators,
propPane,
} from "../../../../../support/Objects/ObjectsCore";

// Issue link: https://github.com/appsmithorg/appsmith/issues/26696
describe(
"Select widget tests validating OnDropdownClose events are rendering show alert only once",
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
{ tags: ["@tag.Widget", "@tag.Select"] },
function () {
before(() => {
entityExplorer.DragDropWidgetNVerify(draggableWidgets.SELECT);
});

it("Validate OnDropdownClose events are rendering show alert only once", () => {
propPane.EnterJSContext(
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
"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!");
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
cy.get("#ToastId12 > .Toastify__toast-body")
.contains("Dropdown closed!")
.should("have.length", 1);
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
});
},
);
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 10 additions & 3 deletions app/client/src/widgets/SelectWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ class SelectComponent extends React.Component<
}
};

togglePopoverVisibility = () => {
togglePopoverVisibilityFromButton = () => {
this.togglePopoverVisibility(true);
};

togglePopoverVisibility = (isButtonClick = false) => {
// This is an edge case, this method gets called twice if user closes it by clicking on the `SelectButton`
// which in turn triggers handleOnDropdownClose twice, to solve we have this exception to tell if click event is from button
if (isButtonClick && this.state.isOpen) return;

if (this.state.isOpen) {
this.handleOnDropdownClose();
} else {
prasad-madine marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -189,7 +197,6 @@ class SelectComponent extends React.Component<
handleCloseList = () => {
if (this.state.isOpen) {
this.togglePopoverVisibility();

if (!this.props.selectedIndex) return;

return this.handleActiveItemChange(
Expand Down Expand Up @@ -456,7 +463,7 @@ class SelectComponent extends React.Component<
hideCancelIcon={this.props.hideCancelIcon}
isRequired={this.props.isRequired}
spanRef={this.spanRef}
togglePopoverVisibility={this.togglePopoverVisibility}
togglePopoverVisibility={this.togglePopoverVisibilityFromButton}
tooltipText={tooltipText}
value={this.props.value?.toString()}
/>
Expand Down