2020-02-03 10:24:25 +01:00
|
|
|
const testAppDef = require("../appPackages/testApp/appDefinition.json")
|
|
|
|
const testAccessLevels = require("../appPackages/testApp/access_levels.json")
|
2020-02-10 16:51:09 +01:00
|
|
|
const mainPage = require("../appPackages/testApp/pages/main/page.json")
|
|
|
|
const unauthenticatedPage = require("../appPackages/testApp/pages/unauthenticated/page.json")
|
2020-02-03 10:24:25 +01:00
|
|
|
const testComponents = require("../appPackages/testApp/customComponents/components.json")
|
|
|
|
const testMoreComponents = require("../appPackages/testApp/moreCustomComponents/components.json")
|
|
|
|
const statusCodes = require("../utilities/statusCodes")
|
2020-02-10 16:51:09 +01:00
|
|
|
const screen1 = require("../appPackages/testApp/pages/main/screens/screen1.json")
|
|
|
|
const screen2 = require("../appPackages/testApp/pages/main/screens/screen2.json")
|
|
|
|
const { readJSON, pathExists, unlink, readFile } = require("fs-extra")
|
|
|
|
const { getHashedCssPaths } = require("../utilities/builder/convertCssToFiles")
|
2020-02-11 18:23:25 +01:00
|
|
|
const listScreens = require("../utilities/builder/listScreens");
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
const app = require("./testApp")()
|
|
|
|
testComponents.textbox.name = `./customComponents/textbox`
|
|
|
|
testMoreComponents.textbox.name = `./moreCustomComponents/textbox`
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2019-07-27 08:31:31 +02:00
|
|
|
beforeAll(async () => {
|
2020-02-10 16:51:09 +01:00
|
|
|
const testScreen = "./appPackages/testApp/pages/main/screens/newscreen.json"
|
|
|
|
const testScreenAfterMove =
|
|
|
|
"./appPackages/testApp/pages/main/screens/anotherscreen.json"
|
2019-07-27 08:31:31 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
if (await pathExists(testScreen)) await unlink(testScreen)
|
|
|
|
if (await pathExists(testScreenAfterMove)) await unlink(testScreenAfterMove)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
await app.start()
|
|
|
|
})
|
|
|
|
afterAll(async () => await app.destroy())
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get appDefinition", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.appDefinition).toEqual(testAppDef)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get access levels", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(body.accessLevels).toEqual(testAccessLevels)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
|
|
|
it("/apppackage should get pages", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(body.pages).toEqual({
|
|
|
|
main: mainPage,
|
|
|
|
unauthenticated: unauthenticatedPage,
|
|
|
|
})
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
it("/apppackage should get components", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
|
|
|
.get("/_builder/api/testApp/appPackage")
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(body.components.components["./customComponents/textbox"]).toBeDefined()
|
|
|
|
expect(
|
|
|
|
body.components.components["./moreCustomComponents/textbox"]
|
|
|
|
).toBeDefined()
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(body.components.components["./customComponents/textbox"]).toEqual(
|
2020-02-03 10:24:25 +01:00
|
|
|
testComponents.textbox
|
|
|
|
)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(body.components.components["./moreCustomComponents/textbox"]).toEqual(
|
2020-02-03 10:24:25 +01:00
|
|
|
testMoreComponents.textbox
|
|
|
|
)
|
|
|
|
})
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("/pages/:pageName/screens should get screens", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const { body } = await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.get("/_builder/api/testApp/pages/main/screens")
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const expectedComponents = {
|
2020-02-10 16:51:09 +01:00
|
|
|
screen1: { ...screen1, name: "screen1" },
|
|
|
|
screen2: { ...screen2, name: "screen2" },
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
2019-07-26 16:13:15 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(body).toEqual(expectedComponents)
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("should be able to create new screen", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const newscreen = {
|
2020-02-10 16:51:09 +01:00
|
|
|
name: "newscreen",
|
2020-02-03 10:24:25 +01:00
|
|
|
props: {
|
2020-02-10 16:51:09 +01:00
|
|
|
_component: "@budibase/standard-component/div",
|
|
|
|
className: "something",
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.post("/_builder/api/testApp/pages/main/screen", newscreen)
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const screenFile = "./appPackages/testApp/pages/main/screens/newscreen.json"
|
|
|
|
expect(await pathExists(screenFile)).toBe(true)
|
|
|
|
expect(await readJSON(screenFile)).toEqual(newscreen)
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("should be able to update screen", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
const updatedscreen = {
|
2020-02-10 16:51:09 +01:00
|
|
|
name: "newscreen",
|
2020-02-03 10:24:25 +01:00
|
|
|
props: {
|
2020-02-10 16:51:09 +01:00
|
|
|
_component: "@budibase/standard-component/div",
|
|
|
|
className: "something else",
|
2020-02-03 10:24:25 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.post("/_builder/api/testApp/pages/main/screen", updatedscreen)
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const screenFile = "./appPackages/testApp/pages/main/screens/newscreen.json"
|
|
|
|
expect(await readJSON(screenFile)).toEqual(updatedscreen)
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("should be able to rename screen", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.patch("/_builder/api/testApp/pages/main/screen", {
|
|
|
|
oldname: "newscreen",
|
|
|
|
newname: "anotherscreen",
|
2020-02-03 10:24:25 +01:00
|
|
|
})
|
|
|
|
.expect(statusCodes.OK)
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const oldcomponentFile =
|
|
|
|
"./appPackages/testApp/pages/main/screens/newscreen.json"
|
2020-02-03 10:24:25 +01:00
|
|
|
const newcomponentFile =
|
2020-02-10 16:51:09 +01:00
|
|
|
"./appPackages/testApp/pages/main/screens/anotherscreen.json"
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(await pathExists(oldcomponentFile)).toBe(false)
|
|
|
|
expect(await pathExists(newcomponentFile)).toBe(true)
|
|
|
|
})
|
2019-07-26 18:08:59 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("should be able to delete screen", async () => {
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.delete("/_builder/api/testApp/pages/main/screen/anotherscreen")
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const componentFile =
|
2020-02-10 16:51:09 +01:00
|
|
|
"./appPackages/testApp/pages/main/screens/anotherscreen.json"
|
2020-02-03 10:24:25 +01:00
|
|
|
expect(await pathExists(componentFile)).toBe(false)
|
|
|
|
})
|
2019-09-09 06:24:14 +02:00
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
it("/savePage should prepare all necessary client files", async () => {
|
|
|
|
const mainCss = "/*main page css*/"
|
|
|
|
mainPage._css = mainCss
|
|
|
|
const screen1Css = "/*screen1 css*/"
|
|
|
|
screen1._css = screen1Css
|
|
|
|
const screen2Css = "/*screen2 css*/"
|
|
|
|
screen2._css = screen2Css
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
await app
|
2020-02-10 16:51:09 +01:00
|
|
|
.post("/_builder/api/testApp/pages/main", {
|
2020-02-03 10:24:25 +01:00
|
|
|
appDefinition: testAppDef,
|
|
|
|
accessLevels: testAccessLevels,
|
2020-02-10 16:51:09 +01:00
|
|
|
page: mainPage,
|
|
|
|
uiFunctions: "{'1234':() => 'test return'}",
|
|
|
|
screens: [screen1, screen2],
|
2019-09-09 06:24:14 +02:00
|
|
|
})
|
2020-02-03 10:24:25 +01:00
|
|
|
.expect(statusCodes.OK)
|
|
|
|
|
|
|
|
const publicFolderMain = relative =>
|
|
|
|
"./appPackages/testApp/public/main" + relative
|
2020-02-10 16:51:09 +01:00
|
|
|
|
|
|
|
const cssDir = publicFolderMain("/css")
|
2020-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
expect(await pathExists(publicFolderMain("/index.html"))).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderMain("/lib/customComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(publicFolderMain("/lib/moreCustomComponents/index.js"))
|
|
|
|
).toBe(true)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
await pathExists(
|
|
|
|
publicFolderMain(
|
|
|
|
"/lib/node_modules/@budibase/standard-components/dist/index.js"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).toBe(true)
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const indexHtmlMain = await readFile(publicFolderMain("/index.html"), "utf8")
|
|
|
|
|
|
|
|
const pageCssPaths = getHashedCssPaths(cssDir, mainCss)
|
|
|
|
const screen1CssPaths = getHashedCssPaths(cssDir, screen1Css)
|
|
|
|
const screen2CssPaths = getHashedCssPaths(cssDir, screen2Css)
|
|
|
|
|
|
|
|
expect(await pathExists(publicFolderMain(pageCssPaths.url))).toBe(true)
|
|
|
|
const savedPageCss = await readFile(
|
|
|
|
publicFolderMain(pageCssPaths.url),
|
|
|
|
"utf8"
|
|
|
|
)
|
|
|
|
expect(savedPageCss).toEqual(mainCss)
|
|
|
|
expect(indexHtmlMain.includes(pageCssPaths.url)).toBe(true)
|
|
|
|
|
|
|
|
expect(await pathExists(publicFolderMain(screen1CssPaths.url))).toBe(true)
|
|
|
|
const savedScreen1Css = await readFile(
|
|
|
|
publicFolderMain(screen1CssPaths.url),
|
|
|
|
"utf8"
|
|
|
|
)
|
|
|
|
expect(savedScreen1Css).toEqual(screen1Css)
|
|
|
|
expect(indexHtmlMain.includes(screen1CssPaths.url)).toBe(true)
|
|
|
|
|
|
|
|
expect(await pathExists(publicFolderMain(screen2CssPaths.url))).toBe(true)
|
|
|
|
const savedScreen2Css = await readFile(
|
|
|
|
publicFolderMain(screen2CssPaths.url),
|
|
|
|
"utf8"
|
2020-02-03 10:24:25 +01:00
|
|
|
)
|
2020-02-10 16:51:09 +01:00
|
|
|
expect(savedScreen2Css).toEqual(screen2Css)
|
|
|
|
expect(indexHtmlMain.includes(screen2CssPaths.url)).toBe(true)
|
2019-09-09 06:24:14 +02:00
|
|
|
})
|
2020-02-11 18:23:25 +01:00
|
|
|
|
|
|
|
it("builds the correct stateOrigins object from a screen definition with no handlers", () => {
|
|
|
|
expect(listScreens.buildStateOrigins(screen1)).toEqual({});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("builds the correct stateOrigins object from a screen definition with handlers", () => {
|
|
|
|
expect(listScreens.buildStateOrigins({
|
|
|
|
"name": "screen1",
|
|
|
|
"description": "",
|
|
|
|
"props": {
|
|
|
|
"_component": "@budibase/standard-components/div",
|
|
|
|
"className": "",
|
|
|
|
"onClick": [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
"parameters": {
|
|
|
|
"path": "testKey",
|
|
|
|
"value": "value"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})).toEqual({
|
|
|
|
"testKey": {
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
"parameters": {
|
|
|
|
"path": "testKey",
|
|
|
|
"value": "value"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|