floatingResourceSearch.test.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import { mount } from '@vue/test-utils'
  3. import FloatingResourceSearch from '../../src/client/components/app/FloatingResourceSearch.vue'
  4. afterEach(() => { document.body.innerHTML = '' })
  5. describe('FloatingResourceSearch', () => {
  6. it('groups team, archived, and topic results and emits the selected entry', async () => {
  7. const wrapper = mount(FloatingResourceSearch, {
  8. props: {
  9. section: 'groups',
  10. label: '搜索话题、团队或归档',
  11. items: [
  12. { id: 'room:r1', title: '测试团队', subtitle: '2 个 Agent', section: '团队', avatar: '' },
  13. { id: 'search:archived', title: '已归档内容', subtitle: '查看已归档团队和话题', section: '已归档', icon: 'archive' },
  14. { id: 'topic:r1:t1', title: '发布检查', subtitle: '测试团队:准备上线', section: '话题', avatar: '', topic: true },
  15. ],
  16. },
  17. attachTo: document.body,
  18. })
  19. document.dispatchEvent(new CustomEvent('hermes-yaoyao:sidebar-search', { detail: { section: 'groups' } }))
  20. await wrapper.vm.$nextTick()
  21. const dialog = document.querySelector('[role="dialog"]')
  22. expect(dialog?.textContent).toContain('团队')
  23. expect(dialog?.textContent).toContain('已归档')
  24. expect(dialog?.textContent).toContain('话题')
  25. expect(dialog?.querySelectorAll('.floating-resource-search__section')).toHaveLength(3)
  26. expect(dialog?.querySelectorAll('.team-avatar')).toHaveLength(2)
  27. const archived = [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')]
  28. .find(button => button.textContent?.includes('已归档内容'))
  29. archived?.click()
  30. await wrapper.vm.$nextTick()
  31. expect(wrapper.emitted('select')).toEqual([['search:archived']])
  32. wrapper.unmount()
  33. })
  34. })