editor-layout.spec.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { expect, test } from "@playwright/test"
  2. for (const theme of ["light", "dark"] as const) {
  3. for (const [width, height] of [
  4. [360, 740],
  5. [960, 700],
  6. [1440, 900],
  7. ]) {
  8. test(`editor keeps fields clear of actions at ${width}x${height} in ${theme}`, async ({ page }) => {
  9. await page.setViewportSize({ width, height })
  10. await page.emulateMedia({ colorScheme: theme })
  11. await page.goto("/e2e/paas/index.html?ux")
  12. await page.evaluate((mode) => {
  13. document.documentElement.style.colorScheme = mode
  14. document.documentElement.setAttribute("data-color-scheme", mode)
  15. }, theme)
  16. await page.getByLabel("API Key", { exact: true }).fill("editor-layout")
  17. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  18. const agents = page.getByRole("button", { name: "智能体", exact: true })
  19. if (!(await agents.isVisible())) await page.getByRole("button", { name: "打开导航", exact: true }).click()
  20. await agents.click()
  21. await page.getByRole("button", { name: "编辑 科研助手", exact: true }).click()
  22. const save = page.getByRole("button", { name: "保存修改", exact: true })
  23. await expect(save).toBeInViewport()
  24. await expect(page.getByText("保存后应用于后续任务", { exact: true })).toBeVisible()
  25. const geometry = await page.locator(".paas-agent-edit").evaluate((element) => {
  26. const scroll = element.querySelector(".paas-edit-scroll")!.getBoundingClientRect()
  27. const footer = element.querySelector(".paas-edit-footer")!.getBoundingClientRect()
  28. const content = element.closest(".paas-content")!
  29. const section = element.querySelector("fieldset")!.getBoundingClientRect()
  30. const title = element.querySelector("legend")!.getBoundingClientRect()
  31. return {
  32. scrollBottom: scroll.bottom,
  33. footerTop: footer.top,
  34. footerBottom: footer.bottom,
  35. viewport: innerHeight,
  36. outerOverflow: content.scrollHeight - content.clientHeight,
  37. titleInset: title.top - section.top,
  38. }
  39. })
  40. expect(geometry.scrollBottom).toBeLessThanOrEqual(geometry.footerTop + 1)
  41. expect(geometry.footerBottom).toBeLessThanOrEqual(height)
  42. expect(geometry.outerOverflow).toBeLessThanOrEqual(1)
  43. expect(geometry.titleInset).toBeGreaterThanOrEqual(16)
  44. const fields = page.locator(".paas-edit-scroll :is(input,textarea,select):visible")
  45. for (const field of await fields.all()) {
  46. await field.scrollIntoViewIfNeeded()
  47. const bounds = await field.boundingBox()
  48. const footer = await page.locator(".paas-edit-footer").boundingBox()
  49. const scroll = await page.locator(".paas-edit-scroll").boundingBox()
  50. expect(bounds!.y).toBeGreaterThanOrEqual(scroll!.y - 1)
  51. expect(bounds!.y + bounds!.height).toBeLessThanOrEqual(footer!.y + 1)
  52. expect(bounds!.x + bounds!.width).toBeLessThanOrEqual(width)
  53. }
  54. await page.getByText("高级配置(JSON)", { exact: true }).click()
  55. const json = page.getByLabel("智能体配置", { exact: true })
  56. await json.scrollIntoViewIfNeeded()
  57. await expect(json).toBeInViewport()
  58. await expect(save).toBeInViewport()
  59. expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
  60. const rounds = page.getByLabel("最多研究轮次", { exact: true })
  61. await rounds.fill("9")
  62. await save.click()
  63. await expect(rounds).toBeFocused()
  64. const box = await rounds.boundingBox()
  65. const footer = await page.locator(".paas-edit-footer").boundingBox()
  66. expect(box!.y + box!.height).toBeLessThan(footer!.y)
  67. })
  68. }
  69. }