把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
176 lines
5.6 KiB
TypeScript
176 lines
5.6 KiB
TypeScript
/**
|
|
* 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({ dispatch: 'sync' });
|
|
const getProcessExecution = vi.fn();
|
|
const refreshBadge = vi.fn().mockResolvedValue(undefined);
|
|
|
|
vi.mock('@/features/chat/api/shipping.api', () => ({
|
|
confirmWorkspaceShippingCustomer: vi.fn(),
|
|
listWorkspaceShippingCustomerOptions: vi.fn().mockResolvedValue([]),
|
|
}));
|
|
|
|
vi.mock('@/features/shipping-process-gates/api/process-gates.api', () => ({
|
|
postWorkspaceProcessGateAction: (...args: unknown[]) => postGateAction(...args),
|
|
getWorkspaceProcessExecution: (...args: unknown[]) => getProcessExecution(...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: '<div data-testid="gate-stub" :data-can-handle="canHandle" />',
|
|
},
|
|
}));
|
|
|
|
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' },
|
|
actions: {
|
|
primary: {
|
|
code: 'retry_onhand_matching', kind: 'recovery', enabled: true,
|
|
label: '重新匹配', dispatch: 'mutation',
|
|
requires_confirmation: false,
|
|
},
|
|
secondary: [],
|
|
},
|
|
user_mode: 'must_human',
|
|
process_gate: {
|
|
execution_no: 'SPE-1',
|
|
current_blocking_gate: {
|
|
gate_code: 'onhand_matching',
|
|
evaluation_version: 3,
|
|
},
|
|
},
|
|
},
|
|
} as unknown as ShippingTaskDetail;
|
|
}
|
|
|
|
describe('TaskTodoPanel actionsExecutable', () => {
|
|
beforeEach(() => {
|
|
postGateAction.mockClear();
|
|
postGateAction.mockResolvedValue({ dispatch: 'sync' });
|
|
getProcessExecution.mockReset();
|
|
refreshBadge.mockClear();
|
|
});
|
|
|
|
it('does not expose a hidden action-code executor when the Gate card is read-only', async () => {
|
|
const wrapper = mount(TaskTodoPanel, {
|
|
props: {
|
|
detail: detail(),
|
|
gateCanHandle: false,
|
|
actionsExecutable: true,
|
|
hidePrimaryActions: false,
|
|
},
|
|
global: { plugins: [i18n] },
|
|
});
|
|
expect(wrapper.get('[data-testid="gate-stub"]').attributes('data-can-handle')).toBe('false');
|
|
expect((wrapper.vm as { invokeActionByCode?: unknown }).invokeActionByCode).toBeUndefined();
|
|
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: 'onhand_preparation',
|
|
evaluation_version: 3,
|
|
next_action_code: 'poll_onhand_preparation',
|
|
},
|
|
},
|
|
} as ShippingTaskDetail['ui_state'];
|
|
|
|
const wrapper = mount(TaskTodoPanel, {
|
|
props: { detail: task, actionsExecutable: true },
|
|
global: { plugins: [i18n] },
|
|
});
|
|
|
|
// 自动推进阶段只允许 Gate 的刷新进度入口,不能泄漏正式任务编辑。
|
|
expect(wrapper.text()).not.toContain('编辑正式任务');
|
|
});
|
|
|
|
it('hides an action that has no user-facing label instead of exposing its code', () => {
|
|
const task = detail();
|
|
task.ui_state = {
|
|
...task.ui_state,
|
|
actions: {
|
|
primary: { code: 'internal_only_action', kind: 'recovery', enabled: true },
|
|
secondary: [],
|
|
},
|
|
process_gate: undefined,
|
|
} as ShippingTaskDetail['ui_state'];
|
|
|
|
const wrapper = mount(TaskTodoPanel, {
|
|
props: { detail: task, actionsExecutable: true },
|
|
global: { plugins: [i18n] },
|
|
});
|
|
|
|
// 用户面没有受控文案的动作必须 fail-closed,不能再次暴露内部 action code。
|
|
expect(wrapper.text()).not.toContain('internal_only_action');
|
|
});
|
|
});
|