workspace.spec.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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('uses the yaoyao-webui grouped model picker without a mobile full-screen sheet', async ({ page }) => {
  12. await page.goto('/chat/session-demo')
  13. await page.locator('.composer-tool--model').click()
  14. const dialog = page.getByRole('dialog', { name: '选择模型' })
  15. await expect(dialog).toBeVisible()
  16. await expect(dialog.getByPlaceholder('搜索模型名称或 ID')).toBeFocused()
  17. await expect(dialog.locator('.model-dialog__group-header')).toContainText('OpenAI')
  18. await expect(dialog.locator('.model-dialog__item--active')).toContainText('gpt-5.6')
  19. const desktopBox = await dialog.boundingBox()
  20. expect(desktopBox?.width).toBeGreaterThanOrEqual(450)
  21. expect(desktopBox?.width).toBeLessThanOrEqual(480)
  22. await dialog.getByPlaceholder('搜索模型名称或 ID').fill('gpt-5.5')
  23. await expect(dialog.locator('.model-dialog__item')).toHaveCount(1)
  24. await page.keyboard.press('Escape')
  25. await expect(dialog).toBeHidden()
  26. await page.setViewportSize({ width: 390, height: 844 })
  27. await page.locator('.composer-tool--model').click()
  28. const mobileBox = await dialog.boundingBox()
  29. expect(mobileBox?.x).toBeGreaterThanOrEqual(12)
  30. expect(mobileBox?.width).toBeLessThanOrEqual(366)
  31. expect(mobileBox?.height).toBeLessThan(820)
  32. })
  33. test('navigates every 9119 workspace without blank transitions', async ({ page }) => {
  34. const consoleErrors: string[] = []
  35. page.on('console', message => { if (message.type() === 'error') consoleErrors.push(message.text()) })
  36. await expect(page.getByRole('option').first()).toContainText('夭夭 Web 验收会话')
  37. await expect(page.getByRole('option').first()).toContainText('夭夭')
  38. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  39. await page.getByRole('button', { name: '群聊' }).click()
  40. await expect(page.getByRole('heading', { name: '设计与工程协作' })).toBeVisible()
  41. await expect(page.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  42. await expect(page.getByRole('button', { name: '群聊', exact: true })).toHaveCount(0)
  43. await expect(page.getByRole('button', { name: '文件库', exact: true })).toHaveCount(0)
  44. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  45. await expect(page.getByRole('button', { name: '新建群聊' })).toBeVisible()
  46. await expect(page.getByRole('button', { name: '新建群聊' })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  47. await expect(page.getByRole('button', { name: '新建群聊' })).toHaveCSS('font-weight', '580')
  48. await expect(page.getByRole('button', { name: '管理群聊' })).toBeVisible()
  49. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  50. await page.goto('/files')
  51. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  52. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  53. const firstFileCard = page.locator('.library-grid article').first()
  54. const cardGeometry = await firstFileCard.evaluate(element => {
  55. const card = element.getBoundingClientRect()
  56. const preview = element.querySelector('.library-thumb')?.getBoundingClientRect()
  57. return { width: card.width, previewHeight: preview?.height || 0 }
  58. })
  59. expect(cardGeometry.width).toBeGreaterThanOrEqual(220)
  60. expect(cardGeometry.previewHeight).toBe(154)
  61. await page.getByText('demo-report.pdf').click()
  62. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  63. await expect(page.locator('.preview-meta')).toHaveCount(0)
  64. const previewDialog = page.getByRole('dialog', { name: /预览 demo-report.pdf/ })
  65. await expect(previewDialog.getByRole('link', { name: '下载' })).toBeVisible()
  66. await expect(previewDialog.getByRole('button', { name: '加入输入框' })).toBeVisible()
  67. await expect(previewDialog.locator('.preview-close')).toBeVisible()
  68. const modalHeight = await page.locator('.preview-modal').evaluate(element => element.getBoundingClientRect().height)
  69. expect(modalHeight).toBeGreaterThan(600)
  70. await previewDialog.locator('.preview-close').click()
  71. await page.goto('/artifacts')
  72. await expect(page).toHaveURL(/\/chat$/)
  73. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  74. expect(consoleErrors).toEqual([])
  75. })
  76. test('keeps pins first and loads the next session page at the list bottom', async ({ page }) => {
  77. const sidebar = page.locator('.desktop-sidebar')
  78. const items = sidebar.locator('.sidebar-list [role="option"]')
  79. await expect(items).toHaveCount(100)
  80. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  81. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  82. const list = sidebar.locator('.sidebar-list')
  83. await list.evaluate(element => {
  84. element.scrollTop = element.scrollHeight
  85. element.dispatchEvent(new Event('scroll'))
  86. })
  87. await expect(items).toHaveCount(103)
  88. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  89. })
  90. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  91. await page.route('**/api/app/sessions/unread*', async route => {
  92. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  93. })
  94. await page.goto('/chat/session-demo')
  95. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  96. await page.reload()
  97. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  98. })
  99. test('opens a conversation even when marking it read is unsupported', async ({ page }) => {
  100. const pageErrors: string[] = []
  101. page.on('pageerror', error => pageErrors.push(error.message))
  102. await page.route('**/api/app/sessions/unread/*', async route => {
  103. await route.fulfill({ status: 405, contentType: 'application/json', body: JSON.stringify({ error: 'Method Not Allowed' }) })
  104. })
  105. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  106. await expect(page).toHaveURL(/\/chat\/session-second\?profile=yaoyao/)
  107. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  108. expect(pageErrors).toEqual([])
  109. })
  110. test('syncs the blue fast-mode shortcut with the iOS-compatible session config', async ({ page }) => {
  111. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  112. await page.goto('/chat/session-demo')
  113. const fast = page.getByRole('button', { name: '快速模式:已关闭' })
  114. await expect(fast).toHaveAttribute('aria-pressed', 'false')
  115. await fast.click()
  116. const enabled = page.getByRole('button', { name: '快速模式:已开启' })
  117. await expect(enabled).toHaveAttribute('aria-pressed', 'true')
  118. await expect(enabled).toHaveCSS('color', 'rgb(22, 119, 255)')
  119. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('使用快速模式')
  120. await page.getByRole('button', { name: '发送消息' }).click()
  121. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  122. const payload = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as { requests: Array<{ method: string; params: Record<string, unknown> }> }
  123. const fastConfigIndex = payload.requests.findIndex(request => request.method === 'config.set' && request.params.key === 'fast')
  124. const promptIndex = payload.requests.findIndex(request => request.method === 'prompt.submit')
  125. expect(fastConfigIndex).toBeGreaterThanOrEqual(0)
  126. expect(promptIndex).toBeGreaterThan(fastConfigIndex)
  127. expect(payload.requests[fastConfigIndex]?.params).toMatchObject({ key: 'fast', value: 'fast', scope: 'session' })
  128. await enabled.click()
  129. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toHaveAttribute('aria-pressed', 'false')
  130. await expect.poll(async () => {
  131. const next = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as typeof payload
  132. return next.requests.filter(request => request.method === 'config.set' && request.params.key === 'fast').at(-1)?.params.value
  133. }).toBe('normal')
  134. })
  135. test('reconciles an iOS fast-mode selection from the resumed 9119 session', async ({ page }) => {
  136. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  137. await page.goto('/chat/session-yaoer?profile=yaoer')
  138. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toBeVisible()
  139. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('读取 iOS 快速模式')
  140. await page.getByRole('button', { name: '发送消息' }).click()
  141. await expect(page.getByRole('button', { name: '快速模式:已开启' })).toHaveCSS('color', 'rgb(22, 119, 255)')
  142. const payload = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as { requests: Array<{ method: string; params: Record<string, unknown> }> }
  143. expect(payload.requests.some(request => request.method === 'session.resume' && request.params.session_id === 'session-yaoer')).toBe(true)
  144. expect(payload.requests.some(request => request.method === 'config.set' && request.params.key === 'fast')).toBe(false)
  145. })
  146. test('keeps the show-thinking preference across sessions of the same Agent', async ({ page }) => {
  147. await page.goto('/chat/session-demo')
  148. await expect(page.locator('.turn-trace')).toHaveCount(1)
  149. await page.locator('.composer-tool[aria-label="设置"]').click()
  150. const setting = page.getByRole('switch', { name: /显示思考/ })
  151. await expect(setting).toHaveAttribute('aria-checked', 'true')
  152. await setting.click()
  153. await expect(page.locator('.turn-trace')).toHaveCount(0)
  154. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  155. await expect(page.locator('.turn-trace')).toHaveCount(0)
  156. await page.locator('.composer-tool[aria-label="设置"]').click()
  157. await page.getByRole('switch', { name: /显示思考/ }).click()
  158. await expect(page.locator('.turn-trace')).toHaveCount(1)
  159. })
  160. test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
  161. await page.goto('/chat/session-yaoer')
  162. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  163. await expect(page).toHaveURL(/\/chat\/session-yaoer\?profile=yaoer/)
  164. await page.reload()
  165. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  166. })
  167. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  168. await page.goto('/chat/session-demo')
  169. const image = page.locator('.markdown img[alt="夭夭 Logo"]')
  170. await expect(image).toBeVisible()
  171. await image.click()
  172. const mediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  173. await expect(mediaDialog).toBeVisible()
  174. await expect(mediaDialog.getByRole('button', { name: '下一张媒体' })).toBeVisible()
  175. await mediaDialog.getByRole('button', { name: '下一张媒体' }).click()
  176. await expect(mediaDialog.locator('img')).toHaveAttribute('src', /variant=2/)
  177. await page.keyboard.press('ArrowLeft')
  178. await expect(mediaDialog.locator('img')).not.toHaveAttribute('src', /variant=2/)
  179. await expect(mediaDialog.getByRole('link', { name: /下载 AppIcon-1024\.png/ })).toBeVisible()
  180. await page.keyboard.press('Escape')
  181. await expect(page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })).toBeHidden()
  182. await image.click()
  183. const reopenedMediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  184. await reopenedMediaDialog.getByRole('button', { name: '添加到聊天' }).click()
  185. await expect(reopenedMediaDialog).toBeHidden()
  186. await expect(page.locator('.composer-attachments img[alt="AppIcon-1024.png"]')).toBeVisible()
  187. await page.getByRole('button', { name: '群聊' }).click()
  188. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  189. })
  190. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  191. await page.goto('/chat/session-demo')
  192. const trace = page.locator('.turn-trace').first()
  193. await expect(trace).not.toHaveAttribute('open', '')
  194. await expect(trace.locator('summary')).toContainText('思考与工具')
  195. await expect(trace.locator('summary')).toContainText('2 段思考 · 2 个工具')
  196. await trace.locator('summary').click()
  197. await expect(trace.locator('.turn-trace__reasoning')).toHaveCount(2)
  198. await expect(trace.locator('.tool-trace')).toHaveCount(2)
  199. await expect(trace.locator('.tool-trace__details')).toHaveCount(2)
  200. await expect(trace.locator('.tool-trace__details').filter({ hasText: '/tmp/demo-report.pdf' })).toBeVisible()
  201. await expect(page.locator('[data-message-id="message-tool-call"]')).toHaveCount(0)
  202. await expect(page.locator('.message--tool')).toHaveCount(0)
  203. })
  204. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  205. await page.goto('/chat/session-demo')
  206. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  207. const delegation = page.locator('.delegation-event').filter({ hasText: '子任务已完成' })
  208. await expect(delegation).toContainText('2 个子任务 · 2 已完成')
  209. await expect(delegation).not.toHaveAttribute('open', '')
  210. })
  211. test('renders context compaction as a collapsed timeline event', async ({ page }) => {
  212. await page.goto('/chat/session-demo')
  213. const compaction = page.locator('[data-message-id="message-compaction"] .compaction-event')
  214. await expect(compaction).toContainText('上下文已压缩')
  215. await expect(compaction).toContainText('压缩摘要已归档 · 点击查看')
  216. await expect(compaction).not.toHaveAttribute('open', '')
  217. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeHidden()
  218. await compaction.locator('summary').click()
  219. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeVisible()
  220. await expect(page.locator('[data-message-id="message-compaction"]')).toHaveClass(/message--system/)
  221. })
  222. test('renders model changes as a collapsed system event', async ({ page }) => {
  223. await page.goto('/chat/session-demo')
  224. await expect(page.getByText('模型已切换:gpt-5.6-terra', { exact: true })).toBeVisible()
  225. await expect(page.locator('.system-event')).not.toHaveAttribute('open', '')
  226. })
  227. test('opens a local message file link as a floating preview card', async ({ page }) => {
  228. await page.goto('/chat/session-demo')
  229. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  230. await expect(card).toHaveClass(/file-link-card/)
  231. await card.click()
  232. const dialog = page.getByRole('dialog', { name: '预览 方案草稿.md' })
  233. await expect(dialog).toBeVisible()
  234. const stageHeight = await dialog.locator('.preview-stage').evaluate(stage => stage.getBoundingClientRect().height)
  235. expect(stageHeight).toBeGreaterThan(500)
  236. })
  237. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  238. const logo = page.locator('.rail__brand img')
  239. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  240. const emptyLogo = page.locator('.new-chat-empty__logo')
  241. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  242. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  243. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  244. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  245. await page.getByRole('button', { name: '推理强度:默认' }).click()
  246. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  247. await page.getByRole('button', { name: '设置' }).click()
  248. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  249. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  250. await page.locator('.composer-shell').click()
  251. await page.getByRole('option').first().click()
  252. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  253. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  254. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  255. const assistantMessage = page.locator('.message--assistant-anonymous:not(.message--tool-only)').first()
  256. await page.mouse.move(1200, 20)
  257. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '0')
  258. await assistantMessage.hover()
  259. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '1')
  260. await expect(page.locator('.message--tool-only .message__actions')).toHaveCount(0)
  261. await expect(page.locator('[data-message-id="message-thinking-tool"]')).toHaveCount(0)
  262. await expect(page.locator('.turn-trace')).toHaveCount(1)
  263. await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
  264. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  265. await page.getByRole('button', { name: '会话操作' }).click()
  266. const sessionMenu = page.getByRole('menu', { name: '会话操作' })
  267. await expect(sessionMenu.getByText('会话大纲', { exact: true })).toBeVisible()
  268. await sessionMenu.getByText('会话大纲', { exact: true }).click()
  269. const outline = page.getByRole('navigation', { name: '会话大纲' })
  270. await expect(outline).toBeVisible()
  271. await expect(outline.getByText('请检查今天生成的产物。MEDIA:/brand/AppIcon-1024.png', { exact: true })).toBeVisible()
  272. await expect(outline.getByText('验收摘要', { exact: true })).toBeVisible()
  273. await outline.getByRole('button', { name: '跳转到 验收摘要' }).click()
  274. await expect(page.locator('[data-message-id="message-assistant"]')).toHaveClass(/message--revealed/)
  275. await page.getByRole('button', { name: '关闭会话大纲' }).click()
  276. await expect(outline).toBeHidden()
  277. await page.getByRole('button', { name: '会话操作' }).click()
  278. await expect(sessionMenu.getByText('取消置顶', { exact: true })).toBeVisible()
  279. const unpinIcon = sessionMenu.getByRole('menuitem', { name: '取消置顶' }).locator('.app-icon')
  280. await expect(unpinIcon.locator('path')).toHaveCount(2)
  281. await expect(unpinIcon.locator('path').last()).toHaveAttribute('d', 'M4 4l16 16')
  282. await expect(page.locator('.desktop-sidebar .sidebar-item--single-line').first().locator('.app-icon path')).toHaveAttribute('fill', 'currentColor')
  283. await expect(sessionMenu.getByText('重命名', { exact: true })).toBeVisible()
  284. await expect(sessionMenu.getByText('删除会话', { exact: true })).toBeVisible()
  285. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  286. const menuBox = await sessionMenu.evaluate(element => element.getBoundingClientRect().toJSON())
  287. expect(menuBox.width).toBeLessThanOrEqual(220)
  288. expect(menuBox.height).toBeLessThan(165)
  289. await expect(page.locator('.session-action-layer')).toHaveCount(0)
  290. await sessionMenu.getByText('取消置顶', { exact: true }).click()
  291. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toHaveCount(0)
  292. await page.getByRole('button', { name: '会话操作' }).click()
  293. await sessionMenu.getByText('置顶会话', { exact: true }).click()
  294. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  295. const compactSession = page.locator('.desktop-sidebar .sidebar-item--single-line').first()
  296. const compactMetrics = await compactSession.evaluate(element => {
  297. const title = element.querySelector('strong')
  298. return {
  299. height: element.getBoundingClientRect().height,
  300. weight: title ? Number(getComputedStyle(title).fontWeight) : 0,
  301. }
  302. })
  303. expect(compactMetrics.height).toBeLessThanOrEqual(31)
  304. expect(compactMetrics.weight).toBeLessThan(500)
  305. await compactSession.click({ button: 'right' })
  306. await expect(sessionMenu).toBeVisible()
  307. await page.keyboard.press('Escape')
  308. const composer = page.locator('.composer-shell')
  309. await expect(composer).toBeVisible()
  310. const geometry = await composer.evaluate(element => {
  311. const rect = element.getBoundingClientRect()
  312. const style = getComputedStyle(element)
  313. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  314. })
  315. expect(geometry.width).toBeLessThanOrEqual(760)
  316. expect(geometry.minHeight).toBe('72px')
  317. expect(geometry.radius).toBe('18px')
  318. const send = page.getByRole('button', { name: '发送消息' })
  319. await expect(send).toHaveCSS('width', '34px')
  320. await expect(send).toHaveCSS('height', '34px')
  321. })
  322. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  323. const sidebar = page.locator('.desktop-sidebar')
  324. await expect(sidebar).toBeVisible()
  325. await expect(sidebar).toHaveCSS('width', '264px')
  326. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  327. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  328. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  329. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  330. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  331. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  332. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('font-weight', '580')
  333. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  334. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  335. const triggerBox = await searchTrigger.boundingBox()
  336. await searchTrigger.click()
  337. const search = page.getByPlaceholder('搜索会话').filter({ visible: true })
  338. await expect(search).toBeVisible()
  339. await page.waitForTimeout(150)
  340. const inputBox = await search.evaluate(element => {
  341. const rect = element.closest('label')?.getBoundingClientRect()
  342. return rect ? { y: rect.y, height: rect.height } : null
  343. })
  344. expect(inputBox?.y).toBe(triggerBox?.y)
  345. expect(inputBox?.height).toBe(triggerBox?.height)
  346. await search.fill('验收')
  347. await expect(page.getByRole('option', { name: /夭夭 Web 验收会话/ })).toBeVisible()
  348. await search.press('Escape')
  349. await expect(search).toBeHidden()
  350. await expect(searchTrigger).toBeVisible()
  351. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  352. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  353. await expect(sidebar).toHaveCSS('width', '68px')
  354. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  355. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  356. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  357. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  358. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  359. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  360. await page.reload()
  361. await expect(sidebar).toHaveCSS('width', '68px')
  362. await page.getByRole('button', { name: '搜索', exact: true }).click()
  363. await expect(sidebar).toHaveCSS('width', '264px')
  364. await expect(page.getByPlaceholder('搜索会话').filter({ visible: true })).toBeVisible()
  365. })
  366. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  367. await page.setViewportSize({ width: 390, height: 844 })
  368. await page.reload()
  369. await expect(page.getByRole('navigation')).not.toBeVisible()
  370. const drawer = page.locator('.mobile-drawer')
  371. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  372. await expect(drawer).toHaveAttribute('inert', '')
  373. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  374. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  375. })