/* @vitest-environment jsdom */ import { fireEvent, render, screen } from '@testing-library/react'; import type { FormEvent } from 'react'; import { describe, expect, it, vi } from 'vitest'; import { EditorAgentDraftTextarea } from './EditorAgentDraftTextarea.tsx'; describe('EditorAgentDraftTextarea', () => { it('forwards draft changes and paste events through the Agent wrapper', () => { const onChange = vi.fn(); const onPaste = vi.fn(); render( , ); const input = screen.getByLabelText( '发送给画布 Agent', ) as HTMLTextAreaElement; expect(input.className).toContain('auto-grow-text-area'); expect(input.className).toContain( 'editor-agent-conversation__draft-input', ); fireEvent.change(input, { target: { value: '新草稿' } }); expect(onChange).toHaveBeenCalledWith('新草稿'); fireEvent.paste(input); expect(onPaste).toHaveBeenCalledTimes(1); }); it('submits on Enter and keeps line breaks or IME confirmation from submitting', () => { const onSubmit = vi.fn((event: FormEvent) => { event.preventDefault(); }); render(
, ); const input = screen.getByLabelText('发送给画布 Agent'); fireEvent.keyDown(input, { key: 'Enter', shiftKey: true }); expect(onSubmit).not.toHaveBeenCalled(); fireEvent.keyDown(input, { key: 'Enter', isComposing: false, keyCode: 229, }); expect(onSubmit).not.toHaveBeenCalled(); fireEvent.keyDown(input, { key: 'Enter' }); expect(onSubmit).toHaveBeenCalledTimes(1); }); });