Files
syops/frontend/src/features/chat/composables/useChatRouteSync.spec.ts
T
hugo 5ef8329bd8 refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
2026-08-15 10:19:10 +08:00

64 lines
2.1 KiB
TypeScript

/**
* features/chat/composables/useChatRouteSync.spec.ts
* 用途:验证聊天路由初始化的关键首屏请求调度。
* 依赖:vitest、useChatRouteSync。
* 逻辑:历史会话列表属于后台辅助数据,不能阻塞指定 conversation 的消息与进度加载。
*/
import { describe, expect, it, vi } from 'vitest';
vi.mock('vue', () => ({
onBeforeUnmount: vi.fn(),
onMounted: vi.fn(),
watch: vi.fn(),
}));
import { useChatRouteSync } from './useChatRouteSync';
describe('useChatRouteSync', () => {
it('starts the requested conversation before the history list resolves', async () => {
let resolveHistory!: () => void;
const loadHistory = vi.fn(() => new Promise<void>((resolve) => {
resolveHistory = resolve;
}));
const loadConversation = vi.fn(async () => undefined);
const routeSync = useChatRouteSync({
deps: {
route: {
params: { agentId: '24' },
query: { conversation_id: 'conversation-b' },
},
router: { push: vi.fn() },
} as never,
currentAgentId: { value: 24 } as never,
presetQuestion: { value: '' } as never,
shippingTaskIdFromQuery: { value: null } as never,
isShippingNoticeAgent: { value: true } as never,
resetChatStateForAgentChange: vi.fn(),
cancelVoiceInput: vi.fn(),
syncCurrentUserProfile: vi.fn(async () => undefined),
loadAgent: vi.fn(async () => undefined),
loadUserAgents: vi.fn(async () => undefined),
loadHistory,
loadConversation,
resumeShippingTaskFromQuery: vi.fn(async () => undefined),
handleSend: vi.fn(async () => undefined),
createNewChatView: vi.fn(),
onAuthLogout: vi.fn(),
onViewportResize: vi.fn(),
disposePeripherals: vi.fn(),
scheduleScrollToBottom: vi.fn(),
input: { value: '' } as never,
});
const pending = routeSync.syncChatStateForRoute();
await vi.waitFor(() => {
expect(loadHistory).toHaveBeenCalledTimes(1);
expect(loadConversation).toHaveBeenCalledWith('conversation-b', { force: true });
});
resolveHistory();
await pending;
});
});