floatingResourceSearch.test.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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('keeps team and archived filters on the left while updating right-side results', async () => {
  7. const wrapper = mount(FloatingResourceSearch, {
  8. props: {
  9. section: 'groups',
  10. label: '搜索话题、团队或归档',
  11. split: true,
  12. items: [
  13. {
  14. id: 'search:all', title: '全部', subtitle: '1 个话题', section: '团队', icon: 'groups',
  15. children: [{ id: 'topic:r1:t1', title: '发布检查', subtitle: '测试团队:准备上线', section: '话题', avatar: '' }],
  16. },
  17. {
  18. id: 'room:r1', title: '测试团队', subtitle: '2 个 Agent', section: '团队', avatar: '',
  19. children: [{ id: 'topic:r1:t1', title: '团队内话题', subtitle: '测试团队:准备上线', section: '话题', avatar: '' }],
  20. },
  21. {
  22. id: 'search:archived', title: '已归档内容', subtitle: '1 个团队 · 1 个话题', section: '归档', icon: 'archive',
  23. children: [
  24. { id: 'archived-room:r2', title: '旧团队', subtitle: '2 个 Agent', section: '团队', avatar: '' },
  25. { id: 'archived-topic:r2:t2', title: '旧话题', subtitle: '旧团队:历史消息', section: '话题', avatar: '' },
  26. ],
  27. },
  28. ],
  29. },
  30. attachTo: document.body,
  31. })
  32. document.dispatchEvent(new CustomEvent('hermes-yaoyao:sidebar-search', { detail: { section: 'groups' } }))
  33. await wrapper.vm.$nextTick()
  34. const dialog = document.querySelector('[role="dialog"]')
  35. expect(dialog?.textContent).toContain('全部')
  36. expect(dialog?.textContent).toContain('团队')
  37. expect(dialog?.textContent).toContain('归档')
  38. expect(dialog?.textContent).toContain('话题')
  39. expect(dialog?.querySelectorAll('.floating-resource-search__navigation-heading')).toHaveLength(2)
  40. expect(dialog?.querySelector('.floating-resource-search__context')?.textContent).toContain('全部')
  41. expect(dialog?.textContent).toContain('发布检查')
  42. expect(wrapper.emitted('open')).toHaveLength(1)
  43. const team = [...document.querySelectorAll<HTMLButtonElement>('.floating-resource-search__navigation button')]
  44. .find(button => button.textContent?.trim() === '测试团队')
  45. team?.click()
  46. await wrapper.vm.$nextTick()
  47. expect(document.body.textContent).toContain('团队内话题')
  48. expect(document.querySelector('[aria-label="返回搜索结果"]')).toBeNull()
  49. expect(wrapper.emitted('select')).toBeUndefined()
  50. const archived = [...document.querySelectorAll<HTMLButtonElement>('.floating-resource-search__navigation button')]
  51. .find(button => button.textContent?.includes('已归档内容'))
  52. archived?.click()
  53. await wrapper.vm.$nextTick()
  54. expect(document.body.textContent).toContain('旧团队')
  55. expect(document.body.textContent).toContain('旧话题')
  56. expect(wrapper.emitted('select')).toBeUndefined()
  57. const archivedTopic = [...document.querySelectorAll<HTMLButtonElement>('[role="option"]')]
  58. .find(button => button.textContent?.includes('旧话题'))
  59. archivedTopic?.click()
  60. await wrapper.vm.$nextTick()
  61. expect(wrapper.emitted('select')).toEqual([['archived-topic:r2:t2']])
  62. wrapper.unmount()
  63. })
  64. })