2019-08-14 23:11:59 +02:00
|
|
|
import {
|
2020-02-03 10:24:25 +01:00
|
|
|
getInstanceProps,
|
|
|
|
getScreenInfo,
|
|
|
|
getComponentInfo,
|
|
|
|
} from "../src/userInterface/pagesParsing/createProps"
|
|
|
|
import { keys, some, find } from "lodash/fp"
|
|
|
|
import { componentsAndScreens } from "./testData"
|
2019-08-14 23:11:59 +02:00
|
|
|
|
|
|
|
describe("getComponentInfo", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
it("should return default props for root component", () => {
|
|
|
|
const result = getComponentInfo(
|
|
|
|
componentsAndScreens().components,
|
|
|
|
"budibase-components/TextBox"
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result.errors).toEqual([])
|
|
|
|
expect(result.fullProps).toEqual({
|
|
|
|
_component: "budibase-components/TextBox",
|
|
|
|
size: "",
|
|
|
|
isPassword: false,
|
|
|
|
placeholder: "",
|
|
|
|
label: "",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it("getInstanceProps should set supplied props on top of default props", () => {
|
|
|
|
const result = getInstanceProps(
|
|
|
|
getComponentInfo(
|
|
|
|
componentsAndScreens().components,
|
|
|
|
"budibase-components/TextBox"
|
|
|
|
),
|
|
|
|
{ size: "small" }
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result).toEqual({
|
|
|
|
_component: "budibase-components/TextBox",
|
|
|
|
size: "small",
|
|
|
|
isPassword: false,
|
|
|
|
placeholder: "",
|
|
|
|
label: "",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-08-14 23:11:59 +02:00
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
describe("getScreenInfo", () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result.errors).toEqual([])
|
|
|
|
expect(result.fullProps).toEqual({
|
|
|
|
_component: "common/SmallTextbox",
|
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result.errors).toEqual([])
|
|
|
|
expect(result.fullProps).toEqual({
|
|
|
|
_component: "common/PasswordBox",
|
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(result.unsetProps).toEqual(["placeholder", "label"])
|
|
|
|
})
|
|
|
|
})
|