workspace-chat.spec.ts 5.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { test, expect, type Page } from '@playwright/test'
  2. async function login(page: Page) {
  3. await page.goto('/conversations')
  4. await page.getByRole('textbox', { name: '账号', exact: true }).fill('fixture')
  5. await page.getByRole('textbox', { name: '密码', exact: true }).fill('fixture-pass')
  6. await page.getByRole('button', { name: '登录', exact: true }).click()
  7. await expect(page.getByRole('heading', { name: '还没有聊天' })).toBeVisible()
  8. }
  9. async function createAgent(page: Page, name: string) {
  10. await page.getByRole('button', { name: '+ 创建 Agent', exact: true }).click()
  11. const dialog = page.getByRole('dialog')
  12. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill(name)
  13. await dialog
  14. .getByRole('textbox', { name: '角色提示词与规则', exact: true })
  15. .fill(`你是${name},每次回复给出验收证据。`)
  16. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  17. await expect(page.getByRole('heading', { name, exact: true })).toBeVisible()
  18. }
  19. test('created roles and immutable teams share a durable chat list without plugin calls', async ({
  20. page,
  21. context,
  22. }, testInfo) => {
  23. const pluginCalls: string[] = []
  24. page.on('request', (r) => {
  25. if (r.url().includes('/plugins/yaoyao')) pluginCalls.push(r.url())
  26. })
  27. await login(page)
  28. await page.addInitScript(() => { Object.defineProperty(crypto, 'randomUUID', { value: undefined, configurable: true }) })
  29. await page.reload()
  30. await createAgent(page, '产品经理')
  31. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('请说明角色职责')
  32. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  33. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  34. await expect(page.locator('.message--assistant a').first()).toHaveAttribute(
  35. 'href',
  36. /\/api\/app\/files\/.+\/download/,
  37. )
  38. await page.getByRole('button', {name:'置顶聊天',exact:true}).click()
  39. await expect(page.getByRole('button', {name:'取消置顶',exact:true})).toBeVisible()
  40. const directURL = page.url()
  41. await createAgent(page, '开发工程师')
  42. await expect(page.locator('.message')).toHaveCount(0)
  43. await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click()
  44. const dialog = page.getByRole('dialog')
  45. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('产品开发团队')
  46. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).check()
  47. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).check()
  48. await dialog
  49. .getByRole('combobox', { name: '管理员', exact: true })
  50. .selectOption({ label: '产品经理' })
  51. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  52. await expect(page.getByRole('heading', { name: '产品开发团队', exact: true })).toBeVisible()
  53. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(3)
  54. await expect(page.locator('.desktop-sidebar')).not.toContainText('话题')
  55. await expect(page.locator('.desktop-sidebar .sidebar-account-switcher')).not.toContainText(
  56. '通用助手',
  57. )
  58. await page.getByRole('button', { name: '聊天设置', exact: true }).click()
  59. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  60. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).toBeDisabled()
  61. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  62. await page.getByPlaceholder('输入消息,Enter 发送,Shift + Enter 换行').fill('@开发工程师 给出实现结果')
  63. await page.getByRole('button', { name: '发送消息', exact: true }).click()
  64. await expect(page.locator('.message--assistant')).toHaveCount(2)
  65. await expect(page.locator('.run-status')).toHaveCount(0)
  66. const second = await context.newPage()
  67. await second.goto(page.url())
  68. await expect(second.locator('.message--assistant')).toHaveCount(2)
  69. await page.screenshot({ path: testInfo.outputPath('mixed-chats.png'), fullPage: true })
  70. const groupURL=page.url()
  71. await page.getByRole('button',{name:'文件库',exact:true}).click()
  72. await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
  73. await expect(page).toHaveURL(groupURL)
  74. await page.getByRole('button', { name: '归档聊天', exact: true }).click()
  75. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(2)
  76. await page.getByRole('checkbox', { name: '显示已归档', exact: true }).first().check()
  77. await expect(page.locator('.desktop-sidebar .sidebar-item')).toHaveCount(1)
  78. await page.getByRole('button', { name: '恢复聊天', exact: true }).click()
  79. await page.goto(directURL)
  80. await expect(page.locator('.message--assistant')).toHaveCount(1)
  81. await expect(page.locator('.message--assistant')).toContainText('我是产品经理')
  82. await page.getByRole('button', { name: '原生对话', exact: true }).click()
  83. await expect(page).toHaveURL(/\/chat/)
  84. expect(pluginCalls).toEqual([])
  85. await second.close()
  86. })