1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00
budibase/packages/builder/tests/buildCodeForScreen.spec.js
Michael Shanks c7cbe6ca8b
#24 - Control Flow (#79)
* removed binding references to array type

* refactored initialiseChildren into seperate file

* render function, with code blocks - tested simple cases

* few mores tests for control flow

* md components - getting TestApp to work

* new render wrapper - bug fix

* client: providing access to component root elements

* code editor working

* code editor improvements
2020-01-31 23:11:50 +00:00

65 lines
1.4 KiB
JavaScript

import { buildCodeForScreens } from "../src/builderStore/buildCodeForScreens";
describe("buildCodeForScreen",() => {
it("should package _code into runnable function, for simple screen props", () => {
const screen = {
props: {
_id: "1234",
_code: "render('render argument');"
}
}
let renderArg;
const render = (arg) => {
renderArg = arg;
}
const uiFunctions = getFunctions(screen);
const targetfunction = uiFunctions[screen.props._id];
expect(targetfunction).toBeDefined();
targetfunction(render);
expect(renderArg).toBe("render argument");
});
it("should package _code into runnable function, for _children ", () => {
const screen = {
props: {
_id: "parent",
_code: "render('parent argument');",
_children: [
{
_id: "child1",
_code: "render('child 1 argument');"
},
{
_id: "child2",
_code: "render('child 2 argument');"
}
]
}
}
let renderArg;
const render = (arg) => {
renderArg = arg;
}
const uiFunctions = getFunctions(screen);
const targetfunction = uiFunctions["child2"];
expect(targetfunction).toBeDefined();
targetfunction(render);
expect(renderArg).toBe("child 2 argument");
})
});
const getFunctions = (screen) =>
new Function(buildCodeForScreens([screen]))();