workspace.spec.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { expect, test } from '@playwright/test'
  2. test.beforeEach(async ({ page }) => {
  3. await page.goto('/chat')
  4. if (await page.getByRole('heading', { name: '登录 Hermes' }).isVisible()) {
  5. await page.getByLabel('账号').fill('test')
  6. await page.getByLabel('密码').fill('test')
  7. await page.getByRole('button', { name: '登录' }).click()
  8. }
  9. await expect(page.getByRole('navigation')).toBeVisible()
  10. })
  11. test('navigates every 9119 workspace without blank transitions', async ({ page }) => {
  12. const consoleErrors: string[] = []
  13. page.on('console', message => { if (message.type() === 'error') consoleErrors.push(message.text()) })
  14. await expect(page.getByRole('option').first()).toContainText('第二个会话')
  15. await expect(page.getByRole('option').first()).toContainText('夭夭')
  16. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  17. await page.getByRole('button', { name: '群聊' }).click()
  18. await expect(page.getByRole('heading', { name: '设计与工程协作' })).toBeVisible()
  19. await expect(page.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  20. await expect(page.getByRole('button', { name: '群聊', exact: true })).toHaveCount(0)
  21. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  22. await expect(page.getByRole('button', { name: '新建群聊' })).toBeVisible()
  23. await expect(page.getByRole('button', { name: '管理群聊' })).toBeVisible()
  24. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  25. await page.getByRole('button', { name: '文件库' }).click()
  26. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  27. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  28. await page.getByText('demo-report.pdf').click()
  29. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  30. await page.getByRole('button', { name: '关闭预览' }).click()
  31. await page.goto('/artifacts')
  32. await expect(page).toHaveURL(/\/chat$/)
  33. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  34. expect(consoleErrors).toEqual([])
  35. })
  36. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  37. const logo = page.locator('.rail__brand img')
  38. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  39. const emptyLogo = page.locator('.new-chat-empty__logo')
  40. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  41. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  42. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  43. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  44. await page.getByRole('button', { name: '推理强度:默认' }).click()
  45. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  46. await page.getByRole('button', { name: '设置' }).click()
  47. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  48. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  49. await page.locator('.composer-shell').click()
  50. await page.getByRole('option').first().click()
  51. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(245, 248, 252)')
  52. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  53. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  54. await page.getByRole('button', { name: '会话操作' }).click()
  55. await expect(page.getByText('重命名', { exact: true })).toBeVisible()
  56. await expect(page.getByText('删除会话', { exact: true })).toBeVisible()
  57. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  58. const composer = page.locator('.composer-shell')
  59. await expect(composer).toBeVisible()
  60. const geometry = await composer.evaluate(element => {
  61. const rect = element.getBoundingClientRect()
  62. const style = getComputedStyle(element)
  63. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  64. })
  65. expect(geometry.width).toBeLessThanOrEqual(760)
  66. expect(geometry.minHeight).toBe('72px')
  67. expect(geometry.radius).toBe('18px')
  68. const send = page.getByRole('button', { name: '发送消息' })
  69. await expect(send).toHaveCSS('width', '34px')
  70. await expect(send).toHaveCSS('height', '34px')
  71. })
  72. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  73. const sidebar = page.locator('.desktop-sidebar')
  74. await expect(sidebar).toBeVisible()
  75. await expect(sidebar).toHaveCSS('width', '264px')
  76. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  77. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  78. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  79. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  80. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  81. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  82. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  83. const triggerBox = await searchTrigger.boundingBox()
  84. await searchTrigger.click()
  85. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  86. await expect(search).toBeVisible()
  87. await page.waitForTimeout(150)
  88. const inputBox = await search.evaluate(element => {
  89. const rect = element.closest('label')?.getBoundingClientRect()
  90. return rect ? { y: rect.y, height: rect.height } : null
  91. })
  92. expect(inputBox?.y).toBe(triggerBox?.y)
  93. expect(inputBox?.height).toBe(triggerBox?.height)
  94. await search.fill('验收')
  95. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  96. await search.press('Escape')
  97. await expect(search).toBeHidden()
  98. await expect(searchTrigger).toBeVisible()
  99. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  100. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  101. await expect(sidebar).toHaveCSS('width', '68px')
  102. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  103. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  104. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  105. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  106. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  107. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  108. await page.reload()
  109. await expect(sidebar).toHaveCSS('width', '68px')
  110. await page.getByRole('button', { name: '搜索', exact: true }).click()
  111. await expect(sidebar).toHaveCSS('width', '264px')
  112. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  113. })
  114. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  115. await page.setViewportSize({ width: 390, height: 844 })
  116. await page.reload()
  117. await expect(page.getByRole('navigation')).not.toBeVisible()
  118. const drawer = page.locator('.mobile-drawer')
  119. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  120. await expect(drawer).toHaveAttribute('inert', '')
  121. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  122. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  123. })