1
0
Fork 0
mirror of synced 2024-07-13 10:15:49 +12:00
budibase/packages/builder/tests/binding.spec.js

130 lines
3.2 KiB
JavaScript
Raw Normal View History

2020-08-04 22:10:02 +12:00
import fetchBindableProperties from "../src/builderStore/fetchBindableProperties"
2020-08-04 02:06:51 +12:00
describe("fetch bindable properties", () => {
it("should return bindable properties from screen components", () => {
2020-08-04 22:10:02 +12:00
const result = fetchBindableProperties({
2020-08-04 02:06:51 +12:00
componentInstanceId: "heading-id",
...testData()
})
const componentBinding = result.find(r => r.instance._id === "search-input-id")
2020-08-04 22:10:02 +12:00
console.debug(componentBinding)
console.debug("result:" + JSON.stringify(result))
2020-08-04 02:06:51 +12:00
expect(componentBinding).toBeDefined()
expect(componentBinding.type).toBe("instance")
expect(componentBinding.runtimeBinding).toBe("state.search-input-id.value")
})
it("should not return bindable components when not in their context", () => {
2020-08-04 22:10:02 +12:00
const result = fetchBindableProperties({
componentInstanceId: "heading-id",
...testData()
})
const componentBinding = result.find(r => r.instance._id === "list-item-input-id")
expect(componentBinding).not.toBeDefined()
2020-08-04 02:06:51 +12:00
})
it("should return model schema, when inside a context", () => {
})
it("should return model schema, for grantparent context", () => {
})
it("should return bindable component props, from components in same context", () => {
})
it("should not return model props from child context", () => {
})
})
const testData = () => {
const screen = {
instanceName: "test screen",
name: "screen-id",
route: "/",
props: {
_id:"screent-root-id",
_component: "@budibase/standard-components/container",
_children: [
{
_id: "heading-id",
_instanceName: "list item heading",
_component: "@budibase/standard-components/heading",
text: "Screen Title"
},
{
_id: "search-input-id",
_instanceName: "Search Input",
_component: "@budibase/standard-components/input",
value: "search phrase"
},
{
_id: "list-id",
_component: "@budibase/standard-components/list",
_instanceName: "list-name",
model: "test-model-id",
_children: [
{
_id: "list-item-heading-id",
_instanceName: "list item heading",
_component: "@budibase/standard-components/heading",
text: "hello"
2020-08-04 22:10:02 +12:00
},
{
_id: "list-item-input-id",
_instanceName: "List Item Input",
_component: "@budibase/standard-components/input",
value: "list item"
},
2020-08-04 02:06:51 +12:00
]
},
]
}
}
const models = [{
2020-08-04 22:10:02 +12:00
_id: "test-model-id",
2020-08-04 02:06:51 +12:00
name: "Test Model",
schema: {
name: {
type: "string"
},
description: {
type: "string"
}
}
}]
const components = {
"@budibase/standard-components/container" : {
props: {},
},
"@budibase/standard-components/list" : {
context: "model",
props: {
model: "string"
},
},
"@budibase/standard-components/input" : {
bindable: "value",
props: {
value: "string"
},
},
"@budibase/standard-components/heading" : {
props: {
text: "string"
},
},
}
return { screen, models, components }
}