131 lines
4.4 KiB
TypeScript
131 lines
4.4 KiB
TypeScript
/**
|
|
* features/chat/shipping/useChatShippingMenuHandler.spec.ts
|
|
* 用途:验证发货聊天动作菜单在工作台显式 taskId 场景下会命中指定任务,而不是误用当前激活任务。
|
|
* 依赖:vitest、vue refs、shipping.api、useChatShippingMenuHandler。
|
|
* 逻辑:覆盖 retry_rpa、generate_excel 等动作,锁死 Chat Turn 分发时的任务归属。
|
|
*/
|
|
import { computed, ref } from 'vue';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { createShippingMenuHandlers, type ShippingMenuHandlerContext } from './useChatShippingMenuHandler';
|
|
|
|
const {
|
|
confirmWorkspaceShippingInventorySource,
|
|
getWorkspaceShippingTask,
|
|
} = vi.hoisted(() => ({
|
|
confirmWorkspaceShippingInventorySource: vi.fn(),
|
|
getWorkspaceShippingTask: vi.fn(),
|
|
}));
|
|
|
|
const { downloadWorkspaceShippingExcelFile } = vi.hoisted(() => ({
|
|
downloadWorkspaceShippingExcelFile: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('@/features/chat/api/shipping.api', () => ({
|
|
confirmWorkspaceShippingInventorySource,
|
|
getWorkspaceShippingTask,
|
|
}));
|
|
|
|
vi.mock('./shippingDownload', () => ({
|
|
downloadWorkspaceShippingExcelFile,
|
|
}));
|
|
|
|
const createContext = (
|
|
overrides: Partial<ShippingMenuHandlerContext> = {},
|
|
): ShippingMenuHandlerContext => ({
|
|
isThinking: ref(false),
|
|
currentAgentId: computed(() => 42),
|
|
getActiveShippingTaskId: () => 'SN-ACTIVE-001',
|
|
getActiveShippingBatchNo: () => 'BATCH-001',
|
|
messages: ref([]),
|
|
sendShippingMenuMessage: vi.fn(async () => undefined),
|
|
openShippingInventoryMappingFormForTask: vi.fn(async () => true),
|
|
openShippingInventoryPicker: vi.fn((_taskId?: string) => true),
|
|
openShippingNoticePicker: vi.fn((_taskId?: string) => true),
|
|
executeShippingDecision: vi.fn(async () => true),
|
|
executeShippingManualUpload: vi.fn(async () => true),
|
|
refreshShippingActions: vi.fn(async () => undefined),
|
|
startChatTurn: vi.fn(async () => true),
|
|
msg: {
|
|
warning: vi.fn(),
|
|
info: vi.fn(),
|
|
},
|
|
t: (key: string) => key,
|
|
...overrides,
|
|
});
|
|
|
|
describe('useChatShippingMenuHandler', () => {
|
|
beforeEach(() => {
|
|
confirmWorkspaceShippingInventorySource.mockReset();
|
|
getWorkspaceShippingTask.mockReset();
|
|
downloadWorkspaceShippingExcelFile.mockReset();
|
|
});
|
|
|
|
it('uses explicit taskId for retry_rpa workspace actions', async () => {
|
|
const ctx = createContext();
|
|
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
|
|
|
await handleShippingMenuAction(
|
|
{ id: 'retry_rpa', label: '重新获取库存', message: '重新获取库存' },
|
|
undefined,
|
|
{ taskId: 'sn-target-009' },
|
|
);
|
|
|
|
expect(ctx.executeShippingDecision).toHaveBeenCalledWith(
|
|
'retry_rpa',
|
|
'重新获取库存',
|
|
{ taskId: 'SN-TARGET-009' },
|
|
);
|
|
expect(ctx.executeShippingDecision).not.toHaveBeenCalledWith(
|
|
'retry_rpa',
|
|
'重新获取库存',
|
|
{ taskId: 'SN-ACTIVE-001' },
|
|
);
|
|
});
|
|
|
|
it('uses explicit taskId for generate_excel via Chat Turn', async () => {
|
|
const ctx = createContext();
|
|
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
|
|
|
await handleShippingMenuAction(
|
|
{ id: 'generate_excel', label: '生成发货文件', message: '请生成发货文件' },
|
|
undefined,
|
|
{ taskId: 'sn-target-777' },
|
|
);
|
|
|
|
expect(ctx.startChatTurn).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
inputType: 'action',
|
|
actionType: 'shipping.generate_excel',
|
|
payload: { task_no: 'SN-TARGET-777' },
|
|
refs: expect.objectContaining({ task_no: 'SN-TARGET-777' }),
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('passes explicit taskId into inventory picker actions', async () => {
|
|
const ctx = createContext();
|
|
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
|
|
|
await handleShippingMenuAction(
|
|
{ id: 'upload_inventory_file', label: '上传库存文件', message: '请上传库存文件' },
|
|
undefined,
|
|
{ taskId: 'sn-picker-123' },
|
|
);
|
|
|
|
expect(ctx.openShippingInventoryPicker).toHaveBeenCalledWith('SN-PICKER-123');
|
|
});
|
|
|
|
it('passes explicit taskId into notice picker actions', async () => {
|
|
const ctx = createContext();
|
|
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
|
|
|
await handleShippingMenuAction(
|
|
{ id: 'replace_notice_file', label: '重新上传通知', message: '请重新上传通知' },
|
|
undefined,
|
|
{ taskId: 'sn-notice-123' },
|
|
);
|
|
|
|
expect(ctx.openShippingNoticePicker).toHaveBeenCalledWith('SN-NOTICE-123');
|
|
});
|
|
});
|