budibase/packages/builder/tests/getComponentInfo.spec.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-08-14 23:11:59 +02:00
import {
2019-08-16 16:48:45 +02:00
getInstanceProps,
2019-08-14 23:11:59 +02:00
getComponentInfo
} from "../src/userInterface/pagesParsing/createProps";
import {
keys, some
} from "lodash/fp";
import { allComponents } from "./testData";
describe("getComponentInfo", () => {
it("should return default props for root component", () => {
const result = getComponentInfo(
allComponents(),
"budibase-components/TextBox");
expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({
2019-08-22 08:57:56 +02:00
_component: "budibase-components/TextBox",
2019-08-14 23:11:59 +02:00
size: "",
isPassword: false,
placeholder: "",
label:""
});
});
it("should return no inherited for root component", () => {
const result = getComponentInfo(
allComponents(),
"budibase-components/TextBox");
expect(result.inheritedProps).toEqual([]);
});
2019-08-16 16:48:45 +02:00
it("getInstanceProps should set supplied props on top of default props", () => {
const result = getInstanceProps(
2019-08-14 23:11:59 +02:00
getComponentInfo(
allComponents(),
"budibase-components/TextBox"),
{size:"small"});
expect(result).toEqual({
2019-08-22 08:57:56 +02:00
_component: "budibase-components/TextBox",
2019-08-14 23:11:59 +02:00
size: "small",
isPassword: false,
placeholder: "",
label:""
});
});
it("should return correct props for derived component", () => {
const result = getComponentInfo(
allComponents(),
"common/SmallTextbox");
expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({
2019-08-22 08:57:56 +02:00
_component: "common/SmallTextbox",
2019-08-14 23:11:59 +02:00
size: "small",
isPassword: false,
placeholder: "",
label:""
});
});
it("should return correct props for twice derived component", () => {
const result = getComponentInfo(
allComponents(),
"common/PasswordBox");
expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({
2019-08-22 08:57:56 +02:00
_component: "common/PasswordBox",
2019-08-14 23:11:59 +02:00
size: "small",
isPassword: true,
placeholder: "",
label:""
});
});
it("should list inheirted props as those that are defined in ancestor, derived components", () => {
const result = getComponentInfo(
allComponents(),
"common/PasswordBox");
// size is inherited from SmallTextbox
expect(result.inheritedProps).toEqual(["size"]);
});
it("should list unset props as those that are only defined in root", () => {
const result = getComponentInfo(
allComponents(),
"common/PasswordBox");
expect(result.unsetProps).toEqual([
"placeholder", "label"]);
});
})