workspace.spec.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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: '新建群聊' })).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 pins first and loads the next session page at the list bottom', async ({ page }) => {
  37. const sidebar = page.locator('.desktop-sidebar')
  38. const items = sidebar.locator('.sidebar-list [role="option"]')
  39. await expect(items).toHaveCount(100)
  40. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  41. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  42. const list = sidebar.locator('.sidebar-list')
  43. await list.evaluate(element => {
  44. element.scrollTop = element.scrollHeight
  45. element.dispatchEvent(new Event('scroll'))
  46. })
  47. await expect(items).toHaveCount(103)
  48. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  49. })
  50. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  51. await page.route('**/api/app/sessions/unread*', async route => {
  52. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  53. })
  54. await page.goto('/chat/session-demo')
  55. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  56. await page.reload()
  57. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  58. })
  59. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  60. await page.goto('/chat/session-demo')
  61. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  62. await page.getByRole('button', { name: '群聊' }).click()
  63. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  64. })
  65. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  66. await page.goto('/chat/session-demo')
  67. const tool = page.getByRole('button', { name: /file_search/ })
  68. await expect(tool).toBeVisible()
  69. await tool.click()
  70. await expect(page.locator('.tool-trace pre')).toContainText('/tmp/demo-report.pdf')
  71. await expect(page.locator('.message--tool')).toHaveCount(0)
  72. })
  73. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  74. await page.goto('/chat/session-demo')
  75. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  76. await expect(page.locator('.delegation-event')).toContainText('2 个子任务 · 2 已完成')
  77. await expect(page.locator('.delegation-event')).not.toHaveAttribute('open', '')
  78. })
  79. test('opens a local message file link as a floating preview card', async ({ page }) => {
  80. await page.goto('/chat/session-demo')
  81. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  82. await expect(card).toHaveClass(/file-link-card/)
  83. await card.click()
  84. await expect(page.getByRole('dialog', { name: '预览 方案草稿.md' })).toBeVisible()
  85. })
  86. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  87. const logo = page.locator('.rail__brand img')
  88. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  89. const emptyLogo = page.locator('.new-chat-empty__logo')
  90. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  91. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  92. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  93. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  94. await page.getByRole('button', { name: '推理强度:默认' }).click()
  95. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  96. await page.getByRole('button', { name: '设置' }).click()
  97. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  98. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  99. await page.locator('.composer-shell').click()
  100. await page.getByRole('option').first().click()
  101. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  102. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  103. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  104. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  105. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  106. await page.getByRole('button', { name: '会话操作' }).click()
  107. await expect(page.getByText('重命名', { exact: true })).toBeVisible()
  108. await expect(page.getByText('删除会话', { exact: true })).toBeVisible()
  109. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  110. const composer = page.locator('.composer-shell')
  111. await expect(composer).toBeVisible()
  112. const geometry = await composer.evaluate(element => {
  113. const rect = element.getBoundingClientRect()
  114. const style = getComputedStyle(element)
  115. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  116. })
  117. expect(geometry.width).toBeLessThanOrEqual(760)
  118. expect(geometry.minHeight).toBe('72px')
  119. expect(geometry.radius).toBe('18px')
  120. const send = page.getByRole('button', { name: '发送消息' })
  121. await expect(send).toHaveCSS('width', '34px')
  122. await expect(send).toHaveCSS('height', '34px')
  123. })
  124. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  125. const sidebar = page.locator('.desktop-sidebar')
  126. await expect(sidebar).toBeVisible()
  127. await expect(sidebar).toHaveCSS('width', '264px')
  128. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  129. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  130. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  131. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  132. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  133. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  134. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  135. const triggerBox = await searchTrigger.boundingBox()
  136. await searchTrigger.click()
  137. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  138. await expect(search).toBeVisible()
  139. await page.waitForTimeout(150)
  140. const inputBox = await search.evaluate(element => {
  141. const rect = element.closest('label')?.getBoundingClientRect()
  142. return rect ? { y: rect.y, height: rect.height } : null
  143. })
  144. expect(inputBox?.y).toBe(triggerBox?.y)
  145. expect(inputBox?.height).toBe(triggerBox?.height)
  146. await search.fill('验收')
  147. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  148. await search.press('Escape')
  149. await expect(search).toBeHidden()
  150. await expect(searchTrigger).toBeVisible()
  151. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  152. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  153. await expect(sidebar).toHaveCSS('width', '68px')
  154. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  155. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  156. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  157. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  158. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  159. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  160. await page.reload()
  161. await expect(sidebar).toHaveCSS('width', '68px')
  162. await page.getByRole('button', { name: '搜索', exact: true }).click()
  163. await expect(sidebar).toHaveCSS('width', '264px')
  164. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  165. })
  166. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  167. await page.setViewportSize({ width: 390, height: 844 })
  168. await page.reload()
  169. await expect(page.getByRole('navigation')).not.toBeVisible()
  170. const drawer = page.locator('.mobile-drawer')
  171. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  172. await expect(drawer).toHaveAttribute('inert', '')
  173. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  174. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  175. })