/** * features/chat/components/shipping-review/ReviewCurrentProcessingCard.spec.ts * 用途:验证工作台右侧当前任务卡只在需要人工处理时渲染业务动作。 * 依赖:Vitest、Vue Test Utils、Vue I18n、ReviewCurrentProcessingCard。 * 逻辑:库存自动处理中即使遗留 primary_action,也不得显示编辑正式任务;可重试状态仍保留重试入口; * loading 是「权威投影读取中」占位:已知阶段照常展示,状态/下一步给中性加载文案(非系统处理中)。 */ import { mount } from '@vue/test-utils'; import { createI18n } from 'vue-i18n'; import { describe, expect, it } from 'vitest'; import ReviewCurrentProcessingCard from './ReviewCurrentProcessingCard.vue'; const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages: { 'zh-CN': { 'chat.shippingOrderReview.processGate.actionCodes.retry_inventory_matching': '重新库存匹配', workspace: { shippingNotice: { processGate: { actionCodes: { reload_inventory_result: '重新读取库存结果', retry_inventory_preparation: '重新获取库存', }, inventoryActions: { reloadInventoryResult: '重新读取库存结果', retryInventoryMatching: '重新库存匹配', retryInventoryPreparation: '重新获取库存', }, reasons: { inventory_shortage_review_required: '存在库存缺口,需要人工处理', }, }, }, }, chat: { shippingOrderReview: { saveOrderAndValidate: '提交订单', currentProcessing: { waitingStart: '等待系统启动', stageLoading: '正在获取最新状态…', statusIdle: '待机', status: '状态', stages: { excel_generating: 'Excel 生成', }, }, currentTask: { title: '当前任务', labelStage: '当前门禁', statusRunning: '系统处理中', statusWaitingHuman: '待人工处理', statusRetryable: '可重试', statusFailed: '自动处理失败', statusCompleted: '已完成', statusCancelled: '已取消', nextStepTitle: '下一步', nextStepRunning: '系统正在处理,暂不需要人工操作', nextStepUnknown: '状态待确认', nextStepWaitingExternal: '等待外部系统回执,暂不需要人工操作', }, }, shippingProcessing: { gateReasons: { generic: '当前步骤需要人工处理', }, }, }, }, }, }); describe('ReviewCurrentProcessingCard', () => { it('hides a legacy primary action while inventory preparation is running', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_preparation', userStatus: 'running', primaryAction: { code: 'edit_formal_task', i18nKey: 'edit_formal_task' }, }, global: { plugins: [i18n] }, }); // 自动处理只显示状态,不能让历史的正式任务编辑动作干扰当前库存阶段。 expect(wrapper.find('[data-testid="review-current-task-actions"]').exists()).toBe(false); }); it('keeps the retry action for retryable states', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_preparation', userStatus: 'retryable', retryable: true, primaryAction: { code: 'retry_inventory_preparation', i18nKey: 'workspace.shippingNotice.processGate.inventoryActions.retryInventoryPreparation' }, }, global: { plugins: [i18n] }, }); // 失败后的人工恢复路径不能被运行态过滤误伤。 expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(true); }); it('renders reload inventory result as the timeout primary action', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_preparation', userStatus: 'retryable', retryable: true, primaryAction: { code: 'reload_inventory_result' }, }, global: { plugins: [i18n] }, }); expect(wrapper.find('[data-testid="review-current-task-primary-action"]').text()).toBe('重新读取库存结果'); }); it('hides the order-review entry when the user is already in the lifecycle workbench', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'order_review', userStatus: 'waiting_human', primaryAction: { code: 'open_order_review', i18nKey: 'chat.shippingProcessing.action.open_order_review' }, }, global: { plugins: [i18n] }, }); // 批次中心可以用它进入工作台;工作台当前阶段不能再显示同一个自跳转入口。 expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false); }); it('renders Gate label_key for every primary action presentation', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_matching', userStatus: 'waiting_human', primaryAction: { code: 'retry_inventory_matching', label_key: 'chat.shippingOrderReview.processGate.actionCodes.retry_inventory_matching', } as any, }, global: { plugins: [i18n] }, }); expect(wrapper.find('[data-testid="review-current-processing-retry"]').text()).toBe('重新库存匹配'); }); it('does not render save and validate as a current-task action', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'order_review', userStatus: 'waiting_human', }, global: { plugins: [i18n] }, }); // 提交订单是底栏唯一动作;未提交前必须给出明确交接提示,不能显示系统处理中。 expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false); expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()).toBe('提交订单'); }); it('labels an unqueued automatic Gate as waiting for system start', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'fulfillment_prep', userStatus: 'running', gateStatus: 'pending', }, global: { plugins: [i18n] }, }); expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('等待系统启动'); }); it('explains external wait without calling it generic system processing', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'upload_complete', userStatus: 'running', gateStatus: 'waiting_external', }, global: { plugins: [i18n] }, }); expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()) .toBe('等待外部系统回执,暂不需要人工操作'); }); it('never exposes an internal action code when its presentation is absent', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'order_review', userStatus: 'waiting_human', primaryAction: { code: 'edit_draft' }, }, global: { plugins: [i18n] }, }); // 回退显示 edit_draft 会泄漏内部能力码;必须 fail-closed 隐藏。 expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false); expect(wrapper.text()).not.toContain('edit_draft'); }); it('hides an unlabeled primary action instead of rendering an icon-only ghost button', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'fulfillment_prep', userStatus: 'waiting_human', // 后端下发了动作码,但前端无受控文案(缺失 i18n 映射 / 未登记), // 必须整体隐藏按钮,不能渲染成只有 Bot/RefreshCw 图标的“幽灵按钮”。 primaryAction: { code: 'unknown_system_action', i18nKey: 'workspace.shippingNotice.processGate.actionCodes.unknown_system_action' }, }, global: { plugins: [i18n] }, }); expect(wrapper.find('[data-testid="review-current-task-actions"]').exists()).toBe(false); expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false); expect(wrapper.text()).not.toContain('unknown_system_action'); }); it('renders a localized reason instead of an internal blocking code in the next step', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_matching', userStatus: 'waiting_human', blockingReason: { code: 'inventory_shortage_review_required' }, }, global: { plugins: [i18n] }, }); const nextStep = wrapper.get('[data-testid="review-current-task-next-step-text"]').text(); expect(nextStep).toBe('存在库存缺口,需要人工处理'); expect(nextStep).not.toContain('inventory_shortage_review_required'); }); it('hides internal inventory recovery targets while retaining the stable primary action', async () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'inventory_matching', userStatus: 'waiting_human', primaryAction: { code: 'retry_inventory_matching', i18nKey: 'retry_inventory_matching' }, recoveryActions: [{ code: 'retry_inventory_from_preparation', i18nKey: 'chat.shippingOrderReview.processGate.actionCodes.retry_inventory_matching', }], }, global: { plugins: [i18n] }, }); expect(wrapper.find('[data-testid="review-current-task-recovery-retry_inventory_from_preparation"]').exists()).toBe(false); expect(wrapper.findAll('button').length).toBe(1); }); it('emits rematch and RPA refresh as distinct actions for a shortage with an active inventory file', async () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { stageCode: 'fulfillment_prep', userStatus: 'waiting_human', primaryAction: { code: 'retry_inventory_matching' }, recoveryActions: [{ code: 'retry_inventory_preparation' }], }, global: { plugins: [i18n] }, }); await wrapper.get('[data-testid="review-current-processing-retry"]').trigger('click'); await wrapper.get('[data-testid="review-current-task-recovery-retry_inventory_preparation"]').trigger('click'); // 两个稳定 action 码分别进入 Gate API:重匹配不可误触 RPA,重新获取库存才会触发 RPA。 expect(wrapper.emitted('action')).toEqual([ ['retry_inventory_matching', {}], ['retry_inventory_preparation', {}], ]); }); it('keeps the known stage and status while the authoritative projection is still loading', () => { // Case 先到、Projection 后到的过渡窗口:阶段与投影同源(project_stage_for_task), // status 也来自后端 automation 运行态,必须照常展示,不能退回骨架/「正在更新状态」占位。 const wrapper = mount(ReviewCurrentProcessingCard, { props: { loading: true, stageCode: 'excel_generating', stageLabelKey: 'excel_generating', userStatus: 'running', }, global: { plugins: [i18n] }, }); expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toBe('Excel 生成'); // loading 只抑制动作,不掩盖真值:运行态照常显示「系统处理中」。 expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toBe('系统处理中'); expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()) .toBe('系统正在处理,暂不需要人工操作'); }); it('shows the neutral idle value instead of a skeleton when nothing is actionable yet', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { loading: true, stageCode: 'excel_generating', stageLabelKey: 'excel_generating' }, global: { plugins: [i18n] }, }); // 空用户态自然落到「待机 / 状态待确认」,与投影稳态一致——不做骨架→真值的二次刷新。 expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toBe('Excel 生成'); expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toBe('待机'); expect(wrapper.get('[data-testid="review-current-task-next-step-text"]').text()).toBe('状态待确认'); }); it('falls back to a neutral stage placeholder only when no stage is known', () => { const wrapper = mount(ReviewCurrentProcessingCard, { props: { loading: true }, global: { plugins: [i18n] }, }); expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toBe('正在获取最新状态…'); expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toBe('待机'); }); });