Fix workflow tests

This commit is contained in:
Andrew Kingston 2020-09-14 12:38:17 +01:00
parent 590e7d810d
commit 12d44ffcad
3 changed files with 88 additions and 131 deletions

View File

@ -1,44 +1,37 @@
import Workflow from "../Workflow"; import Workflow from "../Workflow"
import TEST_WORKFLOW from "./testWorkflow"; import TEST_WORKFLOW from "./testWorkflow"
const TEST_BLOCK = { const TEST_BLOCK = {
id: "VFWeZcIPx", id: "AUXJQGZY7",
name: "Update UI State", name: "Delay",
tagline: "Update <b>{{path}}</b> to <b>{{value}}</b>", icon: "ri-time-fill",
icon: "ri-refresh-line", tagline: "Delay for <b>{{time}}</b> milliseconds",
description: "Update your User Interface with some data.", description: "Delay the workflow until an amount of time has passed.",
environment: "CLIENT", params: { time: "number" },
params: { type: "LOGIC",
path: "string", args: { time: "5000" },
value: "longText", stepId: "DELAY",
},
args: {
path: "foo",
value: "started...",
},
actionId: "SET_STATE",
type: "ACTION",
} }
describe("Workflow Data Object", () => { describe("Workflow Data Object", () => {
let workflow let workflow
beforeEach(() => { beforeEach(() => {
workflow = new Workflow({ ...TEST_WORKFLOW }); workflow = new Workflow({ ...TEST_WORKFLOW })
}); })
it("adds a workflow block to the workflow", () => { it("adds a workflow block to the workflow", () => {
workflow.addBlock(TEST_BLOCK); workflow.addBlock(TEST_BLOCK)
expect(workflow.workflow.definition) expect(workflow.workflow.definition)
}) })
it("updates a workflow block with new attributes", () => { it("updates a workflow block with new attributes", () => {
const firstBlock = workflow.workflow.definition.steps[0]; const firstBlock = workflow.workflow.definition.steps[0]
const updatedBlock = { const updatedBlock = {
...firstBlock, ...firstBlock,
name: "UPDATED" name: "UPDATED",
}; }
workflow.updateBlock(updatedBlock, firstBlock.id); workflow.updateBlock(updatedBlock, firstBlock.id)
expect(workflow.workflow.definition.steps[0]).toEqual(updatedBlock) expect(workflow.workflow.definition.steps[0]).toEqual(updatedBlock)
}) })
@ -46,12 +39,10 @@ describe("Workflow Data Object", () => {
const { steps } = workflow.workflow.definition const { steps } = workflow.workflow.definition
const originalLength = steps.length const originalLength = steps.length
const lastBlock = steps[steps.length - 1]; const lastBlock = steps[steps.length - 1]
workflow.deleteBlock(lastBlock.id); workflow.deleteBlock(lastBlock.id)
expect(workflow.workflow.definition.steps.length).toBeLessThan(originalLength); expect(workflow.workflow.definition.steps.length).toBeLessThan(
}) originalLength
)
it("builds a tree that gets rendered in the flowchart builder", () => {
expect(Workflow.buildUiTree(TEST_WORKFLOW.definition)).toMatchSnapshot();
}) })
}) })

View File

@ -1,49 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Workflow Data Object builds a tree that gets rendered in the flowchart builder 1`] = `
Array [
Object {
"args": Object {
"time": 3000,
},
"body": "Delay for <b>3000</b> milliseconds",
"heading": "DELAY",
"id": "zJQcZUgDS",
"name": "Delay",
"params": Object {
"time": "number",
},
"type": "LOGIC",
},
Object {
"args": Object {
"path": "foo",
"value": "finished",
},
"body": "Update <b>foo</b> to <b>finished</b>",
"heading": "SET_STATE",
"id": "3RSTO7BMB",
"name": "Update UI State",
"params": Object {
"path": "string",
"value": "longText",
},
"type": "ACTION",
},
Object {
"args": Object {
"path": "foo",
"value": "started...",
},
"body": "Update <b>foo</b> to <b>started...</b>",
"heading": "SET_STATE",
"id": "VFWeZcIPx",
"name": "Update UI State",
"params": Object {
"path": "string",
"value": "longText",
},
"type": "ACTION",
},
]
`;

View File

@ -1,63 +1,78 @@
export default { export default {
_id: "53b6148c65d1429c987e046852d11611", name: "Test workflow",
_rev: "4-02c6659734934895812fa7be0215ee59",
name: "Test Workflow",
definition: { definition: {
steps: [ steps: [
{ {
id: "VFWeZcIPx", id: "ANBDINAPS",
name: "Update UI State", description: "Send an email.",
tagline: "Update <b>{{path}}</b> to <b>{{value}}</b>", tagline: "Send email to <b>{{to}}</b>",
icon: "ri-refresh-line", icon: "ri-mail-open-fill",
description: "Update your User Interface with some data.", name: "Send Email",
environment: "CLIENT",
params: { params: {
path: "string", to: "string",
value: "longText", from: "string",
subject: "longText",
text: "longText",
}, },
args: {
path: "foo",
value: "started...",
},
actionId: "SET_STATE",
type: "ACTION", type: "ACTION",
},
{
id: "zJQcZUgDS",
name: "Delay",
icon: "ri-time-fill",
tagline: "Delay for <b>{{time}}</b> milliseconds",
description: "Delay the workflow until an amount of time has passed.",
environment: "CLIENT",
params: {
time: "number",
},
args: { args: {
time: 3000, text: "A user was created!",
subject: "New Budibase User",
from: "budimaster@budibase.com",
to: "test@test.com",
}, },
actionId: "DELAY", stepId: "SEND_EMAIL",
type: "LOGIC",
},
{
id: "3RSTO7BMB",
name: "Update UI State",
tagline: "Update <b>{{path}}</b> to <b>{{value}}</b>",
icon: "ri-refresh-line",
description: "Update your User Interface with some data.",
environment: "CLIENT",
params: {
path: "string",
value: "longText",
},
args: {
path: "foo",
value: "finished",
},
actionId: "SET_STATE",
type: "ACTION",
}, },
], ],
trigger: {
id: "iRzYMOqND",
name: "Record Saved",
event: "record:save",
icon: "ri-save-line",
tagline: "Record is added to <b>{{model.name}}</b>",
description: "Fired when a record is saved to your database.",
params: { model: "model" },
type: "TRIGGER",
args: {
model: {
type: "model",
views: {},
name: "users",
schema: {
name: {
type: "string",
constraints: {
type: "string",
length: { maximum: 123 },
presence: { allowEmpty: false },
},
name: "name",
},
age: {
type: "number",
constraints: {
type: "number",
presence: { allowEmpty: false },
numericality: {
greaterThanOrEqualTo: "",
lessThanOrEqualTo: "",
},
},
name: "age",
},
},
_id: "c6b4e610cd984b588837bca27188a451",
_rev: "7-b8aa1ce0b53e88928bb88fc11bdc0aff",
},
},
stepId: "RECORD_SAVED",
},
}, },
type: "workflow", type: "workflow",
live: true, ok: true,
id: "b384f861f4754e1693835324a7fcca62",
rev: "1-aa1c2cbd868ef02e26f8fad531dd7e37",
live: false,
_id: "b384f861f4754e1693835324a7fcca62",
_rev: "108-4116829ec375e0481d0ecab9e83a2caf",
} }