/** * features/chat/composables/useChatShipping.spec.ts * 用途:验证发货批次切换后的默认焦点解析,避免右侧工作台沿用旧批次的 focused task。 * 依赖:vitest、useChatShipping 纯函数导出。 * 逻辑:覆盖 current focus、process summary 回退、首票回退与无任务时清空焦点原因四种路径。 */ import { describe, expect, it } from 'vitest'; import { resolveShippingBatchFocusState } from './useChatShipping'; describe('useChatShipping batch focus sync', () => { it('prefers batch current focus task and keeps default reason', () => { expect(resolveShippingBatchFocusState( { current_focus_task_no: 'SN-BATCH-B2', process_summary: { current_task_no: 'SN-BATCH-B1' }, }, [{ task_no: 'SN-BATCH-B0' }], '当前聚焦任务', )).toEqual({ taskNo: 'SN-BATCH-B2', focusReason: '当前聚焦任务', }); }); it('falls back to process summary and first task when current focus is absent', () => { expect(resolveShippingBatchFocusState( { current_focus_task_no: '', process_summary: { current_task_no: 'SN-BATCH-C1' }, }, [{ task_no: 'SN-BATCH-C0' }], '当前聚焦任务', )).toEqual({ taskNo: 'SN-BATCH-C1', focusReason: '当前聚焦任务', }); expect(resolveShippingBatchFocusState( { current_focus_task_no: '', process_summary: { current_task_no: '' }, }, [{ task_no: 'SN-BATCH-D0' }], '当前聚焦任务', )).toEqual({ taskNo: 'SN-BATCH-D0', focusReason: '当前聚焦任务', }); }); it('clears focus state when the new batch has no resolvable task', () => { expect(resolveShippingBatchFocusState( { current_focus_task_no: '', process_summary: { current_task_no: '' }, }, [], '当前聚焦任务', )).toEqual({ taskNo: '', focusReason: '', }); }); });