workspace-chat.spec.ts 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 createAgent(page, '产品经理')
  29. await page.getByRole('textbox', { name: '消息', exact: true }).fill('请说明角色职责')
  30. await page.getByRole('button', { name: '发送', exact: true }).click()
  31. await expect(page.locator('.message.assistant')).toContainText('我是产品经理')
  32. await expect(page.locator('.message.assistant a').first()).toHaveAttribute(
  33. 'href',
  34. /\/api\/app\/files\/.+\/download/,
  35. )
  36. const directURL = page.url()
  37. await createAgent(page, '开发工程师')
  38. await expect(page.locator('.message')).toHaveCount(0)
  39. await page.getByRole('button', { name: '+ 创建群聊', exact: true }).click()
  40. const dialog = page.getByRole('dialog')
  41. await dialog.getByRole('textbox', { name: '名称', exact: true }).fill('产品开发团队')
  42. await dialog.getByRole('checkbox', { name: '产品经理', exact: true }).check()
  43. await dialog.getByRole('checkbox', { name: '开发工程师', exact: true }).check()
  44. await dialog
  45. .getByRole('combobox', { name: '管理员', exact: true })
  46. .selectOption({ label: '产品经理' })
  47. await dialog.getByRole('button', { name: '保存', exact: true }).click()
  48. await expect(page.getByRole('heading', { name: '产品开发团队', exact: true })).toBeVisible()
  49. await expect(page.locator('.desktop-sidebar .conversation-row')).toHaveCount(3)
  50. await expect(page.locator('.desktop-sidebar')).not.toContainText('话题')
  51. await expect(page.locator('.desktop-sidebar .sidebar-account-switcher')).not.toContainText(
  52. '通用助手',
  53. )
  54. await page.getByRole('button', { name: '设置', exact: true }).click()
  55. await expect(dialog.getByRole('checkbox', { name: '产品经理', exact: true })).toBeDisabled()
  56. await expect(dialog.getByRole('checkbox', { name: '开发工程师', exact: true })).toBeDisabled()
  57. await dialog.getByRole('button', { name: '取消', exact: true }).click()
  58. await page.getByRole('checkbox', { name: '@开发工程师', exact: true }).check()
  59. await page.getByRole('textbox', { name: '消息', exact: true }).fill('给出实现结果')
  60. await page.getByRole('button', { name: '发送', exact: true }).click()
  61. await expect(page.locator('.message.assistant')).toHaveCount(2)
  62. await expect(page.locator('.run-status')).toHaveCount(0)
  63. const second = await context.newPage()
  64. await second.goto(page.url())
  65. await expect(second.locator('.message.assistant')).toHaveCount(2)
  66. await page.screenshot({ path: testInfo.outputPath('mixed-chats.png'), fullPage: true })
  67. const groupURL=page.url()
  68. await page.getByRole('button',{name:'文件库',exact:true}).click()
  69. await page.getByRole('button',{name:'查看来源',exact:true}).first().click()
  70. await expect(page).toHaveURL(groupURL)
  71. await page.getByRole('button', { name: '归档', exact: true }).click()
  72. await expect(page.locator('.desktop-sidebar .conversation-row')).toHaveCount(2)
  73. await page.getByRole('checkbox', { name: '显示已归档', exact: true }).first().check()
  74. await expect(page.locator('.desktop-sidebar .conversation-row')).toHaveCount(1)
  75. await page.getByRole('button', { name: '恢复', exact: true }).click()
  76. await page.goto(directURL)
  77. await expect(page.locator('.message.assistant')).toHaveCount(1)
  78. await expect(page.locator('.message.assistant')).toContainText('我是产品经理')
  79. await page.getByRole('button', { name: '原生对话', exact: true }).click()
  80. await expect(page).toHaveURL(/\/chat/)
  81. expect(pluginCalls).toEqual([])
  82. await second.close()
  83. })