Skip to content

Commit

Permalink
fix: bug with different approach and added alerts and count of alert …
Browse files Browse the repository at this point in the history
…for cypress test case
  • Loading branch information
PrasadMadine committed Sep 25, 2024
1 parent c0fde14 commit 98d07b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
import {
agHelper,
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",
{ tags: ["@tag.Widget", "@tag.Select"] },
function () {
before(() => {
entityExplorer.DragDropWidgetNVerify(draggableWidgets.SELECT);
});



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);
});
},
);

20 changes: 14 additions & 6 deletions app/client/src/widgets/SelectWidget/component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ class SelectComponent extends React.Component<
togglePopoverVisibility = () => {
if (this.state.isOpen) {
this.handleOnDropdownClose();
} else {
this.handleOnDropdownOpen();
this.setState(
(prev) => {
return { ...prev, isOpen: false };
},
);
}

this.setState({ isOpen: !this.state.isOpen });
};

handleActiveItemChange = (activeItem: DropdownOption | null) => {
Expand Down Expand Up @@ -188,7 +189,7 @@ class SelectComponent extends React.Component<
};
handleCloseList = () => {
if (this.state.isOpen) {
// this.togglePopoverVisibility();
this.togglePopoverVisibility();
if (!this.props.selectedIndex) return;

return this.handleActiveItemChange(
Expand Down Expand Up @@ -455,7 +456,14 @@ class SelectComponent extends React.Component<
hideCancelIcon={this.props.hideCancelIcon}
isRequired={this.props.isRequired}
spanRef={this.spanRef}
togglePopoverVisibility={this.togglePopoverVisibility}
togglePopoverVisibility={() => {
if(!this.state.isOpen){
this.handleOnDropdownOpen();
this.setState((prev) => {
return { ...prev, isOpen: !prev.isOpen };
});
}
}}
tooltipText={tooltipText}
value={this.props.value?.toString()}
/>
Expand Down

0 comments on commit 98d07b2

Please sign in to comment.