2020-08-04 12:10:02 +02:00
|
|
|
import fetchBindableProperties from "../src/builderStore/fetchBindableProperties"
|
2020-08-27 11:10:35 +02:00
|
|
|
|
2020-08-03 16:06:51 +02:00
|
|
|
describe("fetch bindable properties", () => {
|
|
|
|
it("should return bindable properties from screen components", () => {
|
2020-08-04 12:10:02 +02:00
|
|
|
const result = fetchBindableProperties({
|
2020-08-03 16:06:51 +02:00
|
|
|
componentInstanceId: "heading-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const componentBinding = result.find(
|
|
|
|
r => r.instance._id === "search-input-id" && r.type === "instance"
|
|
|
|
)
|
2020-08-03 16:06:51 +02:00
|
|
|
expect(componentBinding).toBeDefined()
|
|
|
|
expect(componentBinding.type).toBe("instance")
|
2020-11-30 17:14:45 +01:00
|
|
|
expect(componentBinding.runtimeBinding).toBe("search-input-id")
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should not return bindable components when not in their context", () => {
|
2020-08-04 12:10:02 +02:00
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "heading-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 12:10:02 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const componentBinding = result.find(
|
|
|
|
r => r.instance._id === "list-item-input-id"
|
|
|
|
)
|
2020-08-04 12:10:02 +02:00
|
|
|
expect(componentBinding).not.toBeDefined()
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
2020-10-09 19:49:23 +02:00
|
|
|
it("should return table schema, when inside a context", () => {
|
2020-08-04 17:11:46 +02:00
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "list-item-input-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 17:11:46 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const contextBindings = result.filter(
|
|
|
|
r => r.instance._id === "list-id" && r.type === "context"
|
|
|
|
)
|
|
|
|
// 2 fields + _id + _rev
|
2020-09-11 10:29:23 +02:00
|
|
|
expect(contextBindings.length).toBe(4)
|
2020-10-13 12:27:18 +02:00
|
|
|
|
|
|
|
const namebinding = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "list-id.name"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(namebinding).toBeDefined()
|
2020-10-13 12:19:34 +02:00
|
|
|
expect(namebinding.readableBinding).toBe("list-name.Test Table.name")
|
2020-10-13 12:27:18 +02:00
|
|
|
|
|
|
|
const descriptionbinding = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "list-id.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(descriptionbinding).toBeDefined()
|
2020-10-13 12:27:18 +02:00
|
|
|
expect(descriptionbinding.readableBinding).toBe(
|
2020-10-13 18:27:46 +02:00
|
|
|
"list-name.Test Table.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
|
|
|
|
2020-11-30 17:14:45 +01:00
|
|
|
const idbinding = contextBindings.find(
|
|
|
|
b => b.runtimeBinding === "list-id._id"
|
|
|
|
)
|
2020-09-11 10:29:23 +02:00
|
|
|
expect(idbinding).toBeDefined()
|
2020-10-13 12:19:34 +02:00
|
|
|
expect(idbinding.readableBinding).toBe("list-name.Test Table._id")
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
2020-10-09 19:49:23 +02:00
|
|
|
it("should return table schema, for grantparent context", () => {
|
2020-08-04 17:11:46 +02:00
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "child-list-item-input-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 17:11:46 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const contextBindings = result.filter(r => r.type === "context")
|
2020-10-09 19:49:23 +02:00
|
|
|
// 2 fields + _id + _rev ... x 2 tables
|
2020-09-11 10:29:23 +02:00
|
|
|
expect(contextBindings.length).toBe(8)
|
2020-10-13 12:27:18 +02:00
|
|
|
|
|
|
|
const namebinding_parent = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "list-id.name"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(namebinding_parent).toBeDefined()
|
2020-10-13 12:19:34 +02:00
|
|
|
expect(namebinding_parent.readableBinding).toBe("list-name.Test Table.name")
|
2020-10-13 12:27:18 +02:00
|
|
|
|
|
|
|
const descriptionbinding_parent = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "list-id.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(descriptionbinding_parent).toBeDefined()
|
2020-10-13 12:27:18 +02:00
|
|
|
expect(descriptionbinding_parent.readableBinding).toBe(
|
2020-10-13 18:27:46 +02:00
|
|
|
"list-name.Test Table.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const namebinding_own = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "child-list-id.name"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(namebinding_own).toBeDefined()
|
2020-10-13 12:27:18 +02:00
|
|
|
expect(namebinding_own.readableBinding).toBe(
|
2020-10-13 18:27:46 +02:00
|
|
|
"child-list-name.Test Table.name"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const descriptionbinding_own = contextBindings.find(
|
2020-11-30 17:14:45 +01:00
|
|
|
b => b.runtimeBinding === "child-list-id.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(descriptionbinding_own).toBeDefined()
|
2020-10-13 12:27:18 +02:00
|
|
|
expect(descriptionbinding_own.readableBinding).toBe(
|
2020-10-13 18:27:46 +02:00
|
|
|
"child-list-name.Test Table.description"
|
2020-10-13 12:27:18 +02:00
|
|
|
)
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it("should return bindable component props, from components in same context", () => {
|
2020-08-04 17:11:46 +02:00
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "list-item-heading-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 17:11:46 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const componentBinding = result.find(
|
|
|
|
r => r.instance._id === "list-item-input-id" && r.type === "instance"
|
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(componentBinding).toBeDefined()
|
2020-11-30 17:14:45 +01:00
|
|
|
expect(componentBinding.runtimeBinding).toBe("list-item-input-id")
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
2020-08-04 17:11:46 +02:00
|
|
|
it("should not return components from child context", () => {
|
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "list-item-heading-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 17:11:46 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const componentBinding = result.find(
|
|
|
|
r =>
|
|
|
|
r.instance._id === "child-list-item-input-id" && r.type === "instance"
|
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(componentBinding).not.toBeDefined()
|
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
|
2020-08-04 17:11:46 +02:00
|
|
|
it("should return bindable component props, from components in same context (when nested context)", () => {
|
|
|
|
const result = fetchBindableProperties({
|
|
|
|
componentInstanceId: "child-list-item-heading-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
...testData(),
|
2020-08-04 17:11:46 +02:00
|
|
|
})
|
2020-10-13 12:27:18 +02:00
|
|
|
const componentBinding = result.find(
|
|
|
|
r =>
|
|
|
|
r.instance._id === "child-list-item-input-id" && r.type === "instance"
|
|
|
|
)
|
2020-08-04 17:11:46 +02:00
|
|
|
expect(componentBinding).toBeDefined()
|
2020-10-13 12:27:18 +02:00
|
|
|
})
|
2020-08-03 16:06:51 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const testData = () => {
|
|
|
|
const screen = {
|
|
|
|
instanceName: "test screen",
|
|
|
|
name: "screen-id",
|
|
|
|
route: "/",
|
|
|
|
props: {
|
2020-10-13 12:27:18 +02:00
|
|
|
_id: "screent-root-id",
|
2020-08-03 16:06:51 +02:00
|
|
|
_component: "@budibase/standard-components/container",
|
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_id: "heading-id",
|
|
|
|
_instanceName: "list item heading",
|
|
|
|
_component: "@budibase/standard-components/heading",
|
2020-10-13 12:27:18 +02:00
|
|
|
text: "Screen Title",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: "search-input-id",
|
|
|
|
_instanceName: "Search Input",
|
|
|
|
_component: "@budibase/standard-components/input",
|
2020-10-13 12:27:18 +02:00
|
|
|
value: "search phrase",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: "list-id",
|
|
|
|
_component: "@budibase/standard-components/list",
|
|
|
|
_instanceName: "list-name",
|
2020-10-13 18:27:46 +02:00
|
|
|
table: {
|
|
|
|
type: "table",
|
|
|
|
tableId: "test-table-id",
|
|
|
|
label: "Test Table",
|
|
|
|
name: "all_test-table-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
},
|
2020-08-03 16:06:51 +02:00
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_id: "list-item-heading-id",
|
|
|
|
_instanceName: "list item heading",
|
|
|
|
_component: "@budibase/standard-components/heading",
|
2020-10-13 12:27:18 +02:00
|
|
|
text: "hello",
|
2020-08-04 12:10:02 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: "list-item-input-id",
|
|
|
|
_instanceName: "List Item Input",
|
|
|
|
_component: "@budibase/standard-components/input",
|
2020-10-13 12:27:18 +02:00
|
|
|
value: "list item",
|
2020-08-04 12:10:02 +02:00
|
|
|
},
|
2020-08-04 17:11:46 +02:00
|
|
|
{
|
|
|
|
_id: "child-list-id",
|
|
|
|
_component: "@budibase/standard-components/list",
|
|
|
|
_instanceName: "child-list-name",
|
2020-10-13 18:27:46 +02:00
|
|
|
table: {
|
|
|
|
type: "table",
|
|
|
|
tableId: "test-table-id",
|
|
|
|
label: "Test Table",
|
|
|
|
name: "all_test-table-id",
|
2020-10-13 12:27:18 +02:00
|
|
|
},
|
2020-08-04 17:11:46 +02:00
|
|
|
_children: [
|
|
|
|
{
|
|
|
|
_id: "child-list-item-heading-id",
|
|
|
|
_instanceName: "child list item heading",
|
|
|
|
_component: "@budibase/standard-components/heading",
|
2020-10-13 12:27:18 +02:00
|
|
|
text: "hello",
|
2020-08-04 17:11:46 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: "child-list-item-input-id",
|
|
|
|
_instanceName: "Child List Item Input",
|
|
|
|
_component: "@budibase/standard-components/input",
|
2020-10-13 12:27:18 +02:00
|
|
|
value: "child list item",
|
2020-08-04 17:11:46 +02:00
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
],
|
2020-08-04 17:11:46 +02:00
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
],
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
],
|
|
|
|
},
|
2020-08-03 16:06:51 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:27:46 +02:00
|
|
|
const tables = [
|
2020-10-13 12:27:18 +02:00
|
|
|
{
|
2020-10-13 18:27:46 +02:00
|
|
|
_id: "test-table-id",
|
|
|
|
name: "Test Table",
|
2020-08-03 16:06:51 +02:00
|
|
|
schema: {
|
|
|
|
name: {
|
2020-10-13 12:27:18 +02:00
|
|
|
type: "string",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
description: {
|
2020-10-13 12:27:18 +02:00
|
|
|
type: "string",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2020-08-03 16:06:51 +02:00
|
|
|
|
2021-01-18 16:54:25 +01:00
|
|
|
const queries = []
|
|
|
|
|
2020-08-03 16:06:51 +02:00
|
|
|
const components = {
|
2020-10-13 12:27:18 +02:00
|
|
|
"@budibase/standard-components/container": {
|
2020-08-03 16:06:51 +02:00
|
|
|
props: {},
|
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
"@budibase/standard-components/list": {
|
2020-10-09 19:49:23 +02:00
|
|
|
context: "table",
|
2020-08-03 16:06:51 +02:00
|
|
|
props: {
|
2020-10-13 18:27:46 +02:00
|
|
|
table: "string",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
"@budibase/standard-components/input": {
|
2020-08-03 16:06:51 +02:00
|
|
|
bindable: "value",
|
|
|
|
props: {
|
2020-10-13 12:27:18 +02:00
|
|
|
value: "string",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
},
|
2020-10-13 12:27:18 +02:00
|
|
|
"@budibase/standard-components/heading": {
|
2020-08-03 16:06:51 +02:00
|
|
|
props: {
|
2020-10-13 12:27:18 +02:00
|
|
|
text: "string",
|
2020-08-03 16:06:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-01-18 16:54:25 +01:00
|
|
|
return { screen, tables, components, queries }
|
2020-10-13 12:27:18 +02:00
|
|
|
}
|