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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user