Unverified Commit e1031759 authored by Dannon's avatar Dannon Committed by GitHub
Browse files

Merge pull request #13639 from davelopez/fix_quotas_form_field_population

[22.01] Fix FormElement: doesn't populate options for parameters
parents d42a149d fe155b7b
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
import Ui from "mvc/ui/ui-misc";
import ParameterFactory from "./parameters";

jest.mock("app");
jest.mock("mvc/ui/ui-misc", () => ({
    TextSelect: jest.fn(() => {
        return {
            value: jest.fn(),
        };
    }),
    Input: jest.fn(() => {
        return {
            value: jest.fn(),
        };
    }),
}));

describe("ParameterFactory", () => {
    it("should create a TEXT parameter input when no type is specified", async () => {
        const input = {
            id: "type-less parameter",
            type: "",
            value: "initial_value",
        };
        const parameter = new ParameterFactory();
        parameter.create(input);
        expect(Ui.Input).toHaveBeenCalled();
        expect(Ui.TextSelect).not.toHaveBeenCalled();
    });

    it("should create a SELECT parameter input when no type is specified and the input has options", async () => {
        const input = {
            id: "type-less parameter with options",
            type: "",
            value: "initial_value",
            options: [("Option A", "a"), ("Option B", "b")],
        };
        const parameter = new ParameterFactory();
        parameter.create(input);
        expect(Ui.TextSelect).toHaveBeenCalled();
        expect(Ui.Input).not.toHaveBeenCalled();
    });
});
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ export default {
        },
        type: {
            type: String,
            default: "text",
            default: "",
        },
        value: {
            default: null,