feat: 统一按钮

This commit is contained in:
Wxw-Gu
2026-08-21 00:07:00 +08:00
parent 740bec6d04
commit 67b1df7e80
12 changed files with 118 additions and 56 deletions
+16 -12
View File
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from '@testing-library/react'
import { render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ExportWorkspace } from '../../src/renderer/src/components/export/ExportWorkspace'
@@ -64,17 +64,21 @@ describe('ExportWorkspace multi-chat selection', () => {
const { loadPreviewMessages } = renderWorkspace(onStartExport)
expect(screen.getAllByText('聊天 A')).toHaveLength(2)
expect(screen.getByRole('button', { name: 'CSV' })).toBeEnabled()
expect(screen.getByRole('radio', { name: 'CSV' })).toBeEnabled()
expect(await screen.findByText('聊天 A 的预览')).toBeVisible()
await userEvent.click(screen.getByRole('button', { name: '+ 添加聊天' }))
await userEvent.click(screen.getByRole('button', { name: /聊天 B/ }))
expect(screen.getByText('已选 2 / 5 个')).toBeVisible()
expect(screen.getByRole('button', { name: 'CSV' })).toBeDisabled()
expect(screen.getByRole('button', { name: 'JSON' })).toBeDisabled()
expect(screen.getByRole('button', { name: 'Markdown' })).toBeDisabled()
expect(screen.getByRole('button', { name: /HTML/ })).toHaveClass('active')
expect(screen.getByRole('radio', { name: 'CSV' })).toBeDisabled()
expect(screen.getByRole('radio', { name: 'JSON' })).toBeDisabled()
expect(screen.getByRole('radio', { name: 'Markdown' })).toBeDisabled()
expect(
within(screen.getByRole('radiogroup', { name: '导出格式' })).getByRole('radio', {
name: /HTML/
})
).toBeChecked()
expect(await screen.findByText('聊天 B 的预览')).toBeVisible()
expect(screen.getByText('2 个聊天 · 合并预览')).toBeVisible()
@@ -91,7 +95,7 @@ describe('ExportWorkspace multi-chat selection', () => {
await userEvent.click(screen.getByRole('button', { name: '恢复默认' }))
expect(screen.queryByText('已选 2 / 5 个')).not.toBeInTheDocument()
expect(screen.getByRole('button', { name: 'CSV' })).toBeEnabled()
expect(screen.getByRole('radio', { name: 'CSV' })).toBeEnabled()
expect(screen.getAllByText('聊天 A').length).toBeGreaterThanOrEqual(2)
expect(loadPreviewMessages).toHaveBeenCalledWith(contacts[0])
expect(contacts[0].md5).toBe('contact-1')
@@ -123,10 +127,10 @@ describe('ExportWorkspace multi-chat selection', () => {
await userEvent.click(screen.getByRole('button', { name: /全部导出/ }))
expect(screen.getByText(/全部群聊 1 个和全部联系人 5 个/)).toBeVisible()
expect(screen.getByRole('button', { name: 'CSV' })).toBeEnabled()
expect(screen.getByRole('button', { name: 'CSV' })).toHaveClass('active')
expect(screen.getByRole('button', { name: 'JSON' })).toBeEnabled()
expect(screen.getByRole('button', { name: 'Markdown' })).toBeEnabled()
expect(screen.getByRole('radio', { name: 'CSV' })).toBeEnabled()
expect(screen.getByRole('radio', { name: 'CSV' })).toBeChecked()
expect(screen.getByRole('radio', { name: 'JSON' })).toBeEnabled()
expect(screen.getByRole('radio', { name: 'Markdown' })).toBeEnabled()
expect(loadPreviewMessages).toHaveBeenCalledTimes(1)
await userEvent.click(screen.getByRole('button', { name: '开始导出' }))
@@ -203,7 +207,7 @@ describe('ExportWorkspace multi-chat selection', () => {
const onStartExport = vi.fn(async () => ({ success: false }))
renderWorkspace(onStartExport)
await userEvent.click(screen.getByRole('button', { name: '自定义时间' }))
await userEvent.click(screen.getByRole('radio', { name: '自定义时间' }))
await userEvent.type(screen.getByLabelText('开始时间'), '2026-08-01T09:30')
await userEvent.type(screen.getByLabelText('结束时间'), '2026-08-02T18:45')
await userEvent.click(screen.getByRole('button', { name: '选择位置' }))