mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-21 21:47:00 +08:00
refactor(ui): 统一迁移原生按钮、输入框及交互控件
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import type { ReactElement } from 'react'
|
||||
import { render, screen, type RenderResult } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { ChatHeader } from '../../src/renderer/src/components/chat/ChatHeader'
|
||||
import { ChatStatusBar } from '../../src/renderer/src/components/chat/ChatStatusBar'
|
||||
import { ExportMenu } from '../../src/renderer/src/components/chat/ExportMenu'
|
||||
import { TooltipProvider } from '../../src/renderer/src/components/ui'
|
||||
import type { Contact } from '../../src/shared/types'
|
||||
|
||||
const contact: Contact = {
|
||||
@@ -12,11 +15,15 @@ const contact: Contact = {
|
||||
type: 'group'
|
||||
}
|
||||
|
||||
function renderWithTooltip(element: ReactElement): RenderResult {
|
||||
return render(<TooltipProvider>{element}</TooltipProvider>)
|
||||
}
|
||||
|
||||
describe('chat menus', () => {
|
||||
it('runs the selected export range and closes the menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onExport = vi.fn()
|
||||
render(<ExportMenu disabled={false} onExport={onExport} />)
|
||||
renderWithTooltip(<ExportMenu disabled={false} onExport={onExport} />)
|
||||
|
||||
const trigger = screen.getByRole('button', { name: '导出' })
|
||||
await user.click(trigger)
|
||||
@@ -30,7 +37,7 @@ describe('chat menus', () => {
|
||||
it('closes the chat More menu with Escape and invokes refresh data once', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onRefreshData = vi.fn()
|
||||
render(
|
||||
renderWithTooltip(
|
||||
<ChatHeader
|
||||
contact={contact}
|
||||
isGroupChat
|
||||
@@ -57,4 +64,85 @@ describe('chat menus', () => {
|
||||
await user.click(screen.getByRole('menuitem', { name: '刷新数据' }))
|
||||
expect(onRefreshData).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('keeps header search and actions wired to their existing callbacks', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onContentFilterChange = vi.fn()
|
||||
const onRefresh = vi.fn()
|
||||
const onOpenAiSettings = vi.fn()
|
||||
renderWithTooltip(
|
||||
<ChatHeader
|
||||
contact={contact}
|
||||
isGroupChat
|
||||
loadedCount={8}
|
||||
filteredCount={2}
|
||||
contentFilter=""
|
||||
isAiLoading={false}
|
||||
onContentFilterChange={onContentFilterChange}
|
||||
onRefresh={onRefresh}
|
||||
onRefreshData={vi.fn()}
|
||||
onTestSend={vi.fn()}
|
||||
onOpenAiSettings={onOpenAiSettings}
|
||||
/>
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '搜索当前聊天' }))
|
||||
const searchInput = screen.getByRole('textbox', { name: '搜索当前聊天内容' })
|
||||
expect(searchInput).toHaveFocus()
|
||||
await user.type(searchInput, '测试')
|
||||
expect(onContentFilterChange).toHaveBeenCalledTimes(2)
|
||||
expect(screen.getByRole('button', { name: '发送消息' })).toBeDisabled()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '关闭搜索' }))
|
||||
expect(onContentFilterChange).toHaveBeenLastCalledWith('')
|
||||
expect(screen.queryByRole('textbox', { name: '搜索当前聊天内容' })).not.toBeInTheDocument()
|
||||
|
||||
await user.click(screen.getByRole('button', { name: '刷新聊天记录' }))
|
||||
await user.click(screen.getByRole('button', { name: '生成 AI 日报' }))
|
||||
expect(onRefresh).toHaveBeenCalledOnce()
|
||||
expect(onOpenAiSettings).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('preserves status switch, reload, and jump callbacks', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onShowAvatarChange = vi.fn()
|
||||
const onReloadAvatars = vi.fn()
|
||||
const onJumpToLatest = vi.fn()
|
||||
renderWithTooltip(
|
||||
<ChatStatusBar
|
||||
count={5}
|
||||
showAvatar={false}
|
||||
isAtLatest={false}
|
||||
isReloadingAvatars={false}
|
||||
onShowAvatarChange={onShowAvatarChange}
|
||||
onReloadAvatars={onReloadAvatars}
|
||||
onJumpToLatest={onJumpToLatest}
|
||||
/>
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('switch', { name: '显示头像' }))
|
||||
await user.click(screen.getByRole('button', { name: '重新加载头像' }))
|
||||
await user.click(screen.getByRole('button', { name: '跳转到最新消息' }))
|
||||
|
||||
expect(onShowAvatarChange).toHaveBeenCalledWith(true)
|
||||
expect(onReloadAvatars).toHaveBeenCalledOnce()
|
||||
expect(onJumpToLatest).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('keeps loading and latest status actions disabled', () => {
|
||||
renderWithTooltip(
|
||||
<ChatStatusBar
|
||||
count={5}
|
||||
showAvatar
|
||||
isAtLatest
|
||||
isReloadingAvatars
|
||||
onShowAvatarChange={vi.fn()}
|
||||
onReloadAvatars={vi.fn()}
|
||||
onJumpToLatest={vi.fn()}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByRole('button', { name: '加载中' })).toBeDisabled()
|
||||
expect(screen.getByRole('button', { name: '已是最新消息' })).toBeDisabled()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user