connection.spec.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { expect, test } from "@playwright/test"
  2. test("failed connection keeps the entered credentials for an explicit retry", async ({ page }) => {
  3. await page.goto("/e2e/paas/index.html?ux")
  4. await page.evaluate(() => {
  5. window.paasUX.connectError = "无法连接 AgentPaaS,请检查网络。"
  6. })
  7. await page.getByLabel("API Key", { exact: true }).fill("retry-test-only")
  8. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  9. await expect(page.getByRole("alert")).toBeVisible()
  10. await expect(page.getByLabel("API Key", { exact: true })).toHaveValue("retry-test-only")
  11. await page.evaluate(() => {
  12. window.paasUX.connectError = ""
  13. })
  14. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  15. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  16. expect(await page.evaluate(() => window.paasTestCalls.some((c) => c.action === "execute"))).toBe(false)
  17. })
  18. test("directory failures change connection status while preserving drafts and recover without execution", async ({
  19. page,
  20. }, info) => {
  21. await page.goto("/e2e/paas/index.html?ux")
  22. await page.getByLabel("API Key", { exact: true }).fill("health-test-only")
  23. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  24. await page.getByRole("textbox", { name: "消息", exact: true }).fill("保留我的研究问题")
  25. await page.evaluate(() => {
  26. window.paasUX.catalogError = "HTTP 401:平台凭证已失效"
  27. })
  28. await page.getByRole("button", { name: "查看平台连接状态", exact: true }).click()
  29. await page.getByRole("button", { name: "检查连接", exact: true }).click()
  30. await expect(page.getByRole("button", { name: "查看平台连接状态" })).toHaveText("连接待检查")
  31. await page.getByRole("button", { name: "会话", exact: true }).click()
  32. await expect(page.getByLabel("平台同步异常")).toBeVisible()
  33. await page.screenshot({ path: info.outputPath("connection-recovery.png"), fullPage: true })
  34. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("保留我的研究问题")
  35. await page.evaluate(() => {
  36. window.paasUX.catalogError = ""
  37. })
  38. await page.getByRole("button", { name: "重试同步", exact: true }).click()
  39. await expect(page.getByRole("button", { name: "查看平台连接状态" })).toHaveText("平台已连接")
  40. await expect(page.getByLabel("平台同步异常")).toHaveCount(0)
  41. await expect(page.getByRole("alert")).toHaveCount(0)
  42. expect(await page.evaluate(() => window.paasTestCalls.some((c) => c.action === "execute"))).toBe(false)
  43. })
  44. test("editing connection returns to the form and restores the same account draft", async ({ page }) => {
  45. await page.goto("/e2e/paas/index.html?ux")
  46. await page.getByLabel("API Key", { exact: true }).fill("same-account")
  47. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  48. await page.getByRole("textbox", { name: "消息", exact: true }).fill("重连后继续填写")
  49. await page.getByRole("button", { name: "查看平台连接状态", exact: true }).click()
  50. await page.getByRole("button", { name: "修改连接", exact: true }).click()
  51. await expect(page.getByLabel("API Key", { exact: true })).toHaveValue("")
  52. await page.getByLabel("API Key", { exact: true }).fill("same-account")
  53. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  54. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("重连后继续填写")
  55. })
  56. test("disconnected conversation has an actionable connection entry", async ({ page }) => {
  57. await page.goto("/e2e/paas/index.html?ux")
  58. await page.getByRole("button", { name: "会话", exact: true }).click()
  59. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  60. await expect(page.getByLabel("API Key", { exact: true })).toBeVisible()
  61. await expect(page.getByText("当前平台还没有可用智能体。", { exact: true })).toHaveCount(0)
  62. })