import { expect, test } from "@playwright/test" test("connection validation stays inline without browser invalid events", async ({ page }) => { await page.goto("/e2e/paas/index.html?ux") await page.evaluate(() => { Object.assign(window, { nativeInvalidEvents: 0 }) document.addEventListener( "invalid", () => { const state = window as unknown as { nativeInvalidEvents: number } state.nativeInvalidEvents++ }, true, ) }) const key = page.getByLabel("API Key", { exact: true }) const url = page.getByLabel("平台地址", { exact: true }) const submit = page.getByRole("button", { name: "连接平台", exact: true }) await submit.click() await expect(page.getByText("请输入平台访问凭证。", { exact: true })).toBeVisible() await expect(key).toHaveAttribute("aria-invalid", "true") await key.fill("form-check") await expect(page.getByText("请输入平台访问凭证。", { exact: true })).toHaveCount(0) await url.fill("not-a-platform-url") await submit.click() await expect(page.getByText("请输入以 http:// 或 https:// 开头的平台地址。", { exact: true })).toBeVisible() await expect(url).toHaveAttribute("aria-invalid", "true") await expect(key).toHaveValue("form-check") await page.screenshot({ path: test.info().outputPath("inline-validation.png"), }) expect(await page.evaluate(() => (window as unknown as { nativeInvalidEvents: number }).nativeInvalidEvents)).toBe(0) await url.fill("http://127.0.0.1:8000") await submit.click() await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled() expect(await page.locator("form").evaluateAll((forms) => forms.every((form) => form.noValidate))).toBe(true) }) test("invalid research settings show a field error and valid settings still save", async ({ page }) => { await page.goto("/e2e/paas/index.html?ux") await page.getByLabel("API Key", { exact: true }).fill("form-settings") await page.getByRole("button", { name: "连接平台", exact: true }).click() await page.getByRole("button", { name: "研究设置", exact: true }).click() const rounds = page.getByLabel("最多研究轮次", { exact: true }) await rounds.fill("9") await page.getByRole("button", { name: "保存修改", exact: true }).click() await expect(rounds).toBeFocused() await expect(rounds).toHaveAttribute("aria-invalid", "true") await expect(page.getByRole("alert")).toContainText("最多研究轮次") expect(await page.evaluate(() => window.paasTestCalls.filter((call) => call.action === "update-agent"))).toHaveLength( 0, ) await rounds.fill("6") await expect(page.getByRole("alert")).toHaveCount(0) await page.getByRole("button", { name: "保存修改", exact: true }).click() await expect .poll(() => page.evaluate(() => window.paasTestCalls.filter((call) => call.action === "update-agent").length)) .toBe(1) })