refactor(shipping-notice): 统一料号字段,移除过时的 SKU 相关字段,更新相关逻辑以支持新字段命名
This commit is contained in:
1 parent
dde25344ca
commit
46eb63f5bb
111 files changed
+3116
-1250
No files matched your search
@@ -35,7 +35,7 @@ function createContext(overrides: Partial<ChatPageSendContext> = {}): ChatPageSe
|
||||
]),
|
||||
createMessageAttachmentSnapshots: vi.fn(() => attachmentSnapshots.map((item) => ({ ...item }))),
|
||||
clearAttachments: vi.fn(),
|
||||
sendMessage: vi.fn(async () => true),
|
||||
sendMessage: vi.fn(async () => ({ accepted: true, completed: true })),
|
||||
refreshHistoryAfterSend: vi.fn(async () => undefined),
|
||||
refreshConversationAfterSend: vi.fn(async () => undefined),
|
||||
tryHandleShippingAttachmentAutoFlow: vi.fn(async () => false),
|
||||
@@ -62,25 +62,26 @@ describe('createChatPageSendApi attachment lifecycle', () => {
|
||||
expect(ctx.sendMessage).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps uploaded attachments when message sending fails', async () => {
|
||||
it('keeps uploaded attachments and restores input when the request is not accepted', async () => {
|
||||
const ctx = createContext({
|
||||
sendMessage: vi.fn(async () => { throw new Error('stream failed'); }),
|
||||
});
|
||||
|
||||
await expect(createChatPageSendApi(ctx).handleSend()).rejects.toThrow('stream failed');
|
||||
|
||||
expect(ctx.clearAttachments).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps uploaded attachments when the real send result reports failure', async () => {
|
||||
const ctx = createContext({
|
||||
sendMessage: vi.fn(async () => false),
|
||||
sendMessage: vi.fn(async () => ({ accepted: false, completed: false })),
|
||||
});
|
||||
|
||||
await createChatPageSendApi(ctx).handleSend();
|
||||
|
||||
expect(ctx.clearAttachments).not.toHaveBeenCalled();
|
||||
expect(ctx.refreshHistoryAfterSend).not.toHaveBeenCalled();
|
||||
expect(ctx.input.value).toBe('请分析附件');
|
||||
});
|
||||
|
||||
it('clears attachments when the request is accepted even if the assistant stream fails', async () => {
|
||||
const ctx = createContext({
|
||||
sendMessage: vi.fn(async () => ({ accepted: true, completed: false, chatLogId: 42 })),
|
||||
});
|
||||
|
||||
await createChatPageSendApi(ctx).handleSend();
|
||||
|
||||
expect(ctx.clearAttachments).toHaveBeenCalledOnce();
|
||||
expect(ctx.refreshHistoryAfterSend).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('clears attachments only after message sending succeeds', async () => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { copyTextToClipboard } from '@/shared/utils/clipboard';
|
||||
import type { ChatMessage, ChatMessageAttachment } from '../types/chat.types';
|
||||
import type { SendMessageLifecycleHooks } from '../composables/useChat';
|
||||
import type { ChatUploadFileSpec } from '../types/shipping.types';
|
||||
import type { ChatMessageSendResult } from '../types/chat-turn.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
|
||||
const looksLikeCompletedAssistantReply = (content: string) => {
|
||||
@@ -55,7 +56,7 @@ export interface ChatPageSendContext {
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => Promise<boolean | void>;
|
||||
) => Promise<ChatMessageSendResult>;
|
||||
refreshHistoryAfterSend: () => Promise<void>;
|
||||
refreshConversationAfterSend?: () => Promise<void>;
|
||||
tryHandleShippingAttachmentAutoFlow: (
|
||||
@@ -133,7 +134,8 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof textOrEvent !== 'string') ctx.input.value = '';
|
||||
const shouldClearInput = typeof textOrEvent !== 'string';
|
||||
if (shouldClearInput) ctx.input.value = '';
|
||||
|
||||
const requestContent = trimmed || ctx.t('chat.attachment.defaultPrompt');
|
||||
const sendContext = {
|
||||
@@ -152,7 +154,10 @@ export function createChatPageSendApi(ctx: ChatPageSendContext) {
|
||||
onAssistantMessageFinished: ctx.onAssistantMessageFinished,
|
||||
},
|
||||
);
|
||||
if (sent === false) return;
|
||||
if (!sent.accepted) {
|
||||
if (shouldClearInput) ctx.input.value = content;
|
||||
return;
|
||||
}
|
||||
ctx.clearAttachments();
|
||||
await ctx.refreshHistoryAfterSend();
|
||||
await ctx.refreshConversationAfterSend?.();
|
||||
|
||||
Reference in new issue
Block a user