workspace.spec.ts 17 KB

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