fullcheck.spec.ts 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { expect, test, type Page } from "@playwright/test"
  2. async function connect(page: Page, suffix = "") {
  3. await page.goto(`/e2e/paas/index.html?ux${suffix}`)
  4. await page.getByLabel("API Key", { exact: true }).fill("fullcheck")
  5. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  6. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toBeEnabled()
  7. }
  8. test("unsent drafts and their attachments remain reachable after switching and reloading", async ({ page }) => {
  9. await connect(page)
  10. await page.getByRole("textbox", { name: "消息", exact: true }).fill("尚未提交的研究设想")
  11. await page.getByRole("button", { name: "添加文件", exact: true }).click()
  12. await page.locator(".paas-new-session").click()
  13. await page.getByRole("textbox", { name: "消息", exact: true }).fill("另一项研究")
  14. await page.reload()
  15. await page.getByLabel("API Key", { exact: true }).fill("fullcheck")
  16. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  17. const drafts = page.getByRole("region", { name: "未发送草稿", exact: true })
  18. await expect(drafts.getByRole("button")).toHaveCount(2)
  19. await drafts.getByRole("button", { name: /尚未提交的研究设想/ }).click()
  20. await expect(page.getByRole("textbox", { name: "消息", exact: true })).toHaveValue("尚未提交的研究设想")
  21. await expect(page.getByRole("button", { name: "移除成功.txt", exact: true })).toBeVisible()
  22. await expect
  23. .poll(() =>
  24. page.evaluate(
  25. () =>
  26. (window as unknown as { paasTestCalls: { action: string }[] }).paasTestCalls.filter(
  27. (c) => c.action === "execute",
  28. ).length,
  29. ),
  30. )
  31. .toBe(0)
  32. })
  33. test("title editing keeps Chinese composition open and Escape returns focus", async ({ page }) => {
  34. await connect(page)
  35. const title = page.locator(".paas-topbar-chat-title")
  36. await title.click()
  37. const input = page.getByRole("textbox", { name: "会话名称", exact: true })
  38. await input.fill("科研标题")
  39. await input.dispatchEvent("keydown", { key: "Enter", code: "Enter", isComposing: true, bubbles: true })
  40. await expect(input).toBeVisible()
  41. await input.press("Enter")
  42. await expect(title).toHaveText("科研标题")
  43. await expect(title).toBeFocused()
  44. await title.press("Enter")
  45. await input.fill("不应保存")
  46. await input.press("Escape")
  47. await expect(title).toHaveText("科研标题")
  48. await expect(title).toBeFocused()
  49. })
  50. test("Escape closes the more menu and restores keyboard focus", async ({ page }) => {
  51. await connect(page)
  52. const more = page.locator(".paas-more-actions")
  53. await more.locator("summary").click()
  54. await more.getByRole("button", { name: "重命名会话", exact: true }).focus()
  55. await page.keyboard.press("Escape")
  56. await expect(more).not.toHaveAttribute("open", "")
  57. await expect(more.locator("summary")).toBeFocused()
  58. })
  59. for (const os of ["macos", "windows"]) {
  60. for (const width of [587, 1280]) {
  61. test(`${os} layout at ${width}px keeps native caption space and toolbar visible`, async ({ page }, testInfo) => {
  62. await page.setViewportSize({ width, height: 705 })
  63. await connect(page, `&os=${os}`)
  64. const toolbar = page.locator(".paas-chat-header-actions")
  65. await expect(toolbar).toBeInViewport()
  66. expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(width)
  67. const box = await toolbar.boundingBox()
  68. expect(box).not.toBeNull()
  69. if (os === "windows") expect(box!.y).toBeGreaterThanOrEqual(46)
  70. if (os === "macos" && width === 587) {
  71. const toggle = await page.locator(".paas-nav-toggle").boundingBox()
  72. expect(toggle!.x).toBeGreaterThanOrEqual(80)
  73. }
  74. await page.screenshot({ path: testInfo.outputPath(`${os}-${width}.png`) })
  75. })
  76. }
  77. }
  78. test("narrow windows retain settings and developer actions in the more menu", async ({ page }) => {
  79. await page.setViewportSize({ width: 520, height: 705 })
  80. await connect(page)
  81. await expect(page.locator(".paas-action-settings")).toBeHidden()
  82. await expect(page.locator(".paas-action-workspace")).toBeHidden()
  83. const menu = page.locator(".paas-more-actions")
  84. await menu.locator("summary").click()
  85. await expect(menu.getByRole("button", { name: "在开发区打开工作区", exact: true })).toBeVisible()
  86. await menu.getByRole("button", { name: "研究设置", exact: true }).click()
  87. await expect(page.getByRole("heading", { name: "编辑智能体", exact: true })).toBeVisible()
  88. })