- 抽取 Job 续抽交接时 defer_stp_enqueue,STP 入队推迟到 run 收口统一触发,消除与续抽 Job 互抢行锁的死锁(2026-09-22 生产事故) - 草稿显式 validate 在内容未变时幂等短路:不递增版本、不写事件、不重复触发下游,防连点「保存并校验」产生版本/Job 风暴(事故根因) - STP 自动建单入队前 supersede 同文档过期排队 Job,防止旧版本 Job 抢跑 - 抽取 Job 异常收口识别 PostgreSQL 瞬时锁冲突(40P01/55P03)标记可重试,不再终态失败要求人工重新识别 - 订单凭据加密抽离为 app/core/credential_crypto 通用模块,shipping_notice 委托调用并保留原错误码 - 同步复核视图与测试:新增草稿校验幂等契约测试,更新 STP 入队与 Worker 重试用例
4454 lines
205 KiB
TypeScript
4454 lines
205 KiB
TypeScript
/**
|
||
* features/chat/views/ShippingOrderReviewView.spec.ts
|
||
* 用途:锁定复核工作台布局与统一重试契约。
|
||
* 依赖:vitest、@vue/test-utils、vue-i18n、vue-router mocks。
|
||
* 逻辑:标准模式无对话上下文、无常驻 PDF 列;底栏无「确认并创建任务」;
|
||
* 正式 OT / STP 对象级重试走 /retry 或 STP retry;敏感面板审计失败不打开。
|
||
*/
|
||
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
|
||
import { computed, nextTick, ref } from 'vue';
|
||
import { flushPromises, mount } from '@vue/test-utils';
|
||
import { createI18n } from 'vue-i18n';
|
||
import { createRouter, createMemoryHistory } from 'vue-router';
|
||
import ShippingOrderReviewView from './ShippingOrderReviewView.vue';
|
||
import ReviewCurrentProcessingCard from '../components/shipping-review/ReviewCurrentProcessingCard.vue';
|
||
import ReviewFieldConflictPanel from '../components/shipping-review/ReviewFieldConflictPanel.vue';
|
||
import ManualUploadEvidenceDialog from '@/features/workspace/shipping-task-center/ManualUploadEvidenceDialog.vue';
|
||
import { CHAT_PAGE_KEY } from '@/features/chat/composables/chat.context';
|
||
import {
|
||
auditWorkspaceShippingOrderReviewEligibilityDetails,
|
||
auditWorkspaceShippingOrderReviewVersionHistory,
|
||
getWorkspaceShippingFreightNoticeGroups,
|
||
getWorkspaceShippingOrderReviewCase,
|
||
getWorkspaceShippingTask,
|
||
decideWorkspaceShippingOrderReviewLineFulfillment,
|
||
waveWorkspaceShippingOrderReviewLineFulfillment,
|
||
retryWorkspaceShippingOrderStpAutoCreate,
|
||
retryShippingNoticeIntake,
|
||
} from '@/features/chat/api/shipping.api';
|
||
|
||
const { batchConfirmFreightMock, batchRpaFreightMock, downloadFreightArchiveMock } = vi.hoisted(() => ({
|
||
batchConfirmFreightMock: vi.fn().mockResolvedValue({ results: [] }),
|
||
batchRpaFreightMock: vi.fn().mockResolvedValue({ results: [] }),
|
||
downloadFreightArchiveMock: vi.fn().mockResolvedValue(undefined),
|
||
}));
|
||
|
||
const { downloadWorkspaceShippingLineInventoryFileMock } = vi.hoisted(() => ({
|
||
downloadWorkspaceShippingLineInventoryFileMock: vi.fn().mockResolvedValue(undefined),
|
||
}));
|
||
const { downloadWorkspaceShippingExcelFileMock } = vi.hoisted(() => ({
|
||
downloadWorkspaceShippingExcelFileMock: vi.fn().mockResolvedValue(undefined),
|
||
}));
|
||
const { downloadWorkspaceShippingNoticeExcelFileMock } = vi.hoisted(() => ({
|
||
downloadWorkspaceShippingNoticeExcelFileMock: vi.fn().mockResolvedValue(undefined),
|
||
}));
|
||
|
||
vi.mock('@/features/chat/shipping/shippingDownload', () => ({
|
||
downloadWorkspaceShippingLineInventoryFile: downloadWorkspaceShippingLineInventoryFileMock,
|
||
downloadWorkspaceShippingNoticeExcelFile: downloadWorkspaceShippingNoticeExcelFileMock,
|
||
downloadWorkspaceShippingNoticeExportArchive: downloadFreightArchiveMock,
|
||
}));
|
||
vi.mock('@/features/workspace/api/shipping-tasks.api', () => ({
|
||
downloadWorkspaceShippingExcelFile: downloadWorkspaceShippingExcelFileMock,
|
||
}));
|
||
|
||
const focusSuggestionField = vi.fn();
|
||
const load = vi.fn().mockResolvedValue(undefined);
|
||
const selectCase = vi.fn().mockResolvedValue(undefined);
|
||
const beginCrossRunSwitch = vi.fn();
|
||
const ensureIntakeParseContextLoaded = vi.fn().mockResolvedValue(true);
|
||
/** 确认建单 mock:用例可改写返回值以断言 confirm_outcome / auto_progress 解析。 */
|
||
const confirmMock = vi.fn();
|
||
const reloadLatestDraftMock = vi.fn().mockResolvedValue(undefined);
|
||
const refreshReviewQueueMock = vi.fn().mockResolvedValue(true);
|
||
const refreshShippingProcessingMock = vi.fn().mockResolvedValue(undefined);
|
||
const startWorkflowProgressPollingMock = vi.fn();
|
||
const stopWorkflowProgressPollingMock = vi.fn();
|
||
const stopReparseCaseRefreshPollingMock = vi.fn();
|
||
const patchLineMock = vi.fn().mockResolvedValue(undefined);
|
||
const reparseDocumentMock = vi.fn().mockResolvedValue({ run: { run_no: 'RUN-2' } });
|
||
let reparseCaseReadyHandler: ((target: { runNo: string; caseNo: string; documentId: number }) => void) | undefined;
|
||
const { submitProcessGatePrimaryActionMock } = vi.hoisted(() => ({
|
||
submitProcessGatePrimaryActionMock: vi.fn().mockResolvedValue({ outcome: 'submitted' }),
|
||
}));
|
||
|
||
/**
|
||
* 本文件每个用例均挂载完整工作台;统一卸载,避免跨用例残留 watch/router 响应式副作用。
|
||
*/
|
||
const mountedWrappers: Array<{ unmount: () => void }> = [];
|
||
const { postFormalGateActionMock } = vi.hoisted(() => ({
|
||
postFormalGateActionMock: vi.fn().mockResolvedValue({}),
|
||
}));
|
||
|
||
const messageMocks = vi.hoisted(() => ({
|
||
info: vi.fn(),
|
||
warning: vi.fn(),
|
||
error: vi.fn(),
|
||
success: vi.fn(),
|
||
}));
|
||
|
||
/** 同步 stub 异步证据抽屉(覆盖相对路径与 @ 别名,供 defineAsyncComponent 解析)。 */
|
||
const evidenceDrawerStub = vi.hoisted(() => ({
|
||
name: 'ReviewDocumentEvidenceDrawer',
|
||
props: ['open', 'pinned', 'expanded', 'docked', 'floatSide'],
|
||
emits: ['close', 'toggle-pin', 'toggle-expand', 'toggle-dock', 'toggle-side'],
|
||
template: `
|
||
<aside
|
||
v-if="open"
|
||
data-testid="review-document-evidence-drawer"
|
||
:data-docked="docked ? 'true' : 'false'"
|
||
:data-presentation="docked ? 'docked' : 'floating'"
|
||
>
|
||
<button data-testid="review-evidence-toggle-dock" @click="$emit('toggle-dock')">dock</button>
|
||
<button data-testid="review-evidence-toggle-expand" @click="$emit('toggle-expand')">expand</button>
|
||
</aside>
|
||
`,
|
||
}));
|
||
|
||
const reviewRun = ref({
|
||
run_no: 'RUN-1',
|
||
items: [
|
||
{
|
||
case_no: 'CASE-1',
|
||
document_id: 1,
|
||
file_name: 'po.pdf',
|
||
status: 'draft',
|
||
issue_count: 0,
|
||
available_actions: ['validate', 'confirm'],
|
||
},
|
||
],
|
||
});
|
||
const reviewQueue = ref({
|
||
conversation_id: 'conv-1',
|
||
summary: { total: 1, needs_action: 1, processing: 0, completed: 0 },
|
||
items: [{
|
||
case_no: 'CASE-1',
|
||
source_run_no: 'RUN-1',
|
||
document_id: 1,
|
||
file_name: 'po.pdf',
|
||
status: 'draft',
|
||
issue_count: 0,
|
||
available_actions: ['validate', 'confirm'],
|
||
}],
|
||
});
|
||
const workItem = ref<Record<string, any> | null>(null);
|
||
const reviewProgressContext = ref<Record<string, any> | null>(null);
|
||
/** Run 解析中的用户态进度;与真实 composable 返回契约保持一致。 */
|
||
const extractionLifecycleProgress = ref<Record<string, any> | null>(null);
|
||
/** 旧重解析横幅状态;回归用例确认它不再驱动独立黄色进度提示。 */
|
||
const statusMessage = ref<string | null>(null);
|
||
const runLoading = ref(false);
|
||
const runSwitchFailed = ref(false);
|
||
/** 与 activeCase 同源共享,供断言 Progress 优先阶段源。 */
|
||
const shippingProcessingProjection = ref<Record<string, any> | null>(null);
|
||
/** 正式任务投影的请求中状态;用于覆盖 Case 先到、Projection 后到的过渡窗口。 */
|
||
const shippingProcessingLoading = ref(false);
|
||
const intakeParseContext = ref<Record<string, any> | null>(null);
|
||
const requestedCaseNo = ref<string | null>(null);
|
||
const reviewEditable = ref(true);
|
||
const reviewFormalEditable = ref(false);
|
||
|
||
/** 每个用例必须从独立的 Case 图快照开始,避免嵌套 schema/draft 被浅拷贝污染。 */
|
||
function createActiveCaseFixture() {
|
||
return {
|
||
case_no: 'CASE-1',
|
||
document_id: 1,
|
||
status: 'draft',
|
||
available_actions: ['validate', 'confirm', 'mark_non_order', 'reparse'],
|
||
schema: {
|
||
schema_version_id: 14,
|
||
fields: [
|
||
{
|
||
field_id: 'fld-po',
|
||
field_code: 'customer_po_number',
|
||
display_name: '客户 PO',
|
||
scope: 'header',
|
||
value_type: 'string',
|
||
required: true,
|
||
options: [],
|
||
},
|
||
{
|
||
field_id: 'fld-inventory-source-hint',
|
||
field_code: 'inventory_source_hint',
|
||
display_name: '库存源线索',
|
||
scope: 'line',
|
||
value_type: 'string',
|
||
required: false,
|
||
options: [],
|
||
},
|
||
],
|
||
},
|
||
draft: {
|
||
draft_version: 1,
|
||
header_values: {
|
||
values: { 'fld-po': { value: 'PO-1', source: 'machine' } },
|
||
machine_fields: [{ field_id: 'fld-po', observations: [{ value: 'PO-1' }] }],
|
||
},
|
||
lines: [{
|
||
draft_line_id: 'LINE-1',
|
||
values: {},
|
||
machine_fields: [],
|
||
}],
|
||
issues: [],
|
||
},
|
||
process_gate: null,
|
||
profile_match: { available: false, visibility: 'admin_only', candidates: [] },
|
||
automation: { status: 'idle', can_auto_create: false, can_build: true },
|
||
};
|
||
}
|
||
|
||
const activeCase = ref<Record<string, any>>(createActiveCaseFixture());
|
||
|
||
vi.mock('@/features/chat/api/shipping.api', async (importOriginal) => {
|
||
const actual = await importOriginal<typeof import('@/features/chat/api/shipping.api')>();
|
||
return {
|
||
...actual,
|
||
auditWorkspaceShippingOrderReviewVersionHistory: vi.fn().mockResolvedValue({ audited: true, case_no: 'CASE-1' }),
|
||
auditWorkspaceShippingOrderReviewEligibilityDetails: vi.fn().mockResolvedValue({ audited: true, case_no: 'CASE-1' }),
|
||
decideWorkspaceShippingOrderReviewLineFulfillment: vi.fn().mockResolvedValue({ status: 'ok' }),
|
||
waveWorkspaceShippingOrderReviewLineFulfillment: vi.fn().mockResolvedValue({ status: 'ok' }),
|
||
retryWorkspaceShippingOrderStpAutoCreate: vi.fn().mockResolvedValue({
|
||
status: 'queued',
|
||
job_id: 901,
|
||
case: null,
|
||
}),
|
||
retryShippingNoticeIntake: vi.fn().mockResolvedValue({ intake_no: 'SNI-RETRY-1', parse_status: 'queued' }),
|
||
getWorkspaceShippingOrderReviewCase: vi.fn().mockResolvedValue({ case: null }),
|
||
getWorkspaceShippingTask: vi.fn().mockResolvedValue({
|
||
task_no: 'SN-MOCK',
|
||
status: 'created',
|
||
}),
|
||
getWorkspaceShippingFreightNoticeGroups: vi.fn().mockResolvedValue({ items: [] }),
|
||
batchConfirmWorkspaceShippingNoticesUploaded: (...args: unknown[]) => batchConfirmFreightMock(...args),
|
||
batchStartWorkspaceShippingNoticeRpaUpload: (...args: unknown[]) => batchRpaFreightMock(...args),
|
||
};
|
||
});
|
||
|
||
/** mock 工厂句柄:vi.mock 提升后由下方 createReviewComposableMock 赋值。 */
|
||
const reviewComposableMockApi = vi.hoisted(() => ({
|
||
create: null as null | (() => Record<string, unknown>),
|
||
}));
|
||
|
||
vi.mock('@/features/chat/shipping-review/useShippingOrderReview', () => ({
|
||
REVIEW_BUILD_ELIGIBILITY_BLOCKED: 'SHIPPING.REVIEW_BUILD_ELIGIBILITY_BLOCKED',
|
||
useShippingOrderReview: (options?: {
|
||
onReparseCaseReady?: (target: { runNo: string; caseNo: string; documentId: number }) => void;
|
||
}) => {
|
||
if (!reviewComposableMockApi.create) {
|
||
throw new Error('createReviewComposableMock not initialized');
|
||
}
|
||
reparseCaseReadyHandler = options?.onReparseCaseReady;
|
||
return reviewComposableMockApi.create();
|
||
},
|
||
}));
|
||
|
||
/**
|
||
* 统一维护 useShippingOrderReview mock 契约,避免新增返回字段时漏改。
|
||
*/
|
||
function createReviewComposableMock() {
|
||
return {
|
||
reviewRun,
|
||
reviewQueue,
|
||
activeCase,
|
||
caseProjectionVersion: ref(1),
|
||
caseLoadingContext: ref(null),
|
||
reviewProgressContext,
|
||
extractionLifecycleProgress,
|
||
workItem,
|
||
authoritativeOrderTaskNo: computed(() => {
|
||
const no = String(reviewProgressContext.value?.user_task_no || '').trim();
|
||
if (!no || reviewProgressContext.value?.user_task_authoritative === false) return null;
|
||
return no;
|
||
}),
|
||
versions: ref([]),
|
||
statusMessage,
|
||
draftConflict: ref(null),
|
||
draftConflictDiffLines: ref([]),
|
||
buildEligibility: ref({ can_build: true, issues: [], lines: [] }),
|
||
canConfirmBuild: computed(() => true),
|
||
routingRecoveryLines: ref([]),
|
||
isViewingHistoricalVersion: computed(() => false),
|
||
isReadOnly: computed(() => false),
|
||
initialLoading: ref(false),
|
||
runLoading,
|
||
runSwitchFailed,
|
||
loadFailed: ref(false),
|
||
caseSwitchLoading: ref(false),
|
||
caseSwitchFailed: ref(false),
|
||
requestedCaseNo,
|
||
saving: ref(false),
|
||
validationInProgress: ref(false),
|
||
saveFailed: ref(false),
|
||
versionsLoading: ref(false),
|
||
evidence: ref([
|
||
{
|
||
field_id: 'fld-po',
|
||
page_no: 1,
|
||
quote: 'PO-1',
|
||
bbox: { x0: 0.1, y0: 0.1, x1: 0.2, y1: 0.2 },
|
||
},
|
||
]),
|
||
llmSuggestions: ref([]),
|
||
suggestionLoading: ref(false),
|
||
focusedFieldId: ref(null),
|
||
focusedLineKey: ref(null),
|
||
previewUrl: ref('blob:mock-pdf'),
|
||
previewLoading: ref(false),
|
||
previewLoadFailed: ref(false),
|
||
ensurePreviewLoaded: vi.fn().mockResolvedValue(true),
|
||
ensureEmailEvidenceLoaded: vi.fn().mockResolvedValue(true),
|
||
ensureIntakeParseContextLoaded,
|
||
emailPreview: ref(null),
|
||
intakeParseContext,
|
||
intakeParseLoading: ref(false),
|
||
intakeParseLoadFailed: ref(false),
|
||
load,
|
||
loadReviewCase: vi.fn().mockResolvedValue(undefined),
|
||
selectCase,
|
||
beginCrossRunSwitch,
|
||
refreshWorkItemContext: vi.fn(),
|
||
openCurrentVersion: vi.fn(),
|
||
reloadLatestDraft: reloadLatestDraftMock,
|
||
refreshReviewQueue: refreshReviewQueueMock,
|
||
toggleConflictDiff: vi.fn(),
|
||
patchHeader: vi.fn(),
|
||
patchLine: patchLineMock,
|
||
addLine: vi.fn(),
|
||
copyLine: vi.fn(),
|
||
deleteLine: vi.fn(),
|
||
validate: vi.fn(),
|
||
setLineInventoryCandidates: vi.fn(),
|
||
rerouteInventoryRouting: vi.fn(),
|
||
adoptInventoryRoutingSuggestion: vi.fn(),
|
||
keepManualInventoryRouting: vi.fn(),
|
||
confirm: confirmMock,
|
||
createManualDraft: vi.fn(),
|
||
markNonOrder: vi.fn(),
|
||
markQualityIssue: vi.fn(),
|
||
reparseDocument: reparseDocumentMock,
|
||
focusSuggestionField,
|
||
setEvidenceDrawerFocus: vi.fn(),
|
||
clearEvidenceDrawerFocus: vi.fn(),
|
||
requestSuggestion: vi.fn(),
|
||
decideSuggestion: vi.fn(),
|
||
editable: computed(() => reviewEditable.value),
|
||
formalEditable: computed(() => reviewFormalEditable.value),
|
||
canEditFormalFields: computed(() => false),
|
||
isFieldEditable: () => true,
|
||
isWorkItemClosed: computed(() => false),
|
||
showWorkflowProgress: computed(() => false),
|
||
workflowProgressPolling: computed(() => false),
|
||
startStpAutoCreateTracking: vi.fn(),
|
||
startWorkflowProgressPolling: startWorkflowProgressPollingMock,
|
||
stopWorkflowProgressPolling: stopWorkflowProgressPollingMock,
|
||
stopReparseCaseRefreshPolling: stopReparseCaseRefreshPollingMock,
|
||
shippingProcessingProjection,
|
||
shippingProcessingLoading,
|
||
shippingProcessingError: ref(null),
|
||
refreshShippingProcessing: refreshShippingProcessingMock,
|
||
};
|
||
}
|
||
|
||
reviewComposableMockApi.create = createReviewComposableMock;
|
||
|
||
vi.mock('@/shared/composables/useMessage', () => ({
|
||
useMessage: () => messageMocks,
|
||
}));
|
||
|
||
vi.mock('@/features/shipping-process-gates/composables/useShippingProcessGateRecovery', () => ({
|
||
useShippingProcessGateRecovery: () => ({
|
||
busy: ref(false),
|
||
submitPrimaryAction: submitProcessGatePrimaryActionMock,
|
||
}),
|
||
}));
|
||
|
||
vi.mock('@/features/shipping-process-gates/api/process-gates.api', () => ({
|
||
postWorkspaceProcessGateAction: (...args: unknown[]) => postFormalGateActionMock(...args),
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewDocumentPreview.vue', () => ({
|
||
default: {
|
||
name: 'ReviewDocumentPreview',
|
||
template: '<div data-testid="mock-pdf-preview" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewDocumentEvidenceDrawer.vue', () => ({
|
||
default: evidenceDrawerStub,
|
||
}));
|
||
vi.mock('@/features/chat/components/shipping-review/ReviewDocumentEvidenceDrawer.vue', () => ({
|
||
default: evidenceDrawerStub,
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewBuildEligibilitySummary.vue', () => ({
|
||
default: {
|
||
name: 'ReviewBuildEligibilitySummary',
|
||
props: ['eligibility', 'exceptionCount', 'exceptionOrdinal'],
|
||
emits: ['open-details', 'navigate-exception'],
|
||
template:
|
||
'<div data-testid="mock-eligibility-summary">'
|
||
+ '<button data-testid="review-open-eligibility-details" @click="$emit(\'open-details\')">详情</button>'
|
||
+ '<div v-if="exceptionCount" data-testid="review-exception-nav">'
|
||
+ '<button data-testid="review-exception-prev" @click="$emit(\'navigate-exception\', -1)">上一</button>'
|
||
+ '<button data-testid="review-exception-next" @click="$emit(\'navigate-exception\', 1)">下一</button>'
|
||
+ '</div>'
|
||
+ '</div>',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewBuildEligibilityDetailsDrawer.vue', () => ({
|
||
default: {
|
||
name: 'ReviewBuildEligibilityDetailsDrawer',
|
||
props: ['open'],
|
||
template: '<div v-if="open" data-testid="mock-eligibility-details" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewInventoryIssueList.vue', () => ({
|
||
default: {
|
||
name: 'ReviewInventoryIssueList',
|
||
template: '<div data-testid="mock-inventory-issues" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewInventoryCandidatesPanel.vue', () => ({
|
||
default: {
|
||
name: 'ReviewInventoryCandidatesPanel',
|
||
template: '<div data-testid="mock-inventory" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('@/features/shipping-process-gates/components/ProcessGateRecoveryCard.vue', () => ({
|
||
default: {
|
||
name: 'ProcessGateRecoveryCard',
|
||
props: ['showActions'],
|
||
template: '<div data-testid="mock-process-gate" :data-actions="showActions === false ? \'hidden\' : \'shown\'" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewLlmSuggestionDrawer.vue', () => ({
|
||
default: {
|
||
name: 'ReviewLlmSuggestionDrawer',
|
||
template: '<div data-testid="mock-llm-drawer" />',
|
||
},
|
||
}));
|
||
|
||
vi.mock('../components/shipping-review/ReviewVersionHistoryDrawer.vue', () => ({
|
||
default: {
|
||
name: 'ReviewVersionHistoryDrawer',
|
||
props: ['open'],
|
||
template: '<div v-if="open" data-testid="mock-versions-drawer" />',
|
||
},
|
||
}));
|
||
|
||
/**
|
||
* 挂载复核工作台视图并注入最小 Chat 上下文。
|
||
*/
|
||
async function mountView(query: Record<string, string> = {}) {
|
||
const i18n = createI18n({
|
||
legacy: false,
|
||
locale: 'zh-CN',
|
||
messages: {
|
||
'zh-CN': {
|
||
chat: {
|
||
shippingOrderReview: {
|
||
title: '订单人工复核',
|
||
run: '识别批次 {runNo}',
|
||
workItemHeader: '{itemNo} {version}',
|
||
backToSession: '返回',
|
||
readOnly: '只读',
|
||
loading: '加载中',
|
||
unavailable: '不可用',
|
||
retryLoad: '重试',
|
||
caseSwitchLoading: '正在加载当前 PDF…',
|
||
caseSwitchFailed: '当前 PDF 加载失败,可重试',
|
||
caseSwitchRetry: '重试',
|
||
documentNavigation: 'PDF 导航',
|
||
documents: 'PDF',
|
||
lifecycle: {
|
||
autoAdvanced: '已自动推进到{stage}',
|
||
stages: { fulfillment_prep: '通知准备' },
|
||
},
|
||
unnamedDocument: '未命名',
|
||
caseStatus: '{status} · {count}',
|
||
caseStatuses: { draft: '草稿', unknown: '未知' },
|
||
previewTitle: 'PDF 预览',
|
||
previewLoading: '加载 PDF',
|
||
previewUnavailable: '无预览',
|
||
locateSource: '定位 {field}',
|
||
locateUnavailableHint: '无可靠坐标,点击查看诊断',
|
||
locateCandidateHint: '候选位置',
|
||
dblclickLocateHint: '双击定位',
|
||
exceptionNav: {
|
||
prev: '上一异常',
|
||
next: '下一异常',
|
||
prevHint: '上一异常',
|
||
nextHint: '下一异常',
|
||
},
|
||
issues: '问题',
|
||
highlightQuality: {
|
||
verified: '已验证',
|
||
candidate: '候选',
|
||
unavailable: '无坐标',
|
||
invalid: '无效',
|
||
},
|
||
orderFields: '订单字段',
|
||
schemaVersion: 'V{version}',
|
||
lines: '明细',
|
||
line: '行 {index}',
|
||
noLines: '无明细',
|
||
noMachineOrder: '无订单',
|
||
createManualDraft: '手工建草稿',
|
||
markNonOrder: '非订单',
|
||
markQualityIssue: '质量异常',
|
||
reparse: '重新识别',
|
||
saveNow: '保存并校验',
|
||
saveOrderAndValidate: '提交订单',
|
||
submitOrderHint: '提交后自动校验,满足条件将自动建单。',
|
||
confirmCreate: '确认并建单',
|
||
restoreMachine: '恢复',
|
||
moreFields: '更多 {count}',
|
||
moreLineFields: '更多列 {count}',
|
||
collapseFields: '收起',
|
||
addLine: '新增行',
|
||
copyLine: '复制行',
|
||
deleteLine: '删除行',
|
||
emptyValue: '空',
|
||
valueSources: { machine: '系统' },
|
||
primaryBlockTitle: '阻断',
|
||
primaryBlockParty: '{party}',
|
||
versionHistory: { title: '版本历史' },
|
||
auditTrail: { open: '查看审计' },
|
||
customerResolution: {
|
||
title: '客户确认',
|
||
subtitle: '建单前确认标准客户',
|
||
unresolved: '未确认',
|
||
confirmed: '已确认',
|
||
status: {
|
||
unmatched: '未匹配',
|
||
confirmed: '已确认',
|
||
},
|
||
standardCustomer: '标准客户',
|
||
select: '选择客户',
|
||
selectCustomer: '选择客户',
|
||
retryCustomer: '重新匹配客户',
|
||
pdfReparseHint: '重新识别 PDF 不会确认客户',
|
||
search: '搜索',
|
||
empty: '无候选',
|
||
confirm: '确认',
|
||
cancel: '取消',
|
||
},
|
||
workbench: {
|
||
mode: {
|
||
standard: '标准复核',
|
||
evidence: '证据核对',
|
||
inventory: '库存处理',
|
||
reparse: '重新识别',
|
||
confirm_progress: '建单进度',
|
||
},
|
||
moreStatus: '更多状态',
|
||
enterInventory: '查看库存问题',
|
||
returnStandard: '返回标准复核',
|
||
openPdf: '打开 PDF',
|
||
closePdf: '关闭 PDF',
|
||
pinPdf: '退出后保留',
|
||
unpinPdf: '退出后关闭',
|
||
pinPdfHint: '退出证据模式后仍保留 PDF 打开(不会固定在视口)',
|
||
unpinPdfHint: '退出证据模式时关闭 PDF',
|
||
openVersionHistory: '版本历史',
|
||
auditFailed: '审计记录失败,敏感面板未打开,请重试',
|
||
summaryRail: '摘要',
|
||
actionSuccess: '已完成',
|
||
resultNotReady: '结果未就绪',
|
||
},
|
||
evidenceAt: 'PDF 第 {page} 页',
|
||
evidenceNoHighlight: '无坐标',
|
||
evidenceDrawer: {
|
||
title: '证据核对',
|
||
pageUnknown: '页码未知',
|
||
prevEvidence: '上一证据',
|
||
nextEvidence: '下一证据',
|
||
field: '字段:{field}',
|
||
currentValue: '当前值',
|
||
machineValue: '机器值',
|
||
source: '来源',
|
||
},
|
||
llmSuggestion: { request: '请求 AI' },
|
||
restoreMachine: '恢复机器值',
|
||
saving: '保存中',
|
||
saved: '已保存',
|
||
saveFailed: '失败',
|
||
versionConflict: { badge: '冲突' },
|
||
statusBanner: { unknown: '未知' },
|
||
autoProgress: {
|
||
status: { unknown: '', needs_retry: '待重试', needs_human: '需要人工处理' },
|
||
result: '{status}',
|
||
position: '{position}',
|
||
viewTask: '返回对话查看进度',
|
||
returnToChat: '返回对话查看进度',
|
||
retry: '重试自动推进',
|
||
retryObject: '重试',
|
||
retrySuccess: '已重新触发',
|
||
retryStp: '重试自动推进',
|
||
retryStpSuccess: '已重新入队自动建单',
|
||
},
|
||
conversationRetry: {
|
||
title: '对话重试结果',
|
||
retried: '已重试',
|
||
skipped: '已跳过',
|
||
failed: '失败',
|
||
closeAndRefresh: '关闭并刷新',
|
||
},
|
||
currentProcessing: {
|
||
title: '当前处理状态',
|
||
status: '状态',
|
||
formalOt: '正式 OT',
|
||
waitingStart: '等待系统启动',
|
||
taskMissing: '正式任务关联异常',
|
||
taskMissingHint: '正式任务关联异常,请联系管理员',
|
||
stateInconsistent: '状态同步中',
|
||
statusRunning: '系统处理中',
|
||
statusFailedRetryable: '失败可重试',
|
||
statusCompleted: '已完成',
|
||
statusIdle: '待机',
|
||
statusTaskMissing: '关联异常',
|
||
stageLoading: '正在获取最新状态…',
|
||
stages: {
|
||
waiting_system_start: '等待系统启动',
|
||
waiting_to_start: '等待系统启动',
|
||
order_creating: '等待系统启动',
|
||
inventory_matching: '库存匹配',
|
||
excel_generating: 'Excel 生成',
|
||
},
|
||
},
|
||
currentTask: {
|
||
title: '当前任务',
|
||
labelStage: '当前门禁',
|
||
labelFormalSn: '正式 OT',
|
||
statusRunning: '系统处理中',
|
||
statusWaitingHuman: '待人工处理',
|
||
statusRetryable: '可重试',
|
||
statusFailed: '自动处理失败',
|
||
statusCompleted: '已完成',
|
||
statusCancelled: '已取消',
|
||
nextStepTitle: '下一步',
|
||
nextStepUnknown: '状态待确认',
|
||
},
|
||
automation: {
|
||
waitingPreOt: '等待自动建单',
|
||
waitingPostOt: '等待系统启动自动推进',
|
||
},
|
||
buildEligibility: {
|
||
confirmBlocked: '不可建单',
|
||
autoGateWaitingHint: '资格已达标,等待系统自动建单',
|
||
autoGateRunningHint: '系统正在自动推进',
|
||
},
|
||
fulfillmentDecision: {
|
||
actions: '操作',
|
||
availableQty: '可用',
|
||
shortage: '缺口',
|
||
},
|
||
lineOps: {
|
||
retry: '重试',
|
||
moreActions: '更多操作',
|
||
inventorySource: '库存源',
|
||
},
|
||
lineActions: {
|
||
closeLine: '结案(不再发货)',
|
||
closeLineConfirm: '确认结案',
|
||
editLine: '编辑',
|
||
more: '更多操作',
|
||
},
|
||
inlineEdit: {
|
||
save: '保存',
|
||
cancel: '取消',
|
||
busy: '系统处理中,请稍后再修改',
|
||
},
|
||
releaseBar: {
|
||
label: '放行补录',
|
||
missingPrefix: '缺 ',
|
||
missingSuffix: ' 项放行信息',
|
||
},
|
||
workflowProgress: {
|
||
automatingFooterHint: '系统自动推进中',
|
||
},
|
||
confirmSuccess: '{taskNo}',
|
||
confirmAutoProgress: '{taskNo}',
|
||
confirmProgressFailed: '已创建任务 {taskNo},但自动推进失败,请重试推进',
|
||
jumpToCurrentVersion: '跳转',
|
||
currentVersionUnavailable: '不可用',
|
||
lifecycle: {
|
||
autoAdvanced: '已自动推进到{stage}',
|
||
navigation: '订单生命周期阶段',
|
||
current: '当前可处理',
|
||
processing: '处理中',
|
||
prerequisite: '请先完成当前阶段',
|
||
stages: {
|
||
intake_parse: '接收解析',
|
||
order_review: '订单复核',
|
||
fulfillment_prep: '通知准备',
|
||
freight_upload: '货代上传',
|
||
upload_complete: '通知完成',
|
||
},
|
||
prepare: {
|
||
title: '通知准备',
|
||
subtitle: '库存候选、匹配异常和通知文件生成均在此阶段处理。',
|
||
frozenOrder: '冻结订单',
|
||
inventorySource: '库存源',
|
||
downloadInventory: '下载库存文件',
|
||
retryInventory: '重新获取库存',
|
||
releaseShortage: '库存缺口放行',
|
||
releaseShortageHint: '放行后本次发货按缺口处理。',
|
||
releaseReasonPlaceholder: '可填写放行原因(选填)',
|
||
releaseConfirm: '确认放行',
|
||
shortage: '库存不足',
|
||
pending: '库存匹配或通知文件尚未生成。',
|
||
},
|
||
uploadComplete: {
|
||
title: '通知完成',
|
||
subtitle: '上传成功证据已核验。',
|
||
batchCount: '本批已上传 {count} 张发货通知',
|
||
uploadModeManual: '人工确认',
|
||
uploadModeRpa: 'RPA 上传',
|
||
empty: '本批暂无已上传的发货通知。',
|
||
},
|
||
freightUpload: {
|
||
loading: '正在加载发货通知…',
|
||
loadFailed: '发货通知加载失败,请刷新后重试。',
|
||
},
|
||
upload: {
|
||
receipt: '货代回执:{value}',
|
||
attempt: '最近上传尝试:{mode} · {status}',
|
||
},
|
||
completed: '已完成,可查看',
|
||
},
|
||
},
|
||
shippingProcessing: {
|
||
stage: {
|
||
order_creating: '创建正式订单',
|
||
inventory_matching: '库存匹配',
|
||
},
|
||
stageLabel: {
|
||
waiting_system_start: '等待系统启动',
|
||
},
|
||
progress: {
|
||
step: { profile_matching: '正在匹配订单模板', document_queued: '正在等待解析任务启动' },
|
||
lifecycleReason: {
|
||
processing_slow: '当前步骤耗时较长,系统仍在继续。',
|
||
review_required: '当前结果需要人工复核。',
|
||
failed: '当前步骤处理失败,请查看详情后重试。',
|
||
cancelled: '本次处理已取消。',
|
||
},
|
||
systemProcessingNeed: '系统正在自动处理,请稍候或刷新进度',
|
||
lifecycleWaitingNeed: '当前步骤需要人工处理',
|
||
},
|
||
},
|
||
shippingSessionWorkItem: {
|
||
versionLabel: 'V{version}',
|
||
},
|
||
},
|
||
workspace: {
|
||
shippingNotice: {
|
||
processGate: {
|
||
inventoryActions: {
|
||
retryInventoryPreparation: '重新获取库存(RPA)',
|
||
retryInventoryMatching: '重新匹配库存',
|
||
downloadInventoryFile: '下载库存文件',
|
||
releaseInventoryShortage: '库存缺口放行',
|
||
},
|
||
actionCodes: {
|
||
confirm_customer: '确认客户',
|
||
resolve_field_conflicts: '处理字段冲突',
|
||
},
|
||
},
|
||
},
|
||
},
|
||
errors: { generic: '错误' },
|
||
},
|
||
},
|
||
});
|
||
|
||
const router = createRouter({
|
||
history: createMemoryHistory(),
|
||
routes: [
|
||
{ path: '/chat/:agentId', name: 'Chat', component: { template: '<div />' } },
|
||
{
|
||
path: '/workspace/shipping-tasks/:taskNo',
|
||
name: 'workspace-shipping-tasks',
|
||
component: { template: '<div />' },
|
||
},
|
||
],
|
||
});
|
||
await router.push({
|
||
path: '/chat/agent-1',
|
||
query: { mode: 'order-review', run_no: 'RUN-1', ...query },
|
||
});
|
||
await router.isReady();
|
||
|
||
const wrapper = mount(ShippingOrderReviewView, {
|
||
global: {
|
||
plugins: [i18n, router],
|
||
provide: {
|
||
[CHAT_PAGE_KEY as symbol]: {
|
||
conversationId: 'conv-1',
|
||
messages: [],
|
||
bumpWorkflowRefresh: vi.fn(),
|
||
},
|
||
},
|
||
stubs: {
|
||
ReviewActionConfirmDialog: {
|
||
name: 'ReviewActionConfirmDialog',
|
||
props: ['action', 'modelValue', 'confirmLoading'],
|
||
emits: ['confirm', 'cancel', 'update:modelValue'],
|
||
template:
|
||
'<div data-testid="review-action-confirm-dialog">'
|
||
+ '<button data-testid="review-action-confirm-submit" @click="$emit(\'confirm\', { reasonCode: \'ok\' })">确认</button>'
|
||
+ '</div>',
|
||
},
|
||
ReviewDocumentEvidenceDrawer: evidenceDrawerStub,
|
||
},
|
||
},
|
||
});
|
||
mountedWrappers.push(wrapper);
|
||
await flushPromises();
|
||
return wrapper;
|
||
}
|
||
|
||
/**
|
||
* 打开通知准备行的更多操作菜单(⋯)。
|
||
* 核心逻辑:展示态行级动作(重试/放行/下载)已收纳进该菜单,入口按钮在表格行内。
|
||
*/
|
||
async function openLineOverflowMenu(wrapper: { get: (selector: string) => { trigger: (event: string) => Promise<void> } }, lineId: number | string) {
|
||
await wrapper.get(`[data-testid="review-fulfillment-line-more-${lineId}"]`).trigger('click');
|
||
await nextTick();
|
||
}
|
||
|
||
/**
|
||
* 断言行级菜单项已渲染并触发点击。
|
||
* 核心逻辑:菜单经 Teleport 渲染到 body,必须走 document.body 查询而不是 wrapper.find;
|
||
* 点击后 flushPromises 等待菜单收起与异步动作(下载/门禁提交)落位。
|
||
*/
|
||
async function clickLineMenuItem(lineId: number | string, action: string) {
|
||
const item = document.body.querySelector(`[data-testid="review-fulfillment-line-action-${action}-${lineId}"]`) as HTMLButtonElement | null;
|
||
expect(item, `行级菜单项 ${action}-${lineId} 应已渲染`).toBeTruthy();
|
||
item!.click();
|
||
await flushPromises();
|
||
}
|
||
|
||
/** 将共享 Case fixture 恢复为可编辑草稿,避免跨用例污染确认恢复态。 */
|
||
function resetActiveCaseFixture() {
|
||
activeCase.value = createActiveCaseFixture();
|
||
reviewQueue.value = {
|
||
conversation_id: 'conv-1',
|
||
summary: { total: 1, needs_action: 1, processing: 0, completed: 0 },
|
||
items: [{
|
||
case_no: 'CASE-1', source_run_no: 'RUN-1', document_id: 1, file_name: 'po.pdf', status: 'draft',
|
||
issue_count: 0, available_actions: ['validate', 'confirm'],
|
||
}],
|
||
};
|
||
reviewRun.value = {
|
||
run_no: 'RUN-1',
|
||
items: [{
|
||
case_no: 'CASE-1', document_id: 1, file_name: 'po.pdf', status: 'draft',
|
||
issue_count: 0, available_actions: ['validate', 'confirm'],
|
||
}],
|
||
};
|
||
requestedCaseNo.value = null;
|
||
shippingProcessingProjection.value = null;
|
||
shippingProcessingLoading.value = false;
|
||
intakeParseContext.value = null;
|
||
extractionLifecycleProgress.value = null;
|
||
statusMessage.value = null;
|
||
runLoading.value = false;
|
||
runSwitchFailed.value = false;
|
||
}
|
||
|
||
describe('ShippingOrderReviewView layout phase 1', () => {
|
||
beforeEach(() => {
|
||
vi.clearAllMocks();
|
||
reparseCaseReadyHandler = undefined;
|
||
reparseDocumentMock.mockResolvedValue({ run: { run_no: 'RUN-2' } });
|
||
stopReparseCaseRefreshPollingMock.mockReset();
|
||
vi.useRealTimers();
|
||
ensureIntakeParseContextLoaded.mockResolvedValue(true);
|
||
resetActiveCaseFixture();
|
||
reviewEditable.value = true;
|
||
reviewFormalEditable.value = false;
|
||
workItem.value = null;
|
||
reviewProgressContext.value = null;
|
||
});
|
||
|
||
afterEach(() => {
|
||
while (mountedWrappers.length) {
|
||
mountedWrappers.pop()?.unmount();
|
||
}
|
||
vi.useRealTimers();
|
||
});
|
||
|
||
it('puts customer PO line first, keeps the read-only internal line number, and keeps inventory source in the main table', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
schema: {
|
||
...activeCase.value.schema,
|
||
fields: [
|
||
...activeCase.value.schema.fields,
|
||
{ field_id: 'fld-line-no', field_code: 'line_no', display_name: '内部项次', scope: 'line', value_type: 'string', required: true, options: [] },
|
||
{ field_id: 'fld-customer-po-line', field_code: 'customer_po_line_no', display_name: '客户 PO 项次', scope: 'line', value_type: 'string', required: true, options: [] },
|
||
{ field_id: 'fld-part-number', field_code: 'part_number', display_name: '料号', scope: 'line', value_type: 'string', required: true, options: [] },
|
||
],
|
||
},
|
||
draft: {
|
||
...activeCase.value.draft,
|
||
lines: [{
|
||
draft_line_id: 'LINE-1',
|
||
values: {
|
||
'fld-line-no': { value: '10' },
|
||
'fld-customer-po-line': { value: '00010' },
|
||
'fld-part-number': { value: 'PN-ONE' },
|
||
'fld-inventory-source-hint': { value: 'DBS' },
|
||
},
|
||
machine_fields: [],
|
||
}],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
const headers = wrapper.find('[data-testid="review-lines-scroll"]').findAll('th').map((item) => item.text());
|
||
|
||
// 关键断言:业务核对项次优先,订单项次 line_no 固定只读展示;库存源线索作为路由核对列保留且值可见。
|
||
expect(headers.slice(0, 3)).toEqual(['#', '客户 PO 项次 *', '内部项次 *']);
|
||
expect(headers).toContain('料号 *');
|
||
expect(headers).toContain('库存源线索');
|
||
const inventorySourceCell = wrapper.find('[data-testid="review-line-inventory-source"]');
|
||
expect(inventorySourceCell.exists()).toBe(true);
|
||
expect(inventorySourceCell.find('input').element.value).toBe('DBS');
|
||
});
|
||
|
||
it('keeps the requested replacement Case when the loaded Run updates the URL', async () => {
|
||
// 关键断言:新版 Run 先到而旧 URL Case 仍在时,不能拼出 RUN-NEW + CASE-OLD。
|
||
const wrapper = await mountView({ case_no: 'CASE-OLD' });
|
||
requestedCaseNo.value = 'CASE-NEW';
|
||
reviewRun.value = {
|
||
...reviewRun.value,
|
||
run_no: 'RUN-NEW',
|
||
};
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as any).$route.query.run_no).toBe('RUN-NEW');
|
||
expect((wrapper.vm as any).$route.query.case_no).toBe('CASE-NEW');
|
||
});
|
||
|
||
it('opens the replacement Case at its backend current stage after reparse completes', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [{ code: 'intake_parse', state: 'current' }],
|
||
intake_parse_authorized: true,
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
|
||
(wrapper.vm as any).pendingAction = 'reparse';
|
||
await (wrapper.vm as any).submitPendingAction({ reasonCode: 'ok' });
|
||
expect(reparseCaseReadyHandler).toBeTypeOf('function');
|
||
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
case_no: 'CASE-2',
|
||
source_run_no: 'RUN-2',
|
||
document_id: 1,
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'current' },
|
||
],
|
||
}],
|
||
};
|
||
activeCase.value = {
|
||
...createActiveCaseFixture(),
|
||
case_no: 'CASE-2',
|
||
document: { id: 1, file_name: 'po.pdf' },
|
||
};
|
||
reviewRun.value = { run_no: 'RUN-2', items: [{ case_no: 'CASE-2', document_id: 1 }] };
|
||
await nextTick();
|
||
reparseCaseReadyHandler?.({ runNo: 'RUN-2', caseNo: 'CASE-2', documentId: 1 });
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('order_review');
|
||
expect(wrapper.find('[data-testid="review-editor-body"]').exists()).toBe(true);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('keeps the manually selected stage when reparse completes', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [{ code: 'intake_parse', state: 'current' }],
|
||
intake_parse_authorized: true,
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
|
||
(wrapper.vm as any).pendingAction = 'reparse';
|
||
await (wrapper.vm as any).submitPendingAction({ reasonCode: 'ok' });
|
||
await (wrapper.vm as any).selectLifecycleStage('intake_parse');
|
||
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
case_no: 'CASE-2',
|
||
source_run_no: 'RUN-2',
|
||
document_id: 1,
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'current' },
|
||
],
|
||
}],
|
||
};
|
||
activeCase.value = {
|
||
...createActiveCaseFixture(),
|
||
case_no: 'CASE-2',
|
||
document: { id: 1, file_name: 'po.pdf' },
|
||
};
|
||
reviewRun.value = { run_no: 'RUN-2', items: [{ case_no: 'CASE-2', document_id: 1 }] };
|
||
reparseCaseReadyHandler?.({ runNo: 'RUN-2', caseNo: 'CASE-2', documentId: 1 });
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('intake_parse');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('reloads the intake parse context by requested Case when activeCase is unloaded (formal downstream)', async () => {
|
||
// 用户场景:正式下游文件(货代上传 · 已创建任务)切进后 activeCase 为 null(选法 2),
|
||
// 此时回看「接收解析」已完成阶段,上下文必须按 requestedCaseNo 发起请求;
|
||
// 静默跳过会让 ReviewIntakeParsePanel 以空 context 渲染成整块空白。
|
||
const originalQueue = reviewQueue.value;
|
||
const originalActiveCase = activeCase.value;
|
||
const originalRequested = requestedCaseNo.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
has_formal_ot: true,
|
||
lifecycle_stage: 'freight_upload',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'available' },
|
||
{ code: 'fulfillment_prep', state: 'available' },
|
||
{ code: 'freight_upload', state: 'current' },
|
||
],
|
||
}],
|
||
};
|
||
activeCase.value = null;
|
||
requestedCaseNo.value = 'CASE-1';
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
|
||
ensureIntakeParseContextLoaded.mockClear();
|
||
await (wrapper.vm as any).selectLifecycleStage('intake_parse');
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('intake_parse');
|
||
// 关键断言:activeCase 为 null 时不得跳过上下文加载,且以目标 Case 请求。
|
||
expect(ensureIntakeParseContextLoaded).toHaveBeenCalledWith('CASE-1');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
activeCase.value = originalActiveCase;
|
||
requestedCaseNo.value = originalRequested;
|
||
}
|
||
});
|
||
|
||
it('stops the pending reparse navigation when the user selects another PDF', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [
|
||
...reviewQueue.value.items,
|
||
{
|
||
...reviewQueue.value.items[0],
|
||
case_no: 'CASE-OTHER',
|
||
document_id: 2,
|
||
source_run_no: 'RUN-1',
|
||
},
|
||
],
|
||
};
|
||
const wrapper = await mountView();
|
||
|
||
(wrapper.vm as any).pendingAction = 'reparse';
|
||
await (wrapper.vm as any).submitPendingAction({ reasonCode: 'ok' });
|
||
await (wrapper.vm as any).select('CASE-OTHER');
|
||
|
||
// 关键断言:用户主动切换文件后,旧 PDF 的自动恢复轮询必须停止,不能反向抢占工作台。
|
||
expect(stopReparseCaseRefreshPollingMock).toHaveBeenCalledTimes(1);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('shows the five-stage Run progress and current parsing step before a Case is available', async () => {
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-PARSING', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
|
||
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
|
||
completed_step_codes: ['layout_parsing_completed'], health_status: 'normal',
|
||
};
|
||
const wrapper = await mountView();
|
||
expect(wrapper.get('[data-testid="review-run-lifecycle-progress"]').exists()).toBe(true);
|
||
expect(wrapper.get('[data-testid="review-run-lifecycle-current-step"]').text()).toContain('正在匹配订单模板');
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-intake_parse"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-upload_complete"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('keeps the compact Run progress visible with a stable stalled reason', async () => {
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-STALLED', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
|
||
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
|
||
blocking_reason_i18n_key: 'chat.shippingProcessing.progress.lifecycleReason.processing_slow',
|
||
completed_step_codes: [], health_status: 'attention',
|
||
};
|
||
const wrapper = await mountView();
|
||
expect(wrapper.get('[data-testid="review-run-lifecycle-current-step"]').text()).toContain('当前步骤耗时较长');
|
||
});
|
||
|
||
it('uses the lifecycle progress below navigation instead of a legacy yellow reparse banner', async () => {
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
|
||
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
|
||
completed_step_codes: ['layout_parsing_completed'], health_status: 'normal',
|
||
};
|
||
statusMessage.value = 'reparse_in_progress';
|
||
|
||
const wrapper = await mountView();
|
||
|
||
// 关键断言:重解析不再拥有第二条黄色横幅;
|
||
// v2:有 Case 时横幅收窄为无 Case 轻提示——此处不得再出现 Run 级提示行。
|
||
expect(wrapper.find('[data-testid="review-status-banner"]').exists()).toBe(false);
|
||
expect(wrapper.findAll('[data-testid="review-run-lifecycle-progress"]')).toHaveLength(1);
|
||
expect(wrapper.find('[data-testid="review-run-lifecycle-current-step"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('hides the run progress hint for completed or unknown lifecycle statuses', async () => {
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-DONE', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'order_review', lifecycle_status: 'completed',
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
let wrapper = await mountView();
|
||
// 关键断言:completed 不渲染轻提示
|
||
expect(wrapper.find('[data-testid="review-run-lifecycle-current-step"]').exists()).toBe(false);
|
||
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'intake_parse', lifecycle_status: 'weird_state',
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
wrapper = await mountView();
|
||
// 关键断言:未知状态不渲染,更不得回退成“等待启动”
|
||
expect(wrapper.find('[data-testid="review-run-lifecycle-current-step"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('derives the card status from the run lifecycle and embeds its detail', async () => {
|
||
activeCase.value = createActiveCaseFixture();
|
||
activeCase.value.automation = undefined as any;
|
||
shippingProcessingProjection.value = null;
|
||
reviewRun.value = { run_no: 'RUN-REVIEW', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'order_review', lifecycle_status: 'waiting',
|
||
blocking_reason_i18n_key: 'chat.shippingProcessing.progress.lifecycleReason.review_required',
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
let wrapper = await mountView();
|
||
// 关键断言:review_required → 状态行“待人工处理”;纯重复说明被隐藏
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('待人工处理');
|
||
expect(wrapper.find('[data-testid="review-current-task-status-detail"]').exists()).toBe(false);
|
||
|
||
// 关键断言:running + document_queued → 状态“系统处理中” + 内嵌说明“正在等待解析任务启动”
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
|
||
current_step_i18n_key: 'chat.shippingProcessing.progress.step.document_queued',
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
wrapper = await mountView();
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('系统处理中');
|
||
expect(wrapper.get('[data-testid="review-current-task-status-detail"]').text()).toContain('正在等待解析任务启动');
|
||
});
|
||
|
||
it('does not claim automatic processing when the run is waiting at a human gate', async () => {
|
||
// 关键断言:门禁待机(waiting)时不得声称「系统正在自动处理」,也不得渲染呼吸点;
|
||
// 后端此时通常没有 current_step_i18n_key,旧逻辑会落入自动处理兜底文案。
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-WAITING-GATE', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'order_review', lifecycle_status: 'waiting',
|
||
current_step_i18n_key: null,
|
||
blocking_reason_i18n_key: 'chat.shippingProcessing.progress.lifecycleReason.review_required',
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
const wrapper = await mountView();
|
||
const banner = wrapper.get('[data-testid="review-run-lifecycle-current-step"]');
|
||
expect(banner.text()).not.toContain('系统正在自动处理');
|
||
expect(banner.text()).toContain('当前结果需要人工复核');
|
||
expect(banner.html()).not.toContain('animate-pulse');
|
||
});
|
||
|
||
it('shows a waiting fallback without the auto-processing claim when no reason is provided', async () => {
|
||
// 关键断言:waiting 且后端未给原因/步骤时,只展示「需要人工处理」,禁止回到自动处理文案。
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-WAITING-FALLBACK', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'order_review', lifecycle_status: 'waiting',
|
||
current_step_i18n_key: null,
|
||
blocking_reason_i18n_key: null,
|
||
completed_step_codes: [], health_status: 'normal',
|
||
};
|
||
const wrapper = await mountView();
|
||
const banner = wrapper.get('[data-testid="review-run-lifecycle-current-step"]');
|
||
expect(banner.text()).not.toContain('系统正在自动处理');
|
||
expect(banner.text()).toContain('当前步骤需要人工处理');
|
||
});
|
||
|
||
it('does not render the run progress banner for a completed run', async () => {
|
||
// 关键断言:Run 已完成时无待办,横幅直接隐藏,避免「已完成仍显示处理中」的矛盾。
|
||
activeCase.value = null as any;
|
||
reviewRun.value = { run_no: 'RUN-COMPLETED', items: [] };
|
||
extractionLifecycleProgress.value = {
|
||
lifecycle_stage: 'order_review', lifecycle_status: 'completed',
|
||
current_step_i18n_key: null,
|
||
blocking_reason_i18n_key: null,
|
||
completed_step_codes: ['review_ready'], health_status: 'normal',
|
||
};
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-run-lifecycle-current-step"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('loads a cross-Run file once through the route watcher', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
summary: { total: 2, needs_action: 2, processing: 0, completed: 0 },
|
||
items: [
|
||
...reviewQueue.value.items,
|
||
{
|
||
case_no: 'CASE-RUN-2', source_run_no: 'RUN-2', document_id: 2, file_name: 'po-2.pdf',
|
||
status: 'draft', issue_count: 0, available_actions: ['validate'],
|
||
},
|
||
],
|
||
};
|
||
const wrapper = await mountView();
|
||
load.mockClear();
|
||
beginCrossRunSwitch.mockClear();
|
||
|
||
await wrapper.get('[data-testid="review-doc-nav-CASE-RUN-2"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 跨 Run 先清旧 OT 投影权威,再只由路由 watcher 触发一次 load。
|
||
expect(beginCrossRunSwitch).toHaveBeenCalledWith('CASE-RUN-2');
|
||
expect(load).toHaveBeenCalledTimes(1);
|
||
expect(load).toHaveBeenCalledWith('RUN-2', 'CASE-RUN-2', {
|
||
conversationId: 'conv-1', itemNo: undefined,
|
||
});
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('keeps old workbench content in place and shows only a non-layout-shifting loading indicator while a cross-Run target is loading', async () => {
|
||
// 关键断言:跨 Run 不能插入大块 skeleton 把旧内容推离视口;仅允许无布局占位的轻提示。
|
||
runLoading.value = true;
|
||
const wrapper = await mountView();
|
||
|
||
const shell = wrapper.get('[data-testid="review-case-workbench-shell"]');
|
||
expect(wrapper.find('[data-testid="review-workbench-scroll"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-case-switch-loading"]').exists()).toBe(false);
|
||
expect(wrapper.get('[data-testid="review-case-switch-indicator"]').exists()).toBe(true);
|
||
expect(shell.attributes('aria-busy')).toBe('true');
|
||
expect(shell.classes()).toContain('pointer-events-none');
|
||
expect((wrapper.vm as any).workbenchActionsExecutable).toBe(false);
|
||
});
|
||
|
||
it('does not read freight Notice groups while the selected file is outside freight upload', async () => {
|
||
// 关键断言:货代 Notice 聚合只服务货代上传面,不能加入普通文件切换关键路径。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-NOTICE-PREP', confirmed_task_id: 91, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-NOTICE-PREP', status: 'processing', lines: [], events: [],
|
||
ui_state: { lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [], actions: { primary: null, secondary: [] } },
|
||
} as any);
|
||
|
||
await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
expect(taskApi.getWorkspaceShippingFreightNoticeGroups).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('keeps the workbench shell visible with a local retry state when cross-Run loading fails', async () => {
|
||
// 关键断言:跨 Run 失败不能进入页面级 unavailable 分支,旧文件仍可见且可重试。
|
||
runSwitchFailed.value = true;
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-workbench-scroll"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-order-review-load-failed"]').exists()).toBe(false);
|
||
expect(wrapper.get('[data-testid="review-run-switch-failed"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('uses the current-task card as the only Gate action entry for every formal-OT Gate', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 88,
|
||
confirmed_task_no: 'SN-GATE-1',
|
||
process_gate: {
|
||
execution_no: 'EXEC-GATE-1',
|
||
status: 'blocked',
|
||
owner_type: 'human',
|
||
technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'customer_confirmation', status: 'blocked' },
|
||
primary_action: {
|
||
code: 'confirm_customer',
|
||
label_key: 'chat.shippingNotice.processGate.actionCodes.confirm_customer',
|
||
kind: 'current_gate',
|
||
dispatch: 'mutation',
|
||
},
|
||
},
|
||
automation: { status: 'manual_fallback', can_auto_create: false, can_build: true },
|
||
};
|
||
// [§2.4 右卡单源] 主動作必须从 A(shippingProcessingProjection.ui_state.primary_action)读。
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-GATE-1', sourceType: 'direct_pdf',
|
||
rootOrderTaskNo: 'SN-GATE-1', shippingNoticeNo: 'SN-GATE-1', conversationId: 'conv-1',
|
||
submissionNo: 'SUB-GATE-1', intakeNo: 'SNI-GATE-1', status: 'blocked', stage: 'order_review',
|
||
progressVersion: 1, lastActivityAt: '2026-08-18T12:13:30Z',
|
||
currentGate: { gateCode: 'customer_confirmation', status: 'blocked', nextActionCode: 'confirm_customer' },
|
||
availableActions: ['confirm_customer'],
|
||
uiState: {
|
||
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
|
||
primary_action: { code: 'confirm_customer', i18nKey: 'chat.shippingProcessing.action.confirm_customer' },
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-GATE-1', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'confirm_customer', kind: 'current_gate', enabled: true,
|
||
dispatch: 'navigation', ui_handler: 'customer_resolution',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
process_gate: { execution_no: 'EXEC-GATE-1' }, summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 任意正式 OT Gate 的可执行入口只保留在“当前任务”;重复 Gate 卡不再挂载。
|
||
// [§2.4 右卡单源] 主動作从 A(shippingProcessingProjection.ui_state)读;此用例补 A 的 primary_action。
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="mock-process-gate"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('does not expose Excel regeneration from the current-task card', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', has_formal_ot: true, task_missing: false,
|
||
confirmed_task_id: 98, confirmed_task_no: 'SN-EXCEL-1',
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-EXCEL-1', sourceType: 'direct_pdf',
|
||
rootOrderTaskNo: 'SN-EXCEL-1', shippingNoticeNo: 'SN-EXCEL-1', conversationId: 'conv-1',
|
||
submissionNo: 'SUB-EXCEL-1', intakeNo: 'SNI-EXCEL-1', status: 'blocked', stage: 'excel_generating',
|
||
progressVersion: 1, lastActivityAt: '2026-08-18T12:13:30Z', currentGate: {
|
||
gateCode: 'artifact_generation', status: 'blocked_retryable', nextActionCode: 'regenerate_excel_artifact',
|
||
},
|
||
processGate: {
|
||
execution_no: 'EXEC-EXCEL-1', status: 'blocked_retryable', current_gate_code: 'artifact_generation',
|
||
next_action_code: 'regenerate_excel_artifact', allowed_actions: ['regenerate_excel_artifact'],
|
||
current_blocking_gate: { gate_code: 'artifact_generation', status: 'blocked_retryable', evaluation_version: 8 },
|
||
},
|
||
availableActions: ['regenerate_excel_artifact'],
|
||
sourceSummary: { emailSubject: null, filename: 'po.xlsx', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||
childOrderTasks: [],
|
||
uiState: {
|
||
status: 'retryable', stage: 'excel_generating', blocking_reason: null,
|
||
primary_action: { code: 'regenerate_excel_artifact', i18nKey: 'chat.shippingProcessing.action.regenerate_excel' },
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-EXCEL-1', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'regenerate_excel_artifact', kind: 'recovery', enabled: true,
|
||
dispatch: 'mutation',
|
||
target_surface: 'fulfillment_prep', target_anchor: 'excel_artifact',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
process_gate: {
|
||
execution_no: 'EXEC-EXCEL-1',
|
||
current_blocking_gate: {
|
||
gate_code: 'artifact_generation', evaluation_version: 8,
|
||
},
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
// 关键断言:Excel Artifact 属于发货通知单对象,右侧任务摘要不得提供写入口。
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
expect(postFormalGateActionMock).not.toHaveBeenCalled();
|
||
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('does not submit an action merely because its code has a Gate-like prefix', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', has_formal_ot: true, task_missing: false,
|
||
confirmed_task_id: 99, confirmed_task_no: 'SN-UNAUTHORIZED-1',
|
||
// 旧 Case 投影仍可能带上 Gate;不能让它以动作码前缀绕过实时 Projection。
|
||
process_gate: {
|
||
execution_no: 'EXEC-STALE-CASE-1', status: 'blocked_retryable', owner_type: 'human', technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'artifact_generation', status: 'blocked_retryable' },
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-UNAUTHORIZED-1', sourceType: 'direct_pdf',
|
||
rootOrderTaskNo: 'SN-UNAUTHORIZED-1', shippingNoticeNo: 'SN-UNAUTHORIZED-1', conversationId: 'conv-1',
|
||
submissionNo: 'SUB-UNAUTHORIZED-1', intakeNo: 'SNI-UNAUTHORIZED-1', status: 'blocked', stage: 'excel_generating',
|
||
progressVersion: 1, lastActivityAt: '2026-08-18T12:13:30Z', currentGate: {
|
||
gateCode: 'artifact_generation', status: 'blocked_retryable', nextActionCode: 'confirm_customer',
|
||
},
|
||
processGate: {
|
||
execution_no: 'EXEC-UNAUTHORIZED-1', status: 'blocked_retryable', current_gate_code: 'artifact_generation',
|
||
next_action_code: 'confirm_customer', allowed_actions: ['confirm_customer'],
|
||
current_blocking_gate: { gate_code: 'artifact_generation', status: 'blocked_retryable', evaluation_version: 9 },
|
||
},
|
||
availableActions: ['confirm_customer'],
|
||
sourceSummary: { emailSubject: null, filename: 'po.xlsx', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||
childOrderTasks: [],
|
||
uiState: {
|
||
status: 'retryable', stage: 'excel_generating', blocking_reason: null,
|
||
primary_action: { code: 'regenerate_excel_artifact', i18nKey: 'chat.shippingProcessing.action.regenerate_excel' },
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 旧 Projection 的 action 不可替代正式任务动作;详情无同码授权时右侧不展示写按钮。
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('routes the right-rail field-conflict action through the registered focus executor', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
process_gate: {
|
||
execution_no: 'EXEC-CONFLICT-1',
|
||
status: 'blocked',
|
||
owner_type: 'human',
|
||
technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'field_conflict_resolution', status: 'blocked' },
|
||
primary_action: {
|
||
code: 'resolve_field_conflicts',
|
||
label_key: 'workspace.shippingNotice.processGate.actionCodes.resolve_field_conflicts',
|
||
},
|
||
},
|
||
field_conflicts: [{
|
||
conflict_key: '0:part_number', field_code: 'part_number', line_index: 0,
|
||
reason: 'field_conflict', options: [],
|
||
}],
|
||
automation: { status: 'manual_fallback', can_auto_create: false, can_build: false },
|
||
};
|
||
const scrollIntoView = vi.fn();
|
||
Object.defineProperty(HTMLElement.prototype, 'scrollIntoView', {
|
||
configurable: true,
|
||
value: scrollIntoView,
|
||
});
|
||
|
||
const wrapper = await mountView();
|
||
await wrapper.get('[data-testid="review-current-task-primary-action"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 关键断言:右栏上下文入口必须复用字段冲突聚焦执行器,不能落入未知动作提示。
|
||
expect(messageMocks.info).not.toHaveBeenCalled();
|
||
expect(scrollIntoView).toHaveBeenCalled();
|
||
});
|
||
|
||
it('shows the existing running status while an accepted RPA recovery waits for fresh projection', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', has_formal_ot: true, task_missing: false,
|
||
confirmed_task_id: 904, confirmed_task_no: 'SN-RPA-RECOVERY-PENDING',
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-RPA-RECOVERY-PENDING',
|
||
status: 'failed', userStatus: 'failed', stage: 'inventory_fetching',
|
||
progressVersion: 7, currentGate: { status: 'blocked_retryable' },
|
||
uiState: {
|
||
status: 'failed', stage: 'inventory_fetching', lifecycleStage: 'fulfillment_prep',
|
||
primary_action: { code: 'retry_inventory_preparation', i18n_key: 'workspace.shippingNotice.processGate.inventoryActions.retryInventoryPreparation' },
|
||
secondary_actions: [],
|
||
},
|
||
} as any;
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-RPA-RECOVERY-PENDING', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'retry_inventory_preparation', kind: 'current_gate', enabled: true,
|
||
dispatch: 'mutation', requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
process_gate: { execution_no: 'EXEC-RPA-RECOVERY-PENDING' },
|
||
},
|
||
process_gate: { execution_no: 'EXEC-RPA-RECOVERY-PENDING' }, summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
await wrapper.get('[data-testid="review-current-processing-retry"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 复用既有 running/系统处理中文案;轮询新投影到达前不得继续显示旧失败态。
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('系统处理中');
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).not.toContain('自动处理失败');
|
||
});
|
||
|
||
it('submits retry_inventory_preparation from A even when B.actions lacks the code', async () => {
|
||
// 回归:右卡只读 A.primary_action 展示「重新获取库存(RPA)」;若仍按 B.actions
|
||
// 授权,会落到「未识别的动作」。A 展示即写路径授权;capabilities 可作 bypass。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', has_formal_ot: true, task_missing: false,
|
||
confirmed_task_id: 905, confirmed_task_no: 'SN-RPA-A-ONLY',
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-RPA-A-ONLY',
|
||
status: 'failed', userStatus: 'retryable', stage: 'inventory_fetching',
|
||
progressVersion: 3, currentGate: { status: 'blocked_retryable' },
|
||
uiState: {
|
||
status: 'retryable', stage: 'inventory_fetching', lifecycleStage: 'fulfillment_prep',
|
||
primary_action: { code: 'retry_inventory_preparation' },
|
||
secondary_actions: [],
|
||
},
|
||
} as any;
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-RPA-A-ONLY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
// B.actions 故意为空:模拟展示单源收敛后 B 滞后 / 无同码。
|
||
actions: { primary: null, secondary: [] },
|
||
process_gate: {
|
||
execution_no: 'EXEC-RPA-A-ONLY',
|
||
current_blocking_gate: {
|
||
gate_code: 'inventory_preparation', evaluation_version: 2, status: 'blocked_retryable',
|
||
},
|
||
allowed_actions: ['retry_inventory_preparation'],
|
||
recovery_targets: [{ action_code: 'retry_inventory_preparation' }],
|
||
},
|
||
stage_context: {
|
||
preparation: {
|
||
status: 'blocked', source_locked: false, source_options: [{ source_code: 'DSV' }],
|
||
capabilities: [{
|
||
code: 'retry_inventory_preparation', scope: 'task',
|
||
action_code: 'retry_inventory_preparation', enabled: true,
|
||
}],
|
||
frozen_order_lines: [], lines: [],
|
||
},
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
submitProcessGatePrimaryActionMock.mockClear();
|
||
messageMocks.info.mockClear();
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
await wrapper.get('[data-testid="review-current-processing-retry"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
expect(messageMocks.info).not.toHaveBeenCalledWith(
|
||
expect.stringMatching(/未识别的动作|Unrecognized action/),
|
||
);
|
||
expect(submitProcessGatePrimaryActionMock).toHaveBeenCalledWith(
|
||
expect.any(Object),
|
||
expect.objectContaining({
|
||
actionCode: 'retry_inventory_preparation',
|
||
stageCapabilityBypass: true,
|
||
}),
|
||
);
|
||
});
|
||
|
||
it('refreshes the processing projection after field-conflict adjudication refreshes the Case', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
field_conflicts: [{
|
||
conflict_key: '0:part_number', field_code: 'part_number', line_index: 0,
|
||
reason: 'field_conflict', options: [],
|
||
}],
|
||
process_gate: {
|
||
execution_no: 'EXEC-CONFLICT-REFRESH', status: 'blocked', owner_type: 'human', technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'field_conflict_resolution', status: 'blocked' },
|
||
primary_action: { code: 'resolve_field_conflicts', label_key: 'workspace.shippingNotice.processGate.actionCodes.resolve_field_conflicts' },
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
primary_action: { code: 'resolve_field_conflicts' },
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
reloadLatestDraftMock.mockClear();
|
||
refreshShippingProcessingMock.mockClear();
|
||
|
||
wrapper.findComponent(ReviewFieldConflictPanel).vm.$emit('refreshed');
|
||
await flushPromises();
|
||
|
||
// 字段裁决会同时改变 Case 与正式 Gate;两份读取模型必须一起刷新,避免右栏继续展示旧动作。
|
||
expect(reloadLatestDraftMock).toHaveBeenCalledTimes(1);
|
||
expect(refreshShippingProcessingMock).toHaveBeenCalledTimes(1);
|
||
});
|
||
|
||
it('does not revive a Case Gate action when the formal OT ui_state explicitly has no action', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', has_formal_ot: true, task_missing: false,
|
||
confirmed_task_id: 89, confirmed_task_no: 'SN-NO-ACTION-1',
|
||
process_gate: {
|
||
execution_no: 'EXEC-NO-ACTION-1', status: 'blocked', owner_type: 'human', technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'customer_confirmation', status: 'blocked' },
|
||
primary_action: { code: 'confirm_customer', label_key: 'chat.shippingNotice.processGate.actionCodes.confirm_customer' },
|
||
},
|
||
automation: { status: 'running', can_auto_create: false, can_build: true },
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-NO-ACTION-1', sourceType: 'direct_pdf',
|
||
rootOrderTaskNo: 'SN-NO-ACTION-1', shippingNoticeNo: 'SN-NO-ACTION-1', conversationId: 'conv-1',
|
||
submissionNo: 'SUB-NO-ACTION', intakeNo: 'SNI-NO-ACTION', status: 'processing', stage: 'order_creating',
|
||
progressVersion: 1, lastActivityAt: '2026-08-14T00:00:00Z', currentGate: null, availableActions: ['confirm_customer'],
|
||
sourceSummary: { emailSubject: null, filename: 'no-action.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||
childOrderTasks: [], uiState: { status: 'processing', stage: 'order_creating', blocking_reason: null, primary_action: null, secondary_actions: [] },
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 正式 OT 已有后端 ui_state,Case Gate 只是诊断/建单前兼容来源,不能复活按钮。
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('keeps a formal task action loading until its authoritative processing projection arrives', async () => {
|
||
// Case 快照先返回时可能携带历史/降级 Gate;正式 OT 的动作必须等待统一 Projection 裁决。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
confirmed_task_id: 90,
|
||
confirmed_task_no: 'SN-PROJECTION-PENDING',
|
||
process_gate: {
|
||
execution_no: 'EXEC-PROJECTION-PENDING', status: 'blocked_retryable', owner_type: 'human', technical_auto_only: false,
|
||
current_blocking_gate: { gate_code: 'inventory_preparation', status: 'blocked_retryable' },
|
||
primary_action: { code: 'retry', label_key: 'chat.shippingOrderReview.currentTask.actionRetry' },
|
||
},
|
||
automation: { status: 'failed', retryable: true, can_auto_create: false, can_build: true },
|
||
};
|
||
shippingProcessingProjection.value = null;
|
||
shippingProcessingLoading.value = true;
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 关键断言:不得先显示 Case 的通用“重试”,避免 Projection 到达后按钮语义跳变。
|
||
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('shows the stage loading placeholder instead of the Case stage while the authoritative projection is still loading', async () => {
|
||
// [Task3 单源] Case 先到、Projection 后到的过渡窗口:右卡阶段只由投影供给,
|
||
// Case.current_stage 只是降级快照,投影在途时不得先展示(旧「先 Case 后投影」
|
||
// 两跳正是闪烁根因);空阶段由 stageLoading 骨架占位承接。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 91,
|
||
confirmed_task_no: 'SN-STAGE-PENDING',
|
||
current_stage: { code: 'excel_generating', label_key: 'excel_generating', inconsistent: false },
|
||
automation: { status: 'running', retryable: false, can_auto_create: false, can_build: true },
|
||
};
|
||
shippingProcessingProjection.value = null;
|
||
shippingProcessingLoading.value = true;
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 关键断言:阶段行显示读取占位,而不是 Case 下发的「Excel 生成」。
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('正在获取最新状态');
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).not.toContain('Excel 生成');
|
||
// 状态列:loading 只抑制动作,不掩盖后端 automation 运行态真值(系统处理中)。
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('系统处理中');
|
||
});
|
||
|
||
it('shows the stage placeholder in the first frame before the formal task detail and projection arrive', async () => {
|
||
// [Task3 单源] formalTaskDetail 请求在途(formalTaskDetailLoading)且投影未启动的
|
||
// 首帧:右卡 loading=true,阶段行显示 stageLoading 占位,而不是空值「—」或误导文案。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 92,
|
||
confirmed_task_no: 'SN-FIRST-FRAME-1',
|
||
};
|
||
shippingProcessingProjection.value = null;
|
||
// 挂起任务详情请求,模拟「详情未到 + 投影未到」首帧;测试末尾手动放行并恢复默认 mock。
|
||
vi.mocked(getWorkspaceShippingTask).mockImplementation(
|
||
() => new Promise(() => {}) as any,
|
||
);
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
const card = wrapper.findComponent(ReviewCurrentProcessingCard);
|
||
expect(card.props('loading')).toBe(true);
|
||
expect(card.props('stageCode')).toBe('');
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('正在获取最新状态');
|
||
|
||
// 放行挂起请求并恢复 mock 工厂默认实现,避免跨用例泄漏挂起实现。
|
||
vi.mocked(getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-MOCK', status: 'created',
|
||
} as any);
|
||
});
|
||
|
||
it('sources the right-card stage only from the processing projection (single source)', async () => {
|
||
// [Task3 单源] 下游阶段不再读 activeCase.current_stage / formalTaskDetail.ui_state:
|
||
// 投影未就绪 → code='' + loading 占位;投影到达 → code=投影 stage(简报伪代码
|
||
// shippingProcessingProjection={stage:'fulfillment_prep'} 的组件级适配断言)。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 91,
|
||
confirmed_task_no: 'SN-SINGLE-SOURCE-1',
|
||
// 故意下发与投影分叉的 Case 阶段:单源后必须被无视。
|
||
current_stage: { code: 'inventory_matching', label_key: 'inventory_matching', inconsistent: false },
|
||
automation: { status: 'running', retryable: false, can_auto_create: false, can_build: true },
|
||
};
|
||
shippingProcessingProjection.value = null;
|
||
shippingProcessingLoading.value = true;
|
||
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 投影未就绪:空阶段 + loading 占位,而不是 Case 阶段或「步骤未指定」。
|
||
const card = wrapper.findComponent(ReviewCurrentProcessingCard);
|
||
expect(card.props('stageCode')).toBe('');
|
||
expect(card.props('loading')).toBe(true);
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('正在获取最新状态');
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).not.toContain('库存匹配');
|
||
|
||
// 投影到达:阶段只由投影提供,Case.current_stage 仍被无视。
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-SINGLE-SOURCE-1', sourceType: 'eml',
|
||
status: 'processing', stage: 'fulfillment_prep', stageLabelKey: 'fulfillment_prep',
|
||
progressVersion: 1, lastActivityAt: '2026-09-01T00:00:00Z',
|
||
currentGate: null, availableActions: [],
|
||
sourceSummary: { emailSubject: null, filename: 'po.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: 'PO-1' },
|
||
childOrderTasks: [],
|
||
};
|
||
await flushPromises();
|
||
expect(card.props('stageCode')).toBe('fulfillment_prep');
|
||
expect(card.props('stageLabelKey')).toBe('fulfillment_prep');
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).not.toContain('库存匹配');
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).not.toContain('正在获取最新状态');
|
||
|
||
// 投影 label_key 驱动渲染文案(复用现有 stages 词汇,验证投影→文案管线)。
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task', workItemNo: 'SN-SINGLE-SOURCE-1', sourceType: 'eml',
|
||
status: 'processing', stage: 'excel_generating', stageLabelKey: 'excel_generating',
|
||
progressVersion: 2, lastActivityAt: '2026-09-01T00:01:00Z',
|
||
currentGate: null, availableActions: [],
|
||
sourceSummary: { emailSubject: null, filename: 'po.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: 'PO-1' },
|
||
childOrderTasks: [],
|
||
};
|
||
await flushPromises();
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('Excel 生成');
|
||
});
|
||
|
||
it('does not render legacy reparse failure stage as a separate progress source', async () => {
|
||
reviewProgressContext.value = {
|
||
item_no: 'WFI-1',
|
||
current_version_no: 4,
|
||
lifecycle_status: 'reparse_failed',
|
||
displayed_version: { version_no: 3, run_no: 'RUN-3', case_no: 'CASE-1', status: 'restored' },
|
||
latest_attempt: {
|
||
version_no: 4,
|
||
run_no: 'RUN-4',
|
||
status: 'failed',
|
||
failure_stage: 'layout_parsing',
|
||
error_code: 'SHIPPING_NOTICE.ORDER_EXTRACTION_LAYOUT_FAILED',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
|
||
expect(wrapper.find('[data-testid="review-reparse-failed-version-notice"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-reparse-progress"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-reparse-progress-rail"]').exists()).toBe(false);
|
||
// 关键断言:页面只消费统一生命周期/处理投影,禁止用旧失败阶段重建另一条进度轨道。
|
||
expect(wrapper.find('[data-testid="review-workbench-execution-summary"]').exists()).toBe(false);
|
||
expect(wrapper.text()).toContain('V3');
|
||
});
|
||
|
||
it('does not render a legacy reparse progress rail for normal review', async () => {
|
||
reviewProgressContext.value = {
|
||
item_no: 'WFI-1', current_version_no: 3, lifecycle_status: 'pending_review',
|
||
};
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-reparse-progress"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('renders main editor + summary rail without chat context toggle', async () => {
|
||
const wrapper = await mountView({ case_no: 'CASE-1' });
|
||
const selectedOrder = wrapper.find('[data-testid="review-selected-order-summary"]');
|
||
expect(selectedOrder.exists()).toBe(true);
|
||
expect(selectedOrder.text()).toContain('po.pdf');
|
||
expect(selectedOrder.text()).toContain('CASE-1');
|
||
expect(wrapper.find('[data-testid="review-doc-nav-collapse"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode')).toBe('standard');
|
||
expect(wrapper.find('[data-testid="review-main-editor"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-build-gate-rail"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-document-navigation"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-workbench-ot-shell"]').classes()).toContain('contents');
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-context"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-lifecycle-workbench-identity"]').exists()).toBe(false);
|
||
expect(wrapper.text()).not.toContain('对话上下文');
|
||
expect(wrapper.html()).not.toContain('showContext');
|
||
expect(wrapper.html()).not.toContain('hideContext');
|
||
});
|
||
|
||
it('keeps the original adaptive navigation behavior when the run has one order candidate', async () => {
|
||
const wrapper = await mountView();
|
||
|
||
// 关键断言:工作台不得强制 sidebar;单项沿用导航组件原有 hidden 模式。
|
||
const queue = wrapper.find('[data-testid="review-document-navigation"]');
|
||
expect(queue.exists()).toBe(false);
|
||
});
|
||
|
||
it('renders compact file tabs before lifecycle stages for 2–4 files', async () => {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
summary: { total: 2, needs_action: 2, processing: 0, completed: 0 },
|
||
items: [
|
||
...reviewQueue.value.items,
|
||
{
|
||
case_no: 'CASE-2', source_run_no: 'RUN-1', document_id: 2, file_name: 'po-2.pdf',
|
||
status: 'draft', issue_count: 0, available_actions: ['validate', 'confirm'],
|
||
},
|
||
],
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
const shell = wrapper.get('[data-testid="review-workbench-ot-shell"]');
|
||
const navigation = wrapper.get('[data-testid="review-document-navigation"]');
|
||
|
||
// 2–4 文件不浪费一列宽度,但必须在五阶段前完成文件选择。
|
||
expect(navigation.attributes('data-nav-mode')).toBe('tabs');
|
||
expect(shell.classes()).toContain('contents');
|
||
expect(wrapper.html().indexOf('review-document-navigation'))
|
||
.toBeLessThan(wrapper.html().indexOf('review-workbench-status-region'));
|
||
});
|
||
|
||
it('uses a left file list before lifecycle stages for 5+ files', async () => {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
summary: { total: 5, needs_action: 5, processing: 0, completed: 0 },
|
||
items: Array.from({ length: 5 }, (_, index) => ({
|
||
...reviewQueue.value.items[0],
|
||
case_no: `CASE-${index + 1}`,
|
||
document_id: index + 1,
|
||
file_name: `po-${index + 1}.pdf`,
|
||
})),
|
||
};
|
||
|
||
const wrapper = await mountView();
|
||
const shell = wrapper.get('[data-testid="review-workbench-ot-shell"]');
|
||
const navigation = wrapper.get('[data-testid="review-document-navigation"]');
|
||
|
||
expect(navigation.attributes('data-nav-mode')).toBe('sidebar');
|
||
expect(shell.classes()).toContain('lg:grid-cols-[16rem_minmax(0,1fr)]');
|
||
expect(wrapper.html().indexOf('review-document-navigation'))
|
||
.toBeLessThan(wrapper.html().indexOf('review-workbench-status-region'));
|
||
});
|
||
|
||
it('replaces a stale lifecycle deep link with the selected file backend current stage', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
const originalSelectCase = selectCase.getMockImplementation();
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
summary: { total: 2, needs_action: 2, processing: 0, completed: 0 },
|
||
items: [
|
||
{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
{
|
||
case_no: 'CASE-2', source_run_no: 'RUN-1', document_id: 2, file_name: 'po-2.pdf',
|
||
status: 'draft', issue_count: 0, available_actions: ['validate', 'confirm'],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycleEntries: [
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
],
|
||
};
|
||
selectCase.mockImplementation(async (caseNo: string) => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
case_no: caseNo,
|
||
document_id: caseNo === 'CASE-2' ? 2 : 1,
|
||
};
|
||
});
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
await wrapper.get('[data-testid="review-doc-nav-CASE-2"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 深链属于当前文件展示位置;不能把 A 的订单复核参数带到 B 的通知准备。
|
||
expect((wrapper.vm as any).$router.currentRoute.value.query.lifecycle_stage).toBe('fulfillment_prep');
|
||
expect((wrapper.vm as any).$router.currentRoute.value.query.case_no).toBe('CASE-2');
|
||
expect((wrapper.vm as any).$router.currentRoute.value.query.case).toBeUndefined();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
selectCase.mockImplementation(originalSelectCase || (() => Promise.resolve(undefined)));
|
||
}
|
||
});
|
||
|
||
it('does not show auto-advance toast when switching to a file already in fulfillment prep', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
const originalSelectCase = selectCase.getMockImplementation();
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
summary: { total: 2, needs_action: 2, processing: 0, completed: 0 },
|
||
items: [
|
||
{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
{
|
||
case_no: 'CASE-2', source_run_no: 'RUN-1', document_id: 2, file_name: 'po-2.pdf',
|
||
status: 'draft', issue_count: 0, available_actions: ['validate', 'confirm'],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
],
|
||
};
|
||
selectCase.mockImplementation(async (caseNo: string) => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
case_no: caseNo,
|
||
document_id: caseNo === 'CASE-2' ? 2 : 1,
|
||
};
|
||
});
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
messageMocks.success.mockClear();
|
||
await wrapper.get('[data-testid="review-doc-nav-CASE-2"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as any).$route.query.lifecycle_stage).toBe('fulfillment_prep');
|
||
expect(messageMocks.success).not.toHaveBeenCalledWith('已自动推进到通知准备');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
selectCase.mockImplementation(originalSelectCase || (() => Promise.resolve(undefined)));
|
||
}
|
||
});
|
||
|
||
it('does not open a lifecycle stage before the backend authorizes lifecycle entries', async () => {
|
||
// 未收到正式 ui_state.lifecycle_entries 时,前端只能等待实时裁决,
|
||
// 不能因页面默认值自行开放订单复核或其他生命周期阶段。
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
await flushPromises();
|
||
|
||
for (const code of ['order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete']) {
|
||
const stage = wrapper.get(`[data-testid="review-lifecycle-stage-${code}"]`);
|
||
expect(stage.findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
}
|
||
// 无后端当前阶段时,任何卡片都不能被前端默认高亮为“当前订单复核”。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-order_review"]').classes())
|
||
.not.toContain('border-brand-500');
|
||
});
|
||
|
||
it('follows the backend to the next lifecycle stage when the user remains on the former current stage', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
await nextTick();
|
||
await flushPromises();
|
||
|
||
// 用户仍停在刚完成的订单复核时,后端推进后自动替换为通知准备。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('fulfillment_prep');
|
||
// 自动推进落点一次性提示(T7)。
|
||
expect(messageMocks.success).toHaveBeenCalledWith('已自动推进到通知准备');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('follows the backend stage advance when the route has no lifecycle_stage deep link', async () => {
|
||
// 无 lifecycle_stage = 尚未钉工作面,应跟随系统 current,不能因空深链永久停在订单复核。
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const wrapper = await mountView({});
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBeUndefined();
|
||
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
await nextTick();
|
||
await flushPromises();
|
||
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('fulfillment_prep');
|
||
expect(messageMocks.success).toHaveBeenCalledWith('已自动推进到通知准备');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('keeps a manually revisited earlier lifecycle stage when the backend advances', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
await nextTick();
|
||
await flushPromises();
|
||
|
||
// 接收解析是可回看的前序阶段;推进不能把用户强制带离当前查看面。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('intake_parse');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('does not honor a lifecycle deep link with an unknown backend entry state', async () => {
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'order_review',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'paused', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="review-lifecycle-fulfillment-prep"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('prefers the active Case lifecycle entries from the review queue', async () => {
|
||
// Run/Queue 已返回当前 Case 的授权入口时,工作台不得再从旧实时投影或路由默认值裁决阶段。
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
// 关键断言:当前 Case 的 Queue 是更贴近该文件的后端真相,库存准备必须保持禁用。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-fulfillment_prep"]').findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
expect(wrapper.find('[data-testid="review-editor-body"]').exists()).toBe(true);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('does not borrow another file lifecycle when the active Case has no candidate entries', async () => {
|
||
// 空 Candidate Case 的空 entries 是后端的 fail-closed 裁决,不能退回会话级其他 PDF。
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [],
|
||
}],
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
expect(wrapper.find('[data-testid="review-lifecycle-fulfillment-prep"]').exists()).toBe(false);
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('opens the separately authorized intake parse surface without restoring order lifecycle entries', async () => {
|
||
// 无 Candidate Case 可读取解析上下文,但该 capability 不能开放订单复核或后续阶段。
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [],
|
||
intake_parse_authorized: true,
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
await flushPromises();
|
||
|
||
expect(ensureIntakeParseContextLoaded).toHaveBeenCalledWith('CASE-1');
|
||
expect(wrapper.find('[data-testid="intake-parse-panel"]').exists()).toBe(true);
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-intake_parse"]').findAll('button')[1].attributes('disabled')).toBeUndefined();
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-order_review"]').findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('requests intake parse context only when the backend-authorized intake stage opens', async () => {
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [
|
||
{ code: 'intake_parse', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
};
|
||
|
||
await mountView({ lifecycle_stage: 'intake_parse' });
|
||
|
||
// 关键断言:接收解析工作面只以当前 Case 编号按需读取,不在普通复核首屏预取。
|
||
expect(ensureIntakeParseContextLoaded).toHaveBeenCalledWith('CASE-1');
|
||
});
|
||
|
||
it('renders the current Case intake context and keeps parse dispositions out of order review', async () => {
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [
|
||
{ code: 'intake_parse', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
};
|
||
intakeParseContext.value = {
|
||
case_no: 'CASE-1',
|
||
attachment: { document_id: 1, filename: 'current.pdf', mime_type: 'application/pdf', preview_kind: 'pdf' },
|
||
email: { document_id: 2, filename: 'source.eml', render_kind: 'text', text: 'current CASE-1 EML body' },
|
||
};
|
||
|
||
const intakeWrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
await flushPromises();
|
||
// 关键断言:接收解析面板只显示当前 Case context 的邮件正文和附件。
|
||
expect(intakeWrapper.get('[data-testid="intake-parse-email-body"]').text()).toContain('current CASE-1 EML body');
|
||
expect(intakeWrapper.get('[data-testid="intake-parse-attachment-preview"] iframe').attributes('src')).toBe('blob:mock-pdf');
|
||
const intakeFooter = intakeWrapper.get('[data-testid="review-footer-actions"]');
|
||
// 关键断言:接收解析处置复用订单复核的固定底栏,滚动邮件/附件时仍可操作。
|
||
expect(intakeFooter.classes()).toEqual(expect.arrayContaining(['sticky', 'bottom-0']));
|
||
expect(intakeFooter.text()).toContain('非订单');
|
||
expect(intakeWrapper.find('[data-testid="intake-parse-disposition-actions"]').exists()).toBe(false);
|
||
|
||
const orderWrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
// 关键断言:订单复核底栏保留 validate,但不再承载四个接收解析处置入口。
|
||
expect(orderWrapper.find('[data-testid="intake-parse-panel"]').exists()).toBe(false);
|
||
const orderFooter = orderWrapper.get('[data-testid="review-footer-actions"]');
|
||
// 客户确认说明可提及“重新识别 PDF”;这里只裁决底栏是否错误挂接了解析处置动作。
|
||
expect(orderFooter.text()).not.toContain('非订单');
|
||
expect(orderFooter.text()).not.toContain('质量异常');
|
||
expect(orderFooter.text()).not.toContain('重新识别');
|
||
expect(orderFooter.text()).not.toContain('替换 PDF');
|
||
expect(orderFooter.text()).toContain('提交订单');
|
||
});
|
||
|
||
it('switches the workbench to the backend current stage and marks it processing', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
shippingProcessingProjection.value = {
|
||
stage: 'inventory_preparation', status: 'processing',
|
||
uiState: {
|
||
status: 'running', lifecycleStage: 'fulfillment_prep', lifecycleEntries: [],
|
||
primary_action: null, secondary_actions: [],
|
||
},
|
||
};
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
await flushPromises();
|
||
|
||
// 关键断言:后端已推进时,仍停在旧当前阶段的页面必须自动进入新工作面并标注处理中。
|
||
expect((wrapper.vm as any).$router.currentRoute.value.query.lifecycle_stage).toBe('fulfillment_prep');
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').attributes('data-processing')).toBe('1');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
shippingProcessingProjection.value = null;
|
||
}
|
||
});
|
||
|
||
it('keeps a manually selected completed stage after the backend has already advanced', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
|
||
await wrapper.get('[data-testid="review-lifecycle-stage-order_review"]').findAll('button')[1].trigger('click');
|
||
await flushPromises();
|
||
|
||
// 后端并未再次推进时,主动回看订单复核必须保持该工作面,不能被 watcher 改回通知准备。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('order_review');
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('does not request intake context when its lifecycle entry is missing or unavailable', async () => {
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [
|
||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
};
|
||
|
||
await mountView({ lifecycle_stage: 'intake_parse' });
|
||
expect(ensureIntakeParseContextLoaded).not.toHaveBeenCalled();
|
||
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [
|
||
{ code: 'intake_parse', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
};
|
||
await flushPromises();
|
||
expect(ensureIntakeParseContextLoaded).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('mounts all order-review adjudication surfaces only in the order review workbench', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
customer_resolution: { resolved: false, status: 'ambiguous', candidates: [] },
|
||
field_conflicts: [{
|
||
conflict_key: 'conflict-1', field_code: 'customer_po_number', reason: 'ambiguous',
|
||
options: [{ value_key: 'PO-1', display_value: 'PO-1' }],
|
||
}],
|
||
duplicate: {
|
||
status: 'possible_duplicate', blocking: true, fingerprint_strength: 'strong',
|
||
matches: [{ task_no: 'SN-1', document_version: 1, match_type: 'same_active_task', matched_fields: ['po_number'] }],
|
||
allowed_actions: ['open_existing'], resolved: false, needs_adjudication: true,
|
||
},
|
||
reservation: {
|
||
needs_attention: true, status: 'needs_attention', lines: [],
|
||
issues: [{ code: 'reservation_missing', severity: 'blocking', line_index: 0 }],
|
||
},
|
||
};
|
||
|
||
const orderReview = await mountView();
|
||
expect(orderReview.find('[data-testid="review-customer-resolution-panel"]').exists()).toBe(true);
|
||
expect(orderReview.find('[data-testid="review-field-conflict-panel"]').exists()).toBe(true);
|
||
expect(orderReview.find('[data-testid="review-duplicate-panel"]').exists()).toBe(true);
|
||
expect(orderReview.find('[data-testid="review-reservation-panel"]').exists()).toBe(true);
|
||
expect(orderReview.get('[data-testid="review-build-gate-rail"]')
|
||
.find('[data-testid="review-reservation-panel"]').exists()).toBe(true);
|
||
expect(orderReview.get('[data-testid="review-build-gate-rail"]')
|
||
.find('[data-testid="review-customer-resolution-panel"]').exists()).toBe(true);
|
||
expect(orderReview.get('[data-testid="review-build-gate-rail"]')
|
||
.find('[data-testid="review-field-conflict-panel"]').exists()).toBe(true);
|
||
expect(orderReview.get('[data-testid="review-build-gate-rail"]')
|
||
.find('[data-testid="review-duplicate-panel"]').exists()).toBe(true);
|
||
// 关键断言:宽屏右栏的当前任务卡不能替代建单门禁摘要;用户必须能看到具体字段级原因。
|
||
expect(orderReview.get('[data-testid="review-build-gate-rail"]')
|
||
.find('[data-testid="mock-eligibility-summary"]').exists()).toBe(true);
|
||
expect(orderReview.get('[data-testid="review-main-editor"]')
|
||
.find('[data-testid="review-reservation-panel"]').exists()).toBe(false);
|
||
expect(orderReview.get('[data-testid="review-main-editor"]')
|
||
.find('[data-testid="review-customer-resolution-panel"]').exists()).toBe(false);
|
||
expect(orderReview.get('[data-testid="review-main-editor"]')
|
||
.find('[data-testid="review-field-conflict-panel"]').exists()).toBe(false);
|
||
expect(orderReview.get('[data-testid="review-main-editor"]')
|
||
.find('[data-testid="review-duplicate-panel"]').exists()).toBe(false);
|
||
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep', lifecycleEntries: [
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
], primary_action: null, secondary_actions: [],
|
||
},
|
||
};
|
||
const fulfillment = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
expect(fulfillment.find('[data-testid="review-field-conflict-panel"]').exists()).toBe(false);
|
||
expect(fulfillment.find('[data-testid="review-duplicate-panel"]').exists()).toBe(false);
|
||
expect(fulfillment.find('[data-testid="review-reservation-panel"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('stops requesting intake context when the backend revokes its lifecycle entry', async () => {
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [
|
||
{ code: 'intake_parse', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
};
|
||
await mountView({ lifecycle_stage: 'intake_parse' });
|
||
const callsBeforeRevocation = ensureIntakeParseContextLoaded.mock.calls.length;
|
||
expect(callsBeforeRevocation).toBeGreaterThan(0);
|
||
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'intake_parse',
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
lifecycleEntries: [],
|
||
},
|
||
};
|
||
await flushPromises();
|
||
// 关键断言:entry 被后端撤销后,watch 重跑也不能继续读取受控邮件上下文。
|
||
expect(ensureIntakeParseContextLoaded).toHaveBeenCalledTimes(callsBeforeRevocation);
|
||
});
|
||
|
||
it('keeps the fulfillment-prep deep link when only the realtime processing projection is available', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
confirmed_task_id: 901,
|
||
confirmed_task_no: 'SN-MOCK',
|
||
has_formal_ot: true,
|
||
};
|
||
// 正式任务详情尚未含 ui_state 时,工作台仍须使用批次中心同源实时投影,
|
||
// 而不是默认回退到订单复核。
|
||
shippingProcessingProjection.value = {
|
||
status: 'processing',
|
||
stage: 'inventory_matching',
|
||
uiState: {
|
||
status: 'processing',
|
||
stage: 'inventory_matching',
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
blocking_reason: null,
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:批次中心跳转到通知准备时,在正式详情延迟期间也停留在通知准备工作面。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-fulfillment-prep"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-fulfillment_prep"]').attributes('disabled')).toBeUndefined();
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-upload_complete"]').findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
});
|
||
|
||
it('shows an actionable diagnostic instead of a blank preparation page when task detail loading fails', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockRejectedValue(new Error('detail unavailable'));
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
confirmed_task_id: 901,
|
||
confirmed_task_no: 'SN-MOCK',
|
||
has_formal_ot: true,
|
||
current_stage: { code: 'completed', label_key: 'completed' },
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text())
|
||
.toContain('chat.shippingOrderReview.lifecycle.prepare.loadFailed');
|
||
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text())
|
||
.toContain('chat.shippingOrderReview.lifecycle.prepare.retry');
|
||
// 批次中心的阶段深链是纯导航;详情请求失败应留在工作面内诊断,不能误报结果未生成。
|
||
expect(messageMocks.warning).not.toHaveBeenCalledWith('处理结果尚未生成');
|
||
});
|
||
|
||
it('never falls back to case lines for the prep matrix while the task detail is unavailable', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
// Case 行回退兜底已删除:正式任务详情失败时不得用 Case line_fulfillment 伪造只读矩阵。
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockRejectedValue(new Error('detail unavailable'));
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
confirmed_task_id: 902,
|
||
confirmed_task_no: 'SN-MOCK',
|
||
has_formal_ot: true,
|
||
current_stage: { code: 'completed', label_key: 'completed' },
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-1', reservation_id: 'RSV-FALLBACK', part_number: 'PN-FALLBACK',
|
||
required_qty: '8.0', available_qty: '5.0', shortage_qty: '3.0', inventory_source_code: 'DBS_DUB',
|
||
}],
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:Case 行投影不再回填准备工作区,不出现误导性的只读矩阵与波次入口。
|
||
expect(wrapper.find('[data-testid="review-fulfillment-prep-workspace"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-fulfillment-prep-confirm-wave"]').exists()).toBe(false);
|
||
// 工作面停留在通知准备并给出可重试诊断,不能静默空白或误报结果未生成。
|
||
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text())
|
||
.toContain('chat.shippingOrderReview.lifecycle.prepare.loadFailed');
|
||
expect(messageMocks.warning).not.toHaveBeenCalledWith('处理结果尚未生成');
|
||
});
|
||
|
||
it('renders one row-level inventory workspace with each line source and authorized retry', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 903, confirmed_task_no: 'SN-FROZEN', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-frozen',
|
||
snapshot_line_id: 1001,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
inventory_allowed_actions: ['retry_inventory_preparation', 'retry_inventory_matching'],
|
||
line_allowed_actions: ['release_inventory_shortage'],
|
||
release_template_fields: [
|
||
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
|
||
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
|
||
],
|
||
release_required_fields: [{ field_id: '102', display_name: '库位' }],
|
||
}],
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-FROZEN', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
process_gate: {
|
||
execution_no: 'EXEC-FROZEN-LINE',
|
||
current_blocking_gate: { gate_code: 'inventory_preparation', status: 'blocked_retryable' },
|
||
},
|
||
actions: {
|
||
primary: { code: 'retry_inventory_preparation', enabled: true, dispatch: 'mutation' },
|
||
secondary: [],
|
||
},
|
||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: {
|
||
preparation: {
|
||
status: 'blocked', has_match_result: true,
|
||
frozen_order_lines: [{
|
||
snapshot_line_id: 1001, line_no: 1,
|
||
reservation_id: 'RSV-FROZEN', part_number: 'PN-FROZEN', required_qty: '6',
|
||
}],
|
||
lines: [{
|
||
snapshot_line_id: 1001, line_no: 1,
|
||
reservation_id: 'RSV-FROZEN', part_number: 'PN-FROZEN',
|
||
required_qty: '6', available_qty: null, shortage_qty: null, source_code: 'DBS',
|
||
inventory_file_no: 'SIF-LINE-DBS', status: 'shortage',
|
||
draft_line_id: 'line-frozen',
|
||
inventory_allowed_actions: ['retry_inventory_preparation', 'retry_inventory_matching'],
|
||
line_allowed_actions: ['release_inventory_shortage'],
|
||
release_template_fields: [
|
||
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
|
||
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
|
||
],
|
||
release_required_fields: [{ field_id: '102', display_name: '库位' }],
|
||
}],
|
||
artifact: { file_name: null, status: 'not_generated' },
|
||
},
|
||
},
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:订单基线列和库存事实合为唯一行级工作表,库存源不得退化为任务级 CRANE。
|
||
const workspace = wrapper.get('[data-testid="review-fulfillment-prep-workspace"]');
|
||
// 关键交互断言:标题/选行条不滚动;仅表体横向可读,行级操作列固定在右侧。
|
||
expect(workspace.classes()).toContain('review-fulfillment-prep-workspace');
|
||
expect(workspace.classes()).not.toContain('overflow-x-auto');
|
||
const tableScroll = workspace.get('[data-testid="review-fulfillment-prep-table-scroll"]');
|
||
expect(tableScroll.classes()).toContain('overflow-x-auto');
|
||
expect(tableScroll.get('table').classes()).toContain('review-fulfillment-prep-table');
|
||
expect(tableScroll.get('thead th:last-child').classes()).toContain('review-fulfillment-sticky-action-head');
|
||
expect(tableScroll.get('tbody tr:first-child td:last-child').classes()).toContain('review-fulfillment-sticky-action-cell');
|
||
expect(workspace.text()).toContain('RSV-FROZEN');
|
||
expect(workspace.text()).toContain('PN-FROZEN');
|
||
expect(workspace.text()).toContain('DBS');
|
||
expect(wrapper.find('[data-testid="review-fulfillment-frozen-order"]').exists()).toBe(false);
|
||
// 展示态行级动作收纳进更多菜单(⋯):逐项断言授权动作入口存在,不再有常显按钮。
|
||
await openLineOverflowMenu(wrapper, 1001);
|
||
expect(document.body.querySelector('[data-testid="review-fulfillment-line-action-download_inventory_file-1001"]')).toBeTruthy();
|
||
expect(document.body.querySelector('[data-testid="review-fulfillment-line-action-retry_inventory_preparation-1001"]')).toBeTruthy();
|
||
expect(document.body.querySelector('[data-testid="review-fulfillment-line-action-retry_inventory_matching-1001"]')).toBeTruthy();
|
||
expect(document.body.querySelector('[data-testid="review-fulfillment-line-action-release_inventory_shortage-1001"]')).toBeTruthy();
|
||
expect(workspace.text()).toContain('库存不足');
|
||
await clickLineMenuItem(1001, 'download_inventory_file');
|
||
expect(downloadWorkspaceShippingLineInventoryFileMock).toHaveBeenCalledWith('SN-FROZEN', 'SIF-LINE-DBS');
|
||
await openLineOverflowMenu(wrapper, 1001);
|
||
await clickLineMenuItem(1001, 'retry_inventory_preparation');
|
||
expect(submitProcessGatePrimaryActionMock).toHaveBeenCalledWith(
|
||
expect.any(Object),
|
||
expect.objectContaining({
|
||
actionCode: 'retry_inventory_preparation',
|
||
payload: { snapshot_line_id: 1001 },
|
||
}),
|
||
);
|
||
// Gate 恢复受理后立即启动五阶段轮询,不依赖浏览器手动刷新。
|
||
expect(startWorkflowProgressPollingMock).toHaveBeenCalledTimes(1);
|
||
await openLineOverflowMenu(wrapper, 1001);
|
||
await clickLineMenuItem(1001, 'release_inventory_shortage');
|
||
expect(wrapper.get('[data-testid="review-release-inventory-dialog"]').text()).toContain('ODM ID');
|
||
expect(wrapper.get('[data-testid="review-release-inventory-dialog"]').text()).toContain('ODM-001');
|
||
const dialog = wrapper.get('[data-testid="review-release-inventory-dialog"]');
|
||
await dialog.find('textarea').setValue('客户确认分批发货');
|
||
await dialog.find('input').setValue('A-01');
|
||
await dialog.get('button.bg-amber-600').trigger('click');
|
||
expect(vi.mocked(decideWorkspaceShippingOrderReviewLineFulfillment)).toHaveBeenCalledWith('CASE-1', expect.objectContaining({
|
||
draft_line_id: 'line-frozen',
|
||
reason: '客户确认分批发货',
|
||
release_field_values: { '102': 'A-01' },
|
||
}));
|
||
// 放行写成功后立即释放弹窗;后续读取不得阻塞用户确认按钮。
|
||
expect(wrapper.find('[data-testid="review-release-inventory-dialog"]').exists()).toBe(false);
|
||
expect(startWorkflowProgressPollingMock).toHaveBeenCalledTimes(2);
|
||
});
|
||
|
||
it('advances to freight upload after an accepted shortage release', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
let releaseAccepted = false;
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 903, confirmed_task_no: 'SN-FROZEN', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-frozen',
|
||
snapshot_line_id: 1001,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
line_allowed_actions: ['release_inventory_shortage'],
|
||
release_template_fields: [
|
||
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
|
||
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
|
||
],
|
||
release_required_fields: [{ field_id: '102', display_name: '库位' }],
|
||
}],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.decideWorkspaceShippingOrderReviewLineFulfillment).mockImplementation(async () => {
|
||
releaseAccepted = true;
|
||
return { status: 'ok' } as any;
|
||
});
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation(async () => ({
|
||
task_no: 'SN-FROZEN', status: 'waiting_human', lines: [], events: [],
|
||
ui_state: {
|
||
process_gate: {
|
||
execution_no: 'EXEC-FROZEN-LINE',
|
||
current_blocking_gate: { gate_code: 'manual_upload_handoff', status: 'blocked_manual' },
|
||
},
|
||
actions: { primary: null, secondary: [] },
|
||
lifecycle_stage: releaseAccepted ? 'freight_upload' : 'fulfillment_prep',
|
||
lifecycle_entries: releaseAccepted
|
||
? [
|
||
{ code: 'fulfillment_prep', state: 'available' },
|
||
{ code: 'freight_upload', state: 'current' },
|
||
]
|
||
: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: releaseAccepted ? { upload: {} } : {
|
||
preparation: {
|
||
frozen_order_lines: [{ snapshot_line_id: 1001, line_no: 1, reservation_id: 'RSV-FROZEN', part_number: 'PN-FROZEN', required_qty: '6' }],
|
||
lines: [{ snapshot_line_id: 1001, line_no: 1, reservation_id: 'RSV-FROZEN', part_number: 'PN-FROZEN', required_qty: '6', shortage_qty: '3', source_code: 'DBS', status: 'shortage', draft_line_id: 'line-frozen', line_allowed_actions: ['release_inventory_shortage'], release_required_fields: [{ field_id: '102', display_name: '库位' }] }],
|
||
},
|
||
},
|
||
},
|
||
} as any));
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
// 缺字段短缺行:放行入口在更多菜单,必填补录在行内补录条完成(原因不再强制)。
|
||
await openLineOverflowMenu(wrapper, 1001);
|
||
await clickLineMenuItem(1001, 'release_inventory_shortage');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-input-1001-102"]').setValue('A-01');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-confirm-1001"]').trigger('click');
|
||
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
||
await nextTick();
|
||
|
||
// 放行后的首个权威刷新抵达目标阶段时,页面必须同步深链。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('freight_upload');
|
||
});
|
||
|
||
it('advances to freight upload when the release job completes asynchronously after polling', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
let releaseAccepted = false;
|
||
let advanceDone = false;
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 905, confirmed_task_no: 'SN-ASYNC', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-async',
|
||
snapshot_line_id: 1002,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
line_allowed_actions: ['release_inventory_shortage'],
|
||
release_template_fields: [
|
||
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
|
||
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
|
||
],
|
||
release_required_fields: [{ field_id: '102', display_name: '库位' }],
|
||
}],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.decideWorkspaceShippingOrderReviewLineFulfillment).mockImplementation(async () => {
|
||
releaseAccepted = true;
|
||
return { status: 'ok' } as any;
|
||
});
|
||
// 异步推进:放行后首个刷新仍停在通知准备(Job 未完成),随后一次(投影 progressVersion 变化触发
|
||
// loadFormalTaskDetail)才抵达货代上传——这正是生产上与"同步放行即推进"用例的差异。
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation(async () => ({
|
||
task_no: 'SN-ASYNC', status: advanceDone ? 'waiting_human' : 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
process_gate: { execution_no: 'EXEC-ASYNC-LINE', current_blocking_gate: { gate_code: 'manual_upload_handoff', status: 'blocked_manual' } },
|
||
actions: { primary: null, secondary: [] },
|
||
lifecycle_stage: advanceDone ? 'freight_upload' : 'fulfillment_prep',
|
||
lifecycle_entries: advanceDone
|
||
? [{ code: 'fulfillment_prep', state: 'available' }, { code: 'freight_upload', state: 'current' }]
|
||
: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: advanceDone ? { upload: {} } : {
|
||
preparation: {
|
||
frozen_order_lines: [{ snapshot_line_id: 1002, line_no: 1, reservation_id: 'RSV-ASYNC', part_number: 'PN-ASYNC', required_qty: '6' }],
|
||
lines: [{ snapshot_line_id: 1002, line_no: 1, reservation_id: 'RSV-ASYNC', part_number: 'PN-ASYNC', required_qty: '6', shortage_qty: '3', source_code: 'DBS', status: 'shortage', draft_line_id: 'line-async', line_allowed_actions: ['release_inventory_shortage'], release_required_fields: [{ field_id: '102', display_name: '库位' }] }],
|
||
},
|
||
},
|
||
},
|
||
} as any));
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
await openLineOverflowMenu(wrapper, 1002);
|
||
await clickLineMenuItem(1002, 'release_inventory_shortage');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-input-1002-102"]').setValue('A-01');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-confirm-1002"]').trigger('click');
|
||
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
||
await nextTick();
|
||
|
||
// 异步 Job 尚未落地:仍停留在通知准备。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('fulfillment_prep');
|
||
|
||
// 模拟后端异步推进落地:处理投影 progressVersion 变化 → 触发 loadFormalTaskDetail → 抵达货代上传。
|
||
advanceDone = true;
|
||
shippingProcessingProjection.value = {
|
||
progressVersion: 42,
|
||
userStatus: 'waiting_human',
|
||
status: 'waiting_human',
|
||
uiState: { lifecycleStage: 'freight_upload', lifecycleEntries: [{ code: 'freight_upload', state: 'current' }] },
|
||
};
|
||
await flushPromises();
|
||
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
||
await nextTick();
|
||
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('freight_upload');
|
||
});
|
||
|
||
it('keeps notification preparation when the user navigates there while a shortage release is advancing', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
let releaseAccepted = false;
|
||
let resolvePostReleaseTask: ((detail: any) => void) | null = null;
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-MANUAL', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-manual',
|
||
snapshot_line_id: 1003,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
line_allowed_actions: ['release_inventory_shortage'],
|
||
release_template_fields: [
|
||
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
|
||
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
|
||
],
|
||
release_required_fields: [{ field_id: '102', display_name: '库位' }],
|
||
}],
|
||
},
|
||
};
|
||
const taskDetail = () => ({
|
||
task_no: 'SN-MANUAL', status: 'waiting_human', lines: [], events: [],
|
||
ui_state: {
|
||
process_gate: { execution_no: 'EXEC-MANUAL-LINE', current_blocking_gate: { gate_code: 'manual_upload_handoff', status: 'blocked_manual' } },
|
||
actions: { primary: null, secondary: [] },
|
||
lifecycle_stage: releaseAccepted ? 'freight_upload' : 'fulfillment_prep',
|
||
lifecycle_entries: releaseAccepted
|
||
? [{ code: 'fulfillment_prep', state: 'available' }, { code: 'freight_upload', state: 'current' }]
|
||
: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: releaseAccepted ? { upload: {} } : {
|
||
preparation: {
|
||
frozen_order_lines: [{ snapshot_line_id: 1003, line_no: 1, reservation_id: 'RSV-MANUAL', part_number: 'PN-MANUAL', required_qty: '6' }],
|
||
lines: [{ snapshot_line_id: 1003, line_no: 1, reservation_id: 'RSV-MANUAL', part_number: 'PN-MANUAL', required_qty: '6', shortage_qty: '3', source_code: 'DBS', status: 'shortage', draft_line_id: 'line-manual', line_allowed_actions: ['release_inventory_shortage'], release_required_fields: [{ field_id: '102', display_name: '库位' }] }],
|
||
},
|
||
},
|
||
},
|
||
});
|
||
vi.mocked(taskApi.decideWorkspaceShippingOrderReviewLineFulfillment).mockImplementation(async () => {
|
||
releaseAccepted = true;
|
||
return { status: 'ok' } as any;
|
||
});
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation(async () => {
|
||
if (!releaseAccepted) return taskDetail() as any;
|
||
return new Promise((resolve) => { resolvePostReleaseTask = resolve; });
|
||
});
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await openLineOverflowMenu(wrapper, 1003);
|
||
await clickLineMenuItem(1003, 'release_inventory_shortage');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-input-1003-102"]').setValue('A-01');
|
||
await wrapper.get('[data-testid="review-fulfillment-release-confirm-1003"]').trigger('click');
|
||
await wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').findAll('button')[1].trigger('click');
|
||
resolvePostReleaseTask?.(taskDetail());
|
||
await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
||
await nextTick();
|
||
|
||
// 用户显式回看通知准备会消费本次自动推进许可,后端异步投影不得抢回焦点。
|
||
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
|
||
.toBe('fulfillment_prep');
|
||
});
|
||
|
||
it('keeps the manual notice-generation entry in the main workspace for an editable formal task', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
reviewEditable.value = false;
|
||
reviewFormalEditable.value = true;
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-READY', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-ready', snapshot_line_id: 1004,
|
||
line_status: 'pending_decision', can_fulfill_complete_line: true,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
}],
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-READY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: {
|
||
preparation: {
|
||
status: 'ready', has_match_result: true, editable: true,
|
||
frozen_order_lines: [{ snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY', required_qty: '20' }],
|
||
lines: [{
|
||
snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY',
|
||
required_qty: '20', available_qty: '65', shortage_qty: '0', source_code: 'DBS', status: 'matched',
|
||
draft_line_id: 'line-ready', line_status: 'pending_decision', can_fulfill_complete_line: true,
|
||
}],
|
||
},
|
||
},
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
const workspace = wrapper.get('[data-testid="review-fulfillment-prep-workspace"]');
|
||
expect(workspace.get('[data-testid="review-fulfillment-prep-confirm-wave"]').exists()).toBe(true);
|
||
expect(wrapper.findComponent({ name: 'ReviewFulfillmentDecisionPanel' }).exists()).toBe(false);
|
||
|
||
await workspace.get('[data-testid="review-fulfillment-line-select-1004"]').setValue(true);
|
||
// [REGRESSION] wave 确认后后端入队异步推进(生成 Excel → OT 进入货代上传);
|
||
// 前端必须因此启动投影轮询,否则自动推进落地后五阶段导航/右栏不会自动刷新(反复出现的 bug)。
|
||
vi.mocked(waveWorkspaceShippingOrderReviewLineFulfillment).mockResolvedValue({
|
||
status: 'ok',
|
||
auto_progress_started: true,
|
||
wave_no: 1,
|
||
task_no: 'OT-WAVE-1',
|
||
} as any);
|
||
await workspace.get('[data-testid="review-fulfillment-prep-confirm-wave"]').trigger('click');
|
||
// 点击处理器是 async 且未被 trigger 等待;需 flush 微任务让 confirmPreparationWave 走到
|
||
// auto_progress_started 分支(backend 已入队异步推进 → 必须启动投影轮询)之后再断言。
|
||
await flushPromises();
|
||
expect(vi.mocked(waveWorkspaceShippingOrderReviewLineFulfillment)).toHaveBeenCalledWith('CASE-1', expect.objectContaining({
|
||
snapshot_line_ids: [1004],
|
||
expected_draft_version: 1,
|
||
}));
|
||
expect(startWorkflowProgressPollingMock).toHaveBeenCalled();
|
||
});
|
||
|
||
it('renders the editable prep matrix from ui_state alone while activeCase stays absent', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
// 关键前置:case 级 formalEditable 关闭,可编辑性只能来自 ui_state.preparation.editable。
|
||
reviewEditable.value = false;
|
||
reviewFormalEditable.value = false;
|
||
// activeCase 缺省(下游懒加载):复核 Case 不拉取,任务身份由 work-item 投影(导航项)提供。
|
||
activeCase.value = null as any;
|
||
requestedCaseNo.value = 'CASE-1';
|
||
reviewQueue.value = {
|
||
...originalQueue,
|
||
items: [{
|
||
...originalQueue.items[0],
|
||
confirmed_task_no: 'SN-READY',
|
||
has_formal_ot: true,
|
||
} as any],
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-READY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: {
|
||
preparation: {
|
||
status: 'ready', has_match_result: true, editable: true,
|
||
frozen_order_lines: [{ snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY', required_qty: '20' }],
|
||
lines: [{
|
||
snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY',
|
||
required_qty: '20', available_qty: '65', shortage_qty: '0', source_code: 'DBS', status: 'matched',
|
||
draft_line_id: 'line-ready', line_status: 'pending_decision', can_fulfill_complete_line: true,
|
||
}],
|
||
},
|
||
},
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 进入 Prep:ui_state 单源就绪即渲染完整可编辑矩阵;无需二次 activeCase。
|
||
expect(wrapper.find('[data-testid="review-fulfillment-prep-confirm-wave"]').exists()).toBe(true);
|
||
// activeCase 缺省(下游懒加载)不影响可编辑性与行矩阵。
|
||
expect(getWorkspaceShippingOrderReviewCase).not.toHaveBeenCalled();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
// 恢复任务详情 mock 默认值,避免 SN-READY 详情泄漏到后续用例。
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-MOCK',
|
||
status: 'created',
|
||
} as any);
|
||
}
|
||
});
|
||
|
||
it('does not start workflow polling when the wave schedules no async auto-progress', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
reviewEditable.value = false;
|
||
reviewFormalEditable.value = true;
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-READY', has_formal_ot: true,
|
||
line_fulfillment: {
|
||
lines: [{
|
||
draft_line_id: 'line-ready', snapshot_line_id: 1004,
|
||
line_status: 'pending_decision', can_fulfill_complete_line: true,
|
||
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
|
||
}],
|
||
},
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
uiState: {
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-READY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
stage_context: {
|
||
preparation: {
|
||
status: 'ready', has_match_result: true, editable: true,
|
||
frozen_order_lines: [{ snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY', required_qty: '20' }],
|
||
lines: [{
|
||
snapshot_line_id: 1004, line_no: 1, reservation_id: 'RSV-READY', part_number: 'PN-READY',
|
||
required_qty: '20', available_qty: '65', shortage_qty: '0', source_code: 'DBS', status: 'matched',
|
||
draft_line_id: 'line-ready', line_status: 'pending_decision', can_fulfill_complete_line: true,
|
||
}],
|
||
},
|
||
},
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
const workspace = wrapper.get('[data-testid="review-fulfillment-prep-workspace"]');
|
||
await workspace.get('[data-testid="review-fulfillment-line-select-1004"]').setValue(true);
|
||
startWorkflowProgressPollingMock.mockClear();
|
||
vi.mocked(waveWorkspaceShippingOrderReviewLineFulfillment).mockResolvedValue({
|
||
status: 'ok',
|
||
auto_progress_started: false,
|
||
wave_no: 1,
|
||
} as any);
|
||
await workspace.get('[data-testid="review-fulfillment-prep-confirm-wave"]').trigger('click');
|
||
await flushPromises();
|
||
expect(startWorkflowProgressPollingMock).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('keeps intake parse on the standard workbench and removes the inventory return row', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [],
|
||
intake_parse_authorized: true,
|
||
}],
|
||
};
|
||
const intakeWrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:接收解析不是库存工作面,避免用户看不到重解析入口。
|
||
expect(intakeWrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode'))
|
||
.toBe('standard');
|
||
expect(intakeWrapper.find('[data-testid="review-enter-inventory-mode"]').exists()).toBe(false);
|
||
expect(intakeWrapper.find('[data-testid="review-return-standard-mode"]').exists()).toBe(false);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('uses the current processing projection instead of a stale formal-task Gate in the current-task card', async () => {
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-GATE-TRUTH', has_formal_ot: true,
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
userStatus: 'running',
|
||
uiState: {
|
||
status: 'running', lifecycleStage: 'fulfillment_prep',
|
||
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
primary_action: null, secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-GATE-TRUTH', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
|
||
process_gate: {
|
||
gate_status: 'blocked_retryable', blocking_reason_code: 'inventory_file_missing',
|
||
primary_action: { code: 'retry_inventory_preparation', label_key: 'retry_inventory_preparation' },
|
||
},
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:正式任务详情是附件/明细快照;当前 Gate 必须由实时 Projection 裁决。
|
||
expect(wrapper.get('[data-testid="review-build-gate-rail"] [data-testid="review-current-processing-card"]')
|
||
.attributes('data-user-status')).toBe('running');
|
||
});
|
||
|
||
it('ignores a late formal-task response after switching to another PDF', async () => {
|
||
const resolvers = new Map<string, (value: any) => void>();
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation((taskNo) => (
|
||
new Promise((resolve) => { resolvers.set(String(taskNo), resolve); }) as any
|
||
));
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_id: 1, confirmed_task_no: 'SN-FIRST', has_formal_ot: true,
|
||
current_stage: { code: 'completed', label_key: 'completed' },
|
||
};
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
expect(resolvers.has('SN-FIRST')).toBe(true);
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
case_no: 'CASE-2', confirmed_task_id: 2, confirmed_task_no: 'SN-SECOND', has_formal_ot: true,
|
||
current_stage: { code: 'completed', label_key: 'completed' },
|
||
};
|
||
await nextTick();
|
||
expect(resolvers.has('SN-SECOND')).toBe(true);
|
||
resolvers.get('SN-SECOND')?.({
|
||
task_no: 'SN-SECOND', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'available', target_surface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', target_surface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', target_surface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', target_surface: 'order_lifecycle_workbench' },
|
||
],
|
||
},
|
||
});
|
||
await flushPromises();
|
||
resolvers.get('SN-FIRST')?.({
|
||
task_no: 'SN-FIRST', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'order_review',
|
||
lifecycle_entries: [{ code: 'order_review', state: 'current', target_surface: 'order_lifecycle_workbench' }],
|
||
},
|
||
});
|
||
await flushPromises();
|
||
|
||
// 关键断言:A 的迟到详情不能覆盖 B 的 lifecycle_entries。
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').findAll('button')[1].attributes('disabled')).toBeUndefined();
|
||
expect(wrapper.get('[data-testid="review-lifecycle-stage-upload_complete"]').findAll('button')[1].attributes('disabled')).toBeDefined();
|
||
});
|
||
|
||
it('hides PDF evidence drawer in standard mode by default', async () => {
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-document-evidence-drawer"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('keeps footer actions without confirm-create when draft exists', async () => {
|
||
const wrapper = await mountView();
|
||
// 关键断言:底栏仍在,但正常路径不再暴露「确认并创建任务」。
|
||
expect(wrapper.find('[data-testid="review-footer-actions"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-confirm-create"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('keeps legacy order review editing and validate when lifecycle entries are absent', async () => {
|
||
shippingProcessingProjection.value = null;
|
||
|
||
const wrapper = await mountView();
|
||
|
||
// 关键断言:接收解析才需新 entry 授权;旧投影不能因此丢失订单复核编辑和校验入口。
|
||
expect(wrapper.find('[data-testid="intake-parse-panel"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-editor-body"]').exists()).toBe(true);
|
||
expect(wrapper.get('[data-testid="review-footer-actions"]').text()).toContain('提交订单');
|
||
});
|
||
|
||
it('keeps notification completion read-only even when an obsolete manual-upload action arrives', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-UPLOAD-1', confirmed_task_id: 11, has_formal_ot: true,
|
||
};
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0], lifecycle_stage: 'upload_complete',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-UPLOAD-1', status: 'processing', lines: [], events: [],
|
||
ui_state: { actions: { primary: null, secondary: [] }, summary: {}, steps: [] },
|
||
} as any);
|
||
const withoutAuthorization = await mountView({ lifecycle_stage: 'upload_complete' });
|
||
await flushPromises();
|
||
expect(withoutAuthorization.find('[data-testid="review-lifecycle-upload-manual"]').exists()).toBe(false);
|
||
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-UPLOAD-1', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
|
||
target_surface: 'freight_upload',
|
||
target_anchor: 'manual_upload',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
const withAuthorization = await mountView({ lifecycle_stage: 'upload_complete' });
|
||
await flushPromises();
|
||
// 完成面必须屏蔽迟到的 Gate 写操作;主区只保留验证成功事实与审计摘要。
|
||
expect(withAuthorization.find('[data-testid="review-lifecycle-upload-manual"]').exists()).toBe(false);
|
||
expect(withAuthorization.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
// 正式动作直接提交当前 Gate,不允许无界面 TaskTodoPanel 作为隐藏执行器。
|
||
expect((withAuthorization.vm as { formalTodoPanelRef?: unknown }).formalTodoPanelRef).toBeUndefined();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
}, 15000);
|
||
|
||
it('keeps manual-upload confirmation out of the current-task card', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-UPLOAD-DIALOG', confirmed_task_id: 19, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-UPLOAD-DIALOG', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
|
||
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
|
||
target_surface: 'freight_upload', target_anchor: 'manual_upload',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-DOWNLOAD',
|
||
items: [{ business_no: 'WYC26082401', po_number: 'PO-DOWNLOAD', lines: [
|
||
{ line_no: '10', part_number: 'PN-ONE', reservation_id: 'RSV-1', shipment_qty: '4' },
|
||
{ line_no: '20', part_number: 'PN-TWO', reservation_id: 'RSV-2', shipment_qty: '7' },
|
||
] }],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
// 人工确认由主区选中发货通知单后的批量入口处理,右侧不再打开单任务弹窗。
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="manual-upload-evidence-dialog"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('refreshes left-nav queue after manual upload confirmation success', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-UPLOAD-QUEUE', confirmed_task_id: 21, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-UPLOAD-QUEUE', status: 'completed', business_no: 'WYC26082499',
|
||
lines: [], events: [], export_artifacts: [{ id: 1 }],
|
||
ui_state: { lifecycle_stage: 'upload_complete', actions: { primary: null, secondary: [] }, summary: {}, steps: [] },
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-QUEUE',
|
||
items: [{ business_no: 'WYC26082499', po_number: 'PO-QUEUE', lines: [] }],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
reloadLatestDraftMock.mockClear();
|
||
refreshReviewQueueMock.mockClear();
|
||
refreshShippingProcessingMock.mockClear();
|
||
|
||
wrapper.findComponent(ManualUploadEvidenceDialog).vm.$emit('success');
|
||
await flushPromises();
|
||
|
||
// 确认上传后五阶段会到「通知完成」;左侧本批队列必须同步重拉 lifecycle_stage。
|
||
expect(reloadLatestDraftMock).toHaveBeenCalled();
|
||
expect(refreshReviewQueueMock).toHaveBeenCalled();
|
||
expect(refreshShippingProcessingMock).toHaveBeenCalled();
|
||
});
|
||
|
||
it('renders one Notice card and one business_no Excel download for freight upload', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-DOWNLOAD-DISPATCH', confirmed_task_id: 20, has_formal_ot: true,
|
||
schema: {
|
||
...activeCase.value.schema,
|
||
fields: [
|
||
...activeCase.value.schema.fields,
|
||
{ field_id: 'fld-line-no', field_code: 'line_no', display_name: '项次', scope: 'line', value_type: 'string', required: true, options: [] },
|
||
{ field_id: 'fld-part-number', field_code: 'part_number', display_name: '料号', scope: 'line', value_type: 'string', required: true, options: [] },
|
||
{ field_id: 'fld-quantity', field_code: 'quantity', display_name: '数量', scope: 'line', value_type: 'number', required: true, options: [] },
|
||
],
|
||
},
|
||
draft: {
|
||
...activeCase.value.draft,
|
||
lines: [
|
||
{ draft_line_id: 'LINE-1', values: { 'fld-line-no': { value: '10' }, 'fld-part-number': { value: 'PN-ONE' }, 'fld-quantity': { value: '4' } }, machine_fields: [] },
|
||
{ draft_line_id: 'LINE-2', values: { 'fld-line-no': { value: '20' }, 'fld-part-number': { value: 'PN-TWO' }, 'fld-quantity': { value: '7' } }, machine_fields: [] },
|
||
],
|
||
},
|
||
line_fulfillment: {
|
||
lines: [
|
||
{ draft_line_id: 'LINE-1', reservation_id: 'RSV-1', line_status: 'fulfilled' },
|
||
{ draft_line_id: 'LINE-2', reservation_id: 'RSV-2', line_status: 'fulfilled' },
|
||
],
|
||
},
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-DOWNLOAD-DISPATCH', status: 'completed', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
|
||
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [{
|
||
code: 'download_excel', label: '下载 Excel', kind: 'view', enabled: true,
|
||
dispatch: 'view', ui_handler: 'excel_download',
|
||
target_surface: 'freight_upload', target_anchor: 'excel_artifact',
|
||
requires_confirmation: false,
|
||
}],
|
||
},
|
||
lifecycle_stage: 'freight_upload',
|
||
lifecycle_entries: [{ code: 'freight_upload', state: 'current' }],
|
||
process_gate: { execution_no: 'EXEC-DOWNLOAD-DISPATCH' }, summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-DOWNLOAD',
|
||
items: [{ business_no: 'WYC26082401', po_number: 'PO-DOWNLOAD', lines: [
|
||
{ line_no: '10', part_number: 'PN-ONE', reservation_id: 'RSV-1', shipment_qty: '4' },
|
||
{ line_no: '20', part_number: 'PN-TWO', reservation_id: 'RSV-2', shipment_qty: '7' },
|
||
] }],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
|
||
const rows = wrapper.findAll('[data-testid="review-freight-upload-line"]');
|
||
expect(rows).toHaveLength(2);
|
||
expect(rows[0].text()).toContain('PN-ONE');
|
||
expect(rows[1].text()).toContain('PN-TWO');
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-download"]').length).toBeGreaterThanOrEqual(1);
|
||
|
||
await wrapper.get('[data-testid="review-freight-upload-download"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 下载是 Artifact 只读操作;订单行不按 PO 聚合,且不得伪装成 Gate mutation。
|
||
expect(downloadWorkspaceShippingNoticeExcelFileMock).toHaveBeenCalledWith('WYC26082401');
|
||
expect(messageMocks.success).not.toHaveBeenCalled();
|
||
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
|
||
});
|
||
|
||
it('keeps backend-authorized Excel regeneration out of fulfillment preparation main area', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-EXCEL-RETRY', confirmed_task_id: 12, has_formal_ot: true,
|
||
};
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0], lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-EXCEL-RETRY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'regenerate_excel_artifact', kind: 'recovery', enabled: true,
|
||
dispatch: 'mutation',
|
||
target_surface: 'fulfillment_prep',
|
||
target_anchor: 'excel_artifact',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
stage_context: { preparation: { status: 'blocked', has_match_result: false, lines: [] } },
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// Gate 18 的写入口只属于右侧“当前任务”;准备区仅展示库存与产物事实。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-preparation-regenerate_excel_artifact"]').exists()).toBe(false);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('does not place a backend action in a lifecycle area when its anchor differs', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-ANCHOR-1', confirmed_task_id: 13, has_formal_ot: true,
|
||
};
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0], lifecycle_stage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||
],
|
||
}],
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-ANCHOR-1', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'regenerate_excel_artifact', kind: 'recovery', enabled: true,
|
||
dispatch: 'mutation',
|
||
target_surface: 'fulfillment_prep', target_anchor: 'inventory_matching',
|
||
requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
stage_context: { preparation: { status: 'blocked', has_match_result: false, lines: [] } },
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
// 位置必须同时由后端 surface 与 anchor 授权;前端不能仅凭动作码或阶段补放。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-preparation-regenerate_excel_artifact"]').exists()).toBe(false);
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
}, 15000);
|
||
|
||
it('renders a persistent result panel for a completed formal task', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
confirmed_task_no: 'SN-MOCK',
|
||
confirmed_task_id: 1,
|
||
has_formal_ot: true,
|
||
current_stage: { code: 'completed', label_key: 'completed' },
|
||
automation: { status: 'completed', can_auto_create: false, can_build: false },
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValueOnce({
|
||
task_no: 'SN-MOCK',
|
||
status: 'completed',
|
||
upload_status: 'uploaded',
|
||
upload_status: 'uploaded',
|
||
lines: [],
|
||
line_results: [{
|
||
part_number: 'PN-1', reservation_id: 'RES-1', required_qty: 2,
|
||
available_qty: 2, shortage_qty: 0, line_status: 'ok',
|
||
}],
|
||
export_artifacts: [{ id: 1, artifact_no: 'EXP-1', status: 'ready', file_name: 'result.xlsx' }],
|
||
events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: { code: 'download_excel', kind: 'view', enabled: true, requires_confirmation: false },
|
||
secondary: [],
|
||
},
|
||
summary: {}, process_gate: null,
|
||
},
|
||
} as any);
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-context"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('does not show Excel download merely because a historical artifact is present', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
confirmed_task_no: 'SN-MOCK',
|
||
confirmed_task_id: 1,
|
||
has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValueOnce({
|
||
task_no: 'SN-MOCK', status: 'processing', upload_status: 'pending', lines: [], events: [],
|
||
export_file_name: 'stale.xlsx',
|
||
export_artifacts: [{ id: 1, artifact_no: 'EXP-STALE', status: 'ready', file_name: 'stale.xlsx' }],
|
||
ui_state: { actions: { primary: null, secondary: [] }, summary: {}, process_gate: null },
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'upload_complete' });
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="review-lifecycle-upload-download"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('retries the server-authorized failed Intake from the current lifecycle card and refreshes projections', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
available_actions: ['retry_parse'],
|
||
intake_no: 'SNI-RETRY-1',
|
||
};
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0],
|
||
lifecycle_stage: 'intake_parse',
|
||
lifecycle_entries: [],
|
||
intake_parse_authorized: true,
|
||
available_actions: ['retry_parse'],
|
||
intake_no: 'SNI-RETRY-1',
|
||
}],
|
||
};
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
|
||
// 关键断言:已发送 EML 的恢复从当前阶段卡执行,并且使用服务端下发的原 SNI。
|
||
await wrapper.get('[data-testid="review-lifecycle-stage-retry-parse"]').trigger('click');
|
||
await flushPromises();
|
||
expect(retryShippingNoticeIntake).toHaveBeenCalledWith('SNI-RETRY-1');
|
||
expect(reloadLatestDraftMock).toHaveBeenCalled();
|
||
expect(refreshShippingProcessingMock).toHaveBeenCalled();
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('does not show intake retry while parsing or after cancellation', async () => {
|
||
const originalQueue = reviewQueue.value;
|
||
try {
|
||
reviewQueue.value = {
|
||
...reviewQueue.value,
|
||
items: [{
|
||
...reviewQueue.value.items[0], lifecycle_stage: 'intake_parse', lifecycle_entries: [], intake_parse_authorized: true,
|
||
}],
|
||
};
|
||
for (const status of ['parsing', 'cancelled']) {
|
||
activeCase.value = { ...activeCase.value, status, available_actions: [], intake_no: null };
|
||
const wrapper = await mountView({ lifecycle_stage: 'intake_parse' });
|
||
// 关键断言:运行中等待超时回收,取消态不可复活,均无 retry_parse 入口。
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-retry-parse"]').exists()).toBe(false);
|
||
}
|
||
} finally {
|
||
reviewQueue.value = originalQueue;
|
||
}
|
||
});
|
||
|
||
it('renders completion evidence only from the verified succeeded attempt', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-VERIFIED-EVIDENCE', confirmed_task_id: 22, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-VERIFIED-EVIDENCE', status: 'completed', upload_status: 'uploaded', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'upload_complete',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'available' },
|
||
{ code: 'fulfillment_prep', state: 'available' },
|
||
{ code: 'freight_upload', state: 'available' },
|
||
{ code: 'upload_complete', state: 'current' },
|
||
],
|
||
actions: {
|
||
primary: {
|
||
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
|
||
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
|
||
},
|
||
secondary: [],
|
||
},
|
||
stage_context: {
|
||
upload: {
|
||
latest_attempt: { status: 'failed', mode: 'rpa', freight_ref_no: 'LATEST-FAILED' },
|
||
succeeded_attempt: { status: 'succeeded', mode: 'manual', freight_ref_no: 'LEGACY-REF-MUST-NOT-BE-SHOWN' },
|
||
},
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
// 完成面按「已上传通知聚合」消费同一份 freight groups。
|
||
// 契约:聚合接口 upload_status 已经投影归一,成功终态为 uploaded。
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-100',
|
||
items: [
|
||
{ business_no: 'WYC26082401', po_number: 'PO-100', upload_status: 'uploaded', upload_mode: 'manual', export_file_name: 'WYC26082401.xlsx', lines: [
|
||
{ line_no: '00010', part_number: 'PART-A', reservation_id: 'RSV-A', qty: '2' },
|
||
] },
|
||
{ business_no: 'WYC26082402', po_number: 'PO-100', upload_status: 'pending', export_file_name: 'WYC26082402.xlsx', lines: [] },
|
||
],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'upload_complete' });
|
||
await flushPromises();
|
||
|
||
const evidence = wrapper.get('[data-testid="review-lifecycle-upload-complete"]');
|
||
// 只展示已成功上传通知(uploaded),未上传(pending)不进入完成面。
|
||
expect(wrapper.get('[data-testid="review-upload-complete-toolbar"]').text()).toContain('本批已上传 1 张发货通知');
|
||
expect(evidence.text()).toContain('WYC26082401');
|
||
expect(evidence.text()).not.toContain('WYC26082402');
|
||
// 人工确认不再展示或依赖货代回执号,即使历史投影仍带有 freight_ref_no。
|
||
expect(evidence.text()).not.toContain('LEGACY-REF-MUST-NOT-BE-SHOWN');
|
||
expect(evidence.text()).not.toContain('LATEST-FAILED');
|
||
// 上传来源徽标:成功事实取自 ShippingUploadAttempt 的 mode=manual。
|
||
expect(wrapper.find('[data-testid="review-upload-complete-mode"]').text()).toContain(
|
||
'人工确认',
|
||
);
|
||
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(false);
|
||
expect(wrapper.get('[data-testid="review-current-processing-card"]').text()).toContain('已完成');
|
||
expect(wrapper.get('[data-testid="review-current-processing-card"]').text()).not.toContain('状态待确认');
|
||
expect(wrapper.find('[data-testid="review-current-task-next-step-section"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('keeps upload-complete evidence on the loading placeholder until freight groups arrive', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-UPCOMPLETE-LOADING', confirmed_task_id: 25, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-UPCOMPLETE-LOADING', status: 'completed', upload_status: 'uploaded', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'upload_complete',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'available' },
|
||
{ code: 'fulfillment_prep', state: 'available' },
|
||
{ code: 'freight_upload', state: 'available' },
|
||
{ code: 'upload_complete', state: 'current' },
|
||
],
|
||
actions: { primary: null, secondary: [] }, summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
// 分组请求保持挂起:模拟直入通知完成时 freightNoticeGroups 尚未就绪的首屏窗口。
|
||
let resolveGroups: (value: unknown) => void = () => {};
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockImplementation(
|
||
() => new Promise((resolve) => { resolveGroups = resolve; }) as any,
|
||
);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'upload_complete' });
|
||
await flushPromises();
|
||
|
||
const evidence = wrapper.get('[data-testid="review-lifecycle-upload-complete"]');
|
||
// 直入上传完成(freightNoticeGroups 未就绪):段内显示 loading,不闪「0 已上传/空」。
|
||
expect(evidence.text()).toContain('正在加载发货通知…');
|
||
expect(evidence.text()).not.toContain('本批已上传');
|
||
expect(evidence.text()).not.toContain('本批暂无已上传的发货通知。');
|
||
expect(wrapper.find('[data-testid="review-upload-complete-groups"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-upload-complete-toolbar"]').exists()).toBe(false);
|
||
|
||
// 分组到达后:loading 让位,batchCount 工具栏与已上传列表恢复渲染。
|
||
// 契约:后端 Notice 面 upload_status 已投影为 uploaded。
|
||
resolveGroups({
|
||
po_number: 'PO-UPCOMPLETE',
|
||
items: [{
|
||
business_no: 'WYC-UPCOMPLETE-1', po_number: 'PO-UPCOMPLETE', upload_status: 'uploaded',
|
||
upload_mode: 'manual', export_file_name: 'WYC-UPCOMPLETE-1.xlsx', lines: [],
|
||
}],
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.get('[data-testid="review-upload-complete-toolbar"]').text()).toContain('本批已上传 1 张发货通知');
|
||
expect(wrapper.find('[data-testid="review-upload-complete-groups"]').exists()).toBe(true);
|
||
expect(wrapper.text()).toContain('WYC-UPCOMPLETE-1');
|
||
});
|
||
|
||
it('allows inspecting a completed order-review stage without allowing edits', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-COMPLETED-REVIEW', confirmed_task_id: 23, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-COMPLETED-REVIEW', status: 'completed', upload_status: 'uploaded', lines: [], events: [],
|
||
ui_state: {
|
||
lifecycle_stage: 'upload_complete',
|
||
lifecycle_entries: [
|
||
{ code: 'intake_parse', state: 'available' },
|
||
{ code: 'order_review', state: 'available' },
|
||
{ code: 'fulfillment_prep', state: 'available' },
|
||
{ code: 'freight_upload', state: 'available' },
|
||
{ code: 'upload_complete', state: 'current' },
|
||
],
|
||
actions: { primary: null, secondary: [] }, summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="review-editor-body"]').exists()).toBe(true);
|
||
expect(wrapper.get('[data-testid="shipping-order-review-view"]').attributes('data-readonly')).toBe('true');
|
||
expect(wrapper.find('[data-testid="review-header-field-input"]').attributes('disabled')).toBeDefined();
|
||
});
|
||
|
||
it('aggregates freight upload by business_no and keeps one Excel action per notice', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-PO-WAVE-1', confirmed_task_id: 22, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-PO-WAVE-1', business_no: 'WYC26082401', status: 'processing', upload_status: 'pending',
|
||
lines: [], events: [],
|
||
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-100',
|
||
items: [
|
||
{ business_no: 'WYC26082401', po_number: 'PO-100', upload_status: 'pending', export_file_name: 'WYC26082401.xlsx', lines: [
|
||
{ line_no: '00010', part_number: 'PART-A', reservation_id: 'RSV-A', qty: '2' },
|
||
{ line_no: '00020', part_number: 'PART-B', reservation_id: 'RSV-B', qty: '1' },
|
||
] },
|
||
{ business_no: 'WYC26082402', po_number: 'PO-100', upload_status: 'pending', export_file_name: 'WYC26082402.xlsx', lines: [
|
||
{ line_no: '00030', part_number: 'PART-C', reservation_id: 'RSV-C', qty: '4' },
|
||
] },
|
||
],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
|
||
const groups = wrapper.findAll('[data-testid="review-freight-upload-notice"]');
|
||
expect(groups).toHaveLength(2);
|
||
expect(wrapper.text()).toContain('WYC26082401');
|
||
expect(wrapper.text()).toContain('WYC26082402');
|
||
expect(wrapper.text()).toContain('PART-A');
|
||
expect(wrapper.text()).toContain('PART-C');
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-download"]')).toHaveLength(2);
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-line"]')).toHaveLength(3);
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-download-SN-PO-WAVE-1"]')).toHaveLength(0);
|
||
});
|
||
|
||
it('shows inline RPA and confirm actions when freight notice groups authorize them', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed', confirmed_task_no: 'SN-PO-ACTIONS', confirmed_task_id: 25, has_formal_ot: true,
|
||
};
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-PO-ACTIONS', business_no: 'WYC-ACTIONS', status: 'processing', lines: [], events: [],
|
||
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-ACTIONS',
|
||
items: [{
|
||
business_no: 'WYC-ACTIONS',
|
||
po_number: 'PO-ACTIONS',
|
||
upload_status: 'pending',
|
||
export_file_name: 'WYC-ACTIONS.xlsx',
|
||
available_actions: ['download_excel', 'retry_freight_upload_rpa', 'mark_manual_uploaded'],
|
||
lines: [],
|
||
}],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
|
||
// 关键断言:后端授权后的 RPA/确认必须作为行内主按钮出现,不能再藏进空白「更多」菜单。
|
||
expect(wrapper.find('[data-testid="review-freight-upload-download"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-freight-upload-rpa"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-freight-upload-confirm"]').exists()).toBe(true);
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-more"]')).toHaveLength(0);
|
||
});
|
||
|
||
it('sends selected business_nos for freight batch actions', async () => {
|
||
activeCase.value = { ...activeCase.value, status: 'confirmed', confirmed_task_no: 'SN-PO-BATCH', confirmed_task_id: 23, has_formal_ot: true };
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-PO-BATCH', status: 'processing', lines: [], events: [],
|
||
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-BATCH', items: [
|
||
{ business_no: 'WYC26082411', po_number: 'PO-BATCH', lines: [] },
|
||
{ business_no: 'WYC26082412', po_number: 'PO-BATCH', lines: [] },
|
||
],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
|
||
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
|
||
await wrapper.get('[data-testid="review-freight-upload-batch-toolbar"]').find('button').trigger('click');
|
||
await flushPromises();
|
||
expect(downloadFreightArchiveMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
|
||
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
|
||
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
|
||
await wrapper.get('[data-testid="review-freight-upload-batch-rpa"]').trigger('click');
|
||
await flushPromises();
|
||
expect(batchRpaFreightMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
|
||
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
|
||
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
|
||
await wrapper.get('[data-testid="review-freight-upload-batch-confirm"]').trigger('click');
|
||
await flushPromises();
|
||
expect(batchConfirmFreightMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
|
||
});
|
||
|
||
it('disables upload batch actions and hides more actions when an uploaded notice is selected', async () => {
|
||
activeCase.value = { ...activeCase.value, status: 'confirmed', confirmed_task_no: 'SN-PO-UPLOADED', confirmed_task_id: 24, has_formal_ot: true };
|
||
const taskApi = await import('@/features/chat/api/shipping.api');
|
||
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-PO-UPLOADED', status: 'processing', lines: [], events: [],
|
||
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
|
||
} as any);
|
||
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
|
||
po_number: 'PO-UPLOADED', items: [
|
||
{ business_no: 'WYC-UPLOADED', po_number: 'PO-UPLOADED', upload_status: 'uploaded', lines: [] },
|
||
{ business_no: 'WYC-PENDING', po_number: 'PO-UPLOADED', upload_status: 'pending', lines: [] },
|
||
],
|
||
} as any);
|
||
|
||
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
|
||
await flushPromises();
|
||
await wrapper.get('[aria-label="WYC-UPLOADED"]').setValue(true);
|
||
await wrapper.get('[aria-label="WYC-PENDING"]').setValue(true);
|
||
|
||
// 已上传项混入选择集时,批量写入不允许部分静默提交,必须让用户显式取消选择。
|
||
expect(wrapper.get('[data-testid="review-freight-upload-batch-rpa"]').attributes('disabled')).toBeDefined();
|
||
expect(wrapper.get('[data-testid="review-freight-upload-batch-confirm"]').attributes('disabled')).toBeDefined();
|
||
expect(wrapper.findAll('[data-testid="review-freight-upload-more"]')).toHaveLength(0);
|
||
});
|
||
|
||
it('keeps the inventory source hint as a routing check column in the primary line table', async () => {
|
||
const wrapper = await mountView();
|
||
const headers = wrapper.find('[data-testid="review-lines-scroll"]').findAll('th').map((item) => item.text());
|
||
// 关键断言:库存源线索作为路由核对列始终保留在主表,便于用户核对各库存源;无值时仍保留列头。
|
||
expect(headers).toContain('库存源线索');
|
||
expect(wrapper.find('[data-testid="review-line-inventory-source"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('ignores a stale line change after the current draft has accepted the value', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
schema: {
|
||
...activeCase.value.schema,
|
||
fields: [{
|
||
field_id: 'fld-part', field_code: 'part_number', display_name: '内部料号', scope: 'line',
|
||
value_type: 'string', required: true, options: [],
|
||
}],
|
||
},
|
||
draft: {
|
||
...activeCase.value.draft,
|
||
lines: [{
|
||
draft_line_id: 'LINE-1',
|
||
values: { 'fld-part': { value: 'D4-AR1200072A1', source: 'manual' } },
|
||
machine_fields: [],
|
||
}],
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
const input = wrapper.find('[data-testid="review-line-field-input"]');
|
||
|
||
(input.element as HTMLInputElement).value = '';
|
||
await input.trigger('change');
|
||
await flushPromises();
|
||
|
||
// 关键断言:旧节点的空 change 不能覆盖当前草稿中已确认的人工内部料号。
|
||
expect(patchLineMock).not.toHaveBeenCalled();
|
||
// 此 describe 共享响应式 fixture;恢复默认值,避免影响后续证据交互回归。
|
||
resetActiveCaseFixture();
|
||
});
|
||
|
||
it('does not render resident AI card without focused field', async () => {
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-llm-field-entry"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="mock-llm-drawer"]').exists()).toBe(true);
|
||
expect(wrapper.html()).not.toContain('panelTitle');
|
||
});
|
||
|
||
it('opens evidence PDF drawer only via locate action, not via input focus', async () => {
|
||
const wrapper = await mountView();
|
||
const input = wrapper.find('[data-testid="review-header-field-input"]');
|
||
expect(input.exists()).toBe(true);
|
||
await input.trigger('focus');
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode')).toBe('standard');
|
||
expect(wrapper.find('[data-testid="review-document-evidence-drawer"]').exists()).toBe(false);
|
||
|
||
const locate = wrapper.find('[data-testid="review-field-locate"]');
|
||
expect(locate.exists()).toBe(true);
|
||
await locate.trigger('click');
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode')).toBe('evidence');
|
||
expect(wrapper.find('[data-testid="review-document-evidence-drawer"]').exists()).toBe(true);
|
||
// 关键断言:定位后字段与 PDF 证据联动高亮。
|
||
expect(wrapper.find('[data-testid="review-header-field-input"]').attributes('data-evidence-active')).toBe('true');
|
||
});
|
||
|
||
it('opens evidence PDF drawer via field double-click', async () => {
|
||
const wrapper = await mountView();
|
||
const input = wrapper.find('[data-testid="review-header-field-input"]');
|
||
await input.trigger('dblclick');
|
||
await flushPromises();
|
||
// 关键断言:双击字段等价于定位原文,进入证据模式。
|
||
expect(wrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode')).toBe('evidence');
|
||
expect(wrapper.find('[data-testid="review-document-evidence-drawer"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('navigates exception fields from the summary rail', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
draft: {
|
||
...activeCase.value.draft,
|
||
issues: [
|
||
{
|
||
code: 'required_field_missing',
|
||
severity: 'blocking',
|
||
field_id: 'fld-po',
|
||
message: '缺少 PO',
|
||
},
|
||
],
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
expect(wrapper.find('[data-testid="review-exception-nav"]').exists()).toBe(true);
|
||
await wrapper.find('[data-testid="review-exception-next"]').trigger('click');
|
||
await flushPromises();
|
||
// 关键断言:异常导航会打开证据并定位到问题字段。
|
||
expect(wrapper.find('[data-testid="shipping-order-review-view"]').attributes('data-workbench-mode')).toBe('evidence');
|
||
expect(wrapper.find('[data-testid="review-header-field-input"]').attributes('data-evidence-active')).toBe('true');
|
||
});
|
||
|
||
it('opens evidence as floating panel without docking editor body layout', async () => {
|
||
const wrapper = await mountView();
|
||
await wrapper.find('[data-testid="review-field-locate"]').trigger('click');
|
||
await flushPromises();
|
||
const body = wrapper.find('[data-testid="review-editor-body"]');
|
||
const drawer = wrapper.find('[data-testid="review-document-evidence-drawer"]');
|
||
// 关键断言:定位证据默认浮窗;主编辑区不切换为 PDF 网格列。
|
||
expect(drawer.attributes('data-presentation')).toBe('floating');
|
||
expect(body.attributes('data-evidence-docked')).toBe('false');
|
||
expect(body.classes()).toContain('space-y-4');
|
||
expect(body.classes().some((cls) => cls.includes('minmax(280px'))).toBe(false);
|
||
});
|
||
});
|
||
|
||
describe('ShippingOrderReviewView audit and progress recovery', () => {
|
||
beforeEach(async () => {
|
||
vi.clearAllMocks();
|
||
resetActiveCaseFixture();
|
||
reviewProgressContext.value = null;
|
||
vi.mocked(auditWorkspaceShippingOrderReviewVersionHistory).mockResolvedValue({
|
||
audited: true,
|
||
case_no: 'CASE-1',
|
||
});
|
||
vi.mocked(auditWorkspaceShippingOrderReviewEligibilityDetails).mockResolvedValue({
|
||
audited: true,
|
||
case_no: 'CASE-1',
|
||
});
|
||
}, 20000);
|
||
|
||
it('refuses to open version history when access audit fails', async () => {
|
||
vi.mocked(auditWorkspaceShippingOrderReviewVersionHistory).mockRejectedValueOnce(new Error('audit down'));
|
||
const wrapper = await mountView();
|
||
await wrapper.find('[data-testid="review-open-version-history"]').trigger('click');
|
||
await flushPromises();
|
||
// 关键断言:审计失败有告警且不打开版本历史面板。
|
||
expect(wrapper.find('[data-testid="mock-versions-drawer"]').exists()).toBe(false);
|
||
expect(messageMocks.warning).toHaveBeenCalledWith('审计记录失败,敏感面板未打开,请重试');
|
||
});
|
||
|
||
it('refuses to open eligibility details when access audit fails', async () => {
|
||
vi.mocked(auditWorkspaceShippingOrderReviewEligibilityDetails).mockRejectedValueOnce(new Error('audit down'));
|
||
const wrapper = await mountView();
|
||
await wrapper.find('[data-testid="review-open-eligibility-details"]').trigger('click');
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="mock-eligibility-details"]').exists()).toBe(false);
|
||
expect(messageMocks.warning).toHaveBeenCalledWith('审计记录失败,敏感面板未打开,请重试');
|
||
});
|
||
|
||
it('waits for the authoritative Gate projection instead of restoring Case retry after reload', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 7,
|
||
confirmed_task_no: 'SN-RECOVER-1',
|
||
automation: {
|
||
status: 'failed',
|
||
retryable: true,
|
||
phase: 'post_ot_progress',
|
||
can_auto_create: false,
|
||
can_build: true,
|
||
},
|
||
post_confirm_auto_progress: {
|
||
task_no: 'SN-RECOVER-1',
|
||
needs_retry: true,
|
||
status: 'needs_retry',
|
||
message: '已建单但任务仍停在待推进,可重试自动推进',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
// 关键断言:正式 OT 的旧 Case 快照不是写授权;实时 Gate 未返回时只能等待。
|
||
expect(wrapper.find('[data-testid="review-confirm-outcome"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="retry-auto-progress-after-confirm"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(false);
|
||
// 发货通知单号与订单明细行绑定,不在任务级整单显示;当前任务卡不展示单条通知单号。
|
||
expect(wrapper.find('[data-testid="review-current-processing-ot"]').exists()).toBe(false);
|
||
}, 15000);
|
||
|
||
it('does not submit an action before the formal OT Gate projection arrives (UI-01)', async () => {
|
||
// 关键断言:刷新后无实时 Gate 时,不得用任务号推断或提交重试。
|
||
submitProcessGatePrimaryActionMock.mockClear();
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 42,
|
||
confirmed_task_no: 'SN-OT-FAIL-1',
|
||
current_stage: { code: 'order_creating', inconsistent: false },
|
||
automation: {
|
||
status: 'failed',
|
||
retryable: true,
|
||
phase: 'post_ot_progress',
|
||
can_auto_create: false,
|
||
can_build: true,
|
||
},
|
||
post_confirm_auto_progress: {
|
||
task_no: 'SN-OT-FAIL-1',
|
||
needs_retry: true,
|
||
status: 'needs_retry',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
const retryBtn = wrapper.find('[data-testid="review-current-processing-retry"]');
|
||
expect(retryBtn.exists()).toBe(false);
|
||
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
|
||
}, 15000);
|
||
|
||
it('disables the formal Gate retry while inventory preparation is waiting for RPA callback', async () => {
|
||
// 关键断言:Gate 仍为 blocked_retryable 时,PreparationAttempt 的等待事实优先禁用重试。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
confirmed_task_id: 43,
|
||
confirmed_task_no: 'SN-OT-WAITING-INVENTORY',
|
||
automation: { status: 'failed', retryable: true, can_auto_create: false, can_build: true },
|
||
};
|
||
shippingProcessingProjection.value = {
|
||
shippingNoticeNo: 'SN-OT-WAITING-INVENTORY',
|
||
retryable: true,
|
||
userStatus: 'retryable',
|
||
primaryAction: { code: 'retry_inventory_preparation' },
|
||
currentGate: { status: 'blocked_retryable' },
|
||
inventoryPreparation: {
|
||
activeAttemptCount: 1,
|
||
gateAttemptActive: true,
|
||
pendingSources: ['CRANE'],
|
||
},
|
||
uiState: {
|
||
status: 'retryable',
|
||
primary_action: { code: 'retry_inventory_preparation' },
|
||
secondary_actions: [],
|
||
},
|
||
};
|
||
vi.mocked(getWorkspaceShippingTask).mockResolvedValue({
|
||
task_no: 'SN-OT-WAITING-INVENTORY', status: 'processing', lines: [], events: [],
|
||
ui_state: {
|
||
actions: {
|
||
primary: {
|
||
code: 'retry_inventory_preparation', kind: 'recovery', enabled: true,
|
||
dispatch: 'mutation', requires_confirmation: false,
|
||
},
|
||
secondary: [],
|
||
},
|
||
process_gate: {
|
||
execution_no: 'EXEC-INVENTORY-WAITING',
|
||
current_blocking_gate: {
|
||
gate_code: 'inventory_preparation', evaluation_version: 1,
|
||
},
|
||
},
|
||
summary: {}, steps: [],
|
||
},
|
||
} as any);
|
||
|
||
// 正式 OT 动作只有进入履约工作面后才读取 ShippingTask.ui_state;测试必须提供真实阶段上下文。
|
||
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
|
||
await flushPromises();
|
||
|
||
expect(wrapper.get('[data-testid="review-current-processing-retry"]').attributes('disabled')).toBeDefined();
|
||
}, 15000);
|
||
|
||
it('keeps top / wide / narrow stage labels identical via Progress projection (waiting_system_start)', async () => {
|
||
// 关键断言:Case.current_stage 故意降级为误导码;三处必须消费 Progress label_key 文案。
|
||
shippingProcessingProjection.value = {
|
||
workItemType: 'order_task',
|
||
workItemNo: 'OT-WAIT-1',
|
||
sourceType: 'eml',
|
||
rootOrderTaskNo: 'OT-WAIT-1',
|
||
shippingNoticeNo: 'SN-WAIT-1',
|
||
conversationId: 'conv-1',
|
||
submissionNo: 'SUB-1',
|
||
intakeNo: 'INT-1',
|
||
status: 'automating',
|
||
stage: 'order_creating',
|
||
stageLabelKey: 'waiting_system_start',
|
||
progressVersion: 1,
|
||
lastActivityAt: '2026-08-07T00:00:00Z',
|
||
currentGate: null,
|
||
availableActions: [],
|
||
sourceSummary: {
|
||
emailSubject: null,
|
||
filename: 'po.pdf',
|
||
documentCount: 1,
|
||
parsedDocumentCount: 1,
|
||
candidateCount: 1,
|
||
customerName: null,
|
||
poNumber: 'PO-1',
|
||
},
|
||
childOrderTasks: [],
|
||
};
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 88,
|
||
confirmed_task_no: 'SN-WAIT-1',
|
||
// 故意与 Progress 文案分叉:若宽屏仍直读 Case code,会显示「库存匹配」。
|
||
current_stage: {
|
||
code: 'inventory_matching',
|
||
label_key: 'inventory_matching',
|
||
inconsistent: false,
|
||
},
|
||
automation: {
|
||
status: 'waiting_to_start',
|
||
retryable: false,
|
||
phase: 'post_ot_progress',
|
||
can_auto_create: false,
|
||
can_build: true,
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
const expected = '等待系统启动';
|
||
const cards = wrapper.findAll('[data-testid="review-current-processing-card"]');
|
||
expect(cards.length).toBeGreaterThan(0);
|
||
expect(wrapper.find('[data-testid="review-lifecycle-stage-detail-order_review"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('shows STP retry button for failed automation and calls retry API (UI-02)', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'ready',
|
||
confirmed_task_no: null,
|
||
available_actions: ['validate', 'retry_stp_auto_create'],
|
||
automation: {
|
||
status: 'failed',
|
||
retryable: true,
|
||
can_auto_create: true,
|
||
can_build: true,
|
||
reason_code: 'stp_job_failed',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
// 关键断言:failed 态主卡/底栏露出 STP 重试(非确认后 auto_progress)。
|
||
// [契约 §1.1「当前门禁 —」] 建单前无 processing projection:阶段为空渲染中性
|
||
// 占位文案(stageLoading),不再由 Case automation 兜底推导「创建正式订单」阶段,也禁止落「—」。
|
||
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('正在获取最新状态');
|
||
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('自动处理失败');
|
||
const railBtn = wrapper.find('[data-testid="review-current-processing-retry"]');
|
||
const footerBtn = wrapper.find('[data-testid="review-retry-stp-auto-create"]');
|
||
expect(railBtn.exists() || footerBtn.exists()).toBe(true);
|
||
await (railBtn.exists() ? railBtn : footerBtn).trigger('click');
|
||
await flushPromises();
|
||
expect(retryWorkspaceShippingOrderStpAutoCreate).toHaveBeenCalledWith('CASE-1');
|
||
}, 15000);
|
||
|
||
it('hides the duplicate submit-order guidance while STP auto-create is running', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'ready',
|
||
available_actions: ['validate'],
|
||
automation: {
|
||
status: 'running',
|
||
retryable: false,
|
||
can_auto_create: true,
|
||
can_build: true,
|
||
phase: 'pre_ot_stp',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
|
||
// 关键断言:系统接管建单后,底栏只能保留运行态,不得同时出现提交按钮及其旧说明。
|
||
expect(wrapper.find('[data-testid="review-footer-automating-hint"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="review-submit-order-hint"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-footer-actions"]').text()).not.toContain('提交订单');
|
||
}, 15000);
|
||
|
||
it('shows STP retry for manual_fallback without confirm-create (UI-02)', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'ready',
|
||
confirmed_task_no: null,
|
||
available_actions: ['validate', 'retry_stp_auto_create'],
|
||
automation: {
|
||
status: 'manual_fallback',
|
||
retryable: true,
|
||
can_auto_create: true,
|
||
can_build: true,
|
||
reason_code: 'stp_waiting_timeout',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
expect(
|
||
wrapper.find('[data-testid="review-current-processing-retry"]').exists()
|
||
|| wrapper.find('[data-testid="review-retry-stp-auto-create"]').exists(),
|
||
).toBe(true);
|
||
// 关键断言:正常路径不再保留「确认并创建任务」兜底。
|
||
expect(wrapper.find('[data-testid="review-confirm-create"]').exists()).toBe(false);
|
||
}, 15000);
|
||
|
||
it('hides profile match panel when profile_match.available is false', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
profile_match: { available: false, visibility: 'admin_only', candidates: [] },
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
// 关键断言:普通用户裁剪后 DOM 不得出现模板匹配面板。
|
||
expect(wrapper.find('[data-testid="review-profile-match-panel"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('shows profile match panel for admin when profile_match.available is true', async () => {
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
profile_match: {
|
||
available: true,
|
||
visibility: 'admin',
|
||
status: 'matched',
|
||
candidates: [{ profile_id: 1, score: 0.9 }],
|
||
selected_profile: { profile_id: 1, profile_code: 'P1' },
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="review-profile-match-panel"]').exists()).toBe(true);
|
||
}, 15000);
|
||
|
||
it('does not hydrate a write retry from Case projection without formal Gate data', async () => {
|
||
// 关键断言:无确认建单按钮时,Case 的失败状态只能作为历史摘要,不能恢复写入口。
|
||
activeCase.value = {
|
||
...activeCase.value,
|
||
status: 'confirmed',
|
||
has_formal_ot: true,
|
||
task_missing: false,
|
||
confirmed_task_id: 55,
|
||
confirmed_task_no: 'SN-CONFIRM-PROGRESS-FAIL',
|
||
automation: {
|
||
status: 'failed',
|
||
retryable: true,
|
||
phase: 'post_ot_progress',
|
||
can_auto_create: false,
|
||
can_build: true,
|
||
},
|
||
post_confirm_auto_progress: {
|
||
task_no: 'SN-CONFIRM-PROGRESS-FAIL',
|
||
needs_retry: true,
|
||
status: 'needs_retry',
|
||
message: '入队失败',
|
||
},
|
||
};
|
||
const wrapper = await mountView();
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="review-confirm-create"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(false);
|
||
// 发货通知单号随订单明细绑定,不在任务级整单展示;当前任务卡不含单条通知单号。
|
||
expect(wrapper.find('[data-testid="review-current-processing-ot"]').exists()).toBe(false);
|
||
}, 15000);
|
||
});
|
||
|
||
describe('ShippingOrderReviewView viewport layout remediation', () => {
|
||
beforeEach(() => {
|
||
vi.clearAllMocks();
|
||
resetActiveCaseFixture();
|
||
});
|
||
|
||
it('uses a single primary vertical scroll container (not nested editor/rail scroll)', async () => {
|
||
const wrapper = await mountView();
|
||
const scroll = wrapper.find('[data-testid="review-workbench-scroll"]');
|
||
const editor = wrapper.find('[data-testid="review-main-editor"]');
|
||
const rail = wrapper.find('[data-testid="review-build-gate-rail"]');
|
||
// 关键断言:仅外层主滚动带 overflow-y-auto;编辑区与摘要栏不得再套纵向滚动。
|
||
expect(scroll.classes()).toContain('overflow-y-auto');
|
||
expect(editor.classes()).not.toContain('overflow-y-auto');
|
||
expect(rail.classes()).not.toContain('overflow-y-auto');
|
||
expect(editor.classes()).not.toContain('xl:max-h-[calc(100vh-12rem)]');
|
||
});
|
||
|
||
it('keeps footer sticky for always-visible actions', async () => {
|
||
const wrapper = await mountView();
|
||
const footer = wrapper.find('[data-testid="review-footer-actions"]');
|
||
expect(footer.classes()).toContain('sticky');
|
||
expect(footer.classes()).toContain('bottom-0');
|
||
});
|
||
|
||
it('keeps summary rail visible in floating evidence mode and docks only on demand', async () => {
|
||
const wrapper = await mountView();
|
||
await wrapper.find('[data-testid="review-field-locate"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
const rail = wrapper.find('[data-testid="review-build-gate-rail"]');
|
||
// 关键断言:浮窗证据不再为挤 PDF 而隐藏摘要栏。
|
||
expect(rail.classes()).not.toContain('hidden');
|
||
expect(rail.classes()).toContain('xl:sticky');
|
||
|
||
await wrapper.find('[data-testid="review-evidence-toggle-dock"]').trigger('click');
|
||
await flushPromises();
|
||
const body = wrapper.find('[data-testid="review-editor-body"]');
|
||
const drawer = wrapper.find('[data-testid="review-document-evidence-drawer"]');
|
||
// 关键断言:用户主动固定后才进入双栏网格。
|
||
expect(body.attributes('data-evidence-docked')).toBe('true');
|
||
expect(drawer.attributes('data-docked')).toBe('true');
|
||
expect(wrapper.html()).toContain('minmax(420px,1fr)');
|
||
});
|
||
});
|