mirror of https://github.com/Budibase/budibase.git
18 changed files with 621 additions and 176 deletions
@ -0,0 +1,15 @@ |
|||
{ |
|||
// Use IntelliSense to learn about possible attributes. |
|||
// Hover to view descriptions of existing attributes. |
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
|||
"version": "0.2.0", |
|||
"configurations": [ |
|||
{ |
|||
"type": "chrome", |
|||
"request": "launch", |
|||
"name": "Launch Chrome against localhost", |
|||
"url": "http://localhost:3000", |
|||
"webRoot": "${workspaceFolder}" |
|||
} |
|||
] |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
import { expandPropsDefinition } from "../src/userInterface/pagesParsing/types"; |
|||
|
|||
const propDef = { |
|||
label: "string", |
|||
width: {type:"number"}, |
|||
color: {type:"string", required:true}, |
|||
child: "component", |
|||
navitems: { |
|||
type: "array", |
|||
elementDefinition: { |
|||
name: {type:"string"}, |
|||
height: "number" |
|||
} |
|||
} |
|||
} |
|||
|
|||
describe("expandPropDefintion", () => { |
|||
|
|||
it("should expand property defined as string, into default for that type", () => { |
|||
|
|||
const result = expandPropsDefinition(propDef); |
|||
|
|||
expect(result.label.type).toBe("string"); |
|||
expect(result.label.required).toBe(false); |
|||
}); |
|||
|
|||
it("should add members to property defined as object, when members do not exist", () => { |
|||
|
|||
const result = expandPropsDefinition(propDef); |
|||
expect(result.width.required).toBe(false); |
|||
}); |
|||
|
|||
it("should not override existing memebers", () => { |
|||
|
|||
const result = expandPropsDefinition(propDef); |
|||
expect(result.color.required).toBe(true); |
|||
}); |
|||
|
|||
it("should also expand out elementdefinition of array", () => { |
|||
const result = expandPropsDefinition(propDef); |
|||
expect(result.navitems.elementDefinition.height.type).toBe("number"); |
|||
}) |
|||
|
|||
}) |
|||
@ -0,0 +1,103 @@ |
|||
import { |
|||
getFinalProps, |
|||
getComponentInfo |
|||
} from "../src/userInterface/pagesParsing/createProps"; |
|||
import { |
|||
keys, some |
|||
} from "lodash/fp"; |
|||
import { allComponents } from "./testData"; |
|||
|
|||
|
|||
|
|||
describe("getComponentInfo", () => { |
|||
|
|||
it("should return default props for root component", () => { |
|||
const result = getComponentInfo( |
|||
allComponents(), |
|||
"budibase-components/TextBox"); |
|||
|
|||
expect(result.errors).toEqual([]); |
|||
expect(result.fullProps).toEqual({ |
|||
_component: "budibase-components/TextBox", |
|||
size: "", |
|||
isPassword: false, |
|||
placeholder: "", |
|||
label:"" |
|||
}); |
|||
}); |
|||
|
|||
it("should return no inherited for root component", () => { |
|||
const result = getComponentInfo( |
|||
allComponents(), |
|||
"budibase-components/TextBox"); |
|||
|
|||
expect(result.inheritedProps).toEqual([]); |
|||
|
|||
}); |
|||
|
|||
it("getFinalProps should set supplied props on top of default props", () => { |
|||
const result = getFinalProps( |
|||
getComponentInfo( |
|||
allComponents(), |
|||
"budibase-components/TextBox"), |
|||
{size:"small"}); |
|||
|
|||
expect(result).toEqual({ |
|||
_component: "budibase-components/TextBox", |
|||
size: "small", |
|||
isPassword: false, |
|||
placeholder: "", |
|||
label:"" |
|||
}); |
|||
|
|||
}); |
|||
|
|||
it("should return correct props for derived component", () => { |
|||
const result = getComponentInfo( |
|||
allComponents(), |
|||
"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 result = getComponentInfo( |
|||
allComponents(), |
|||
"common/PasswordBox"); |
|||
|
|||
expect(result.errors).toEqual([]); |
|||
expect(result.fullProps).toEqual({ |
|||
_component: "common/PasswordBox", |
|||
size: "small", |
|||
isPassword: true, |
|||
placeholder: "", |
|||
label:"" |
|||
}); |
|||
}); |
|||
|
|||
it("should list inheirted props as those that are defined in ancestor, derived components", () => { |
|||
const result = getComponentInfo( |
|||
allComponents(), |
|||
"common/PasswordBox"); |
|||
|
|||
// size is inherited from SmallTextbox
|
|||
expect(result.inheritedProps).toEqual(["size"]); |
|||
}); |
|||
|
|||
it("should list unset props as those that are only defined in root", () => { |
|||
const result = getComponentInfo( |
|||
allComponents(), |
|||
"common/PasswordBox"); |
|||
|
|||
expect(result.unsetProps).toEqual([ |
|||
"placeholder", "label"]); |
|||
}); |
|||
|
|||
}) |
|||
@ -0,0 +1,44 @@ |
|||
|
|||
export const allComponents = () => ([ |
|||
{ |
|||
name: "budibase-components/TextBox", |
|||
tags: ["Text", "input"], |
|||
props: { |
|||
size: {type:"options", options:["small", "medium", "large"]}, |
|||
isPassword: "bool", |
|||
placeholder: "string", |
|||
label:"string" |
|||
} |
|||
}, |
|||
{ |
|||
name: "budibase-components/Button", |
|||
tags: ["input"], |
|||
props: { |
|||
size: {type:"options", options:["small", "medium", "large"]}, |
|||
css: "string", |
|||
content: "component" |
|||
} |
|||
}, |
|||
{ |
|||
inherits:"budibase-components/TextBox", |
|||
name: "common/SmallTextbox", |
|||
props: { |
|||
size: "small" |
|||
} |
|||
}, |
|||
{ |
|||
inherits:"common/SmallTextbox", |
|||
name: "common/PasswordBox", |
|||
tags: ["mask"], |
|||
props: { |
|||
isPassword: true |
|||
} |
|||
}, |
|||
{ |
|||
inherits:"budibase-components/Button", |
|||
name:"PrimaryButton", |
|||
props: { |
|||
css:"btn-primary" |
|||
} |
|||
} |
|||
]) |
|||
Loading…
Reference in new issue