PromucFlow_constructor/app/client/src/components/propertyControls/DropDownControl.test.tsx
Aswath K ef2e3b370e
fix: JS toggle issue with Numeric Input & multi select dropdown controls (#14892)
* fix: JS toggle issue for NumericInputControl

* fix: DropdownControl's JS toggle for multi select
2022-07-07 05:37:50 +00:00

89 lines
2.4 KiB
TypeScript

import { EditorTheme } from "components/editorComponents/CodeEditor/EditorConfig";
import { noop } from "lodash";
import DropDownControl, { DropDownControlProps } from "./DropDownControl";
const requiredParams: DropDownControlProps = {
evaluatedValue: undefined,
widgetProperties: undefined,
parentPropertyName: "",
parentPropertyValue: undefined,
placeholderText: "",
searchPlaceholderText: "",
additionalDynamicData: {},
label: "",
propertyName: "",
propertyValue: "1",
controlType: "",
isBindProperty: false,
isTriggerProperty: false,
openNextPanel: noop,
deleteProperties: noop,
theme: EditorTheme.LIGHT,
};
describe("DropDownControl.canDisplayValue", () => {
const options = [
{
label: "0",
value: 0,
},
{
label: "1",
value: 1,
},
{
label: "2",
value: 2,
},
{
label: "A",
value: "A",
},
];
const config = { ...requiredParams, options };
it("Should return true when a value in the option is passed", () => {
expect(DropDownControl.canDisplayValueInUI(config, "0")).toEqual(true);
expect(DropDownControl.canDisplayValueInUI(config, "1")).toEqual(true);
expect(DropDownControl.canDisplayValueInUI(config, "A")).toEqual(true);
});
it("Should return false when a value that is not in the option is passed", () => {
expect(DropDownControl.canDisplayValueInUI(config, "6")).toEqual(false);
});
});
describe("DropDownControl[isMultiSelect].canDisplayValue", () => {
const options = [
{
label: "0",
value: 0,
},
{
label: "1",
value: 1,
},
{
label: "2",
value: 2,
},
{
label: "A",
value: "A",
},
];
const config = { ...requiredParams, options, isMultiSelect: true };
it("Should return true when a value in the option is passed", () => {
expect(DropDownControl.canDisplayValueInUI(config, "[0]")).toEqual(true);
expect(DropDownControl.canDisplayValueInUI(config, "[1]")).toEqual(true);
expect(DropDownControl.canDisplayValueInUI(config, '["A"]')).toEqual(true);
});
it("Should return false when a value that is not in the option is passed", () => {
expect(DropDownControl.canDisplayValueInUI(config, "[6]")).toEqual(false);
});
it("Should return false when an invalid option is passed", () => {
expect(DropDownControl.canDisplayValueInUI(config, "0")).toEqual(false);
});
});