import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { ConversationSidebar } from '../../src/renderer/src/components/conversation/ConversationSidebar'
import { TooltipProvider } from '../../src/renderer/src/components/ui'
vi.mock('@tanstack/react-virtual', () => ({
useVirtualizer: ({ count }: { count: number }) => ({
getTotalSize: () => count * 58,
getVirtualItems: () =>
Array.from({ length: count }, (_, index) => ({
index,
key: index,
start: index * 58,
size: 58
}))
})
}))
describe('ConversationSidebar', () => {
it('keeps official accounts in their own collapsible section', async () => {
render(
undefined)}
/>
)
expect(screen.getByRole('button', { name: '公众号 (1)' })).toBeInTheDocument()
expect(screen.getByRole('button', { name: '联系人 (1)' })).toBeInTheDocument()
expect(screen.queryByText('测试公众号')).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: '公众号 (1)' }))
expect(screen.getByText('测试公众号')).toBeInTheDocument()
})
it('reveals contact results when searching a collapsed contact section', async () => {
render(
undefined)}
/>
)
expect(screen.queryByText('微信昵称')).not.toBeInTheDocument()
await userEvent.type(screen.getByRole('searchbox', { name: '搜索会话' }), 'xiaohao')
expect(screen.getByText('微信昵称')).toBeInTheDocument()
})
})