2019-08-14 23:11:59 +02:00
|
|
|
import {
|
2019-08-16 16:48:45 +02:00
|
|
|
getInstanceProps,
|
2020-01-18 00:06:42 +01:00
|
|
|
getScreenInfo ,
|
|
|
|
getComponentInfo
|
2019-08-14 23:11:59 +02:00
|
|
|
} from "../src/userInterface/pagesParsing/createProps";
|
|
|
|
import {
|
2020-01-18 00:06:42 +01:00
|
|
|
keys, some, find
|
2019-08-14 23:11:59 +02:00
|
|
|
} from "lodash/fp";
|
2020-01-18 00:06:42 +01:00
|
|
|
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(
|
2020-01-18 00:06:42 +01:00
|
|
|
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(
|
2020-01-18 00:06:42 +01:00
|
|
|
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:""
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2020-01-18 00:06:42 +01:00
|
|
|
});
|
2019-08-14 23:11:59 +02:00
|
|
|
|
2020-01-18 00:06:42 +01: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", () => {
|
2020-01-18 00:06:42 +01:00
|
|
|
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", () => {
|
2020-01-18 00:06:42 +01:00
|
|
|
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"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
})
|