统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成 设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程 删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本 替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段 更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
193 lines
6.1 KiB
TypeScript
193 lines
6.1 KiB
TypeScript
/**
|
|
* useChatShippingRefresh.spec.ts
|
|
* 用途:验证发货 UI State 刷新只同步通知态,不再把 action_buttons 映射为消息按钮。
|
|
* 依赖:vitest、vue refs、useChatShippingRefresh 纯函数导出。
|
|
* 逻辑:覆盖任务编号解析优先级,以及刷新后 shipping_actions 始终清空。
|
|
*/
|
|
import { computed, ref } from 'vue';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { createShippingActionsRefresher, resolvePreferredShippingTaskId } from './useChatShippingRefresh';
|
|
|
|
const { getWorkspaceShippingTaskUiState } = vi.hoisted(() => ({
|
|
getWorkspaceShippingTaskUiState: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('@/features/chat/api/shipping.api', () => ({
|
|
getWorkspaceShippingTaskUiState,
|
|
}));
|
|
|
|
describe('useChatShippingRefresh', () => {
|
|
beforeEach(() => {
|
|
getWorkspaceShippingTaskUiState.mockReset();
|
|
});
|
|
|
|
it('prefers current batch focus task over other explicit anchors', () => {
|
|
expect(resolvePreferredShippingTaskId({
|
|
batchTaskId: 'sn-batch-001',
|
|
messageTaskId: 'sn-message-001',
|
|
resolvedTaskId: 'sn-resolved-001',
|
|
queryTaskId: 'sn-query-001',
|
|
})).toBe('SN-BATCH-001');
|
|
});
|
|
|
|
it('returns empty string when no explicit task anchor is available', () => {
|
|
expect(resolvePreferredShippingTaskId({
|
|
batchTaskId: '',
|
|
messageTaskId: '',
|
|
resolvedTaskId: '',
|
|
queryTaskId: '',
|
|
})).toBe('');
|
|
});
|
|
|
|
it('syncs ui_state for notifications without attaching chat action buttons', async () => {
|
|
getWorkspaceShippingTaskUiState.mockResolvedValue({
|
|
task_no: 'SN-FOCUS-B',
|
|
batch_no: 'SB-FOCUS-001',
|
|
checkpoint: 'ready_export',
|
|
match_status: 'matched',
|
|
review_status: null,
|
|
pending_human_reason: null,
|
|
match_status: 'fulfillable',
|
|
current_step: null,
|
|
steps: [],
|
|
summary: {
|
|
title: '可生成发货文件',
|
|
message: '库存匹配已满足发货条件,可以生成发货文件。',
|
|
error_message: null,
|
|
entry_surface: 'task_workbench',
|
|
},
|
|
action_buttons: [
|
|
{
|
|
id: 'generate_excel',
|
|
label: '生成发货文件',
|
|
message: '请生成发货文件',
|
|
variant: 'primary',
|
|
},
|
|
],
|
|
updated_at: '2026-07-01T10:00:00+08:00',
|
|
});
|
|
|
|
const messages = ref([
|
|
{
|
|
role: 'assistant' as const,
|
|
content: '请继续处理当前批次',
|
|
shipping_actions: [
|
|
{
|
|
id: 'old-action',
|
|
label: '旧动作',
|
|
message: '旧动作',
|
|
variant: 'secondary' as const,
|
|
},
|
|
],
|
|
},
|
|
]);
|
|
const resolvedShippingTaskId = ref('SN-FOCUS-A');
|
|
const { refreshShippingActions } = createShippingActionsRefresher({
|
|
isShippingNoticeAgent: computed(() => true),
|
|
messages,
|
|
conversationId: ref('conv-focus-switch'),
|
|
isThinking: ref(false),
|
|
resolvedShippingTaskId,
|
|
shippingTaskIdFromQuery: computed(() => ''),
|
|
getActiveBatchTaskId: () => 'SN-FOCUS-B',
|
|
});
|
|
|
|
await refreshShippingActions();
|
|
|
|
expect(resolvedShippingTaskId.value).toBe('SN-FOCUS-B');
|
|
expect(getWorkspaceShippingTaskUiState).toHaveBeenCalledWith('SN-FOCUS-B');
|
|
expect(messages.value[0].shipping_ui_state?.task_no).toBe('SN-FOCUS-B');
|
|
expect(messages.value[0].shipping_actions).toBeUndefined();
|
|
});
|
|
|
|
it('clears legacy shipping_actions even when api returns action_buttons', async () => {
|
|
getWorkspaceShippingTaskUiState.mockResolvedValue({
|
|
task_no: 'SN-SOURCE-001',
|
|
batch_no: 'SB-SOURCE-001',
|
|
checkpoint: 'ready_export',
|
|
match_status: 'matched',
|
|
review_status: null,
|
|
pending_human_reason: null,
|
|
match_status: 'fulfillable',
|
|
current_step: null,
|
|
steps: [],
|
|
summary: {
|
|
title: '可生成发货文件',
|
|
message: '库存匹配已满足发货条件,可以生成发货文件。',
|
|
error_message: null,
|
|
},
|
|
action_buttons: [
|
|
{
|
|
id: 'download_excel',
|
|
label: '下载发货文件',
|
|
message: '请下载发货文件',
|
|
variant: 'primary',
|
|
},
|
|
],
|
|
updated_at: '2026-07-03T10:00:00+08:00',
|
|
});
|
|
|
|
const messages = ref([
|
|
{
|
|
role: 'assistant' as const,
|
|
content: '请使用下方按钮继续。',
|
|
shipping_actions: [
|
|
{
|
|
id: 'legacy-local-action',
|
|
label: '旧按钮',
|
|
message: '旧按钮',
|
|
variant: 'secondary' as const,
|
|
},
|
|
],
|
|
shipping_ui_state: {
|
|
action_buttons: [
|
|
{
|
|
id: 'legacy-ui-state-action',
|
|
label: '旧状态按钮',
|
|
message: '旧状态按钮',
|
|
variant: 'secondary' as const,
|
|
},
|
|
],
|
|
},
|
|
},
|
|
]);
|
|
const { refreshShippingActions } = createShippingActionsRefresher({
|
|
isShippingNoticeAgent: computed(() => true),
|
|
messages,
|
|
conversationId: ref('conv-source'),
|
|
isThinking: ref(false),
|
|
resolvedShippingTaskId: ref('SN-SOURCE-001'),
|
|
shippingTaskIdFromQuery: computed(() => ''),
|
|
getActiveBatchTaskId: () => 'SN-SOURCE-001',
|
|
});
|
|
|
|
await refreshShippingActions();
|
|
|
|
expect(messages.value[0].shipping_actions).toBeUndefined();
|
|
expect(messages.value[0].shipping_ui_state?.summary?.title).toBe('可生成发货文件');
|
|
});
|
|
|
|
it('does not guess a task id from history metadata when no explicit anchor exists', async () => {
|
|
const messages = ref([
|
|
{
|
|
role: 'assistant' as const,
|
|
content: '请继续处理当前任务',
|
|
},
|
|
]);
|
|
const { refreshShippingActions } = createShippingActionsRefresher({
|
|
isShippingNoticeAgent: computed(() => true),
|
|
messages,
|
|
conversationId: ref('conv-no-anchor'),
|
|
isThinking: ref(false),
|
|
resolvedShippingTaskId: ref(''),
|
|
shippingTaskIdFromQuery: computed(() => ''),
|
|
getActiveBatchTaskId: () => '',
|
|
});
|
|
|
|
await refreshShippingActions();
|
|
|
|
expect(getWorkspaceShippingTaskUiState).not.toHaveBeenCalled();
|
|
expect(messages.value[0].shipping_actions).toBeUndefined();
|
|
});
|
|
});
|