Update all old references in datasources from isModel to type=model

This commit is contained in:
Andrew Kingston 2020-10-13 11:27:18 +01:00
parent 93b0e815c2
commit f9f939152a
2 changed files with 110 additions and 68 deletions

View File

@ -98,7 +98,7 @@ const createScreen = model => ({
label: "Deals", label: "Deals",
name: `all_${model._id}`, name: `all_${model._id}`,
modelId: model._id, modelId: model._id,
isModel: true, type: "model",
}, },
_instanceName: `${model.name} Table`, _instanceName: `${model.name} Table`,
_children: [], _children: [],

View File

@ -1,13 +1,14 @@
import fetchBindableProperties from "../src/builderStore/fetchBindableProperties" import fetchBindableProperties from "../src/builderStore/fetchBindableProperties"
describe("fetch bindable properties", () => { describe("fetch bindable properties", () => {
it("should return bindable properties from screen components", () => { it("should return bindable properties from screen components", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "heading-id", componentInstanceId: "heading-id",
...testData() ...testData(),
}) })
const componentBinding = result.find(r => r.instance._id === "search-input-id" && r.type === "instance") const componentBinding = result.find(
r => r.instance._id === "search-input-id" && r.type === "instance"
)
expect(componentBinding).toBeDefined() expect(componentBinding).toBeDefined()
expect(componentBinding.type).toBe("instance") expect(componentBinding.type).toBe("instance")
expect(componentBinding.runtimeBinding).toBe("search-input-id.value") expect(componentBinding.runtimeBinding).toBe("search-input-id.value")
@ -16,29 +17,39 @@ describe("fetch bindable properties", () => {
it("should not return bindable components when not in their context", () => { it("should not return bindable components when not in their context", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "heading-id", componentInstanceId: "heading-id",
...testData() ...testData(),
}) })
const componentBinding = result.find(r => r.instance._id === "list-item-input-id") const componentBinding = result.find(
r => r.instance._id === "list-item-input-id"
)
expect(componentBinding).not.toBeDefined() expect(componentBinding).not.toBeDefined()
}) })
it("should return model schema, when inside a context", () => { it("should return model schema, when inside a context", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "list-item-input-id", componentInstanceId: "list-item-input-id",
...testData() ...testData(),
}) })
const contextBindings = result.filter(r => r.instance._id === "list-id" && r.type==="context") const contextBindings = result.filter(
// 2 fields + _id + _rev r => r.instance._id === "list-id" && r.type === "context"
)
// 2 fields + _id + _rev
expect(contextBindings.length).toBe(4) expect(contextBindings.length).toBe(4)
const namebinding = contextBindings.find(b => b.runtimeBinding === "data.name") const namebinding = contextBindings.find(
b => b.runtimeBinding === "data.name"
)
expect(namebinding).toBeDefined() expect(namebinding).toBeDefined()
expect(namebinding.readableBinding).toBe("list-name.Test Model.name") expect(namebinding.readableBinding).toBe("list-name.Test Model.name")
const descriptionbinding = contextBindings.find(b => b.runtimeBinding === "data.description") const descriptionbinding = contextBindings.find(
b => b.runtimeBinding === "data.description"
)
expect(descriptionbinding).toBeDefined() expect(descriptionbinding).toBeDefined()
expect(descriptionbinding.readableBinding).toBe("list-name.Test Model.description") expect(descriptionbinding.readableBinding).toBe(
"list-name.Test Model.description"
)
const idbinding = contextBindings.find(b => b.runtimeBinding === "data._id") const idbinding = contextBindings.find(b => b.runtimeBinding === "data._id")
expect(idbinding).toBeDefined() expect(idbinding).toBeDefined()
expect(idbinding.readableBinding).toBe("list-name.Test Model._id") expect(idbinding.readableBinding).toBe("list-name.Test Model._id")
@ -47,35 +58,51 @@ describe("fetch bindable properties", () => {
it("should return model schema, for grantparent context", () => { it("should return model schema, for grantparent context", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "child-list-item-input-id", componentInstanceId: "child-list-item-input-id",
...testData() ...testData(),
}) })
const contextBindings = result.filter(r => r.type==="context") const contextBindings = result.filter(r => r.type === "context")
// 2 fields + _id + _rev ... x 2 models // 2 fields + _id + _rev ... x 2 models
expect(contextBindings.length).toBe(8) expect(contextBindings.length).toBe(8)
const namebinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.name") const namebinding_parent = contextBindings.find(
b => b.runtimeBinding === "parent.data.name"
)
expect(namebinding_parent).toBeDefined() expect(namebinding_parent).toBeDefined()
expect(namebinding_parent.readableBinding).toBe("list-name.Test Model.name") expect(namebinding_parent.readableBinding).toBe("list-name.Test Model.name")
const descriptionbinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.description") const descriptionbinding_parent = contextBindings.find(
b => b.runtimeBinding === "parent.data.description"
)
expect(descriptionbinding_parent).toBeDefined() expect(descriptionbinding_parent).toBeDefined()
expect(descriptionbinding_parent.readableBinding).toBe("list-name.Test Model.description") expect(descriptionbinding_parent.readableBinding).toBe(
"list-name.Test Model.description"
const namebinding_own = contextBindings.find(b => b.runtimeBinding === "data.name") )
const namebinding_own = contextBindings.find(
b => b.runtimeBinding === "data.name"
)
expect(namebinding_own).toBeDefined() expect(namebinding_own).toBeDefined()
expect(namebinding_own.readableBinding).toBe("child-list-name.Test Model.name") expect(namebinding_own.readableBinding).toBe(
"child-list-name.Test Model.name"
const descriptionbinding_own = contextBindings.find(b => b.runtimeBinding === "data.description") )
const descriptionbinding_own = contextBindings.find(
b => b.runtimeBinding === "data.description"
)
expect(descriptionbinding_own).toBeDefined() expect(descriptionbinding_own).toBeDefined()
expect(descriptionbinding_own.readableBinding).toBe("child-list-name.Test Model.description") expect(descriptionbinding_own.readableBinding).toBe(
"child-list-name.Test Model.description"
)
}) })
it("should return bindable component props, from components in same context", () => { it("should return bindable component props, from components in same context", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "list-item-heading-id", componentInstanceId: "list-item-heading-id",
...testData() ...testData(),
}) })
const componentBinding = result.find(r => r.instance._id === "list-item-input-id" && r.type === "instance") const componentBinding = result.find(
r => r.instance._id === "list-item-input-id" && r.type === "instance"
)
expect(componentBinding).toBeDefined() expect(componentBinding).toBeDefined()
expect(componentBinding.runtimeBinding).toBe("list-item-input-id.value") expect(componentBinding.runtimeBinding).toBe("list-item-input-id.value")
}) })
@ -83,125 +110,140 @@ describe("fetch bindable properties", () => {
it("should not return components from child context", () => { it("should not return components from child context", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "list-item-heading-id", componentInstanceId: "list-item-heading-id",
...testData() ...testData(),
}) })
const componentBinding = result.find(r => r.instance._id === "child-list-item-input-id" && r.type === "instance") const componentBinding = result.find(
r =>
r.instance._id === "child-list-item-input-id" && r.type === "instance"
)
expect(componentBinding).not.toBeDefined() expect(componentBinding).not.toBeDefined()
}) })
it("should return bindable component props, from components in same context (when nested context)", () => { it("should return bindable component props, from components in same context (when nested context)", () => {
const result = fetchBindableProperties({ const result = fetchBindableProperties({
componentInstanceId: "child-list-item-heading-id", componentInstanceId: "child-list-item-heading-id",
...testData() ...testData(),
}) })
const componentBinding = result.find(r => r.instance._id === "child-list-item-input-id" && r.type === "instance") const componentBinding = result.find(
r =>
r.instance._id === "child-list-item-input-id" && r.type === "instance"
)
expect(componentBinding).toBeDefined() expect(componentBinding).toBeDefined()
}) })
}) })
const testData = () => { const testData = () => {
const screen = { const screen = {
instanceName: "test screen", instanceName: "test screen",
name: "screen-id", name: "screen-id",
route: "/", route: "/",
props: { props: {
_id:"screent-root-id", _id: "screent-root-id",
_component: "@budibase/standard-components/container", _component: "@budibase/standard-components/container",
_children: [ _children: [
{ {
_id: "heading-id", _id: "heading-id",
_instanceName: "list item heading", _instanceName: "list item heading",
_component: "@budibase/standard-components/heading", _component: "@budibase/standard-components/heading",
text: "Screen Title" text: "Screen Title",
}, },
{ {
_id: "search-input-id", _id: "search-input-id",
_instanceName: "Search Input", _instanceName: "Search Input",
_component: "@budibase/standard-components/input", _component: "@budibase/standard-components/input",
value: "search phrase" value: "search phrase",
}, },
{ {
_id: "list-id", _id: "list-id",
_component: "@budibase/standard-components/list", _component: "@budibase/standard-components/list",
_instanceName: "list-name", _instanceName: "list-name",
model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id" }, model: {
type: "model",
modelId: "test-model-id",
label: "Test Model",
name: "all_test-model-id",
},
_children: [ _children: [
{ {
_id: "list-item-heading-id", _id: "list-item-heading-id",
_instanceName: "list item heading", _instanceName: "list item heading",
_component: "@budibase/standard-components/heading", _component: "@budibase/standard-components/heading",
text: "hello" text: "hello",
}, },
{ {
_id: "list-item-input-id", _id: "list-item-input-id",
_instanceName: "List Item Input", _instanceName: "List Item Input",
_component: "@budibase/standard-components/input", _component: "@budibase/standard-components/input",
value: "list item" value: "list item",
}, },
{ {
_id: "child-list-id", _id: "child-list-id",
_component: "@budibase/standard-components/list", _component: "@budibase/standard-components/list",
_instanceName: "child-list-name", _instanceName: "child-list-name",
model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id"}, model: {
type: "model",
modelId: "test-model-id",
label: "Test Model",
name: "all_test-model-id",
},
_children: [ _children: [
{ {
_id: "child-list-item-heading-id", _id: "child-list-item-heading-id",
_instanceName: "child list item heading", _instanceName: "child list item heading",
_component: "@budibase/standard-components/heading", _component: "@budibase/standard-components/heading",
text: "hello" text: "hello",
}, },
{ {
_id: "child-list-item-input-id", _id: "child-list-item-input-id",
_instanceName: "Child List Item Input", _instanceName: "Child List Item Input",
_component: "@budibase/standard-components/input", _component: "@budibase/standard-components/input",
value: "child list item" value: "child list item",
}, },
] ],
}, },
] ],
}, },
] ],
} },
} }
const models = [{ const models = [
_id: "test-model-id", {
name: "Test Model", _id: "test-model-id",
name: "Test Model",
schema: { schema: {
name: { name: {
type: "string" type: "string",
}, },
description: { description: {
type: "string" type: "string",
} },
} },
}] },
]
const components = { const components = {
"@budibase/standard-components/container" : { "@budibase/standard-components/container": {
props: {}, props: {},
}, },
"@budibase/standard-components/list" : { "@budibase/standard-components/list": {
context: "model", context: "model",
props: { props: {
model: "string" model: "string",
}, },
}, },
"@budibase/standard-components/input" : { "@budibase/standard-components/input": {
bindable: "value", bindable: "value",
props: { props: {
value: "string" value: "string",
}, },
}, },
"@budibase/standard-components/heading" : { "@budibase/standard-components/heading": {
props: { props: {
text: "string" text: "string",
}, },
}, },
} }
return { screen, models, components } return { screen, models, components }
}
}