topicTeamPickerDialog.test.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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,
  7. }, {
  8. id: 'room-b', name: '运维团队', cwd: '', createdAt: 1, updatedAt: 2, archived: false,
  9. agentCount: 2, unreadCount: 0, maxReplyRounds: 3,
  10. }]
  11. afterEach(() => { document.body.innerHTML = '' })
  12. describe('TopicTeamPickerDialog', () => {
  13. it('lists teams and emits the selected team before topic creation', async () => {
  14. const wrapper = mount(TopicTeamPickerDialog, {
  15. props: { open: true, rooms, currentRoomId: 'room-a' },
  16. attachTo: document.body,
  17. })
  18. expect(document.querySelector('[role="dialog"]')?.textContent).toContain('选择团队')
  19. expect(document.body.textContent).toContain('产品团队')
  20. expect(document.body.textContent).toContain('运维团队')
  21. expect(document.body.textContent).toContain('当前')
  22. const buttons = [...document.querySelectorAll<HTMLButtonElement>('.topic-team-picker__list > button')]
  23. buttons[1]?.click()
  24. await wrapper.vm.$nextTick()
  25. expect(wrapper.emitted('select')).toEqual([['room-b']])
  26. wrapper.unmount()
  27. })
  28. it('closes on Escape without selecting a team', async () => {
  29. const wrapper = mount(TopicTeamPickerDialog, { props: { open: true, rooms }, attachTo: document.body })
  30. document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
  31. expect(wrapper.emitted('close')).toHaveLength(1)
  32. expect(wrapper.emitted('select')).toBeUndefined()
  33. wrapper.unmount()
  34. })
  35. })