page-alignment.spec.ts 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { expect, test } from "@playwright/test"
  2. for (const theme of ["light", "dark"] as const) {
  3. for (const width of [360, 960, 1440]) {
  4. test(`workspace pages keep controls within their reading column at ${width}px in ${theme}`, async ({
  5. page,
  6. }, info) => {
  7. await page.setViewportSize({ width, height: 800 })
  8. await page.emulateMedia({ colorScheme: theme })
  9. await page.goto("/e2e/paas/index.html?setup&ux&unified")
  10. await page.getByRole("button", { name: "准备本机服务并连接", exact: true }).click()
  11. if (width > 1100) {
  12. const sidebar = page.locator(".paas-sidebar")
  13. expect(
  14. await sidebar
  15. .locator(".paas-sidebar-controls")
  16. .evaluate((element) => element.scrollHeight - element.clientHeight),
  17. ).toBeLessThanOrEqual(1)
  18. await expect(sidebar.getByRole("button", { name: "平台设置", exact: true })).toBeInViewport()
  19. const archive = sidebar.locator(".paas-archive-toggle")
  20. await expect(archive).toBeVisible()
  21. const geometry = await archive.evaluate((element) => {
  22. const button = element.getBoundingClientRect()
  23. const history = element.closest(".paas-nav-history")!.getBoundingClientRect()
  24. const footer = document.querySelector(".paas-sidebar-footer")!.getBoundingClientRect()
  25. return { bottom: button.bottom, historyBottom: history.bottom, footerTop: footer.top }
  26. })
  27. expect(geometry.bottom).toBeLessThanOrEqual(geometry.historyBottom)
  28. expect(geometry.bottom).toBeLessThanOrEqual(geometry.footerTop)
  29. }
  30. for (const [index, name] of ["应用与插件", "智能体", "平台任务", "成果", "平台设置"].entries()) {
  31. const nav = page.getByRole("navigation", { name: "功能导航", exact: true })
  32. if (!(await nav.isVisible())) await page.getByRole("button", { name: "打开导航", exact: true }).click()
  33. await nav.getByRole("button", { name, exact: true }).click()
  34. await expect(
  35. page.getByRole("heading", { name: name === "平台设置" ? "平台连接" : name, exact: true }).first(),
  36. ).toBeVisible()
  37. const overflow = await page.locator(".paas-content").evaluate((element) => {
  38. const bounds = element.getBoundingClientRect()
  39. return [...element.querySelectorAll("button,input,select,textarea")]
  40. .filter((control) => control.getClientRects().length && !control.closest("[role=table],table,pre"))
  41. .flatMap((control) => {
  42. const rect = control.getBoundingClientRect()
  43. return rect.left < bounds.left - 1 || rect.right > bounds.right + 1
  44. ? [
  45. {
  46. text: control.getAttribute("aria-label") || control.textContent,
  47. left: rect.left,
  48. right: rect.right,
  49. },
  50. ]
  51. : []
  52. })
  53. })
  54. expect(overflow).toEqual([])
  55. expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
  56. await page.screenshot({ path: info.outputPath(`${index}-${theme}-${width}.png`) })
  57. }
  58. await page.getByRole("button", { name: "检查与配置资源", exact: true }).click()
  59. await expect(page.getByRole("heading", { name: "模型与资源", exact: true })).toBeVisible()
  60. const model = page.getByLabel("模型名称", { exact: true })
  61. const provider = page.getByLabel("模型服务", { exact: true })
  62. if (width > 760) {
  63. const fields = await Promise.all([model, provider].map((field) => field.boundingBox()))
  64. expect(Math.abs(fields[0]!.y - fields[1]!.y)).toBeLessThanOrEqual(1)
  65. expect(Math.abs(fields[0]!.height - fields[1]!.height)).toBeLessThanOrEqual(1)
  66. }
  67. await page.screenshot({ path: info.outputPath(`model-${theme}-${width}.png`) })
  68. })
  69. }
  70. }
  71. test("long delegated task names keep their arrow and dialog close action reachable", async ({ page }, info) => {
  72. await page.setViewportSize({ width: 360, height: 800 })
  73. await page.goto("/e2e/paas/index.html?ux")
  74. const title = `分析_${"sales_2026_".repeat(12)}`
  75. await page.evaluate((title) => {
  76. window.paasUX.threads = [
  77. { id: "parent", agent_id: "research", title: "主会话" },
  78. { id: "child", agent_id: "research", title, delegated: true, origin: { kind: "paas", session_id: "parent" } },
  79. ]
  80. window.paasUX.add({
  81. run_id: "parent-run",
  82. agent_id: "research",
  83. thread_id: "parent",
  84. input: "主会话",
  85. output: "研究结果",
  86. status: "completed",
  87. })
  88. }, title)
  89. await page.getByLabel("API Key", { exact: true }).fill("layout-only")
  90. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  91. await page.getByRole("button", { name: "打开导航", exact: true }).click()
  92. await page.locator(".paas-sidebar").getByRole("button", { name: "主会话", exact: true }).click()
  93. const children = page.getByRole("region", { name: "本会话的子任务" })
  94. const open = children.getByRole("button", { name: title, exact: true })
  95. await open.scrollIntoViewIfNeeded()
  96. expect(await children.evaluate((element) => element.scrollWidth - element.clientWidth)).toBeLessThanOrEqual(1)
  97. await open.click()
  98. const dialog = page.getByRole("dialog")
  99. await expect(dialog).toBeVisible()
  100. const close = dialog.locator('[data-slot="dialog-close-button"]')
  101. await expect(close).toBeInViewport()
  102. expect(await dialog.evaluate((element) => element.scrollWidth - element.clientWidth)).toBeLessThanOrEqual(1)
  103. const heading = await dialog.locator('[data-slot="dialog-title"]').boundingBox()
  104. const button = await close.boundingBox()
  105. expect(heading!.x + heading!.width).toBeLessThanOrEqual(button!.x - 8)
  106. await page.screenshot({ path: info.outputPath("long-child-title.png") })
  107. await close.click()
  108. await expect(open).toBeFocused()
  109. })