99d239c8bf
复用了画布agent的输入框: * 高度自适应 * 滑动条样式变为浅色和位置不再出界 before  after  Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/130 Co-authored-by: 王德宇 <kvtodev@outlook.com> Co-committed-by: 王德宇 <kvtodev@outlook.com>
61 lines
1.8 KiB
TypeScript
61 lines
1.8 KiB
TypeScript
/* @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(
|
|
<EditorAgentDraftTextarea
|
|
value=""
|
|
onChange={onChange}
|
|
onPaste={onPaste}
|
|
/>,
|
|
);
|
|
|
|
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<HTMLFormElement>) => {
|
|
event.preventDefault();
|
|
});
|
|
render(
|
|
<form onSubmit={onSubmit}>
|
|
<EditorAgentDraftTextarea value="草稿" onChange={vi.fn()} />
|
|
</form>,
|
|
);
|
|
|
|
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);
|
|
});
|
|
});
|