workspace.spec.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  37. await page.route('**/api/app/sessions/unread*', async route => {
  38. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  39. })
  40. await page.goto('/chat/session-demo')
  41. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  42. await page.reload()
  43. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  44. })
  45. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  46. const logo = page.locator('.rail__brand img')
  47. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  48. const emptyLogo = page.locator('.new-chat-empty__logo')
  49. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  50. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  51. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  52. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  53. await page.getByRole('button', { name: '推理强度:默认' }).click()
  54. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  55. await page.getByRole('button', { name: '设置' }).click()
  56. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  57. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  58. await page.locator('.composer-shell').click()
  59. await page.getByRole('option').first().click()
  60. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  61. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  62. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  63. await page.getByRole('button', { name: '会话操作' }).click()
  64. await expect(page.getByText('重命名', { exact: true })).toBeVisible()
  65. await expect(page.getByText('删除会话', { exact: true })).toBeVisible()
  66. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  67. const composer = page.locator('.composer-shell')
  68. await expect(composer).toBeVisible()
  69. const geometry = await composer.evaluate(element => {
  70. const rect = element.getBoundingClientRect()
  71. const style = getComputedStyle(element)
  72. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  73. })
  74. expect(geometry.width).toBeLessThanOrEqual(760)
  75. expect(geometry.minHeight).toBe('72px')
  76. expect(geometry.radius).toBe('18px')
  77. const send = page.getByRole('button', { name: '发送消息' })
  78. await expect(send).toHaveCSS('width', '34px')
  79. await expect(send).toHaveCSS('height', '34px')
  80. })
  81. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  82. const sidebar = page.locator('.desktop-sidebar')
  83. await expect(sidebar).toBeVisible()
  84. await expect(sidebar).toHaveCSS('width', '264px')
  85. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  86. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  87. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  88. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  89. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  90. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  91. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  92. const triggerBox = await searchTrigger.boundingBox()
  93. await searchTrigger.click()
  94. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  95. await expect(search).toBeVisible()
  96. await page.waitForTimeout(150)
  97. const inputBox = await search.evaluate(element => {
  98. const rect = element.closest('label')?.getBoundingClientRect()
  99. return rect ? { y: rect.y, height: rect.height } : null
  100. })
  101. expect(inputBox?.y).toBe(triggerBox?.y)
  102. expect(inputBox?.height).toBe(triggerBox?.height)
  103. await search.fill('验收')
  104. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  105. await search.press('Escape')
  106. await expect(search).toBeHidden()
  107. await expect(searchTrigger).toBeVisible()
  108. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  109. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  110. await expect(sidebar).toHaveCSS('width', '68px')
  111. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  112. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  113. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  114. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  115. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  116. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  117. await page.reload()
  118. await expect(sidebar).toHaveCSS('width', '68px')
  119. await page.getByRole('button', { name: '搜索', exact: true }).click()
  120. await expect(sidebar).toHaveCSS('width', '264px')
  121. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  122. })
  123. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  124. await page.setViewportSize({ width: 390, height: 844 })
  125. await page.reload()
  126. await expect(page.getByRole('navigation')).not.toBeVisible()
  127. const drawer = page.locator('.mobile-drawer')
  128. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  129. await expect(drawer).toHaveAttribute('inert', '')
  130. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  131. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  132. })