Frontend addresses flows and dashboards by id: routes /flows/$flowId, /dashboards/$id and /view/$id, query keys, saves, lists, device pickers, search, brain and endpoint links and generated results dashboards go by id, while live values, issues, pauses and message names keep the key; tabs take the title from the document; creating uses POST and opens the issued id; the flow and dashboard panels show key and id with a copy button and a served HTTP or WebSocket node shows its hook URL under the flow id; specs create by POST and ids.spec.ts exercises issued ids

This commit is contained in:
2026-11-02 19:57:43 +01:00
parent fd637e0f1e
commit fa15522cb0
65 changed files with 1380 additions and 784 deletions
+5 -3
View File
@@ -1,7 +1,9 @@
import { expect, test } from "@playwright/test"
import { deleteAll } from "./utils/api"
import { deleteAll, openedFlowId } from "./utils/api"
const flowName = `test_clip_${Date.now().toString(36)}`
/** Issued by the server when the first test creates it in the app. */
let flowId = ""
const KEY = "fluksio.nodeClipboard"
declare global {
@@ -17,7 +19,7 @@ test.use({
})
test.afterAll(async ({ browser }) => {
await deleteAll(browser, [`/flows/${flowName}`])
await deleteAll(browser, [`/flows/${flowId}`])
})
test("the canvas clipboard yields to the native one", async ({ page }) => {
@@ -25,7 +27,7 @@ test("the canvas clipboard yields to the native one", async ({ page }) => {
await page.getByTestId("new-flow").click()
await page.getByTestId("new-flow-name").fill(flowName)
await page.getByTestId("create-flow").click()
await page.waitForURL(`/flows/${flowName}`)
flowId = await openedFlowId(page)
await page.getByTestId("add-node").click()
await page
+51 -51
View File
@@ -1,6 +1,12 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* A colour disc sends once, at the end of the gesture.
@@ -27,27 +33,24 @@ test.beforeAll(async ({ browser }) => {
// A node that only declares: nothing consumes the message, so a publish
// reaches the graph without waking an engine run. The widget is what is
// under test, not a flow.
const madeFlow = await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Colour drag",
version: 1,
nodes: [
{
id: "lamp",
type: "python",
provides: [
{ name: "tint", dtype: "list", item: "float" },
{ name: "rgb", dtype: "list", item: "int" },
{ name: "hex", dtype: "str" },
],
},
],
},
const madeFlow = await createFlow(page, {
name: flowName,
title: "Colour drag",
version: 1,
nodes: [
{
id: "lamp",
type: "python",
provides: [
{ name: "tint", dtype: "list", item: "float" },
{ name: "rgb", dtype: "list", item: "int" },
{ name: "hex", dtype: "str" },
],
},
],
})
if (!madeFlow.ok())
throw new Error(`flow PUT ${madeFlow.status()}: ${await madeFlow.text()}`)
throw new Error(`flow POST ${madeFlow.status()}: ${await madeFlow.text()}`)
const flow = await (await api(page, `/flows/${flowName}?draft=true`)).json()
await api(page, `/flows/${flowName}/publish`, {
method: "POST",
@@ -65,38 +68,35 @@ test.beforeAll(async ({ browser }) => {
}
// A leftover from a run that failed before its teardown would answer the
// create with a version conflict.
// create with a conflict.
await api(page, `/dashboards/${dashboard}`, { method: "DELETE" })
const madeBoard = await api(page, `/dashboards/${dashboard}`, {
method: "PUT",
data: {
name: dashboard,
title: "Colour drag",
version: 0,
widgets: [
{
id: "tint",
type: "color",
title: "Tint",
layout: { lg: { x: 0, y: 0, w: 6, h: 4 } },
config: { target, dtype: "list", format: "hsv" },
},
{
id: "rgb",
type: "color",
title: "RGB",
layout: { lg: { x: 6, y: 0, w: 3, h: 4 } },
config: { target: `${flowName}.rgb`, dtype: "list", format: "rgb" },
},
{
id: "hex",
type: "color",
title: "Hex",
layout: { lg: { x: 9, y: 0, w: 3, h: 4 } },
config: { target: `${flowName}.hex`, dtype: "str", format: "hex" },
},
],
},
const madeBoard = await createDashboard(page, {
name: dashboard,
title: "Colour drag",
version: 0,
widgets: [
{
id: "tint",
type: "color",
title: "Tint",
layout: { lg: { x: 0, y: 0, w: 6, h: 4 } },
config: { target, dtype: "list", format: "hsv" },
},
{
id: "rgb",
type: "color",
title: "RGB",
layout: { lg: { x: 6, y: 0, w: 3, h: 4 } },
config: { target: `${flowName}.rgb`, dtype: "list", format: "rgb" },
},
{
id: "hex",
type: "color",
title: "Hex",
layout: { lg: { x: 9, y: 0, w: 3, h: 4 } },
config: { target: `${flowName}.hex`, dtype: "str", format: "hex" },
},
],
})
if (!madeBoard.ok())
throw new Error(
+13 -11
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, deleteAll } from "./utils/api"
import { api, deleteAll, openedFlowId } from "./utils/api"
/**
* Editing writes a draft; only publishing hands it to the engine. The two
@@ -8,13 +8,15 @@ import { api, deleteAll } from "./utils/api"
*/
const flowName = `test_draft_${Date.now().toString(36)}`
/** Issued by the server when the first test creates it in the app. */
let flowId = ""
test.use({ storageState: "playwright/.auth/user.json" })
test.describe.configure({ mode: "serial" })
test.afterAll(async ({ browser }) => {
await deleteAll(browser, [`/flows/${flowName}`])
await deleteAll(browser, [`/flows/${flowId}`])
})
test("a draft stays off the engine until it is published", async ({ page }) => {
@@ -22,7 +24,7 @@ test("a draft stays off the engine until it is published", async ({ page }) => {
await page.getByTestId("new-flow").click()
await page.getByTestId("new-flow-name").fill(flowName)
await page.getByTestId("create-flow").click()
await page.waitForURL(`/flows/${flowName}`)
flowId = await openedFlowId(page)
await page.getByTestId("add-node").click()
await page
@@ -39,7 +41,7 @@ test("a draft stays off the engine until it is published", async ({ page }) => {
// Nothing of this flow is loaded while it is only a draft.
await page.waitForTimeout(1500)
const before = await (await api(page, `/flows/${flowName}/state`)).json()
const before = await (await api(page, `/flows/${flowId}/state`)).json()
expect(before.nodes).toHaveLength(0)
await page.getByTestId("publish-flow").click()
@@ -49,26 +51,26 @@ test("a draft stays off the engine until it is published", async ({ page }) => {
await expect(page.getByTestId("discard-draft")).toBeHidden()
await expect(page.getByTestId("publish-flow")).toBeDisabled()
const after = await (await api(page, `/flows/${flowName}/state`)).json()
const after = await (await api(page, `/flows/${flowId}/state`)).json()
expect(after.nodes.length).toBeGreaterThan(0)
})
test("a save against a version someone else moved on from is refused", async ({
page,
}) => {
await page.goto(`/flows/${flowName}`)
await page.goto(`/flows/${flowId}`)
await page.waitForSelector(".react-flow__node")
const detail = await (await api(page, `/flows/${flowName}`)).json()
const detail = await (await api(page, `/flows/${flowId}`)).json()
// Stand in for a second client that saved first.
const first = await api(page, `/flows/${flowName}`, {
const first = await api(page, `/flows/${flowId}`, {
method: "PUT",
data: { ...detail.definition, title: "Theirs" },
})
expect(first.ok()).toBeTruthy()
const stale = await api(page, `/flows/${flowName}`, {
const stale = await api(page, `/flows/${flowId}`, {
method: "PUT",
data: { ...detail.definition, title: "Mine" },
})
@@ -79,7 +81,7 @@ test("a save against a version someone else moved on from is refused", async ({
})
test("discarding a draft goes back to the published flow", async ({ page }) => {
await page.goto(`/flows/${flowName}`)
await page.goto(`/flows/${flowId}`)
await page.waitForSelector(".react-flow__node")
await page.getByTestId("discard-draft").click()
@@ -87,7 +89,7 @@ test("discarding a draft goes back to the published flow", async ({ page }) => {
await expect(page.getByTestId("discard-draft")).toBeHidden()
await expect(page.getByTestId("publish-flow")).toBeDisabled()
const detail = await (await api(page, `/flows/${flowName}`)).json()
const detail = await (await api(page, `/flows/${flowId}`)).json()
expect(detail.has_draft).toBe(false)
expect(detail.definition.title).not.toBe("Theirs")
})
+2 -2
View File
@@ -1,5 +1,5 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createDashboard, deleteAll } from "./utils/api"
/**
* The dashboard editor's quiet failures.
@@ -41,7 +41,7 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/dashboards/${dashboardName}`, { method: "POST" })
await createDashboard(page, { name: dashboardName })
// The working copy, which is what a new dashboard may be: the editor reads
// the draft, so the setup writes one rather than publishing.
const dashboard = await (
+29 -26
View File
@@ -1,5 +1,11 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* Dashboards and other flows appear on the canvas but are not part of the flow.
@@ -21,30 +27,27 @@ test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
// A flow reading a message, and a dashboard control that sets it.
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
nodes: [
{
id: "sink",
type: "python",
requires: [
{ name: "level", port: "level", dtype: "float" },
{ name: "ceiling", port: "ceiling", dtype: "float" },
],
provides: [],
},
],
inputs: [
{ spec: { name: "level", port: "level", dtype: "float" }, initial: 0 },
{
spec: { name: "ceiling", port: "ceiling", dtype: "float" },
initial: 30,
},
],
version: 1,
},
await createFlow(page, {
name: flowName,
nodes: [
{
id: "sink",
type: "python",
requires: [
{ name: "level", port: "level", dtype: "float" },
{ name: "ceiling", port: "ceiling", dtype: "float" },
],
provides: [],
},
],
inputs: [
{ spec: { name: "level", port: "level", dtype: "float" }, initial: 0 },
{
spec: { name: "ceiling", port: "ceiling", dtype: "float" },
initial: 30,
},
],
version: 1,
})
const saved = await (await api(page, `/flows/${flowName}`)).json()
await api(page, `/flows/${flowName}/publish`, {
@@ -53,7 +56,7 @@ test.beforeAll(async ({ browser }) => {
})
const dashboard = await (
await api(page, `/dashboards/${dashboardName}`, { method: "POST" })
await createDashboard(page, { name: dashboardName })
).json()
dashboard.widgets = [
{
+44 -47
View File
@@ -1,6 +1,6 @@
import { expect, type Page, test } from "@playwright/test"
import { apiUrl } from "./config.ts"
import { api, deleteAll } from "./utils/api"
import { api, createFlow, deleteAll, openedFlowId } from "./utils/api"
/**
* The flow editor's load-bearing behaviour: nodes are placed, connections come
@@ -9,20 +9,22 @@ import { api, deleteAll } from "./utils/api"
*/
const flowName = `test_flow_${Date.now().toString(36)}`
/** Issued by the server when the first test creates it in the app. */
let flowId = ""
test.use({ storageState: "playwright/.auth/user.json" })
test.describe.configure({ mode: "serial" })
test.afterAll(async ({ browser }) => {
await deleteAll(browser, [`/flows/${flowName}`])
await deleteAll(browser, [`/flows/${flowId}`])
})
/** Write a node's source through the API; typing code is not what we test. */
async function setNodeSource(page: Page, nodeId: string, code: string) {
const token = await page.evaluate(() => localStorage.getItem("access_token"))
const response = await page.request.put(
`${apiUrl}/api/v1/flows/${flowName}/nodes/${nodeId}/source`,
`${apiUrl}/api/v1/flows/${flowId}/nodes/${nodeId}/source`,
{ headers: { Authorization: `Bearer ${token}` }, data: { code } },
)
expect(response.ok()).toBeTruthy()
@@ -32,7 +34,7 @@ async function setNodeSource(page: Page, nodeId: string, code: string) {
async function nodeSource(page: Page, nodeId: string) {
const token = await page.evaluate(() => localStorage.getItem("access_token"))
const response = await page.request.get(
`${apiUrl}/api/v1/flows/${flowName}/nodes/${nodeId}/source`,
`${apiUrl}/api/v1/flows/${flowId}/nodes/${nodeId}/source`,
{ headers: { Authorization: `Bearer ${token}` } },
)
expect(response.ok()).toBeTruthy()
@@ -75,7 +77,7 @@ test("a flow can be created, wired up, and comes back after a reload", async ({
await page.getByTestId("new-flow").click()
await page.getByTestId("new-flow-name").fill(flowName)
await page.getByTestId("create-flow").click()
await page.waitForURL(`/flows/${flowName}`)
flowId = await openedFlowId(page)
await addFunctionNode(page, 1)
await addFunctionNode(page, 2)
@@ -94,7 +96,7 @@ test("a flow can be created, wired up, and comes back after a reload", async ({
})
test("running a flow puts values on its edges", async ({ page }) => {
await page.goto(`/flows/${flowName}`)
await page.goto(`/flows/${flowId}`)
await page.waitForSelector(".react-flow__node")
await setNodeSource(
@@ -126,7 +128,7 @@ test("running a flow puts values on its edges", async ({ page }) => {
* a delete has to bring the code back with the node, not just the box.
*/
test("undo brings a deleted node back with its source", async ({ page }) => {
await page.goto(`/flows/${flowName}`)
await page.goto(`/flows/${flowId}`)
await page.waitForSelector(".react-flow__node")
await page.locator(".react-flow__node").first().click()
@@ -156,28 +158,25 @@ test("a port's code name is a field only when it differs from its message", asyn
}) => {
const name = `test_ports_${Date.now().toString(36)}`
await page.goto("/")
const saved = await api(page, `/flows/${name}`, {
method: "PUT",
data: {
name,
nodes: [
{
id: "reader",
type: "python",
requires: [
{ name: "command", port: "prompt", dtype: "str" },
{ name: "outdoor", dtype: "float" },
{ name: "a.level", dtype: "float" },
{ name: "b.level", dtype: "float" },
],
provides: [
{ name: "setpoint", port: "living_room_setpoint", dtype: "float" },
{ name: "pv_kw", dtype: "float" },
],
},
],
inputs: [],
},
const saved = await createFlow(page, {
name,
nodes: [
{
id: "reader",
type: "python",
requires: [
{ name: "command", port: "prompt", dtype: "str" },
{ name: "outdoor", dtype: "float" },
{ name: "a.level", dtype: "float" },
{ name: "b.level", dtype: "float" },
],
provides: [
{ name: "setpoint", port: "living_room_setpoint", dtype: "float" },
{ name: "pv_kw", dtype: "float" },
],
},
],
inputs: [],
})
expect(saved.ok()).toBeTruthy()
try {
@@ -231,9 +230,10 @@ test("code typed into a node's editor is saved", async ({ page }) => {
const name = `test_code_${Date.now().toString(36)}`
const text = "# level, other = 1, 2"
await page.goto("/")
const saved = await api(page, `/flows/${name}`, {
method: "PUT",
data: { name, nodes: [{ id: "writer", type: "python" }], inputs: [] },
const saved = await createFlow(page, {
name,
nodes: [{ id: "writer", type: "python" }],
inputs: [],
})
expect(saved.ok()).toBeTruthy()
try {
@@ -262,21 +262,18 @@ test("code typed into a node's editor is saved", async ({ page }) => {
test("a JSON setting saves only text that parses", async ({ page }) => {
const name = `test_json_${Date.now().toString(36)}`
await page.goto("/")
const saved = await api(page, `/flows/${name}`, {
method: "PUT",
data: {
name,
nodes: [
{
id: "gate",
type: "switch",
params: { rules: [], otherwise: "" },
requires: [{ name: "level", dtype: "float" }],
provides: [{ name: "high", dtype: "float" }],
},
],
inputs: [],
},
const saved = await createFlow(page, {
name,
nodes: [
{
id: "gate",
type: "switch",
params: { rules: [], otherwise: "" },
requires: [{ name: "level", dtype: "float" }],
provides: [{ name: "high", dtype: "float" }],
},
],
inputs: [],
})
expect(saved.ok()).toBeTruthy()
try {
+235
View File
@@ -0,0 +1,235 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
/**
* Objects made the ordinary way, with an id the server issues.
*
* Every other spec pins its id to its key, and with the two equal a key
* passed where an id belongs still works. Here they differ, so each place the
* app has to tell them apart is exercised: routes and API calls by id, live
* values, hooks and message names by key.
*/
const stamp = Date.now().toString(36)
const key = `test_ids_${stamp}`
const boardKey = `${key}_board`
const batchKey = `${key}_batch`
const FLOW_ID = /^f_[a-z2-7]{8}$/
const BOARD_ID = /^d_[a-z2-7]{8}$/
let flowId = ""
let boardId = ""
let batchId = ""
let runId = ""
let resultsId = ""
test.use({
storageState: "playwright/.auth/user.json",
permissions: ["clipboard-read", "clipboard-write"],
})
test.describe.configure({ mode: "serial" })
/** Publish a flow's working copy, whatever version it has reached. */
async function publishFlow(page: Page, id: string) {
const detail = await (await api(page, `/flows/${id}`)).json()
await api(page, `/flows/${id}/publish`, {
method: "POST",
data: { version: detail.definition.version },
})
}
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
// A webhook feeding `level`, created without an id.
const flow = await api(page, "/flows/", {
method: "POST",
data: {
name: key,
nodes: [
{
id: "hook",
type: "http",
params: { url: "/ping", method: "POST" },
requires: [],
provides: [{ name: "level", dtype: "float" }],
},
],
},
})
expect(flow.status()).toBe(201)
flowId = (await flow.json()).definition.id
expect(flowId).toMatch(FLOW_ID)
// A dashboard reading it, bound by the flow's key.
const board = await api(page, "/dashboards/", {
method: "POST",
data: { name: boardKey, title: "Issued board" },
})
expect(board.status()).toBe(201)
const made = await board.json()
boardId = made.id
expect(boardId).toMatch(BOARD_ID)
const saved = await (
await api(page, `/dashboards/${boardId}`, {
method: "PUT",
data: {
...made,
widgets: [
{
id: "level",
type: "stat",
title: "Issued level",
layout: { lg: { x: 0, y: 0, w: 3, h: 2 } },
config: { message: `${key}.level`, dtype: "float" },
},
],
},
})
).json()
await api(page, `/dashboards/${boardId}/publish`, {
method: "POST",
data: { version: saved.version },
})
// A batch flow with one finished run, for its results dashboard.
const batch = await api(page, "/flows/", {
method: "POST",
data: {
name: batchKey,
mode: "batch",
outputs: ["score"],
nodes: [
{
id: "score",
type: "python",
provides: [{ name: "score", dtype: "float" }],
},
],
},
})
batchId = (await batch.json()).definition.id
expect(batchId).toMatch(FLOW_ID)
await api(page, `/flows/${batchId}/nodes/score/source`, {
method: "PUT",
data: { code: 'def process():\n return {"score": 1.5}\n' },
})
await publishFlow(page, batchId)
const run = await api(page, `/runs/flows/${batchId}`, {
method: "POST",
data: { params: {} },
})
expect(run.ok()).toBeTruthy()
runId = (await run.json()).id
await page.close()
})
test.afterAll(async ({ browser }) => {
await deleteAll(
browser,
[
resultsId && `/dashboards/${resultsId}`,
boardId && `/dashboards/${boardId}`,
flowId && `/flows/${flowId}`,
batchId && `/flows/${batchId}`,
// After the flow, as the editor does it, and only by its id.
batchId && `/runs?flow=${batchId}&history=true`,
].filter(Boolean),
)
})
test("a flow opens, saves and publishes by its issued id", async ({ page }) => {
await page.goto(`/flows/${flowId}`)
await page.waitForSelector(".react-flow__node")
// The tab is named from the document, never from the opaque address.
await expect(page).toHaveTitle(`${key} - Fluksio`)
await page.getByTestId("edit-flow").click()
const panel = page.getByTestId("flow-panel")
await expect(panel.getByTestId("identity-key")).toHaveText(key)
await expect(panel.getByTestId("identity-id")).toHaveText(flowId)
await panel.getByLabel("Flow title").fill("Issued id")
await panel.getByTestId("confirm-rename").click()
await expect
.poll(
async () =>
(await (await api(page, `/flows/${flowId}`)).json()).definition.title,
)
.toBe("Issued id")
await expect(page).toHaveTitle("Issued id - Fluksio")
await page.getByTestId("publish-flow").click()
await expect(page.getByTestId("discard-draft")).toBeHidden()
const detail = await (await api(page, `/flows/${flowId}`)).json()
expect(detail.has_draft).toBe(false)
expect(detail.definition.name).toBe(key)
})
test("its hook URL carries the id, and a call through it shows up live", async ({
page,
}) => {
await page.goto(`/flows/${flowId}?node=hook`)
const url = page.getByTestId("hook-url")
await expect(url).toHaveText(new RegExp(`/hooks/${flowId}/ping$`))
const hook = (await url.textContent()) ?? ""
await page.getByRole("button", { name: "Copy the webhook URL" }).click()
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(hook)
// The route is mounted once the published flow is rebuilt.
await expect
.poll(async () =>
(await page.request.post(hook, { data: { level: 7 } })).status(),
)
.toBe(200)
// The value is named by the key, which is what the canvas matches on.
await expect(page.locator(".react-flow__edgelabel-renderer")).toContainText(
"7",
{ timeout: 15000 },
)
// The dashboard drawn on the canvas opens by its own id.
await page.getByText("Issued level").first().click()
await page.waitForURL(`**/dashboards/${boardId}`)
await expect(page).toHaveTitle("Issued board - Fluksio")
await expect(page.getByTestId("canvas-surface")).toContainText("7")
})
test("a dashboard shows its key and id, and its view opens by the id", async ({
page,
}) => {
await page.goto(`/dashboards/${boardId}?edit=true`)
await page.getByTestId("edit-dashboard").click()
const panel = page.getByTestId("dashboard-panel")
await expect(panel.getByTestId("identity-key")).toHaveText(boardKey)
await expect(panel.getByTestId("identity-id")).toHaveText(boardId)
await page.goto(`/view/${boardId}`)
await expect(page).toHaveTitle("Issued board - Fluksio")
await expect(page.getByText("Issued level")).toBeVisible()
})
test("a run's results dashboard is built and opened by its issued id", async ({
page,
}) => {
await page.goto("/")
await expect
.poll(
async () => (await (await api(page, `/runs/${runId}`)).json()).status,
{ timeout: 30_000 },
)
.toBe("ok")
await page.goto(`/runs/${runId}`)
// Labelled by the flow's key, linked by its id.
await expect(page.getByRole("link", { name: batchKey })).toBeVisible()
await page.getByRole("button", { name: "Open in dashboard" }).click()
await page.getByText(`Build a results dashboard for ${batchKey}`).click()
await page.waitForURL(/\/view\/d_[a-z2-7]{8}\?runs=/)
resultsId = new URL(page.url()).pathname.split("/").pop() ?? ""
const results = await (await api(page, `/dashboards/${resultsId}`)).json()
expect(results.name).toBe(`${batchKey}_results`)
})
+16 -19
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createFlow, deleteAll } from "./utils/api"
/**
* One socket serves the whole shell, and it has to survive the routes under it
@@ -18,24 +18,21 @@ test.use({ storageState: "playwright/.auth/user.json" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Live",
nodes: [
{
id: "source",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "sink",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
},
],
},
await createFlow(page, {
name: flowName,
title: "Live",
nodes: [
{
id: "source",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "sink",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
},
],
})
const detail = await (await api(page, `/flows/${flowName}`)).json()
await api(page, `/flows/${flowName}/publish`, {
+51 -51
View File
@@ -1,5 +1,11 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* Every screen at a phone's width, checking the one thing that is easy to
@@ -81,31 +87,28 @@ test.beforeAll(async ({ browser }) => {
// A chain and a four-way fan: enough of a graph to lay out, and wider than
// a phone can take abreast, so the wrapping is exercised.
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Mobile",
nodes: [
{
id: "source",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "scale",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
provides: [{ name: "scaled", dtype: "float" }],
},
...["one", "two", "three", "four"].map((id) => ({
id,
type: "python",
requires: [{ name: "scaled", dtype: "float" }],
})),
],
version: 1,
},
await createFlow(page, {
name: flowName,
title: "Mobile",
nodes: [
{
id: "source",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "scale",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
provides: [{ name: "scaled", dtype: "float" }],
},
...["one", "two", "three", "four"].map((id) => ({
id,
type: "python",
requires: [{ name: "scaled", dtype: "float" }],
})),
],
version: 1,
})
const saved = await (await api(page, `/flows/${flowName}`)).json()
await api(page, `/flows/${flowName}/publish`, {
@@ -113,29 +116,26 @@ test.beforeAll(async ({ browser }) => {
data: { version: saved.definition.version },
})
await api(page, `/flows/${feedName}`, {
method: "PUT",
data: {
name: feedName,
title: "Feed",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "pv", dtype: "float" },
{ name: "days", dtype: "list", item: "record" },
// Long, and with nothing to break at: an unlabelled series puts
// this whole name in the chart's legend.
{ name: "climate_series_reading", dtype: "float" },
{ name: "mode", dtype: "str" },
{ name: "lamp", dtype: "bool" },
],
},
],
},
await createFlow(page, {
name: feedName,
title: "Feed",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "pv", dtype: "float" },
{ name: "days", dtype: "list", item: "record" },
// Long, and with nothing to break at: an unlabelled series puts
// this whole name in the chart's legend.
{ name: "climate_series_reading", dtype: "float" },
{ name: "mode", dtype: "str" },
{ name: "lamp", dtype: "bool" },
],
},
],
})
const feed = await (await api(page, `/flows/${feedName}?draft=true`)).json()
await api(page, `/flows/${feedName}/publish`, {
@@ -175,7 +175,7 @@ test.beforeAll(async ({ browser }) => {
})
const dashboard = await (
await api(page, `/dashboards/${dashboardName}`, { method: "POST" })
await createDashboard(page, { name: dashboardName })
).json()
dashboard.widgets = [
{
@@ -274,7 +274,7 @@ test.beforeAll(async ({ browser }) => {
})
const locked = await (
await api(page, `/dashboards/${lockedName}`, { method: "POST" })
await createDashboard(page, { name: lockedName })
).json()
locked.settings = { ...(locked.settings ?? {}), locked: { value: true } }
locked.widgets = [
+22 -19
View File
@@ -1,5 +1,11 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* A panel carrying more than one dashboard draws the way between them.
@@ -22,23 +28,20 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Panel",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "mode", dtype: "str" },
],
},
],
},
await createFlow(page, {
name: flowName,
title: "Panel",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "mode", dtype: "str" },
],
},
],
})
const flow = await (await api(page, `/flows/${flowName}?draft=true`)).json()
await api(page, `/flows/${flowName}/publish`, {
@@ -51,7 +54,7 @@ test.beforeAll(async ({ browser }) => {
})
for (const name of [first, second]) {
await api(page, `/dashboards/${name}`, { method: "POST" })
await createDashboard(page, { name: name })
const doc = await (await api(page, `/dashboards/${name}?draft=true`)).json()
doc.settings = { look: { value: "glass" } }
doc.widgets = [
+12 -16
View File
@@ -1,5 +1,5 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createDashboard, deleteAll } from "./utils/api"
/**
* An editor save is a rewrite of the whole document, not a patch of what moved.
@@ -48,21 +48,17 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
// Version 0 creates: a first draft is what a save of a name nobody has used
// yet means, and the editor reads the draft.
const made = await api(page, `/dashboards/${dashboardName}`, {
method: "PUT",
data: {
name: dashboardName,
title: "Persistence",
icon: "layout-dashboard",
columns: 12,
canvas_width: 1920,
canvas_height: 1080,
version: 0,
widgets: [MOVED, KEPT],
settings: SETTINGS,
},
// Created as a draft, which is what the editor reads.
const made = await createDashboard(page, {
name: dashboardName,
title: "Persistence",
icon: "layout-dashboard",
columns: 12,
canvas_width: 1920,
canvas_height: 1080,
version: 0,
widgets: [MOVED, KEPT],
settings: SETTINGS,
})
if (!made.ok())
throw new Error(`dashboard PUT ${made.status()}: ${await made.text()}`)
+39 -39
View File
@@ -1,6 +1,12 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* A round dashboard's ring publishes once a turn settles, not per notch.
@@ -21,20 +27,17 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
// One node that only declares: a publish lands without waking a run.
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Ring",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [{ name: "level", dtype: "float" }],
},
],
},
await createFlow(page, {
name: flowName,
title: "Ring",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [{ name: "level", dtype: "float" }],
},
],
})
const flow = await (await api(page, `/flows/${flowName}?draft=true`)).json()
await api(page, `/flows/${flowName}/publish`, {
@@ -43,30 +46,27 @@ test.beforeAll(async ({ browser }) => {
})
await api(page, `/dashboards/${dashboard}`, { method: "DELETE" })
const made = await api(page, `/dashboards/${dashboard}`, {
method: "PUT",
data: {
name: dashboard,
title: "Ring",
version: 0,
canvas_width: 360,
canvas_height: 360,
shape: "round",
widgets: [
{
id: "level",
type: "slider",
title: "Level",
config: { target, dtype: "float", min: 0, max: 10, step: 0.5 },
},
{
id: "note",
type: "markdown",
title: "Note",
config: { content: "The second face" },
},
],
},
const made = await createDashboard(page, {
name: dashboard,
title: "Ring",
version: 0,
canvas_width: 360,
canvas_height: 360,
shape: "round",
widgets: [
{
id: "level",
type: "slider",
title: "Level",
config: { target, dtype: "float", min: 0, max: 10, step: 0.5 },
},
{
id: "note",
type: "markdown",
title: "Note",
config: { content: "The second face" },
},
],
})
if (!made.ok())
throw new Error(`dashboard PUT ${made.status()}: ${await made.text()}`)
+21 -24
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createFlow, deleteAll } from "./utils/api"
/**
* What the runs screen can do to a run, rather than what it can show about one.
@@ -28,29 +28,26 @@ test.afterAll(async ({ browser }) => {
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Runs under test",
// `rate` is declared and never passed, which is what puts its declared
// value in the Inputs panel below.
inputs: [
{ spec: { name: "epochs", dtype: "int" }, initial: 2 },
{ spec: { name: "rate", dtype: "float" }, initial: 0.5 },
],
nodes: [
{
id: "train",
type: "python",
requires: [{ name: "epochs", dtype: "int" }],
provides: [
{ name: "loss", dtype: "float", stream: true },
{ name: "score", dtype: "float" },
],
},
],
},
await createFlow(page, {
name: flowName,
title: "Runs under test",
// `rate` is declared and never passed, which is what puts its declared
// value in the Inputs panel below.
inputs: [
{ spec: { name: "epochs", dtype: "int" }, initial: 2 },
{ spec: { name: "rate", dtype: "float" }, initial: 0.5 },
],
nodes: [
{
id: "train",
type: "python",
requires: [{ name: "epochs", dtype: "int" }],
provides: [
{ name: "loss", dtype: "float", stream: true },
{ name: "score", dtype: "float" },
],
},
],
})
await api(page, `/flows/${flowName}/nodes/train/source`, {
method: "PUT",
+16 -19
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createFlow, deleteAll } from "./utils/api"
/**
* Flows can be taken off the engine and put back, and what a node prints — or
@@ -29,24 +29,21 @@ test.afterAll(async ({ browser }) => {
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Runtime",
nodes: [
{
id: "sensor",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "logger",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
},
],
},
await createFlow(page, {
name: flowName,
title: "Runtime",
nodes: [
{
id: "sensor",
type: "python",
provides: [{ name: "reading", dtype: "float" }],
},
{
id: "logger",
type: "python",
requires: [{ name: "reading", dtype: "float" }],
},
],
})
await api(page, `/flows/${flowName}/nodes/sensor/source`, {
method: "PUT",
+13 -16
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { apiPage, createFlow, deleteAll } from "./utils/api"
/**
* The global search: the only way to reach a node without knowing its flow.
@@ -16,21 +16,18 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Searchable flow",
nodes: [
{
id: "findme",
type: "python",
title: "Find me",
params: { tuning_gain: 7, api_token: "s3cr3t-token" },
},
],
inputs: [{ spec: { name: "findme_input", dtype: "float" } }],
},
await createFlow(page, {
name: flowName,
title: "Searchable flow",
nodes: [
{
id: "findme",
type: "python",
title: "Find me",
params: { tuning_gain: 7, api_token: "s3cr3t-token" },
},
],
inputs: [{ spec: { name: "findme_input", dtype: "float" } }],
})
await page.close()
})
+41 -41
View File
@@ -1,6 +1,12 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* A slider publishes what a *drag* leaves it on, not only what a tap picks.
@@ -20,56 +26,50 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
const madeFlow = await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Slider drag",
version: 1,
nodes: [
{
id: "level",
type: "python",
title: "Level",
requires: [{ name: "level", dtype: "float" }],
provides: [{ name: "echo", dtype: "float" }],
},
],
inputs: [{ spec: { name: "level", dtype: "float" }, initial: 0 }],
},
const madeFlow = await createFlow(page, {
name: flowName,
title: "Slider drag",
version: 1,
nodes: [
{
id: "level",
type: "python",
title: "Level",
requires: [{ name: "level", dtype: "float" }],
provides: [{ name: "echo", dtype: "float" }],
},
],
inputs: [{ spec: { name: "level", dtype: "float" }, initial: 0 }],
})
if (!madeFlow.ok())
throw new Error(`flow PUT ${madeFlow.status()}: ${await madeFlow.text()}`)
throw new Error(`flow POST ${madeFlow.status()}: ${await madeFlow.text()}`)
await api(page, `/flows/${flowName}/nodes/level/source`, {
method: "PUT",
data: { code: "def process(level=0.0):\n return {'echo': level}\n" },
})
// A leftover from a run that failed before its teardown would answer the
// create with a version conflict.
// create with a conflict.
await api(page, `/dashboards/${dashboard}`, { method: "DELETE" })
const madeBoard = await api(page, `/dashboards/${dashboard}`, {
method: "PUT",
data: {
name: dashboard,
title: "Slider drag",
version: 0,
widgets: [
{
id: "level",
type: "slider",
title: "Level",
layout: { lg: { x: 0, y: 0, w: 6, h: 3 } },
config: {
target: `${flowName}.level`,
dtype: "float",
min: 0,
max: 100,
step: 1,
},
const madeBoard = await createDashboard(page, {
name: dashboard,
title: "Slider drag",
version: 0,
widgets: [
{
id: "level",
type: "slider",
title: "Level",
layout: { lg: { x: 0, y: 0, w: 6, h: 3 } },
config: {
target: `${flowName}.level`,
dtype: "float",
min: 0,
max: 100,
step: 1,
},
],
},
},
],
})
if (!madeBoard.ok())
throw new Error(
+47
View File
@@ -32,6 +32,53 @@ export async function apiPage(browser: Browser) {
return page
}
/**
* Create a flow the way the app does, with a POST, under its key as a pinned
* id, so a spec keeps addressing it by the name it chose. The suite signs in
* as a superuser, who may pin. The answer is the request's own.
*/
export function createFlow(
page: Page,
doc: { name: string; [field: string]: unknown },
) {
return api(page, "/flows/", {
method: "POST",
data: { id: doc.name, ...doc },
})
}
/**
* The same for a dashboard. Creating one takes only its key and title, so the
* rest of `doc` is saved over the new draft, and the answer is that save's.
*/
export async function createDashboard(
page: Page,
doc: { name: string; title?: string; [field: string]: unknown },
) {
const made = await api(page, "/dashboards/", {
method: "POST",
data: { id: doc.name, name: doc.name, title: doc.title },
})
const rest = Object.keys(doc).filter(
(key) => key !== "name" && key !== "title",
)
if (!made.ok() || rest.length === 0) return made
const { version } = await made.json()
return api(page, `/dashboards/${doc.name}`, {
method: "PUT",
data: { ...doc, version },
})
}
/**
* The id the server issued a flow just created in the app, read off the
* editor it opened: an opaque `f_` and eight characters, never the key.
*/
export async function openedFlowId(page: Page) {
await page.waitForURL(/\/flows\/f_[a-z2-7]{8}$/)
return new URL(page.url()).pathname.split("/").pop() ?? ""
}
/** Delete the given API paths, whether or not they are still there. */
export async function deleteAll(browser: Browser, paths: string[]) {
const page = await apiPage(browser)
+15 -18
View File
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import { api, apiPage, createFlow, deleteAll } from "./utils/api"
/**
* What a message carrying a dictionary looks like in a panel four hundred
@@ -21,23 +21,20 @@ test.describe.configure({ mode: "serial" })
test.beforeAll(async ({ browser }) => {
const page = await apiPage(browser)
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Values",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "shape", dtype: "record" },
{ name: "label", dtype: "str" },
],
},
],
},
await createFlow(page, {
name: flowName,
title: "Values",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "shape", dtype: "record" },
{ name: "label", dtype: "str" },
],
},
],
})
// Saving writes a draft and moves the version on, so publish what is
// actually there rather than what it was a moment ago.
+32 -31
View File
@@ -1,5 +1,11 @@
import { expect, type Page, test } from "@playwright/test"
import { api, apiPage, deleteAll } from "./utils/api"
import {
api,
apiPage,
createDashboard,
createFlow,
deleteAll,
} from "./utils/api"
/**
* The wall-panel widgets, on the page a panel actually opens.
@@ -39,31 +45,28 @@ test.beforeAll(async ({ browser }) => {
// One node that only declares: nothing consumes these, so publishing a value
// fills the panel without waking an engine run.
await api(page, `/flows/${flowName}`, {
method: "PUT",
data: {
name: flowName,
title: "Widgets",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "pv", dtype: "float" },
{ name: "grid", dtype: "float" },
{ name: "condition", dtype: "str" },
{ name: "days", dtype: "list", item: "record" },
{ name: "mode", dtype: "str" },
{ name: "lamp", dtype: "bool" },
{ name: "setpoint", dtype: "float" },
{ name: "idle", dtype: "float" },
{ name: "tint", dtype: "list", item: "float" },
],
},
],
},
await createFlow(page, {
name: flowName,
title: "Widgets",
version: 1,
nodes: [
{
id: "emit",
type: "python",
provides: [
{ name: "level", dtype: "float" },
{ name: "pv", dtype: "float" },
{ name: "grid", dtype: "float" },
{ name: "condition", dtype: "str" },
{ name: "days", dtype: "list", item: "record" },
{ name: "mode", dtype: "str" },
{ name: "lamp", dtype: "bool" },
{ name: "setpoint", dtype: "float" },
{ name: "idle", dtype: "float" },
{ name: "tint", dtype: "list", item: "float" },
],
},
],
})
// Saving writes a draft and moves the version on, so publish what is
// actually there rather than what it was a moment ago.
@@ -92,7 +95,7 @@ test.beforeAll(async ({ browser }) => {
])
const dashboard = await (
await api(page, `/dashboards/${dashboardName}`, { method: "POST" })
await createDashboard(page, { name: dashboardName })
).json()
// Two rows taller than the default panel: the tiles below already fill it,
// and a widget past the last row is clipped rather than drawn.
@@ -236,9 +239,7 @@ test.beforeAll(async ({ browser }) => {
data: { version: draft.version },
})
const stack = await (
await api(page, `/dashboards/${stackName}`, { method: "POST" })
).json()
const stack = await (await createDashboard(page, { name: stackName })).json()
stack.widgets = [
{
id: "split",
@@ -284,7 +285,7 @@ test.beforeAll(async ({ browser }) => {
})
const locked = await (
await api(page, `/dashboards/${lockedName}`, { method: "POST" })
await createDashboard(page, { name: lockedName })
).json()
locked.settings = { ...(locked.settings ?? {}), locked: { value: true } }
locked.widgets = [