feat: 完善智能体图片聊天与会话恢复
- 增加私有图片上传、绑定、历史回显与生命周期清理 - 支持输入草稿恢复、图片交互和模型图片能力约束 - 修复旧脏会话幂等删除与前端会话恢复
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {mount} from '@vue/test-utils';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
import {describe, expect, it} from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import AiPromptInput from './AiPromptInput.vue';
|
||||
|
||||
@@ -9,10 +9,12 @@ describe('AiPromptInput', () => {
|
||||
const wrapper = mount(AiPromptInput, {
|
||||
props: {
|
||||
loading: false,
|
||||
modelValue: '',
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.find('textarea').setValue('你好');
|
||||
await wrapper.setProps({ modelValue: '你好' });
|
||||
await wrapper.find('[aria-label="发送"]').trigger('click');
|
||||
|
||||
expect(wrapper.emitted('send')?.[0]?.[0]).toBe('你好');
|
||||
@@ -30,4 +32,62 @@ describe('AiPromptInput', () => {
|
||||
|
||||
expect(wrapper.emitted('stop')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('supports sending a ready image without text', async () => {
|
||||
const wrapper = mount(AiPromptInput, {
|
||||
props: {
|
||||
images: [
|
||||
{
|
||||
localId: 'image-1',
|
||||
mimeType: 'image/png',
|
||||
name: 'test.png',
|
||||
previewUrl: 'data:image/png;base64,AA==',
|
||||
size: 1,
|
||||
status: 'ready',
|
||||
uploadId: 'upload-1',
|
||||
},
|
||||
],
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
|
||||
await wrapper.find('[aria-label="发送"]').trigger('click');
|
||||
|
||||
expect(wrapper.emitted('send')?.[0]?.[0]).toBe('');
|
||||
});
|
||||
|
||||
it('extracts image files from clipboard paste', async () => {
|
||||
const wrapper = mount(AiPromptInput, {
|
||||
props: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
const image = new File(['image'], 'pasted.png', { type: 'image/png' });
|
||||
const event = new Event('paste', { bubbles: true, cancelable: true });
|
||||
Object.defineProperty(event, 'clipboardData', {
|
||||
value: { files: [image] },
|
||||
});
|
||||
|
||||
wrapper.find('textarea').element.dispatchEvent(event);
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
expect(event.defaultPrevented).toBe(true);
|
||||
expect(wrapper.emitted('addFiles')?.[0]?.[0]).toEqual([image]);
|
||||
});
|
||||
|
||||
it('extracts image files from drop', async () => {
|
||||
const wrapper = mount(AiPromptInput, {
|
||||
props: {
|
||||
loading: false,
|
||||
},
|
||||
});
|
||||
const image = new File(['image'], 'dropped.jpg', { type: 'image/jpeg' });
|
||||
const text = new File(['text'], 'note.txt', { type: 'text/plain' });
|
||||
|
||||
await wrapper.find('.ai-prompt-input').trigger('drop', {
|
||||
dataTransfer: { files: [image, text] },
|
||||
});
|
||||
|
||||
expect(wrapper.emitted('addFiles')?.[0]?.[0]).toEqual([image]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user