67 lines
2.8 KiB
TypeScript
67 lines
2.8 KiB
TypeScript
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const electronState = vi.hoisted(() => ({ userData: "" }));
|
|
vi.mock("electron", () => ({
|
|
app: {
|
|
getPath: () => electronState.userData,
|
|
getVersion: () => "test"
|
|
}
|
|
}));
|
|
|
|
import { createDemoFlow, createExampleFlows, createFlow, listFlows, saveFlow } from "./flows";
|
|
|
|
describe("flow summaries", () => {
|
|
beforeEach(async () => {
|
|
electronState.userData = await mkdtemp(path.join(os.tmpdir(), "rpa-flow-summary-"));
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await rm(electronState.userData, { recursive: true, force: true });
|
|
});
|
|
|
|
it("loads the latest persisted run into the task summary", async () => {
|
|
const flow = saveFlow(createFlow("运行记录任务"));
|
|
const olderDir = path.join(electronState.userData, "runs", "older");
|
|
const latestDir = path.join(electronState.userData, "runs", "latest");
|
|
await mkdir(olderDir, { recursive: true });
|
|
await mkdir(latestDir, { recursive: true });
|
|
await writeFile(path.join(olderDir, "run.json"), JSON.stringify({
|
|
flowId: flow.id, status: "succeeded", finishedAt: "2026-10-27T01:00:00.000Z", durationMs: 120
|
|
}));
|
|
await writeFile(path.join(latestDir, "run.json"), JSON.stringify({
|
|
flowId: flow.id, status: "failed", finishedAt: "2026-10-27T02:00:00.000Z", durationMs: 456,
|
|
error: { reason: "测试失败原因" }
|
|
}));
|
|
|
|
expect(listFlows()).toContainEqual(expect.objectContaining({
|
|
id: flow.id,
|
|
name: "运行记录任务",
|
|
lastRunStatus: "failed",
|
|
lastRunAt: "2026-10-27T02:00:00.000Z",
|
|
lastRunDurationMs: 456,
|
|
lastRunError: "测试失败原因"
|
|
}));
|
|
});
|
|
|
|
it("creates a connected local browser demo flow", () => {
|
|
const flow = createDemoFlow("http://127.0.0.1:17863/");
|
|
expect(flow.name).toBe("本地网页订单演示");
|
|
expect(flow.nodes.map((node) => node.componentId)).toEqual([
|
|
"Trigger.Manual", "WebBrowser_CreateV3", "Element_SetValue_V6", "Element_SetValue_V6", "Element_Click_V6", "Element_GetText_V5"
|
|
]);
|
|
expect(flow.edges).toHaveLength(5);
|
|
expect(flow.nodes.find((node) => node.id === "node_result")?.options.outputVar).toBe("订单结果");
|
|
});
|
|
|
|
it("creates six stable example flows without duplicate ids", () => {
|
|
const examples = createExampleFlows("http://127.0.0.1:17863/");
|
|
expect(examples).toHaveLength(6);
|
|
expect(new Set(examples.map((flow) => flow.id)).size).toBe(6);
|
|
expect(examples.every((flow) => flow.nodes.length > 2 && flow.edges.length > 1)).toBe(true);
|
|
expect(examples.find((flow) => flow.id === "example_error_route")?.edges.some((edge) => edge.sourceHandle === "error")).toBe(true);
|
|
});
|
|
});
|