diff --git a/app/client/src/components/formControls/DropDownControl.test.tsx b/app/client/src/components/formControls/DropDownControl.test.tsx
new file mode 100644
index 0000000000..c603988e15
--- /dev/null
+++ b/app/client/src/components/formControls/DropDownControl.test.tsx
@@ -0,0 +1,114 @@
+import React from "react";
+import { render, screen, waitFor, fireEvent } from "test/testUtils";
+import DropDownControl from "./DropDownControl";
+import { reduxForm } from "redux-form";
+import "@testing-library/jest-dom";
+import { Provider } from "react-redux";
+import configureStore from "redux-mock-store";
+
+const mockStore = configureStore([]);
+
+const initialValues = {
+ actionConfiguration: {
+ testPath: ["option1", "option2"],
+ },
+};
+
+function TestForm(props: any) {
+ return
{props.children}
;
+}
+
+const ReduxFormDecorator = reduxForm({
+ form: "TestForm",
+ initialValues,
+})(TestForm);
+
+const mockOptions = [
+ { label: "Option 1", value: "option1", children: "Option 1" },
+ { label: "Option 2", value: "option2", children: "Option 2" },
+ { label: "Option 3", value: "option3", children: "Option 3" },
+];
+
+const mockAction = {
+ type: "API_ACTION",
+ name: "Test API Action",
+ datasource: {
+ id: "datasource1",
+ name: "Datasource 1",
+ },
+ actionConfiguration: {
+ body: "",
+ headers: [],
+ testPath: ["option1", "option2"],
+ },
+};
+
+const dropDownProps = {
+ options: mockOptions,
+ placeholderText: "Select Columns",
+ isMultiSelect: true,
+ configProperty: "actionConfiguration.testPath",
+ controlType: "PROJECTION",
+ propertyValue: "",
+ label: "Columns",
+ id: "column",
+ formName: "",
+ isValid: true,
+ formValues: mockAction,
+ isLoading: false,
+};
+
+describe("DropDownControl", () => {
+ let store: any;
+
+ beforeEach(() => {
+ store = mockStore({
+ form: {
+ TestForm: {
+ values: initialValues,
+ },
+ },
+ appState: {},
+ });
+ });
+ it("should renders dropdownControl and options properly", async () => {
+ render(
+
+
+
+
+ ,
+ );
+
+ const dropdownSelect = await waitFor(async () =>
+ screen.findByTestId("t--dropdown-actionConfiguration.testPath"),
+ );
+
+ expect(dropdownSelect).toBeInTheDocument();
+
+ const options = screen.getAllByText(/Optio.../);
+ const optionCount = options.length;
+ expect(optionCount).toBe(2);
+ });
+
+ it("should clear all selected options", async () => {
+ render(
+
+
+
+
+ ,
+ );
+
+ const clearAllButton = document.querySelector(".rc-select-clear");
+
+ expect(clearAllButton).toBeInTheDocument();
+
+ fireEvent.click(clearAllButton!);
+
+ await waitFor(() => {
+ const options = screen.queryAllByText(/Option.../);
+ expect(options.length).toBe(0);
+ });
+ });
+});
diff --git a/app/client/src/components/formControls/DropDownControl.tsx b/app/client/src/components/formControls/DropDownControl.tsx
index ca24c9555e..239fdaa289 100644
--- a/app/client/src/components/formControls/DropDownControl.tsx
+++ b/app/client/src/components/formControls/DropDownControl.tsx
@@ -185,6 +185,20 @@ function renderDropdown(
}
};
+ const clearAllOptions = () => {
+ if (!isNil(selectedValue)) {
+ if (props.isMultiSelect) {
+ if (Array.isArray(selectedValue)) {
+ selectedValue = [];
+ props.input?.onChange([]);
+ }
+ } else {
+ selectedValue = "";
+ props.input?.onChange("");
+ }
+ }
+ };
+
if (props.options.length > 0) {
if (props.isMultiSelect) {
const tempSelectedValues: string[] = [];
@@ -233,11 +247,13 @@ function renderDropdown(
return (