workspace.spec.ts 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. import { expect, test } from '@playwright/test'
  2. const WIDE_DOCX_BASE64 = 'UEsDBAoAAAAIAKwmFF15bjPX6AAAAK0BAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbH1QyU7DMBD9FWuuKHHggBCK0wPLETiUDxjZk8SqN3nc0v49Tlt6QIXjzFv1+tXeO7GjzDYGBbdtB4KCjsaGScHn+rV5AMEFg0EXAyk4EMNq6NeHRCyqNrCCuZT0KCXrmTxyGxOFiowxeyz1zJNMqDc4kbzrunupYygUSlMWDxj6Zxpx64p42df3qUcmxyCeTsQlSwGm5KzGUnG5C+ZXSnNOaKvyyOHZJr6pBJBXExbk74Cz7r0Ok60h8YG5vKGvLPkVs5Em6q2vyvZ/mys94zhaTRf94pZy1MRcF/euvSAebfjpL49zD99QSwMECgAAAAAArCYUXQAAAAAAAAAAAAAAAAYAAABfcmVscy9QSwMECgAAAAgArCYUXZv9N+qtAAAAKQEAAAsAAABfcmVscy8ucmVsc43POw7CMAwG4KtE3mlaBoRQ0y4IqSsqB7ASN61oHkrCo7cnAwNFDIy2f3+W6/ZpZnanECdnBVRFCYysdGqyWsClP232wGJCq3B2lgQsFKFt6jPNmPJKHCcfWTZsFDCm5A+cRzmSwVg4TzZPBhcMplwGzT3KK2ri27Lc8fBpwNpknRIQOlUB6xdP/9huGCZJRydvhmz6ceIrkWUMmpKAhwuKq3e7yCzwpuarF5sXUEsDBAoAAAAAAKwmFF0AAAAAAAAAAAAAAAAFAAAAd29yZC9QSwMECgAAAAgArCYUXalT+9hjAQAABwMAABEAAAB3b3JkL2RvY3VtZW50LnhtbKVSW0/CMBT+K03fpXMBJYRBFAaaYDSKwdeydluTrW3awsBfb7uVDYwmJr6cc75z+c6lHU8PZQH2VGkmeASvewEElCeCMJ5F8H29uBpCoA3mBBeC0wgeqYbTybgaEZHsSsoNsARcj6oI5sbIEUI6yWmJdU9Iym0sFarExkKVoUooIpVIqNaWvyxQGAQ3qMSMQ0e5FeTotHRCOWEmG0YomD/PPoBUdM9oNUbO7aSqZZ1stoVXL8obG1C5oa6DYWB3sq6jtOOTA4bIZ6zwUexMG0rZgRIXRJdES8WIMzOrZ6JoaAd9y4p+daOLStNQJY30xMnmrOT7fKhLPD/GKl6swfrufhWDeL6MfzgF6vr8u9vr4/Lhb+1QsyNqH0LTxHjC7O3Tv0QY9uveubUHw76/n8yesHITCRnB27DOUCzLTYu2whhRtrCgaRfLKSZURbAGqRCmBdnOeNBseBoJnf4Z6v7w5AtQSwECFAAKAAAACACsJhRdeW4z1+gAAACtAQAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRfVHlwZXNdLnhtbFBLAQIUAAoAAAAAAKwmFF0AAAAAAAAAAAAAAAAGAAAAAAAAAAAAEAAAABkBAABfcmVscy9QSwECFAAKAAAACACsJhRdm/036q0AAAApAQAACwAAAAAAAAAAAAAAAAA9AQAAX3JlbHMvLnJlbHNQSwECFAAKAAAAAACsJhRdAAAAAAAAAAAAAAAABQAAAAAAAAAAABAAAAATAgAAd29yZC9QSwECFAAKAAAACACsJhRdqVP72GMBAAAHAwAAEQAAAAAAAAAAAAAAAAA2AgAAd29yZC9kb2N1bWVudC54bWxQSwUGAAAAAAUABQAgAQAAyAMAAAAA'
  3. test.beforeEach(async ({ page }) => {
  4. await page.goto('/chat')
  5. if (await page.getByRole('heading', { name: '登录 Hermes' }).isVisible()) {
  6. await page.getByLabel('账号').fill('test')
  7. await page.getByLabel('密码').fill('test')
  8. await page.getByRole('button', { name: '登录' }).click()
  9. }
  10. await expect(page.getByRole('navigation')).toBeVisible()
  11. })
  12. test('uses the yaoyao-webui grouped model picker without a mobile full-screen sheet', async ({ page }) => {
  13. await page.goto('/chat/session-demo')
  14. await page.locator('.composer-tool--model').click()
  15. const dialog = page.getByRole('dialog', { name: '选择模型' })
  16. await expect(dialog).toBeVisible()
  17. await expect(dialog.getByPlaceholder('搜索模型名称或 ID')).toBeFocused()
  18. await expect(dialog.locator('.model-dialog__group-header')).toContainText('OpenAI')
  19. await expect(dialog.locator('.model-dialog__item--active')).toContainText('gpt-5.6')
  20. const desktopBox = await dialog.boundingBox()
  21. expect(desktopBox?.width).toBeGreaterThanOrEqual(450)
  22. expect(desktopBox?.width).toBeLessThanOrEqual(480)
  23. await dialog.getByPlaceholder('搜索模型名称或 ID').fill('gpt-5.5')
  24. await expect(dialog.locator('.model-dialog__item')).toHaveCount(1)
  25. await page.keyboard.press('Escape')
  26. await expect(dialog).toBeHidden()
  27. await page.setViewportSize({ width: 390, height: 844 })
  28. await page.locator('.composer-tool--model').click()
  29. const mobileBox = await dialog.boundingBox()
  30. expect(mobileBox?.x).toBeGreaterThanOrEqual(12)
  31. expect(mobileBox?.width).toBeLessThanOrEqual(366)
  32. expect(mobileBox?.height).toBeLessThan(820)
  33. })
  34. test('navigates every 9119 workspace without blank transitions', async ({ page }) => {
  35. const consoleErrors: string[] = []
  36. page.on('console', message => { if (message.type() === 'error') consoleErrors.push(message.text()) })
  37. await expect(page.getByRole('option').first()).toContainText('夭夭 Web 验收会话')
  38. await expect(page.getByRole('option').first()).toContainText('夭夭')
  39. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  40. await page.getByRole('button', { name: '群聊' }).click()
  41. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  42. await expect(page.getByRole('button', { name: '对话', exact: true })).toBeVisible()
  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: '产物', exact: true })).toHaveCount(0)
  46. await expect(page.getByRole('button', { name: '新建群聊' })).toBeVisible()
  47. await expect(page.getByRole('button', { name: '新建群聊' })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  48. await expect(page.getByRole('button', { name: '新建群聊' })).toHaveCSS('font-weight', '580')
  49. await expect(page.getByRole('button', { name: '管理群聊' })).toBeVisible()
  50. await expect(page.getByRole('button', { name: '发送消息' })).toBeVisible()
  51. await page.goto('/files')
  52. await expect(page.getByRole('heading', { name: '文件库', exact: true }).last()).toBeVisible()
  53. const fileSidebar = page.locator('.desktop-sidebar')
  54. await expect(fileSidebar.getByRole('button', { name: '新建聊天' })).toBeVisible()
  55. await expect(fileSidebar.getByRole('button', { name: '搜索', exact: true })).toHaveCount(0)
  56. const compactControlHeights = await fileSidebar.locator('.sidebar-search-trigger, .sidebar-primary-action button, .sidebar-feature-nav button').evaluateAll(elements => (
  57. elements.map(element => element.getBoundingClientRect().height)
  58. ))
  59. expect(compactControlHeights.length).toBeGreaterThanOrEqual(3)
  60. expect(Math.max(...compactControlHeights)).toBeLessThanOrEqual(36)
  61. await expect(page.getByText('demo-report.pdf')).toBeVisible()
  62. const firstFileCard = page.locator('.library-grid article').first()
  63. const cardGeometry = await firstFileCard.evaluate(element => {
  64. const card = element.getBoundingClientRect()
  65. const preview = element.querySelector('.library-thumb')?.getBoundingClientRect()
  66. return { width: card.width, previewHeight: preview?.height || 0 }
  67. })
  68. expect(cardGeometry.width).toBeGreaterThanOrEqual(220)
  69. expect(cardGeometry.previewHeight).toBe(154)
  70. await page.getByText('demo-report.pdf').click()
  71. await expect(page.getByRole('dialog', { name: /预览 demo-report.pdf/ })).toBeVisible()
  72. await expect(page.locator('.preview-meta')).toHaveCount(0)
  73. const previewDialog = page.getByRole('dialog', { name: /预览 demo-report.pdf/ })
  74. await expect(previewDialog.getByRole('link', { name: '下载' })).toBeVisible()
  75. await expect(previewDialog.getByRole('button', { name: '加入输入框' })).toBeVisible()
  76. await expect(previewDialog.locator('.preview-close')).toBeVisible()
  77. const modalHeight = await page.locator('.preview-modal').evaluate(element => element.getBoundingClientRect().height)
  78. expect(modalHeight).toBeGreaterThan(600)
  79. await previewDialog.locator('.preview-close').click()
  80. await fileSidebar.getByRole('button', { name: '新建聊天' }).click()
  81. await expect(page).toHaveURL(/\/chat\/draft-[^?]+\?profile=yaoyao/)
  82. await page.goto('/artifacts')
  83. await expect(page).toHaveURL(/\/chat$/)
  84. await expect(page.getByRole('button', { name: '产物', exact: true })).toHaveCount(0)
  85. expect(consoleErrors).toEqual([])
  86. })
  87. test('uses the active session or group title in the browser title', async ({ page }) => {
  88. await page.goto('/chat/session-demo?profile=yaoyao')
  89. await expect(page).toHaveTitle('夭夭 Web 验收会话 · 夭夭')
  90. await page.goto('/groups/group-demo')
  91. await expect(page).toHaveTitle('设计与工程协作 · 夭夭')
  92. })
  93. test('uses a floating search dialog for group rooms', async ({ page }) => {
  94. await page.getByRole('button', { name: '群聊' }).click()
  95. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  96. await page.locator('.desktop-sidebar').getByRole('button', { name: '搜索', exact: true }).click()
  97. const searchDialog = page.getByRole('dialog', { name: '搜索群聊' })
  98. await expect(searchDialog).toBeVisible()
  99. await searchDialog.getByPlaceholder('搜索群聊').fill('设计')
  100. const roomResult = searchDialog.getByRole('option', { name: /设计与工程协作/ })
  101. await expect(roomResult).toBeVisible()
  102. await roomResult.click()
  103. await expect(searchDialog).toBeHidden()
  104. })
  105. test('edits every protocol v4 Agent setting with one inspector close control', async ({ page }) => {
  106. await page.getByRole('button', { name: '群聊' }).click()
  107. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible()
  108. await page.getByRole('button', { name: '管理群聊' }).click()
  109. await expect(page.getByRole('button', { name: '关闭群聊管理' })).toHaveCount(1)
  110. await expect(page.getByRole('button', { name: '关闭预览' })).toHaveCount(0)
  111. await expect(page.getByLabel('最多回复轮数')).toHaveValue('-1')
  112. await page.getByRole('button', { name: '设置夭夭' }).click()
  113. const editor = page.getByRole('dialog', { name: '夭夭 Agent 设置' })
  114. await expect(page.locator('.group-manager .agent-editor')).toHaveCount(0)
  115. await expect(editor.getByLabel('显示名称')).toHaveValue('夭夭')
  116. await expect(editor.getByLabel('职责说明')).toHaveValue('主 Agent')
  117. await expect(editor.getByLabel('模型')).toHaveValue(JSON.stringify(['openai', 'gpt-5.6']))
  118. await expect(editor.getByLabel('推理强度')).toHaveValue('high')
  119. await expect(editor.getByLabel('快速模式')).toHaveValue('true')
  120. await editor.getByLabel('显示名称').fill('所有人')
  121. const rejectedResponse = page.waitForResponse(response => response.request().method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(response.url()).pathname))
  122. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  123. expect((await rejectedResponse).status()).toBe(409)
  124. await expect(editor.getByRole('alert')).toContainText('成员名称不能使用“所有人”')
  125. await editor.getByRole('button', { name: '关闭 Agent 设置' }).click()
  126. await page.getByRole('button', { name: '设置夭夭' }).click()
  127. await expect(editor.getByLabel('显示名称')).toHaveValue('所有人')
  128. await editor.getByLabel('显示名称').fill('夭夭')
  129. await editor.getByLabel('模型').selectOption(JSON.stringify(['openai', 'gpt-5.5']))
  130. await editor.getByLabel('推理强度').selectOption('xhigh')
  131. await editor.getByLabel('快速模式').selectOption('false')
  132. await editor.getByLabel('自动回复').uncheck()
  133. const updateRequest = page.waitForRequest(request => request.method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(request.url()).pathname))
  134. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  135. expect((await updateRequest).postDataJSON()).toMatchObject({
  136. model: 'gpt-5.5', provider: 'openai', reasoningEffort: 'xhigh', fastMode: false, replyWithoutMention: false,
  137. })
  138. await expect(editor.getByLabel('模型')).toHaveValue(JSON.stringify(['openai', 'gpt-5.5']))
  139. await editor.getByLabel('模型').selectOption(JSON.stringify(['openai', 'gpt-5.6']))
  140. await editor.getByLabel('推理强度').selectOption('high')
  141. await editor.getByLabel('快速模式').selectOption('true')
  142. await editor.getByLabel('自动回复').check()
  143. const restoreResponse = page.waitForResponse(response => response.request().method() === 'PATCH' && /\/api\/app\/groups\/rooms\/[^/]+\/agents\/[^/]+$/.test(new URL(response.url()).pathname))
  144. await editor.getByRole('button', { name: '保存 Agent 设置' }).click()
  145. expect((await restoreResponse).status()).toBe(200)
  146. })
  147. test('pins the named Agent typing status above the group composer', async ({ page }) => {
  148. await page.getByRole('button', { name: '群聊' }).click()
  149. const composer = page.locator('.composer-area')
  150. await page.getByRole('textbox', { name: '发消息给群聊,输入 @ 提及 Agent' }).fill('@夭夭 检查输入状态')
  151. await page.getByRole('button', { name: '发送消息' }).click()
  152. const typing = composer.getByRole('status', { name: 'Agent 输入状态' })
  153. await page.waitForTimeout(250)
  154. await expect(typing).toHaveCount(0)
  155. await expect(typing).toHaveText('夭夭正在输入…')
  156. await expect(page.locator('.message-stack .thinking-indicator')).toHaveCount(0)
  157. const typingBox = await typing.boundingBox()
  158. const shellBox = await composer.locator('.composer-shell').boundingBox()
  159. expect(typingBox?.y).toBeLessThan(shellBox?.y ?? 0)
  160. await expect(typing).toHaveCount(0, { timeout: 4_000 })
  161. })
  162. test('reconnects the group event stream after an unexpected close', async ({ page }) => {
  163. await page.getByRole('button', { name: '群聊' }).click()
  164. await expect(page.getByText('已同步', { exact: true })).toBeVisible()
  165. const before = await (await page.request.get('http://127.0.0.1:19119/__test/group-connections')).json() as { count: number }
  166. await page.request.post('http://127.0.0.1:19119/__test/groups/disconnect')
  167. await expect.poll(async () => {
  168. const value = await (await page.request.get('http://127.0.0.1:19119/__test/group-connections')).json() as { count: number }
  169. return value.count
  170. }, { timeout: 5_000 }).toBeGreaterThan(before.count)
  171. await expect(page.getByText('已同步', { exact: true })).toBeVisible()
  172. })
  173. test('recovers the group page after its initial upstream connection fails', async ({ page }) => {
  174. await page.request.post('http://127.0.0.1:19119/__test/groups/availability', { data: { available: false } })
  175. await page.getByRole('button', { name: '群聊' }).click()
  176. await expect(page.getByRole('heading', { name: '群聊服务暂不可用' })).toBeVisible()
  177. await page.request.post('http://127.0.0.1:19119/__test/groups/availability', { data: { available: true } })
  178. await expect(page.getByRole('heading', { name: '设计验收' })).toBeVisible({ timeout: 5_000 })
  179. })
  180. test('previews an octet-stream Markdown file from the file library', async ({ page }) => {
  181. await page.route('**/api/app/files**', async route => {
  182. const url = new URL(route.request().url())
  183. if (url.pathname === '/api/app/files') {
  184. await route.fulfill({
  185. status: 200,
  186. contentType: 'application/json',
  187. body: JSON.stringify({
  188. profile: 'yaoyao',
  189. items: [{
  190. id: 'markdown-file',
  191. path: '/tmp/版本说明.md',
  192. name: '版本说明.md',
  193. extension: '.md',
  194. mimeType: 'application/octet-stream',
  195. size: 48,
  196. modifiedAt: Date.now() / 1000,
  197. exists: true,
  198. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  199. }, {
  200. id: 'empty-markdown-file',
  201. path: '/tmp/空白说明.md',
  202. name: '空白说明.md',
  203. extension: 'md',
  204. mimeType: 'application/octet-stream',
  205. size: 0,
  206. modifiedAt: Date.now() / 1000,
  207. exists: true,
  208. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  209. }],
  210. nextCursor: null,
  211. total: 2,
  212. }),
  213. })
  214. return
  215. }
  216. if (url.pathname === '/api/app/files/markdown-file/preview') {
  217. await route.fulfill({
  218. status: 200,
  219. contentType: 'application/octet-stream',
  220. body: '# 版本说明\n\n- Markdown 预览已恢复',
  221. })
  222. return
  223. }
  224. if (url.pathname === '/api/app/files/empty-markdown-file/preview') {
  225. await route.fulfill({ status: 200, contentType: 'application/octet-stream', body: '' })
  226. return
  227. }
  228. await route.continue()
  229. })
  230. await page.goto('/files')
  231. await page.getByText('版本说明.md', { exact: true }).click()
  232. const dialog = page.getByRole('dialog', { name: '预览 版本说明.md' })
  233. await expect(dialog.locator('.preview-text h1')).toHaveText('版本说明')
  234. await expect(dialog.getByText('Markdown 预览已恢复', { exact: true })).toBeVisible()
  235. await dialog.locator('.preview-close').click()
  236. await page.getByText('空白说明.md', { exact: true }).click()
  237. const emptyDialog = page.getByRole('dialog', { name: '预览 空白说明.md' })
  238. await expect(emptyDialog.locator('.preview-text')).toBeVisible()
  239. await expect(emptyDialog.locator('.preview-unavailable')).toHaveCount(0)
  240. })
  241. test('keeps DOCX body at 36px inset with zero canvas margin', async ({ page }) => {
  242. await page.setViewportSize({ width: 620, height: 760 })
  243. await page.route('**/api/app/files**', async route => {
  244. const url = new URL(route.request().url())
  245. if (url.pathname === '/api/app/files') {
  246. await route.fulfill({
  247. status: 200,
  248. contentType: 'application/json',
  249. body: JSON.stringify({
  250. profile: 'yaoyao',
  251. items: [{
  252. id: 'wide-docx-file',
  253. path: '/tmp/宽版文档.docx',
  254. name: '宽版文档.docx',
  255. extension: 'docx',
  256. mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  257. size: 1024,
  258. modifiedAt: Date.now() / 1000,
  259. exists: true,
  260. origins: [{ profile: 'yaoyao', sessionId: 'session-demo', sessionTitle: '夭夭 Web 验收会话' }],
  261. }],
  262. nextCursor: null,
  263. total: 1,
  264. }),
  265. })
  266. return
  267. }
  268. if (url.pathname === '/api/app/files/wide-docx-file/preview') {
  269. await route.fulfill({
  270. status: 200,
  271. contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  272. body: Buffer.from(WIDE_DOCX_BASE64, 'base64'),
  273. })
  274. return
  275. }
  276. await route.continue()
  277. })
  278. await page.goto('/files')
  279. await page.getByText('宽版文档.docx', { exact: true }).click()
  280. const dialog = page.getByRole('dialog', { name: '预览 宽版文档.docx' })
  281. const office = dialog.locator('.preview-office')
  282. await expect(office.locator('section.docx')).toBeVisible()
  283. const geometry = await office.evaluate(element => {
  284. const wrapper = element.querySelector<HTMLElement>('.docx-wrapper')!
  285. const pageElement = element.querySelector<HTMLElement>('section.docx')!
  286. const article = pageElement.querySelector<HTMLElement>('article')!
  287. const table = article.querySelector<HTMLElement>('table')!
  288. const officeRect = element.getBoundingClientRect()
  289. const pageRect = pageElement.getBoundingClientRect()
  290. const officeStyle = getComputedStyle(element)
  291. const wrapperStyle = getComputedStyle(wrapper)
  292. const articleStyle = getComputedStyle(article)
  293. return {
  294. officeLeft: officeRect.left,
  295. pageLeft: pageRect.left,
  296. pageWidth: pageRect.width,
  297. clientWidth: element.clientWidth,
  298. scrollWidth: element.scrollWidth,
  299. wrapperWidth: wrapper.getBoundingClientRect().width,
  300. articlePaddingTop: Number.parseFloat(articleStyle.paddingTop),
  301. articlePaddingLeft: Number.parseFloat(articleStyle.paddingLeft),
  302. articlePaddingRight: Number.parseFloat(articleStyle.paddingRight),
  303. tableLeft: table.getBoundingClientRect().left,
  304. tableRight: table.getBoundingClientRect().right,
  305. officeBackground: officeStyle.backgroundColor,
  306. wrapperBackground: wrapperStyle.backgroundColor,
  307. wrapperPaddingTop: Number.parseFloat(wrapperStyle.paddingTop),
  308. wrapperPaddingLeft: Number.parseFloat(wrapperStyle.paddingLeft),
  309. wrapperPaddingRight: Number.parseFloat(wrapperStyle.paddingRight),
  310. }
  311. })
  312. expect(geometry.pageWidth).toBeLessThanOrEqual(geometry.clientWidth)
  313. expect(geometry.pageLeft).toBeGreaterThanOrEqual(geometry.officeLeft)
  314. expect(geometry.scrollWidth).toBeLessThanOrEqual(geometry.clientWidth + 1)
  315. expect(Math.abs(geometry.wrapperWidth - geometry.clientWidth)).toBeLessThan(1)
  316. expect(geometry.articlePaddingTop).toBe(36)
  317. expect(geometry.articlePaddingLeft).toBe(36)
  318. expect(geometry.articlePaddingRight).toBe(36)
  319. expect(geometry.tableLeft).toBeGreaterThanOrEqual(geometry.pageLeft - 1)
  320. expect(geometry.tableRight).toBeLessThanOrEqual(geometry.pageLeft + geometry.pageWidth + 1)
  321. expect(geometry.officeBackground).toBe('rgb(255, 255, 255)')
  322. expect(geometry.wrapperBackground).toBe('rgb(255, 255, 255)')
  323. expect(geometry.wrapperPaddingTop).toBe(0)
  324. expect(geometry.wrapperPaddingLeft).toBe(0)
  325. expect(geometry.wrapperPaddingRight).toBe(0)
  326. await page.setViewportSize({ width: 930, height: 760 })
  327. const centered = await office.evaluate(element => {
  328. const pageElement = element.querySelector<HTMLElement>('section.docx')!
  329. const officeRect = element.getBoundingClientRect()
  330. const pageRect = pageElement.getBoundingClientRect()
  331. return {
  332. pageWidth: pageRect.width,
  333. clientWidth: element.clientWidth,
  334. leftGap: pageRect.left - officeRect.left,
  335. rightGap: officeRect.right - pageRect.right,
  336. }
  337. })
  338. expect(centered.pageWidth).toBeLessThan(centered.clientWidth)
  339. expect(centered.leftGap).toBeGreaterThanOrEqual(18)
  340. expect(centered.rightGap).toBeGreaterThanOrEqual(18)
  341. expect(Math.abs(centered.leftGap - centered.rightGap)).toBeLessThanOrEqual(12)
  342. })
  343. test('keeps pins first and loads the next session page at the list bottom', async ({ page }) => {
  344. const sidebar = page.locator('.desktop-sidebar')
  345. const items = sidebar.locator('.sidebar-list [role="option"]')
  346. await expect(items).toHaveCount(100)
  347. await expect(items.first()).toContainText('夭夭 Web 验收会话')
  348. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toBeVisible()
  349. const list = sidebar.locator('.sidebar-list')
  350. await list.evaluate(element => {
  351. element.scrollTop = element.scrollHeight
  352. element.dispatchEvent(new Event('scroll'))
  353. })
  354. await expect(items).toHaveCount(103)
  355. await expect(sidebar.getByRole('button', { name: '继续加载会话' })).toHaveCount(0)
  356. })
  357. test('switches the composer model to the selected historical session model', async ({ page }) => {
  358. await page.goto('/chat/session-demo?profile=yaoyao')
  359. await expect(page.locator('.composer-tool--model')).toContainText('gpt-5.6')
  360. await page.getByRole('option', { name: /第二个会话/ }).click()
  361. await expect(page.locator('.composer-tool--model')).toContainText('gpt-5.5')
  362. })
  363. test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
  364. await page.route('**/api/app/sessions/unread*', async route => {
  365. await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
  366. })
  367. await page.goto('/chat/session-demo')
  368. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  369. await page.reload()
  370. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  371. })
  372. test('opens a conversation even when marking it read is unsupported', async ({ page }) => {
  373. const pageErrors: string[] = []
  374. page.on('pageerror', error => pageErrors.push(error.message))
  375. await page.route('**/api/app/sessions/unread/*', async route => {
  376. await route.fulfill({ status: 405, contentType: 'application/json', body: JSON.stringify({ error: 'Method Not Allowed' }) })
  377. })
  378. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  379. await expect(page).toHaveURL(/\/chat\/session-second\?profile=yaoyao/)
  380. await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
  381. expect(pageErrors).toEqual([])
  382. })
  383. test('syncs the blue fast-mode shortcut with the iOS-compatible session config', async ({ page }) => {
  384. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  385. await page.goto('/chat/session-demo')
  386. const fast = page.getByRole('button', { name: '快速模式:已关闭' })
  387. await expect(fast).toHaveAttribute('aria-pressed', 'false')
  388. await fast.click()
  389. const enabled = page.getByRole('button', { name: '快速模式:已开启' })
  390. await expect(enabled).toHaveAttribute('aria-pressed', 'true')
  391. await expect(enabled).toHaveCSS('color', 'rgb(22, 119, 255)')
  392. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('使用快速模式')
  393. await page.getByRole('button', { name: '发送消息' }).click()
  394. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  395. 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> }> }
  396. const fastConfigIndex = payload.requests.findIndex(request => request.method === 'config.set' && request.params.key === 'fast')
  397. const promptIndex = payload.requests.findIndex(request => request.method === 'prompt.submit')
  398. expect(fastConfigIndex).toBeGreaterThanOrEqual(0)
  399. expect(promptIndex).toBeGreaterThan(fastConfigIndex)
  400. expect(payload.requests[fastConfigIndex]?.params).toMatchObject({ key: 'fast', value: 'fast', scope: 'session' })
  401. await enabled.click()
  402. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toHaveAttribute('aria-pressed', 'false')
  403. await expect.poll(async () => {
  404. const next = await (await page.request.get('http://127.0.0.1:19119/__test/rpc-requests')).json() as typeof payload
  405. return next.requests.filter(request => request.method === 'config.set' && request.params.key === 'fast').at(-1)?.params.value
  406. }).toBe('normal')
  407. })
  408. test('reconciles an iOS fast-mode selection from the resumed 9119 session', async ({ page }) => {
  409. await page.request.post('http://127.0.0.1:19119/__test/rpc-requests/reset')
  410. await page.goto('/chat/session-yaoer?profile=yaoer')
  411. await expect(page.getByRole('button', { name: '快速模式:已关闭' })).toBeVisible()
  412. await page.getByRole('textbox', { name: '输入消息,Enter 发送,Shift + Enter 换行' }).fill('读取 iOS 快速模式')
  413. await page.getByRole('button', { name: '发送消息' }).click()
  414. await expect(page.getByRole('button', { name: '快速模式:已开启' })).toHaveCSS('color', 'rgb(22, 119, 255)')
  415. 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> }> }
  416. expect(payload.requests.some(request => request.method === 'session.resume' && request.params.session_id === 'session-yaoer')).toBe(true)
  417. expect(payload.requests.some(request => request.method === 'config.set' && request.params.key === 'fast')).toBe(false)
  418. })
  419. test('keeps the show-thinking preference across sessions of the same Agent', async ({ page }) => {
  420. await page.goto('/chat/session-demo')
  421. await expect(page.locator('.turn-trace')).toHaveCount(1)
  422. await page.locator('.composer-tool[aria-label="设置"]').click()
  423. const setting = page.getByRole('switch', { name: /显示思考/ })
  424. await expect(setting).toHaveAttribute('aria-checked', 'true')
  425. await setting.click()
  426. await expect(page.locator('.turn-trace')).toHaveCount(0)
  427. await page.getByRole('option').filter({ hasText: '第二个会话' }).click()
  428. await expect(page.locator('.turn-trace')).toHaveCount(0)
  429. await page.locator('.composer-tool[aria-label="设置"]').click()
  430. await page.getByRole('switch', { name: /显示思考/ }).click()
  431. await expect(page.locator('.turn-trace')).toHaveCount(1)
  432. })
  433. test('restores a legacy session link under its owning Agent profile', async ({ page }) => {
  434. await page.goto('/chat/session-yaoer')
  435. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  436. await expect(page).toHaveURL(/\/chat\/session-yaoer\?profile=yaoer/)
  437. await page.reload()
  438. await expect(page.getByText('瑶儿历史消息', { exact: true })).toBeVisible()
  439. })
  440. test('renders historical assistant MEDIA as Markdown in chat and group chat', async ({ page }) => {
  441. await page.goto('/chat/session-demo')
  442. const image = page.locator('.markdown img[alt="夭夭 Logo"]')
  443. await expect(image).toBeVisible()
  444. await image.click()
  445. const mediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  446. await expect(mediaDialog).toBeVisible()
  447. await expect(mediaDialog.getByRole('button', { name: '下一张媒体' })).toBeVisible()
  448. await mediaDialog.getByRole('button', { name: '下一张媒体' }).click()
  449. await expect(mediaDialog.locator('img')).toHaveAttribute('src', /variant=2/)
  450. await page.keyboard.press('ArrowLeft')
  451. await expect(mediaDialog.locator('img')).not.toHaveAttribute('src', /variant=2/)
  452. await expect(mediaDialog.getByRole('link', { name: /下载 AppIcon-1024\.png/ })).toBeVisible()
  453. await page.keyboard.press('Escape')
  454. await expect(page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })).toBeHidden()
  455. await image.click()
  456. const reopenedMediaDialog = page.getByRole('dialog', { name: /预览 AppIcon-1024.png/ })
  457. await reopenedMediaDialog.getByRole('button', { name: '添加到聊天' }).click()
  458. await expect(reopenedMediaDialog).toBeHidden()
  459. await expect(page.locator('.composer-attachments img[alt="AppIcon-1024.png"]')).toBeVisible()
  460. await page.getByRole('button', { name: '群聊' }).click()
  461. await expect(page.locator('.markdown img[alt="AppIcon-1024.png"]')).toBeVisible()
  462. })
  463. test('selects existing group topics and creates a new protocol v4 topic on first send', async ({ page }) => {
  464. const roomId = '22222222-2222-4222-8222-222222222222'
  465. const existingTopicId = '88888888-8888-4888-8888-888888888888'
  466. const existingTopicSidebarId = `topic:${roomId}:${existingTopicId}`
  467. await page.getByRole('button', { name: '群聊' }).click()
  468. const sidebar = page.locator('.desktop-sidebar')
  469. const roomItem = sidebar.locator(`[data-sidebar-id="${roomId}"]`)
  470. const existingTopic = sidebar.locator(`[data-sidebar-id="${existingTopicSidebarId}"]`)
  471. await expect(existingTopic).toContainText('发布检查')
  472. await roomItem.getByRole('button', { name: '收起 设计与工程协作 的话题' }).click()
  473. await expect(existingTopic).toHaveCount(0)
  474. await roomItem.getByRole('button', { name: '展开 设计与工程协作 的话题' }).click()
  475. await expect(existingTopic).toContainText('发布检查')
  476. const existingTopicRequest = page.waitForRequest(request => {
  477. const url = new URL(request.url())
  478. return request.method() === 'GET'
  479. && url.pathname === `/api/app/groups/rooms/${roomId}/messages`
  480. && url.searchParams.get('topicId') === existingTopicId
  481. })
  482. await existingTopic.click()
  483. await existingTopicRequest
  484. await expect(page).toHaveURL(new RegExp(`/groups/${roomId}/${existingTopicId}$`))
  485. const timeline = page.locator('.message-stack')
  486. await expect(timeline.getByText('请核对发布话题的独立历史。', { exact: true })).toBeVisible()
  487. await expect(timeline.getByText('大家好,检查一下群聊输入框。', { exact: true })).toHaveCount(0)
  488. await roomItem.click({ button: 'right' })
  489. const roomActions = page.getByRole('menu', { name: '群聊房间操作' })
  490. await roomActions.getByRole('menuitem', { name: '新建话题' }).click()
  491. const draftTopic = sidebar.locator('.sidebar-item--nested').filter({ hasText: '新话题' })
  492. await expect(draftTopic).toBeVisible()
  493. const draftSidebarId = await draftTopic.getAttribute('data-sidebar-id')
  494. const newTopicId = draftSidebarId?.split(':').at(-1) || ''
  495. expect(newTopicId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i)
  496. expect(newTopicId).not.toBe(existingTopicId)
  497. await expect(page).toHaveURL(new RegExp(`/groups/${roomId}/${newTopicId}$`))
  498. const content = '新的发布验收话题'
  499. const sendRequestPromise = page.waitForRequest(request => {
  500. const url = new URL(request.url())
  501. return request.method() === 'POST' && url.pathname === `/api/app/groups/rooms/${roomId}/messages`
  502. })
  503. await page.getByRole('textbox', { name: '发消息给群聊,输入 @ 提及 Agent' }).fill(content)
  504. await page.getByRole('button', { name: '发送消息' }).click()
  505. const sendRequest = await sendRequestPromise
  506. const sentPayload = sendRequest.postDataJSON() as { topicId: string; content: string; clientMessageId: string }
  507. expect(sentPayload).toMatchObject({ topicId: newTopicId, content })
  508. const createdTopic = sidebar.locator(`[data-sidebar-id="topic:${roomId}:${newTopicId}"]`)
  509. const sentMessage = page.locator(`[data-message-id="${sentPayload.clientMessageId}"]`)
  510. await expect(createdTopic).toContainText(content)
  511. await expect(sentMessage).toContainText(content)
  512. await page.reload()
  513. await expect(createdTopic).toContainText(content)
  514. await expect(sentMessage).toContainText(content)
  515. })
  516. test('renders persisted user file markers as attachment cards', async ({ page }) => {
  517. await page.goto('/chat/session-demo?profile=yaoyao')
  518. const userMessage = page.locator('[data-message-id="message-user-file"]')
  519. await expect(userMessage).toContainText('查看附件')
  520. await expect(userMessage.getByRole('button', { name: /测试报告\.docx/ })).toBeVisible()
  521. await expect(userMessage).not.toContainText('@file:')
  522. await expect(userMessage).not.toContainText('用户附加文件')
  523. })
  524. test('renders persisted user image markers as direct images instead of file cards', async ({ page }) => {
  525. await page.goto('/chat/session-demo?profile=yaoyao')
  526. const userMessage = page.locator('[data-message-id="message-user-image"]')
  527. const imageAttachment = userMessage.locator('.message__attachment--image')
  528. await expect(imageAttachment).toBeVisible()
  529. await expect(imageAttachment.locator('img[alt="测试图片.png"]')).toBeVisible()
  530. await expect(imageAttachment.locator('strong')).toHaveCount(0)
  531. await expect(imageAttachment).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  532. await expect(userMessage).not.toContainText('@image:')
  533. await expect(userMessage).not.toContainText('[screenshot]')
  534. await imageAttachment.click()
  535. await expect(page.getByRole('dialog', { name: '预览 测试图片.png' })).toBeVisible()
  536. })
  537. test('folds tool result rows into their expandable tool call', async ({ page }) => {
  538. await page.goto('/chat/session-demo')
  539. const trace = page.locator('.turn-trace').first()
  540. await expect(trace).not.toHaveAttribute('open', '')
  541. await expect(trace.locator('summary')).toContainText('思考与工具')
  542. await expect(trace.locator('summary')).toContainText('2 段思考 · 2 个工具')
  543. await trace.locator('summary').click()
  544. await expect(trace.locator('.turn-trace__reasoning')).toHaveCount(2)
  545. await expect(trace.locator('.tool-trace')).toHaveCount(2)
  546. await expect(trace.locator('.tool-trace__details')).toHaveCount(2)
  547. await expect(trace.locator('.tool-trace__details').filter({ hasText: '/tmp/demo-report.pdf' })).toBeVisible()
  548. await expect(page.locator('[data-message-id="message-tool-call"]')).toHaveCount(0)
  549. await expect(page.locator('.message--tool')).toHaveCount(0)
  550. })
  551. test('renders subtask completion as a collapsed timeline event', async ({ page }) => {
  552. await page.goto('/chat/session-demo')
  553. await expect(page.getByText('子任务已完成', { exact: true })).toBeVisible()
  554. const delegation = page.locator('.delegation-event').filter({ hasText: '子任务已完成' })
  555. await expect(delegation).toContainText('2 个子任务 · 2 已完成')
  556. await expect(delegation).not.toHaveAttribute('open', '')
  557. })
  558. test('renders context compaction as a collapsed timeline event', async ({ page }) => {
  559. await page.goto('/chat/session-demo')
  560. const compaction = page.locator('[data-message-id="message-compaction"] .compaction-event')
  561. await expect(compaction).toContainText('上下文已压缩')
  562. await expect(compaction).toContainText('压缩摘要已归档 · 点击查看')
  563. await expect(compaction).not.toHaveAttribute('open', '')
  564. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeHidden()
  565. await compaction.locator('summary').click()
  566. await expect(compaction.getByText('Historical Task Snapshot', { exact: true })).toBeVisible()
  567. await expect(page.locator('[data-message-id="message-compaction"]')).toHaveClass(/message--system/)
  568. })
  569. test('renders model changes as a collapsed system event', async ({ page }) => {
  570. await page.goto('/chat/session-demo')
  571. await expect(page.getByText('模型已切换:gpt-5.6-terra', { exact: true })).toBeVisible()
  572. await expect(page.locator('.system-event')).not.toHaveAttribute('open', '')
  573. })
  574. test('opens a local message file link as a floating preview card', async ({ page }) => {
  575. await page.route('**/Users/samien/Agents/%E6%96%B9%E6%A1%88%E8%8D%89%E7%A8%BF.md', route => route.fulfill({
  576. status: 200,
  577. contentType: 'text/markdown',
  578. body: '# 会话文件\n\n这是会话中的文本文件。',
  579. }))
  580. await page.goto('/chat/session-demo')
  581. const card = page.getByRole('link', { name: '预览文件 方案草稿.md' })
  582. await expect(card).toHaveClass(/file-link-card/)
  583. await card.click()
  584. const dialog = page.getByRole('dialog', { name: '预览 方案草稿.md' })
  585. await expect(dialog).toBeVisible()
  586. await expect(dialog.locator('.preview-text')).toBeVisible()
  587. const textPadding = await dialog.locator('.preview-text').evaluate(element => {
  588. const style = getComputedStyle(element)
  589. return { left: Number.parseFloat(style.paddingLeft), right: Number.parseFloat(style.paddingRight) }
  590. })
  591. expect(textPadding.left).toBeGreaterThanOrEqual(24)
  592. expect(textPadding.right).toBeGreaterThanOrEqual(24)
  593. const stageHeight = await dialog.locator('.preview-stage').evaluate(stage => stage.getBoundingClientRect().height)
  594. expect(stageHeight).toBeGreaterThan(500)
  595. })
  596. test('shows a thinking animation after submit until output starts', async ({ page }) => {
  597. await page.goto('/chat/session-demo?profile=yaoyao')
  598. await page.locator('.composer-textarea').fill('请开始思考')
  599. await page.getByRole('button', { name: '发送消息' }).click()
  600. await expect(page.locator('.thinking-indicator')).toBeVisible()
  601. await expect(page.getByText('这是来自假 Gateway 的流式回复。', { exact: true })).toBeVisible()
  602. await expect(page.locator('.thinking-indicator')).toHaveCount(0)
  603. })
  604. test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
  605. const logo = page.locator('.rail__brand img')
  606. await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  607. const emptyLogo = page.locator('.new-chat-empty__logo')
  608. await expect(emptyLogo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
  609. await expect(page.getByText('聊点什么', { exact: true })).toBeVisible()
  610. await expect(page.locator('.timeline-header')).toHaveClass(/timeline-header--transparent/)
  611. await expect(page.locator('.composer-context')).toContainText('剩余 256.0k')
  612. await page.getByRole('button', { name: '推理强度:默认' }).click()
  613. await expect(page.locator('.composer-popover--reasoning')).toBeVisible()
  614. await page.getByRole('button', { name: '设置' }).click()
  615. await expect(page.locator('.composer-popover--settings')).toBeVisible()
  616. await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
  617. await page.locator('.composer-shell').click()
  618. await page.getByRole('option').first().click()
  619. await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
  620. await expect(page.locator('.message--assistant .message__avatar')).toHaveCount(0)
  621. await expect(page.locator('.message--assistant .message__meta')).toHaveCount(0)
  622. const assistantMessage = page.locator('.message--assistant-anonymous:not(.message--tool-only)').first()
  623. await page.mouse.move(1200, 20)
  624. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '0')
  625. await assistantMessage.hover()
  626. await expect(assistantMessage.locator('.message__actions')).toHaveCSS('opacity', '1')
  627. await expect(page.locator('.message--tool-only .message__actions')).toHaveCount(0)
  628. await expect(page.locator('[data-message-id="message-thinking-tool"]')).toHaveCount(0)
  629. await expect(page.locator('.turn-trace')).toHaveCount(1)
  630. const userMessageMeta = page.locator('.message--user .message__meta')
  631. await expect(userMessageMeta).not.toHaveCount(0)
  632. expect(await userMessageMeta.evaluateAll(elements => elements.every(element => getComputedStyle(element).display === 'none'))).toBe(true)
  633. await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
  634. await page.getByRole('button', { name: '会话操作' }).click()
  635. const sessionMenu = page.getByRole('menu', { name: '会话操作' })
  636. await expect(sessionMenu.getByText('会话大纲', { exact: true })).toBeVisible()
  637. await sessionMenu.getByText('会话大纲', { exact: true }).click()
  638. const outline = page.getByRole('navigation', { name: '会话大纲' })
  639. await expect(outline).toBeVisible()
  640. await expect(outline.getByText('请检查今天生成的产物。MEDIA:/brand/AppIcon-1024.png', { exact: true })).toBeVisible()
  641. await expect(outline.getByText('验收摘要', { exact: true })).toBeVisible()
  642. await outline.getByRole('button', { name: '跳转到 验收摘要' }).click()
  643. await expect(page.locator('[data-message-id="message-assistant"]')).toHaveClass(/message--revealed/)
  644. await page.getByRole('button', { name: '关闭会话大纲' }).click()
  645. await expect(outline).toBeHidden()
  646. await page.getByRole('button', { name: '会话操作' }).click()
  647. await expect(sessionMenu.getByText('取消置顶', { exact: true })).toBeVisible()
  648. const unpinIcon = sessionMenu.getByRole('menuitem', { name: '取消置顶' }).locator('.app-icon')
  649. await expect(unpinIcon.locator('path')).toHaveCount(2)
  650. await expect(unpinIcon.locator('path').last()).toHaveAttribute('d', 'M4 4l16 16')
  651. await expect(page.locator('.desktop-sidebar .sidebar-item--single-line').first().locator('.app-icon path')).toHaveAttribute('fill', 'currentColor')
  652. await expect(sessionMenu.getByText('重命名', { exact: true })).toBeVisible()
  653. await expect(sessionMenu.getByText('删除会话', { exact: true })).toBeVisible()
  654. await expect(page.getByText('置顶会话', { exact: true })).toHaveCount(0)
  655. const menuBox = await sessionMenu.evaluate(element => element.getBoundingClientRect().toJSON())
  656. expect(menuBox.width).toBeLessThanOrEqual(220)
  657. expect(menuBox.height).toBeLessThan(165)
  658. await expect(page.locator('.session-action-layer')).toHaveCount(0)
  659. await sessionMenu.getByText('取消置顶', { exact: true }).click()
  660. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toHaveCount(0)
  661. await page.getByRole('button', { name: '会话操作' }).click()
  662. await sessionMenu.getByText('置顶会话', { exact: true }).click()
  663. await expect(page.locator('.desktop-sidebar').getByText('已置顶 1', { exact: true })).toBeVisible()
  664. const compactSession = page.locator('.desktop-sidebar .sidebar-item--single-line').first()
  665. const compactMetrics = await compactSession.evaluate(element => {
  666. const title = element.querySelector('strong')
  667. return {
  668. height: element.getBoundingClientRect().height,
  669. weight: title ? Number(getComputedStyle(title).fontWeight) : 0,
  670. }
  671. })
  672. expect(compactMetrics.height).toBeLessThanOrEqual(31)
  673. expect(compactMetrics.weight).toBeLessThan(500)
  674. await compactSession.click({ button: 'right' })
  675. await expect(sessionMenu).toBeVisible()
  676. await page.keyboard.press('Escape')
  677. const composer = page.locator('.composer-shell')
  678. await expect(composer).toBeVisible()
  679. const geometry = await composer.evaluate(element => {
  680. const rect = element.getBoundingClientRect()
  681. const style = getComputedStyle(element)
  682. return { width: rect.width, minHeight: style.minHeight, radius: style.borderRadius }
  683. })
  684. expect(geometry.width).toBeLessThanOrEqual(760)
  685. expect(geometry.minHeight).toBe('72px')
  686. expect(geometry.radius).toBe('18px')
  687. const send = page.getByRole('button', { name: '发送消息' })
  688. await expect(send).toHaveCSS('width', '34px')
  689. await expect(send).toHaveCSS('height', '34px')
  690. })
  691. test('uses the unified Grok-style sidebar, search trigger, and persistent collapse', async ({ page }) => {
  692. const sidebar = page.locator('.desktop-sidebar')
  693. await expect(sidebar).toBeVisible()
  694. await expect(sidebar).toHaveCSS('width', '264px')
  695. await expect(sidebar.locator('.brand-mark__name')).toHaveCount(0)
  696. await expect(sidebar.locator('.profile-switcher')).toHaveCount(0)
  697. await expect(sidebar.locator('.sidebar-account-switcher')).toHaveCount(1)
  698. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  699. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  700. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
  701. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toHaveCSS('font-weight', '580')
  702. await expect(sidebar.getByText('历史记录', { exact: true })).toBeVisible()
  703. const searchTrigger = page.getByRole('button', { name: '搜索', exact: true })
  704. await searchTrigger.click()
  705. const searchDialog = page.getByRole('dialog', { name: '搜索会话' })
  706. await expect(searchDialog).toBeVisible()
  707. const search = searchDialog.getByPlaceholder('搜索会话')
  708. await expect(search).toBeVisible()
  709. await expect(sidebar.locator('.sidebar-search')).toHaveCount(0)
  710. const originalSessionCount = await sidebar.getByRole('option').count()
  711. await search.fill('验收')
  712. const sessionResult = searchDialog.getByRole('option', { name: /夭夭 Web 验收会话/ })
  713. await expect(sessionResult).toBeVisible()
  714. await expect(sidebar.getByRole('option')).toHaveCount(originalSessionCount)
  715. await sessionResult.click()
  716. await expect(page).toHaveURL(/\/chat\/session-demo\?profile=yaoyao/)
  717. await expect(searchDialog).toBeHidden()
  718. await expect(searchTrigger).toBeVisible()
  719. await expect(searchTrigger).toHaveAttribute('aria-expanded', 'false')
  720. await page.getByRole('button', { name: '折叠侧边栏' }).click()
  721. await expect(sidebar).toHaveCSS('width', '68px')
  722. const collapseBox = await page.getByRole('button', { name: '展开侧边栏' }).boundingBox()
  723. const accountBox = await sidebar.locator('.sidebar-account-switcher__main').boundingBox()
  724. expect(collapseBox?.y).toBeLessThan(accountBox?.y ?? 0)
  725. await expect(sidebar.getByText('历史记录', { exact: true })).toBeHidden()
  726. await expect(page.getByRole('button', { name: '搜索', exact: true })).toBeVisible()
  727. await expect(page.getByRole('button', { name: '新建聊天', exact: true })).toBeVisible()
  728. await page.reload()
  729. await expect(sidebar).toHaveCSS('width', '68px')
  730. await page.getByRole('button', { name: '搜索', exact: true }).click()
  731. await expect(sidebar).toHaveCSS('width', '264px')
  732. await expect(page.getByRole('dialog', { name: '搜索会话' })).toBeVisible()
  733. })
  734. test('uses the mobile composer and keeps the closed drawer inert', async ({ page }) => {
  735. await page.setViewportSize({ width: 390, height: 844 })
  736. await page.reload()
  737. await expect(page.getByRole('navigation')).not.toBeVisible()
  738. const drawer = page.locator('.mobile-drawer')
  739. await expect(drawer).toHaveAttribute('aria-hidden', 'true')
  740. await expect(drawer).toHaveAttribute('inert', '')
  741. await expect(page.locator('.mobile-header .brand-mark__plate')).toBeVisible()
  742. await expect(page.locator('.mobile-header .brand-mark__name')).toHaveCount(0)
  743. await page.getByRole('button', { name: '打开导航' }).click()
  744. await expect(drawer.locator('.brand-mark__plate')).toBeVisible()
  745. await expect(drawer.locator('.brand-mark__name')).toHaveCount(0)
  746. await expect(page.locator('.composer-shell')).toHaveCSS('min-height', '118px')
  747. await expect(page.locator('.composer-textarea')).toHaveCSS('font-size', '16px')
  748. })