typography.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { expect, test, type Locator } from "@playwright/test"
  2. async function typography(locator: Locator) {
  3. return locator.evaluate((element) => {
  4. const style = getComputedStyle(element)
  5. return {
  6. size: Number.parseFloat(style.fontSize),
  7. weight: Number.parseFloat(style.fontWeight),
  8. family: style.fontFamily,
  9. }
  10. })
  11. }
  12. test("page, section, field and helper text retain a distinct hierarchy", async ({ page }) => {
  13. await page.goto("/e2e/paas/index.html?ux")
  14. await page.getByLabel("API Key", { exact: true }).fill("test-only")
  15. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  16. await page.getByRole("button", { name: "智能体", exact: true }).click()
  17. const title = await typography(page.getByRole("heading", { name: "智能体", exact: true }))
  18. const card = await typography(page.getByRole("heading", { name: "科研助手", exact: true }))
  19. const description = await typography(page.locator(".paas-agent-card-description"))
  20. expect(title.size).toBeGreaterThan(card.size)
  21. expect(card.size).toBeGreaterThan(description.size)
  22. expect(card.weight).toBeGreaterThan(description.weight)
  23. await page.getByRole("button", { name: "编辑 科研助手", exact: true }).click()
  24. await expect(page.getByRole("button", { name: "保存修改", exact: true })).toBeVisible()
  25. const section = await typography(page.locator("legend").filter({ hasText: "基本信息" }))
  26. const field = await typography(page.getByLabel("智能体名称", { exact: true }))
  27. const helper = await typography(page.locator(".paas-agent-edit-heading p"))
  28. expect(title.size).toBeGreaterThan(section.size)
  29. expect(section.size).toBeGreaterThan(field.size)
  30. expect(field.size).toBeGreaterThan(helper.size)
  31. expect(field.family).toBe(title.family)
  32. })
  33. test("research text has readable body size and descending heading levels", async ({ page }) => {
  34. await page.goto("/e2e/paas/index.html")
  35. await page.getByLabel("API Key", { exact: true }).fill("test-only")
  36. await page.getByRole("button", { name: "连接平台", exact: true }).click()
  37. await page.getByRole("button", { name: "智能体", exact: true }).click()
  38. await page.getByRole("button", { name: "与 科研助手 对话", exact: true }).click()
  39. await page.getByRole("textbox", { name: "消息", exact: true }).fill("制定研究计划")
  40. await page.getByRole("textbox", { name: "消息", exact: true }).press("Enter")
  41. const heading = page.getByRole("heading", { name: "研究计划", exact: true })
  42. await expect(heading).toBeVisible()
  43. const title = await typography(heading)
  44. const body = await typography(page.locator('[data-component="markdown"] p').filter({ hasText: "已整理材料" }))
  45. const code = await typography(page.locator('[data-component="markdown"] pre code').first())
  46. expect(title.size).toBeGreaterThan(body.size)
  47. expect(body.size).toBeGreaterThanOrEqual(16)
  48. expect(code.size).toBeGreaterThanOrEqual(13)
  49. expect(code.family).not.toBe(body.family)
  50. })