// Production E2E for the research workbench (run where a browser is available). import { test, expect } from "@playwright/test"; test("list, search, create and statistics stay linked", async ({ page }) => { await page.route("**/api/**", async (route) => { const url = new URL(route.request().url()); if (url.pathname === "/api/tasks" && route.request().method() === "GET") { const query = url.searchParams.get("q") ?? ""; const tasks = [ { id: 1, title: "测量超导比特", priority: "high", status: "open" }, { id: 2, title: "整理实验记录", priority: "normal", status: "done" }, ].filter((task) => task.title.includes(query)); return route.fulfill({ json: { tasks } }); } if (url.pathname === "/api/stats") { return route.fulfill({ json: { total: 2, byStatus: { open: 1, doing: 0, done: 1 }, byPriority: { low: 0, normal: 1, high: 1 } } }); } if (url.pathname === "/api/tasks" && route.request().method() === "POST") { const body = route.request().postDataJSON(); if (!String(body.title ?? "").trim()) { return route.fulfill({ status: 400, json: { error: { code: "task.title_required", message: "任务标题不能为空" } } }); } return route.fulfill({ status: 201, json: { task: { id: 3, title: body.title, priority: "normal", status: "open" } } }); } return route.continue(); }); await page.goto("/"); await expect(page.getByTestId("stats")).toContainText("总数 2"); await expect(page.getByTestId("tasks")).toContainText("测量超导比特"); await page.getByLabel("搜索任务").fill("实验"); await expect(page.getByTestId("tasks")).toContainText("整理实验记录"); await expect(page.getByTestId("tasks")).not.toContainText("测量超导比特"); await page.getByLabel("搜索任务").fill(""); await page.getByLabel("标题").fill("新建任务"); await page.getByRole("button", { name: "创建" }).click(); await expect(page.getByTestId("error")).toBeHidden(); await page.getByLabel("标题").fill(" "); await page.getByRole("button", { name: "创建" }).click(); await expect(page.getByTestId("error")).toContainText("任务标题不能为空"); });