/** * features/workspace/shipping-task-center/TaskTodoPanel.actionsExecutable.spec.ts * 用途:验收 A2——Gate 只读时 Footer 委托 invokeActionByCode 仍可写。 * 依赖:Vitest、Vue Test Utils、TaskTodoPanel、shipping.api mock。 * 逻辑:gateCanHandle=false + actionsExecutable=true 时正式 Gate Action 被调用; * actionsExecutable=false 时直接返回;hidePrimaryActions 时不渲染 action_buttons。 */ import { flushPromises, mount } from '@vue/test-utils'; import { createI18n } from 'vue-i18n'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import TaskTodoPanel from './TaskTodoPanel.vue'; import type { ShippingTaskDetail } from '@/features/chat/types/shipping.api.types'; const postGateAction = vi.fn().mockResolvedValue({}); const refreshBadge = vi.fn().mockResolvedValue(undefined); vi.mock('@/features/chat/api/shipping.api', () => ({ confirmWorkspaceShippingCustomer: vi.fn(), confirmWorkspaceShippingInventorySource: vi.fn(), freezeWorkspaceShippingOrder: vi.fn(), listWorkspaceShippingCustomerOptions: vi.fn().mockResolvedValue([]), retryWorkspaceShippingUpload: vi.fn(), submitWorkspaceShippingDecision: vi.fn(), })); vi.mock('@/features/shipping-process-gates/api/process-gates.api', () => ({ postWorkspaceProcessGateAction: (...args: unknown[]) => postGateAction(...args), })); vi.mock('@/features/workspace/api/shipping-tasks.api', () => ({ downloadWorkspaceShippingExcelFile: vi.fn(), })); vi.mock('@/features/workspace/composables/useShippingTodoBadge', () => ({ refreshShippingTodoBadge: (...args: unknown[]) => refreshBadge(...args), })); vi.mock('@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue', () => ({ default: { name: 'ProcessGateRecoveryCard', props: ['summary', 'canHandle'], template: '
', }, })); const i18n = createI18n({ legacy: false, locale: 'zh-CN', messages: { 'zh-CN': { errors: { codes: { SHIPPING_PROCESSING_TASK_OWNERSHIP_MISMATCH: '归属不匹配', }, }, workspace: { shippingNotice: { todo: { currentTodo: '待办', adminViewOnly: '只读', waitingManualUploadNote: '上传', }, actions: { failed: '失败', freezeOrder: '冻结', freezeConfirm: '确认', }, loading: '加载中', }, }, }, }, }); function detail(): ShippingTaskDetail { return { task_no: 'SN-1', ui_state: { summary: { title: 't', message: 'm' }, action_buttons: [], checkpoint_kind: 'inventory', process_gate: { execution_no: 'SPE-1', current_blocking_gate: { gate_code: 'inventory_matching', evaluation_version: 3, }, }, }, } as unknown as ShippingTaskDetail; } describe('TaskTodoPanel actionsExecutable', () => { beforeEach(() => { postGateAction.mockClear(); refreshBadge.mockClear(); }); it('invokes formal Gate Action when gateCanHandle=false but actionsExecutable=true', async () => { const wrapper = mount(TaskTodoPanel, { props: { detail: detail(), gateCanHandle: false, actionsExecutable: true, hidePrimaryActions: true, }, global: { plugins: [i18n] }, }); expect(wrapper.get('[data-testid="gate-stub"]').attributes('data-can-handle')).toBe('false'); await (wrapper.vm as { invokeActionByCode: (id: string) => Promise }).invokeActionByCode('match_inventory'); await flushPromises(); expect(postGateAction).toHaveBeenCalledWith( 'SPE-1', 'inventory_matching', expect.objectContaining({ action_code: 'retry_inventory_matching', expected_gate_version: 3, idempotency_key: expect.any(String), }), ); }); it('blocks fulfillment invoke when expectedNoticeTaskNo mismatches', async () => { const wrapper = mount(TaskTodoPanel, { props: { detail: detail(), gateCanHandle: false, actionsExecutable: true, hidePrimaryActions: true, expectedNoticeTaskNo: 'SN-OTHER', }, global: { plugins: [i18n] }, }); await (wrapper.vm as { invokeActionByCode: (id: string) => Promise }).invokeActionByCode('match_inventory'); await flushPromises(); expect(postGateAction).not.toHaveBeenCalled(); }); it('no-ops invokeActionByCode when actionsExecutable=false', async () => { const wrapper = mount(TaskTodoPanel, { props: { detail: detail(), gateCanHandle: false, actionsExecutable: false, hidePrimaryActions: true, }, global: { plugins: [i18n] }, }); await (wrapper.vm as { invokeActionByCode: (id: string) => Promise }).invokeActionByCode('match_inventory'); await flushPromises(); expect(postGateAction).not.toHaveBeenCalled(); }); it('does not render legacy actions while inventory preparation is auto-progressing', () => { const task = detail(); task.ui_state = { ...task.ui_state, action_buttons: [{ id: 'edit_formal_task', label: '编辑正式任务', message: '', variant: 'primary', }], summary: { title: '获取库存', message: '系统正在自动处理', allowed_actions: ['edit_formal_task'], }, process_gate: { execution_no: 'SPE-1', technical_auto_only: true, current_blocking_gate: { gate_code: 'inventory_preparation', evaluation_version: 3, next_action_code: 'poll_inventory_preparation', }, }, } as ShippingTaskDetail['ui_state']; const wrapper = mount(TaskTodoPanel, { props: { detail: task, actionsExecutable: true }, global: { plugins: [i18n] }, }); // 自动推进阶段只允许 Gate 的刷新进度入口,不能泄漏正式任务编辑。 expect(wrapper.text()).not.toContain('编辑正式任务'); }); });