1
0
Fork 0
mirror of synced 2024-08-18 19:41:30 +12:00
budibase/packages/builder/tests/getComponentInfo.spec.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2019-08-15 09:11:59 +12:00
import {
2019-08-17 02:48:45 +12:00
getInstanceProps,
2019-08-15 09:11:59 +12: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 18:57:56 +12:00
_component: "budibase-components/TextBox",
2019-08-15 09:11:59 +12: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-17 02:48:45 +12:00
it("getInstanceProps should set supplied props on top of default props", () => {
const result = getInstanceProps(
2019-08-15 09:11:59 +12:00
getComponentInfo(
allComponents(),
"budibase-components/TextBox"),
{size:"small"});
expect(result).toEqual({
2019-08-22 18:57:56 +12:00
_component: "budibase-components/TextBox",
2019-08-15 09:11:59 +12: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 18:57:56 +12:00
_component: "common/SmallTextbox",
2019-08-15 09:11:59 +12: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 18:57:56 +12:00
_component: "common/PasswordBox",
2019-08-15 09:11:59 +12: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"]);
});
})