From a6602ba1fcae42d9d7d579e49d005dd6bd61644e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 1 Jun 2020 21:31:55 +0100 Subject: [PATCH] lint + format --- .../store/workflow/tests/testWorkflow.js | 1 - .../EventsEditor/StateBindingCascader.svelte | 4 +- .../userInterface/StateBindingControl.svelte | 52 +-- .../workflow/SetupPanel/SetupPanel.svelte | 8 +- .../workflow/[workflow]/_layout.svelte | 2 +- packages/builder/tests/createProps.spec.js | 12 - packages/client/src/api/workflow/actions.js | 1 + packages/client/tests/bindingDom.spec.js | 363 ------------------ packages/client/tests/domControlFlow.spec.js | 74 ---- packages/server/src/api/controllers/view.js | 2 +- 10 files changed, 33 insertions(+), 486 deletions(-) delete mode 100644 packages/client/tests/bindingDom.spec.js delete mode 100644 packages/client/tests/domControlFlow.spec.js diff --git a/packages/builder/src/builderStore/store/workflow/tests/testWorkflow.js b/packages/builder/src/builderStore/store/workflow/tests/testWorkflow.js index 2ef6018bf0..90c4b17924 100644 --- a/packages/builder/src/builderStore/store/workflow/tests/testWorkflow.js +++ b/packages/builder/src/builderStore/store/workflow/tests/testWorkflow.js @@ -3,7 +3,6 @@ export default { _rev: "4-02c6659734934895812fa7be0215ee59", name: "Test Workflow", definition: { - trigger: {}, steps: [ { id: "VFWeZcIPx", diff --git a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte index 130b0f8269..1edf5d45a0 100644 --- a/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte +++ b/packages/builder/src/components/userInterface/EventsEditor/StateBindingCascader.svelte @@ -5,9 +5,7 @@ import Input from "components/common/Input.svelte" import { find, map, keys, reduce, keyBy } from "lodash/fp" import { pipe } from "components/common/core" - import { - EVENT_TYPE_MEMBER_NAME - } from "components/common/eventHandlers" + import { EVENT_TYPE_MEMBER_NAME } from "components/common/eventHandlers" import { store, workflowStore } from "builderStore" import { ArrowDownIcon } from "components/common/Icons/" diff --git a/packages/builder/src/components/userInterface/StateBindingControl.svelte b/packages/builder/src/components/userInterface/StateBindingControl.svelte index 57a6bf13f9..0246fb71dc 100644 --- a/packages/builder/src/components/userInterface/StateBindingControl.svelte +++ b/packages/builder/src/components/userInterface/StateBindingControl.svelte @@ -21,32 +21,32 @@ size="19" on:click={() => onChanged(!value)} /> - {:else if type === 'models'} - - {:else if type === 'options' || type === 'models'} - + {:else if type === 'models'} + + {:else if type === 'options' || type === 'models'} + {/if} diff --git a/packages/builder/src/components/workflow/SetupPanel/SetupPanel.svelte b/packages/builder/src/components/workflow/SetupPanel/SetupPanel.svelte index f7252a5707..1ae741b55a 100644 --- a/packages/builder/src/components/workflow/SetupPanel/SetupPanel.svelte +++ b/packages/builder/src/components/workflow/SetupPanel/SetupPanel.svelte @@ -1,5 +1,5 @@ \ No newline at end of file + diff --git a/packages/builder/tests/createProps.spec.js b/packages/builder/tests/createProps.spec.js index 269ab8156a..bd468ba41a 100644 --- a/packages/builder/tests/createProps.spec.js +++ b/packages/builder/tests/createProps.spec.js @@ -1,6 +1,5 @@ import { createProps } from "../src/components/userInterface/pagesParsing/createProps" import { keys, some } from "lodash/fp" -import { BB_STATE_BINDINGPATH } from "@budibase/client/src/state/parseBinding" import { stripStandardProps } from "./testData" describe("createDefaultProps", () => { @@ -94,17 +93,6 @@ describe("createDefaultProps", () => { expect(props.onClick).toEqual([]) }) - it("should create a object with empty state when prop def is 'state' ", () => { - const comp = getcomponent() - comp.props.data = "state" - - const { props, errors } = createProps(comp) - - expect(errors).toEqual([]) - expect(props.data[BB_STATE_BINDINGPATH]).toBeDefined() - expect(props.data[BB_STATE_BINDINGPATH]).toBe("") - }) - it("should create a object children array when children == true ", () => { const comp = getcomponent() comp.children = true diff --git a/packages/client/src/api/workflow/actions.js b/packages/client/src/api/workflow/actions.js index f7d4755fbf..794cb184bf 100644 --- a/packages/client/src/api/workflow/actions.js +++ b/packages/client/src/api/workflow/actions.js @@ -9,6 +9,7 @@ export default { ...context, [id]: args, } + return context }, NAVIGATE: () => { // TODO client navigation diff --git a/packages/client/tests/bindingDom.spec.js b/packages/client/tests/bindingDom.spec.js deleted file mode 100644 index 2013803d27..0000000000 --- a/packages/client/tests/bindingDom.spec.js +++ /dev/null @@ -1,363 +0,0 @@ -import { load, makePage, makeScreen } from "./testAppDef" -import { EVENT_TYPE_MEMBER_NAME } from "../src/state/eventHandlers" - -describe("initialiseApp (binding)", () => { - it("should populate root element prop from store value", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - className: { - "##bbstate": "divClassName", - "##bbsource": "state", - "##bbstatefallback": "default", - }, - }) - ) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.className.includes("default")).toBe(true) - }) - - it("should update root element from store", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - className: { - "##bbstate": "divClassName", - "##bbsource": "state", - "##bbstatefallback": "default", - }, - }) - ) - - app.pageStore().update(s => { - s.divClassName = "newvalue" - return s - }) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.className.includes("newvalue")).toBe(true) - }) - - it("should update root element from store, using binding expression", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - className: "state.divClassName", - }) - ) - - app.pageStore().update(s => { - s.divClassName = "newvalue" - return s - }) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.className.includes("newvalue")).toBe(true) - }) - - it("should populate child component with store value", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "testlib/h1", - text: { - "##bbstate": "headerOneText", - "##bbsource": "state", - "##bbstatefallback": "header one", - }, - }, - { - _component: "testlib/h1", - text: { - "##bbstate": "headerTwoText", - "##bbsource": "state", - "##bbstatefallback": "header two", - }, - }, - ], - }) - ) - - const rootDiv = dom.window.document.body.children[0] - - expect(rootDiv.children.length).toBe(2) - expect(rootDiv.children[0].tagName).toBe("H1") - expect(rootDiv.children[0].innerText).toBe("header one") - expect(rootDiv.children[1].tagName).toBe("H1") - expect(rootDiv.children[1].innerText).toBe("header two") - }) - - it("should populate child component with store value", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "testlib/h1", - text: { - "##bbstate": "headerOneText", - "##bbsource": "state", - "##bbstatefallback": "header one", - }, - }, - { - _component: "testlib/h1", - text: { - "##bbstate": "headerTwoText", - "##bbsource": "state", - "##bbstatefallback": "header two", - }, - }, - ], - }) - ) - - app.pageStore().update(s => { - s.headerOneText = "header 1 - new val" - s.headerTwoText = "header 2 - new val" - return s - }) - - const rootDiv = dom.window.document.body.children[0] - - expect(rootDiv.children.length).toBe(2) - expect(rootDiv.children[0].tagName).toBe("H1") - expect(rootDiv.children[0].innerText).toBe("header 1 - new val") - expect(rootDiv.children[1].tagName).toBe("H1") - expect(rootDiv.children[1].innerText).toBe("header 2 - new val") - }) - - it("should populate screen child with store value", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "##builtin/screenslot", - text: "header one", - }, - ], - }), - [ - makeScreen("/", { - _component: "testlib/div", - className: "screen-class", - _children: [ - { - _component: "testlib/h1", - text: { - "##bbstate": "headerOneText", - "##bbsource": "state", - "##bbstatefallback": "header one", - }, - }, - { - _component: "testlib/h1", - text: { - "##bbstate": "headerTwoText", - "##bbsource": "state", - "##bbstatefallback": "header two", - }, - }, - ], - }), - ] - ) - - app.screenStore().update(s => { - s.headerOneText = "header 1 - new val" - s.headerTwoText = "header 2 - new val" - return s - }) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.children.length).toBe(1) - - const screenRoot = rootDiv.children[0] - - expect(screenRoot.children.length).toBe(1) - expect(screenRoot.children[0].children.length).toBe(2) - expect(screenRoot.children[0].children[0].innerText).toBe( - "header 1 - new val" - ) - expect(screenRoot.children[0].children[1].innerText).toBe( - "header 2 - new val" - ) - }) - - it("should fire events", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/button", - onClick: [ - event("Set State", { - path: "address", - value: "123 Main Street", - }), - ], - }) - ) - - const button = dom.window.document.body.children[0] - expect(button.tagName).toBe("BUTTON") - - let storeAddress - app.pageStore().subscribe(s => { - storeAddress = s.address - }) - button.dispatchEvent(new dom.window.Event("click")) - expect(storeAddress).toBe("123 Main Street") - }) - - it("should alter event parameters based on store values", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/button", - onClick: [ - event("Set State", { - path: "address", - value: { - "##bbstate": "sourceaddress", - "##bbsource": "state", - "##bbstatefallback": "fallback address", - }, - }), - ], - }) - ) - - const button = dom.window.document.body.children[0] - expect(button.tagName).toBe("BUTTON") - - let storeAddress - app.pageStore().subscribe(s => { - storeAddress = s.address - }) - - button.dispatchEvent(new dom.window.Event("click")) - expect(storeAddress).toBe("fallback address") - - app.pageStore().update(s => { - s.sourceaddress = "new address" - return s - }) - - button.dispatchEvent(new dom.window.Event("click")) - expect(storeAddress).toBe("new address") - }) - - it("should take event parameters from context values", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/button", - _id: "with_context", - onClick: [ - event("Set State", { - path: "address", - value: { - "##bbstate": "testKey", - "##bbsource": "context", - "##bbstatefallback": "fallback address", - }, - }), - ], - }) - ) - - const button = dom.window.document.body.children[0] - expect(button.tagName).toBe("BUTTON") - - let storeAddress - app.pageStore().subscribe(s => { - storeAddress = s.address - }) - - button.dispatchEvent(new dom.window.Event("click")) - expect(storeAddress).toBe("test value") - }) -}) - -it("should rerender components when their code is bound to the store ", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "testlib/div", - _id: "n_clones_based_on_store", - className: "child_div", - }, - ], - }) - ) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.tagName).toBe("DIV") - expect(rootDiv.children.length).toBe(0) - - app.pageStore().update(s => { - s.componentCount = 3 - return s - }) - - expect(rootDiv.children.length).toBe(3) - expect(rootDiv.children[0].className.includes("child_div")).toBe(true) - - app.pageStore().update(s => { - s.componentCount = 5 - return s - }) - - expect(rootDiv.children.length).toBe(5) - expect(rootDiv.children[0].className.includes("child_div")).toBe(true) - - app.pageStore().update(s => { - s.componentCount = 0 - return s - }) - - expect(rootDiv.children.length).toBe(0) -}) - -it("should be able to read value from context, passed fromm parent, through code", async () => { - const { dom, app } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "testlib/div", - _id: "n_clones_based_on_store", - className: { - "##bbstate": "index", - "##bbsource": "context", - "##bbstatefallback": "nothing", - }, - }, - ], - }) - ) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.tagName).toBe("DIV") - expect(rootDiv.children.length).toBe(0) - - app.pageStore().update(s => { - s.componentCount = 3 - return s - }) - - expect(rootDiv.children.length).toBe(3) - expect(rootDiv.children[0].className.includes("index_0")).toBe(true) - expect(rootDiv.children[1].className.includes("index_1")).toBe(true) - expect(rootDiv.children[2].className.includes("index_2")).toBe(true) -}) - -const event = (handlerType, parameters) => { - const e = {} - e[EVENT_TYPE_MEMBER_NAME] = handlerType - e.parameters = parameters - return e -} diff --git a/packages/client/tests/domControlFlow.spec.js b/packages/client/tests/domControlFlow.spec.js deleted file mode 100644 index 3c817d859d..0000000000 --- a/packages/client/tests/domControlFlow.spec.js +++ /dev/null @@ -1,74 +0,0 @@ -import { load, makePage } from "./testAppDef" - -describe("controlFlow", () => { - it("should display simple div, with always true render function", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - className: "my-test-class", - _id: "always_render", - }) - ) - - expect(dom.window.document.body.children.length).toBe(1) - const child = dom.window.document.body.children[0] - expect(child.className.includes("my-test-class")).toBeTruthy() - }) - - it("should not display div, with always false render function", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - className: "my-test-class", - _id: "never_render", - }) - ) - - expect(dom.window.document.body.children.length).toBe(0) - }) - - it("should display 3 divs in a looped render function", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - className: "my-test-class", - _id: "three_clones", - }) - ) - - expect(dom.window.document.body.children.length).toBe(3) - - const child0 = dom.window.document.body.children[0] - expect(child0.className.includes("my-test-class")).toBeTruthy() - - const child1 = dom.window.document.body.children[1] - expect(child1.className.includes("my-test-class")).toBeTruthy() - - const child2 = dom.window.document.body.children[2] - expect(child2.className.includes("my-test-class")).toBeTruthy() - }) - - it("should display 3 div, in a looped render, as children", async () => { - const { dom } = await load( - makePage({ - _component: "testlib/div", - _children: [ - { - _component: "testlib/div", - className: "my-test-class", - _id: "three_clones", - }, - ], - }) - ) - - expect(dom.window.document.body.children.length).toBe(1) - - const rootDiv = dom.window.document.body.children[0] - expect(rootDiv.children.length).toBe(3) - - expect(rootDiv.children[0].className.includes("my-test-class")).toBeTruthy() - expect(rootDiv.children[1].className.includes("my-test-class")).toBeTruthy() - expect(rootDiv.children[2].className.includes("my-test-class")).toBeTruthy() - }) -}) diff --git a/packages/server/src/api/controllers/view.js b/packages/server/src/api/controllers/view.js index 2f15d41570..9e847da358 100644 --- a/packages/server/src/api/controllers/view.js +++ b/packages/server/src/api/controllers/view.js @@ -11,7 +11,7 @@ const controller = { if ( !name.startsWith("all") && name !== "by_type" && - name !== "by_username" && + name !== "by_username" && name !== "by_workflow_trigger" ) { response.push({