controls-layout.spec.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { expect, test } from "@playwright/test"
  2. for (const theme of ["light", "dark"] as const) {
  3. for (const width of [360, 1440]) {
  4. test(`composer controls align and remain actionable at ${width}px in ${theme}`, async ({ page }) => {
  5. await page.setViewportSize({ width, height: 800 })
  6. await page.emulateMedia({ colorScheme: theme })
  7. await page.goto("/e2e/paas/index.html?ux")
  8. await page.evaluate((mode) => {
  9. document.documentElement.style.colorScheme = mode
  10. document.documentElement.setAttribute("data-color-scheme", mode)
  11. }, theme)
  12. await page.getByLabel("API Key", { exact: true }).fill("controls-layout")
  13. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  14. const topbarAlignment = await page
  15. .locator(".paas-topbar-chat-actions .paas-icon-action, .paas-topbar-chat-actions .paas-more-actions > summary")
  16. .evaluateAll((elements) => {
  17. const centers = elements
  18. .filter((element) => element.getClientRects().length)
  19. .map((element) => {
  20. const box = element.getBoundingClientRect()
  21. return box.y + box.height / 2
  22. })
  23. return Math.max(...centers) - Math.min(...centers)
  24. })
  25. expect(topbarAlignment).toBeLessThanOrEqual(1)
  26. const upload = page.getByRole("button", { name: "添加文件", exact: true })
  27. const role = page.locator(".paas-agent-route > summary")
  28. const submit = page.getByRole("button", { name: "发送消息", exact: true })
  29. for (const control of [upload, role, submit]) await expect(control).toBeInViewport()
  30. const boxes = await Promise.all([upload, role, submit].map((control) => control.boundingBox()))
  31. const centers = boxes.map((box) => box!.y + box!.height / 2)
  32. expect(Math.max(...centers) - Math.min(...centers)).toBeLessThanOrEqual(1)
  33. expect(boxes[0]!.x + boxes[0]!.width).toBeLessThan(boxes[1]!.x)
  34. await role.focus()
  35. await page.keyboard.press("Enter")
  36. await expect(page.getByLabel("选择执行角色")).toBeVisible()
  37. await page.keyboard.press("Escape")
  38. await expect(role).toBeFocused()
  39. expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(width)
  40. await page.screenshot({ path: `/private/tmp/desktop-outcome-controls-${theme}-${width}.png` })
  41. if (width < 1100) await page.getByRole("button", { name: "打开导航", exact: true }).click()
  42. const archiveFits = await page.locator(".paas-archive-toggle").evaluate((element) => {
  43. const box = element.getBoundingClientRect()
  44. const parent = element.closest(".paas-nav-history")!.getBoundingClientRect()
  45. return box.top >= parent.top && box.bottom <= parent.bottom
  46. })
  47. expect(archiveFits).toBe(true)
  48. const project = page.getByLabel("切换项目", { exact: true })
  49. await expect(project).toBeVisible()
  50. const spacing = await project.evaluate((element) => {
  51. const style = getComputedStyle(element)
  52. return {
  53. padding: Number.parseFloat(style.paddingRight),
  54. image: style.backgroundImage,
  55. position: style.backgroundPosition,
  56. }
  57. })
  58. expect(spacing.padding).toBeGreaterThanOrEqual(32)
  59. expect(spacing.image).not.toBe("none")
  60. expect(spacing.position).toContain("12px")
  61. await page.getByRole("button", { name: "项目设置", exact: true }).click()
  62. const bind = page.getByRole("button", { name: "添加工作文件夹", exact: true })
  63. await expect(bind).toBeVisible()
  64. const appearance = await bind.evaluate((element) => {
  65. const style = getComputedStyle(element)
  66. const hint = element.previousElementSibling!
  67. return {
  68. border: Number.parseFloat(style.borderTopWidth),
  69. height: element.getBoundingClientRect().height,
  70. gap: element.getBoundingClientRect().top - hint.getBoundingClientRect().bottom,
  71. }
  72. })
  73. expect(appearance.border).toBeGreaterThanOrEqual(1)
  74. expect(appearance.height).toBeGreaterThanOrEqual(32)
  75. expect(appearance.gap).toBeGreaterThanOrEqual(6)
  76. await bind.click()
  77. await expect(page.getByRole("dialog")).toContainText("D:/Research/optics")
  78. await page.getByRole("button", { name: "完成", exact: true }).click()
  79. if (await page.locator(".paas-nav-backdrop").isVisible()) await page.keyboard.press("Escape")
  80. await expect(
  81. page.locator(".paas-composer-context").getByText("D:/Research/optics", { exact: true }),
  82. ).toBeVisible()
  83. })
  84. }
  85. }