// docs/29 D1:非 UTF-8 文档保存转码提示弹窗的渲染与回调契约。 import { describe, it, expect, vi } from 'vitest' import { createRoot } from 'react-dom/client' import { act } from 'react-dom/test-utils' import { EncodingConvertModal } from '../src/components/Modals' describe('EncodingConvertModal', () => { it('显示原编码与文件名,确认/取消回调正确', async () => { const container = document.createElement('div') document.body.appendChild(container) const root = createRoot(container) const onConfirm = vi.fn() const onCancel = vi.fn() await act(async () => { root.render() }) expect(container.textContent).toContain('GBK') expect(container.textContent).toContain('老文档.md') expect(container.textContent).toContain('转为 UTF-8') const buttons = [...container.querySelectorAll('button')] buttons.find((b) => b.textContent?.includes('转为 UTF-8'))?.click() expect(onConfirm).toHaveBeenCalledTimes(1) buttons.find((b) => b.textContent?.includes('取消'))?.click() expect(onCancel).toHaveBeenCalledTimes(1) await act(async () => { root.unmount() }) }) })