workspace.spec.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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('夭夭 Web 验收会话')
  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: '产物', exact: true })).toHaveCount(0)
  23. await expect(page.getByRole('button', { name: '新建群聊' })).toBeVisible()
  24. await expect(page.getByRole('button', { name: '管理群聊' })).toBeVisible()
  25. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  26. await page.goto('/files')
  27. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  28. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  29. await page.getByText('demo-report.pdf').click()
  30. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  31. await expect(page.locator('.preview-meta')).toHaveCount(0)
  32. const previewDialog = page.getByRole('dialog', { name: /预览 demo-report.pdf/ })
  33. await expect(previewDialog.getByRole('link', { name: '下载' })).toBeVisible()
  34. await expect(previewDialog.getByRole('button', { name: '加入输入框' })).toBeVisible()
  35. await expect(previewDialog.locator('.preview-close')).toBeVisible()
  36. const modalHeight = await page.locator('.preview-modal').evaluate(element => element.getBoundingClientRect().height)
  37. expect(modalHeight).toBeGreaterThan(600)
  38. await previewDialog.locator('.preview-close').click()
  39. await page.goto('/artifacts')
  40. await expect(page).toHaveURL(/\/chat$/)
  41. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  42. expect(consoleErrors).toEqual([])
  43. })
  44. test('keeps pins first and loads the next session page at the list bottom', async ({ page }) => {
  45. const sidebar = page.locator('.desktop-sidebar')
  46. const items = sidebar.locator('.sidebar-list [role="option"]')
  47. await expect(items).toHaveCount(100)
  48. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  49. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  50. const list = sidebar.locator('.sidebar-list')
  51. await list.evaluate(element => {
  52. element.scrollTop = element.scrollHeight
  53. element.dispatchEvent(new Event('scroll'))
  54. })
  55. await expect(items).toHaveCount(103)
  56. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  57. })
  58. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  59. await page.route('**/api/app/sessions/unread*', async route => {
  60. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  61. })
  62. await page.goto('/chat/session-demo')
  63. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  64. await page.reload()
  65. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  66. })
  67. test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
  68. await page.goto('/chat/session-yaoer')
  69. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  70. await expect(page).toHaveURL(/\/chat\/session-yaoer\?profile=yaoer/)
  71. await page.reload()
  72. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  73. })
  74. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  75. await page.goto('/chat/session-demo')
  76. const image = page.locator('.markdown img[alt="夭夭 Logo"]')
  77. await expect(image).toBeVisible()
  78. await image.click()
  79. const mediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  80. await expect(mediaDialog).toBeVisible()
  81. await expect(mediaDialog.getByRole('button', { name: '下一张媒体' })).toBeVisible()
  82. await mediaDialog.getByRole('button', { name: '下一张媒体' }).click()
  83. await expect(mediaDialog.locator('img')).toHaveAttribute('src', /variant=2/)
  84. await page.keyboard.press('Escape')
  85. await expect(page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })).toBeHidden()
  86. await page.getByRole('button', { name: '群聊' }).click()
  87. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  88. })
  89. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  90. await page.goto('/chat/session-demo')
  91. const tool = page.locator('[data-message-id="message-tool-call"]').getByRole('button', { name: /file_search/ })
  92. await expect(tool).toBeVisible()
  93. await tool.click()
  94. await expect(page.locator('.tool-trace pre')).toContainText('/tmp/demo-report.pdf')
  95. await expect(page.locator('.message--tool')).toHaveCount(0)
  96. })
  97. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  98. await page.goto('/chat/session-demo')
  99. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  100. await expect(page.locator('.delegation-event')).toContainText('2 个子任务 · 2 已完成')
  101. await expect(page.locator('.delegation-event')).not.toHaveAttribute('open', '')
  102. })
  103. test('renders model changes as a collapsed system event', async ({ page }) => {
  104. await page.goto('/chat/session-demo')
  105. await expect(page.getByText('模型已切换:gpt-5.6-terra', { exact: true })).toBeVisible()
  106. await expect(page.locator('.system-event')).not.toHaveAttribute('open', '')
  107. })
  108. test('opens a local message file link as a floating preview card', async ({ page }) => {
  109. await page.goto('/chat/session-demo')
  110. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  111. await expect(card).toHaveClass(/file-link-card/)
  112. await card.click()
  113. const dialog = page.getByRole('dialog', { name: '预览 方案草稿.md' })
  114. await expect(dialog).toBeVisible()
  115. const stageHeight = await dialog.locator('.preview-stage').evaluate(stage => stage.getBoundingClientRect().height)
  116. expect(stageHeight).toBeGreaterThan(500)
  117. })
  118. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  119. const logo = page.locator('.rail__brand img')
  120. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  121. const emptyLogo = page.locator('.new-chat-empty__logo')
  122. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  123. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  124. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  125. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  126. await page.getByRole('button', { name: '推理强度:默认' }).click()
  127. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  128. await page.getByRole('button', { name: '设置' }).click()
  129. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  130. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  131. await page.locator('.composer-shell').click()
  132. await page.getByRole('option').first().click()
  133. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  134. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  135. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  136. const assistantMessage = page.locator('.message--assistant-anonymous:not(.message--tool-only)').first()
  137. await page.mouse.move(1200, 20)
  138. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '0')
  139. await assistantMessage.hover()
  140. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '1')
  141. await expect(page.locator('.message--tool-only .message__actions')).toHaveCount(0)
  142. await expect(page.locator('[data-message-id="message-thinking-tool"] .message__actions')).toHaveCount(0)
  143. await expect(page.locator('[data-message-id="message-thinking-tool"]')).toHaveClass(/message--assistant-internal/)
  144. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  145. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  146. await page.getByRole('button', { name: '会话操作' }).click()
  147. await expect(page.getByText('重命名', { exact: true })).toBeVisible()
  148. await expect(page.getByText('删除会话', { exact: true })).toBeVisible()
  149. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  150. const composer = page.locator('.composer-shell')
  151. await expect(composer).toBeVisible()
  152. const geometry = await composer.evaluate(element => {
  153. const rect = element.getBoundingClientRect()
  154. const style = getComputedStyle(element)
  155. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  156. })
  157. expect(geometry.width).toBeLessThanOrEqual(760)
  158. expect(geometry.minHeight).toBe('72px')
  159. expect(geometry.radius).toBe('18px')
  160. const send = page.getByRole('button', { name: '发送消息' })
  161. await expect(send).toHaveCSS('width', '34px')
  162. await expect(send).toHaveCSS('height', '34px')
  163. })
  164. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  165. const sidebar = page.locator('.desktop-sidebar')
  166. await expect(sidebar).toBeVisible()
  167. await expect(sidebar).toHaveCSS('width', '264px')
  168. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  169. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  170. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  171. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  172. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  173. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  174. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  175. const triggerBox = await searchTrigger.boundingBox()
  176. await searchTrigger.click()
  177. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  178. await expect(search).toBeVisible()
  179. await page.waitForTimeout(150)
  180. const inputBox = await search.evaluate(element => {
  181. const rect = element.closest('label')?.getBoundingClientRect()
  182. return rect ? { y: rect.y, height: rect.height } : null
  183. })
  184. expect(inputBox?.y).toBe(triggerBox?.y)
  185. expect(inputBox?.height).toBe(triggerBox?.height)
  186. await search.fill('验收')
  187. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  188. await search.press('Escape')
  189. await expect(search).toBeHidden()
  190. await expect(searchTrigger).toBeVisible()
  191. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  192. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  193. await expect(sidebar).toHaveCSS('width', '68px')
  194. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  195. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  196. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  197. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  198. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  199. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  200. await page.reload()
  201. await expect(sidebar).toHaveCSS('width', '68px')
  202. await page.getByRole('button', { name: '搜索', exact: true }).click()
  203. await expect(sidebar).toHaveCSS('width', '264px')
  204. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  205. })
  206. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  207. await page.setViewportSize({ width: 390, height: 844 })
  208. await page.reload()
  209. await expect(page.getByRole('navigation')).not.toBeVisible()
  210. const drawer = page.locator('.mobile-drawer')
  211. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  212. await expect(drawer).toHaveAttribute('inert', '')
  213. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  214. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  215. })