topicTeamPickerDialog.test.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import TopicTeamPickerDialog from '../../src/client/components/groups/TopicTeamPickerDialog.vue'
  4. const rooms = [{
  5. id: 'room-a', name: '产品团队', cwd: '', createdAt: 1, updatedAt: 2, archived: false,
  6. agentCount: 3, unreadCount: 0, maxReplyRounds: 3, instructions: '负责产品设计与评审', orchestrationMode: 'host' as const,
  7. avatarMembers: [{ profile: 'product', nodeId: 'local', displayName: '产品负责人' }],
  8. }, {
  9. id: 'room-b', name: '运维团队', cwd: '', createdAt: 1, updatedAt: 2, archived: false,
  10. agentCount: 2, unreadCount: 0, maxReplyRounds: 3,
  11. }]
  12. afterEach(() => { document.body.innerHTML = '' })
  13. describe('TopicTeamPickerDialog', () => {
  14. it('lists teams and emits the selected team before topic creation', async () => {
  15. const wrapper = mount(TopicTeamPickerDialog, {
  16. props: { open: true, rooms, currentRoomId: 'room-a' },
  17. attachTo: document.body,
  18. })
  19. expect(document.querySelector('[role="dialog"]')?.textContent).toContain('选择团队')
  20. expect(document.body.textContent).toContain('产品团队')
  21. expect(document.body.textContent).toContain('运维团队')
  22. expect(document.body.textContent).toContain('当前')
  23. const avatars = [...document.querySelectorAll<HTMLElement>('.topic-team-picker__choose .team-avatar')]
  24. expect(avatars[0]?.style.width).toBe('34px')
  25. expect(avatars[0]?.style.height).toBe('34px')
  26. const buttons = [...document.querySelectorAll<HTMLButtonElement>('.topic-team-picker__choose')]
  27. buttons[1]?.click()
  28. await wrapper.vm.$nextTick()
  29. expect(wrapper.emitted('select')).toEqual([['room-b']])
  30. wrapper.unmount()
  31. })
  32. it('shows team details without selecting or creating a topic', async () => {
  33. const wrapper = mount(TopicTeamPickerDialog, {
  34. props: { open: true, rooms, currentRoomId: 'room-a' },
  35. attachTo: document.body,
  36. })
  37. const details = document.querySelector<HTMLButtonElement>('[aria-label="查看产品团队详情"]')
  38. details?.click()
  39. await wrapper.vm.$nextTick()
  40. const panel = document.querySelector('[aria-label="产品团队团队详情"]')
  41. expect(panel?.textContent).toContain('负责产品设计与评审')
  42. expect(panel?.textContent).toContain('产品负责人')
  43. expect(panel?.textContent).toContain('管理员协调')
  44. expect(panel?.textContent).toContain('3 轮')
  45. expect(wrapper.emitted('select')).toBeUndefined()
  46. wrapper.unmount()
  47. })
  48. it('closes on Escape without selecting a team', async () => {
  49. const wrapper = mount(TopicTeamPickerDialog, { props: { open: true, rooms }, attachTo: document.body })
  50. document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
  51. expect(wrapper.emitted('close')).toHaveLength(1)
  52. expect(wrapper.emitted('select')).toBeUndefined()
  53. wrapper.unmount()
  54. })
  55. })