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

96 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-08-14 23:11:59 +02:00
import {
2019-08-16 16:48:45 +02:00
getInstanceProps,
getScreenInfo ,
getComponentInfo
2019-08-14 23:11:59 +02:00
} from "../src/userInterface/pagesParsing/createProps";
import {
keys, some, find
2019-08-14 23:11:59 +02:00
} from "lodash/fp";
import { componentsAndScreens } from "./testData";
2019-08-14 23:11:59 +02:00
describe("getComponentInfo", () => {
it("should return default props for root component", () => {
const result = getComponentInfo(
componentsAndScreens().components,
2019-08-14 23:11:59 +02:00
"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:""
});
});
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(
componentsAndScreens().components,
2019-08-14 23:11:59 +02:00
"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:""
});
});
});
2019-08-14 23:11:59 +02:00
describe("getScreenInfo", () => {
const getScreen = (screens, name) =>
find(s => s.name === name)(screens);
it("should return correct props for screen", () => {
const {components, screens} = componentsAndScreens();
const result = getScreenInfo(
components,
getScreen(screens, "common/SmallTextbox"));
2019-08-14 23:11:59 +02:00
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 {components, screens} = componentsAndScreens();
const result = getScreenInfo(
components,
getScreen(screens, "common/PasswordBox"));
2019-08-14 23:11:59 +02:00
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 unset props as those that are only defined in root", () => {
const {components, screens} = componentsAndScreens();
const result = getScreenInfo(
components,
getScreen(screens, "common/PasswordBox"));
2019-08-14 23:11:59 +02:00
expect(result.unsetProps).toEqual([
"placeholder", "label"]);
});
})