Files
syops/frontend/src/features/shipping-progress/workbenchActionRegistry.spec.ts
T
hugo 1e5aedb9ed feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理
清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
2026-08-26 02:47:07 +08:00

237 lines
9.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* features/shipping-progress/workbenchActionRegistry.spec.ts
* 用途:验收订单处理工作台动作注册表与 fail-closed 规则。
* 依赖:Vitest、workbenchActionRegistry、actionPresentation。
* 逻辑:合法码可渲染;未知码告警且不进入 presentation;review 隐藏自跳转与 refresh。
*/
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import { resolveProcessingActionPresentation } from './actionPresentation';
import {
WORKBENCH_ACTION_REGISTRY,
lookupWorkbenchAction,
resolveWorkbenchActionItem,
shouldRenderWorkbenchAction,
} from './workbenchActionRegistry';
function projection(
overrides: Partial<ShippingProcessingProjection> = {},
): ShippingProcessingProjection {
return {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'eml',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: 'SN-1',
conversationId: 'c1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'blocked',
stage: 'inventory_matching',
progressVersion: 1,
lastActivityAt: '2026-08-05T00:00:00Z',
currentGate: null,
availableActions: [],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 1,
customerName: null,
poNumber: null,
},
childOrderTasks: [],
...overrides,
};
}
describe('workbenchActionRegistry', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('registers Gate fulfillment actions and does not retain legacy aliases', () => {
for (const code of [
'retry_inventory_matching',
'mark_manual_uploaded',
'retry_freight_upload_rpa',
'regenerate_excel_artifact',
'view_result',
'view_record',
'confirm_customer',
'open_profile_review',
]) {
expect(lookupWorkbenchAction(code)).toBeTruthy();
}
expect(WORKBENCH_ACTION_REGISTRY.confirm_customer.reviewBehavior).toBe('open_customer_dialog');
for (const code of ['freeze_order', 'confirm_inventory_source', 'open_inventory_source_review', 'confirm_inventory_field_mapping', 'match_inventory', 'rematch', 'generate_excel', 'retry_upload']) {
expect(lookupWorkbenchAction(code)).toBeNull();
}
// 保存订单并校验只属于工作台底栏,不得注册为右栏当前任务动作。
expect(WORKBENCH_ACTION_REGISTRY.validate).toBeUndefined();
});
it('hides open_order_review / edit_formal_task / refresh on review surface', () => {
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.open_order_review, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.edit_formal_task, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.refresh, {
actionsExecutable: true,
surface: 'review',
})).toBe(false);
});
it('hides write actions when actionsExecutable=false but keeps view_result', () => {
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.retry_inventory_matching, {
actionsExecutable: false,
surface: 'review',
})).toBe(false);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.view_result, {
actionsExecutable: false,
surface: 'review',
})).toBe(true);
});
it('warns and omits unregistered action codes from review presentation', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
const result = resolveProcessingActionPresentation(projection({
uiState: {
status: 'waiting_human', stage: 'waiting_review', blocking_reason: null,
primary_action: { code: 'totally_unknown_action', label_key: 'x' },
secondary_actions: [{ code: 'view_result', enabled: true }],
},
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.intent).toBe('view_result');
expect(warn).toHaveBeenCalled();
const payload = warn.mock.calls[0]?.[1] as { action_code?: string };
expect(payload?.action_code).toBe('totally_unknown_action');
});
it('exposes Gate retry_inventory_matching as primary for review Footer', () => {
const result = resolveProcessingActionPresentation(projection({
uiState: {
status: 'waiting_human', stage: 'inventory_matching', blocking_reason: null,
primary_action: { code: 'retry_inventory_matching', label_key: 'x' }, secondary_actions: [],
},
currentGate: {
gateCode: 'inventory_match',
status: 'blocked',
nextActionCode: 'retry_inventory_matching',
blockingReasonCode: 'inventory_shortage',
attemptNo: 1,
},
availableActions: ['refresh'],
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.intent).toBe('retry_inventory_matching');
expect(result.primary?.actionCode).toBe('retry_inventory_matching');
expect(result.secondary).toBeNull();
});
it('routes backend retry_inventory_matching through the formal Gate todo action', () => {
const result = resolveProcessingActionPresentation(projection({
uiState: {
status: 'retryable', stage: 'inventory_matching', blocking_reason: null,
primary_action: { code: 'retry_inventory_matching', label_key: 'x' }, secondary_actions: [],
},
currentGate: {
gateCode: 'inventory_matching',
status: 'blocked_retryable',
nextActionCode: 'retry_inventory_matching',
blockingReasonCode: 'inventory_match_failed',
attemptNo: 1,
},
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.actionCode).toBe('retry_inventory_matching');
const resolved = resolveWorkbenchActionItem(result.primary!, { postCreate: true });
expect(resolved?.reviewBehavior).toBe('todo_panel');
expect(resolved?.todoActionCode).toBe('retry_inventory_matching');
});
it('routes reload inventory result through the formal Gate todo action', () => {
const result = resolveProcessingActionPresentation(projection({
uiState: {
status: 'retryable', stage: 'inventory_preparation', blocking_reason: null,
primary_action: { code: 'reload_inventory_result', label_key: 'x' }, secondary_actions: [],
},
currentGate: {
gateCode: 'inventory_preparation',
status: 'blocked_retryable',
nextActionCode: 'reload_inventory_result',
},
}), { surface: 'review' });
const resolved = resolveWorkbenchActionItem(result.primary!, { postCreate: true });
expect(result.primary?.intent).toBe('reload_inventory_result');
expect(resolved?.reviewBehavior).toBe('todo_panel');
expect(resolved?.todoActionCode).toBe('reload_inventory_result');
});
it('shows RPA upload retry instead of manual upload entries when Gate 19 is blocked', () => {
const result = resolveProcessingActionPresentation(projection({
stage: 'freight_uploading',
uiState: {
status: 'retryable', stage: 'freight_uploading', blocking_reason: null,
primary_action: { code: 'retry_freight_upload_rpa', label_key: 'x' },
secondary_actions: [{ code: 'download_excel', enabled: true }],
},
currentGate: {
gateCode: 'freight_upload_rpa',
status: 'blocked',
nextActionCode: 'retry_freight_upload_rpa',
blockingReasonCode: 'upload_rpa_failed',
attemptNo: 1,
},
availableActions: ['download_excel', 'mark_manual_uploaded'],
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.actionCode).toBe('retry_freight_upload_rpa');
expect(result.primary?.intent).toBe('retry_freight_upload_rpa');
expect(result.secondary?.actionCode).toBe('download_excel');
expect(result.overflow.map((item) => item.actionCode)).not.toContain('mark_manual_uploaded');
});
it('does not turn the admin todo-regeneration recovery action into manual upload', () => {
const result = resolveProcessingActionPresentation(projection({
stage: 'freight_uploading',
uiState: {
status: 'waiting_human', stage: 'freight_uploading', blocking_reason: null,
primary_action: { code: 'regenerate_manual_upload_todo', label_key: 'x' },
secondary_actions: [{ code: 'download_excel', enabled: true }],
},
currentGate: {
gateCode: 'manual_upload_handoff',
status: 'blocked',
nextActionCode: 'regenerate_manual_upload_todo',
blockingReasonCode: 'manual_upload_todo_missing',
attemptNo: 1,
},
}), { surface: 'review', actionsExecutable: true });
expect(result.primary?.actionCode).toBe('download_excel');
expect(result.overflow.map((item) => item.actionCode)).not.toContain('regenerate_manual_upload_todo');
});
it('hides confirm_customer when customer panel unavailable', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
expect(shouldRenderWorkbenchAction(WORKBENCH_ACTION_REGISTRY.confirm_customer, {
actionsExecutable: true,
surface: 'review',
panels: { customerUnresolved: false },
actionCode: 'confirm_customer',
})).toBe(false);
expect(warn).toHaveBeenCalled();
});
it('does not register inventory source selection or mapping confirmation', () => {
expect(lookupWorkbenchAction('open_inventory_source_review')).toBeNull();
expect(lookupWorkbenchAction('confirm_inventory_field_mapping')).toBeNull();
});
});