- 后端进度写入 step_key 全量切换为 15 阶契约 stage 码 - 投影层清除 CheckPoint stepN_* 遗留别名与子串/前缀启发式,阶段信号按契约码精确匹配 - 建单前 Case 摘要透传草稿首要阻断原因 - 前端标签/归一化/处理卡片同步契约码,阻断原因按 i18n 优先展示 - 修复正式下游回看时 activeCase 刻意为空导致队列定位与接收解析上下文静默跳过 - 同步更新投影/门禁/工作台/RPA 流程测试
1270 lines
57 KiB
TypeScript
1270 lines
57 KiB
TypeScript
/**
|
||
* features/chat/components/shipping/ShippingConversationProcessingCard.spec.ts
|
||
* 用途:验收右侧任务分组卡——needs_action / processing / 处理记录三子段与动作层级。
|
||
* 依赖:Vitest、Vue Test Utils、vue-i18n、ShippingConversationProcessingCard。
|
||
* 逻辑:构造 ConversationProcessingProjection;断言分组文案、处理记录折叠与三类子段、
|
||
* UI-02 单一详情入口、UI-03 history 截断角标、人工 Gate 按钮常驻且不依赖任务焦点。
|
||
*/
|
||
import { mount, flushPromises } from '@vue/test-utils';
|
||
import { describe, expect, it } from 'vitest';
|
||
import { createI18n } from 'vue-i18n';
|
||
import chatZhCn from '@/locales/zh-CN/chat.json';
|
||
import type {
|
||
ConversationProcessingProjection,
|
||
ShippingProcessingProjection,
|
||
} from '@/features/chat/types/shipping.api.types';
|
||
import ShippingConversationProcessingCard from './ShippingConversationProcessingCard.vue';
|
||
|
||
const i18n = createI18n({
|
||
legacy: false,
|
||
locale: 'zh-CN',
|
||
messages: { 'zh-CN': { chat: chatZhCn } },
|
||
});
|
||
|
||
function buildProjection(): ConversationProcessingProjection {
|
||
const needsAction = {
|
||
user_task_no: 'OT-NEED',
|
||
group: 'needs_action' as const,
|
||
status_label: 'pending_review',
|
||
file_count: 2,
|
||
run_no: 'RUN-NEED',
|
||
can_append: false,
|
||
recently_created: false,
|
||
};
|
||
const processing = {
|
||
user_task_no: 'OT-PROC',
|
||
submission_ordinal: 2,
|
||
group: 'processing' as const,
|
||
status_label: 'extracting',
|
||
file_count: 1,
|
||
run_no: 'RUN-PROC',
|
||
can_append: true,
|
||
recently_created: true,
|
||
focused: true,
|
||
};
|
||
const completed = {
|
||
user_task_no: 'OT-DONE',
|
||
group: 'completed' as const,
|
||
status_label: 'completed',
|
||
title: 'done.pdf',
|
||
file_count: 1,
|
||
run_no: 'RUN-DONE',
|
||
can_append: false,
|
||
available_actions: ['view_details'],
|
||
};
|
||
const archived = {
|
||
user_task_no: 'OT-HIST',
|
||
group: 'history' as const,
|
||
status_label: 'completed',
|
||
file_count: 1,
|
||
run_no: 'RUN-HIST',
|
||
can_append: false,
|
||
viewed: true,
|
||
available_actions: ['view_details'],
|
||
};
|
||
const cancelled = {
|
||
user_task_no: 'OT-CANCEL',
|
||
group: 'history' as const,
|
||
status_label: 'cancelled',
|
||
file_count: 1,
|
||
run_no: 'RUN-CANCEL',
|
||
can_append: false,
|
||
viewed: true,
|
||
available_actions: ['view_details'],
|
||
};
|
||
return {
|
||
summary: { total_tasks: 3, processing: 1, needs_action: 1, completed: 1, history: 2 },
|
||
focused_task_no: 'OT-PROC',
|
||
recent_task_no: 'OT-PROC',
|
||
status_groups: {
|
||
failed: [needsAction], waiting_human: [], processing: [processing], completed: [completed],
|
||
cancelled: [cancelled], archived: [archived],
|
||
},
|
||
};
|
||
}
|
||
|
||
/** 测试仅构造权威 status_groups;禁止再把旧四组作为组件输入。 */
|
||
function setStatusGroup(
|
||
projection: ConversationProcessingProjection,
|
||
key: keyof NonNullable<ConversationProcessingProjection['status_groups']>,
|
||
tasks: NonNullable<ConversationProcessingProjection['status_groups']>[keyof NonNullable<ConversationProcessingProjection['status_groups']>],
|
||
) {
|
||
projection.status_groups![key] = tasks;
|
||
}
|
||
|
||
function projectionWithGroups(
|
||
summary: ConversationProcessingProjection['summary'],
|
||
groups: NonNullable<ConversationProcessingProjection['status_groups']>,
|
||
): ConversationProcessingProjection {
|
||
return { summary, status_groups: groups };
|
||
}
|
||
|
||
/** 构造任务卡使用的权威统一进度。 */
|
||
function buildWorkItem(
|
||
taskNo: string,
|
||
patch: Partial<ShippingProcessingProjection> = {},
|
||
): ShippingProcessingProjection {
|
||
return {
|
||
workItemType: 'order_task',
|
||
workItemNo: taskNo,
|
||
sourceType: 'direct_pdf',
|
||
rootOrderTaskNo: taskNo,
|
||
shippingNoticeNo: null,
|
||
conversationId: 'conv-1',
|
||
submissionNo: 'SUB-1',
|
||
intakeNo: 'INT-1',
|
||
status: 'processing',
|
||
stage: 'document_parsing',
|
||
progressVersion: 1,
|
||
lastActivityAt: '2026-08-06T00:00:00Z',
|
||
currentGate: null,
|
||
availableActions: ['view_details'],
|
||
sourceSummary: {
|
||
emailSubject: null,
|
||
filename: `${taskNo}.pdf`,
|
||
documentId: taskNo === 'OT-NEED' ? 1 : 2,
|
||
documentCount: 1,
|
||
parsedDocumentCount: 1,
|
||
candidateCount: 1,
|
||
customerName: null,
|
||
poNumber: null,
|
||
},
|
||
childOrderTasks: [],
|
||
...patch,
|
||
};
|
||
}
|
||
|
||
describe('ShippingConversationProcessingCard', () => {
|
||
it('only exposes file cancellation when the backend explicitly authorizes cancel_unit', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'OT-CANCEL-UNIT', group: 'processing', status_label: 'extracting',
|
||
file_count: 1, run_no: 'RUN-CANCEL-UNIT', can_append: false,
|
||
objects: [{ kind: 'document', object_key: 'DOC-9', label: 'cancel.pdf', filename: 'cancel.pdf',
|
||
document_id: 9, root_document_id: 9, status_label: 'extracting' }],
|
||
}]);
|
||
const workItem = buildWorkItem('OT-CANCEL-UNIT', {
|
||
availableActions: ['cancel_unit'],
|
||
sourceSummary: { ...buildWorkItem('OT-CANCEL-UNIT').sourceSummary, documentId: 9 },
|
||
uiState: {
|
||
status: 'running',
|
||
stage: 'document_parsing',
|
||
blocking_reason: null,
|
||
primary_action: null,
|
||
secondary_actions: [{ code: 'cancel_unit', enabled: true }],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [workItem], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
await wrapper.find('summary').trigger('click');
|
||
await wrapper.find('[data-testid="shipping-processing-file-cancel"]').trigger('click');
|
||
expect(wrapper.emitted('fileAction')?.[0]?.[0]).toMatchObject({
|
||
action: 'cancel_unit', projection: { workItemNo: 'OT-CANCEL-UNIT' },
|
||
});
|
||
});
|
||
|
||
it('does not fall back to legacy cancellation when ui_state revokes it', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'OT-CANCEL-REVOKED', group: 'processing', status_label: 'extracting',
|
||
file_count: 1, run_no: 'RUN-CANCEL-REVOKED', can_append: false,
|
||
objects: [{ kind: 'document', object_key: 'DOC-10', label: 'revoked.pdf', filename: 'revoked.pdf',
|
||
document_id: 10, root_document_id: 10, status_label: 'extracting' }],
|
||
}]);
|
||
const workItem = buildWorkItem('OT-CANCEL-REVOKED', {
|
||
availableActions: ['cancel_unit'],
|
||
sourceSummary: { ...buildWorkItem('OT-CANCEL-REVOKED').sourceSummary, documentId: 10 },
|
||
uiState: {
|
||
status: 'running',
|
||
stage: 'document_parsing',
|
||
blocking_reason: null,
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [workItem], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// ui_state 已出现即表示后端完成了正式动作裁决;遗留 availableActions 不得重新授权。
|
||
expect(wrapper.find('[data-testid="shipping-processing-file-cancel"]').exists()).toBe(false);
|
||
expect(wrapper.emitted('fileAction')).toBeUndefined();
|
||
});
|
||
|
||
it('does not render legacy document_names as a batch file row without a live leaf projection', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'OT-HISTORICAL-SNAPSHOT', group: 'processing', status_label: 'extracting',
|
||
title: 'legacy-run.pdf', document_names: ['legacy-run.pdf'], file_count: 1,
|
||
run_no: 'RUN-HISTORICAL-SNAPSHOT', can_append: false,
|
||
}]);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// 批次中心没有实时叶子投影时不得由历史 Run 快照补造文件行或操作入口。
|
||
expect(wrapper.find('[data-testid="shipping-processing-file-OT-HISTORICAL-SNAPSHOT-document-0"]').exists()).toBe(false);
|
||
expect(wrapper.text()).not.toContain('legacy-run.pdf');
|
||
});
|
||
|
||
it('uses the live leaf summary instead of a stale task object in batch mode', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'OT-LIVE-LEAF', group: 'processing', status_label: 'extracting',
|
||
title: 'snapshot-old-name.pdf', file_count: 1, run_no: 'RUN-LIVE-LEAF', can_append: false,
|
||
objects: [{
|
||
kind: 'document', object_key: 'DOC-88', label: 'snapshot-old-name.pdf',
|
||
filename: 'snapshot-old-name.pdf', document_id: 88, root_document_id: 88,
|
||
status_label: 'pending_review',
|
||
}],
|
||
}]);
|
||
const live = buildWorkItem('OT-LIVE-LEAF', {
|
||
runNo: 'RUN-LIVE-LEAF',
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'realtime-name.pdf', documentId: 88,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-REALTIME',
|
||
},
|
||
uiState: {
|
||
status: 'running', stage: 'order_review', lifecycleStage: 'order_review',
|
||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [live], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const row = wrapper.get('[data-testid="shipping-processing-file-DOC-88"]');
|
||
expect(row.text()).toContain('realtime-name.pdf');
|
||
expect(row.text()).toContain('PO:PO-REALTIME');
|
||
expect(row.text()).not.toContain('snapshot-old-name.pdf');
|
||
});
|
||
|
||
it('expands EML files only from the live aggregate work item', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'INTAKE:EML-LIVE', group: 'processing', status_label: 'extracting',
|
||
title: 'snapshot-mail.eml', document_names: ['snapshot-attachment.pdf'],
|
||
file_count: 1, run_no: 'RUN-EML-LIVE', can_append: false,
|
||
aggregateChildren: [],
|
||
}]);
|
||
const liveChild = buildWorkItem('DOCUMENT:77', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-LIVE', runNo: 'RUN-EML-LIVE',
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'live-attachment.pdf', documentId: 77,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-EML-LIVE',
|
||
},
|
||
uiState: {
|
||
status: 'running', stage: 'order_review', lifecycleStage: 'order_review',
|
||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const liveEmlRoot = buildWorkItem('INTAKE:EML-LIVE', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-LIVE', runNo: 'RUN-EML-LIVE',
|
||
sourceSummary: {
|
||
emailSubject: 'Live mail', filename: 'live-mail.eml', documentId: null,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: null,
|
||
},
|
||
aggregateChildren: [liveChild],
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [liveEmlRoot], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const row = wrapper.get('[data-testid="shipping-processing-file-DOC-77"]');
|
||
expect(row.text()).toContain('live-attachment.pdf');
|
||
expect(row.text()).toContain('PO:PO-EML-LIVE');
|
||
expect(wrapper.text()).not.toContain('snapshot-attachment.pdf');
|
||
});
|
||
|
||
it('keeps selected but unrecognized EML attachments visible without file actions', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'INTAKE:EML-PENDING', group: 'processing', status_label: 'extracting',
|
||
title: 'pending-mail.eml', file_count: 2, run_no: 'RUN-EML-PENDING', can_append: false,
|
||
}]);
|
||
const recognizedLeaf = buildWorkItem('DOCUMENT:91', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-PENDING',
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'recognized.pdf', documentId: 91,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: null,
|
||
},
|
||
});
|
||
const pendingLeaf = buildWorkItem('PLAN:EML-PENDING:missing.pdf', {
|
||
workItemType: 'order_intake', sourceType: 'eml', rootOrderTaskNo: null,
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'missing.pdf', documentId: null,
|
||
documentCount: 0, parsedDocumentCount: 0, candidateCount: 0,
|
||
customerName: null, poNumber: null,
|
||
},
|
||
facts: { recognized: false, planState: 'selected_pending' },
|
||
uiState: undefined,
|
||
});
|
||
const root = buildWorkItem('INTAKE:EML-PENDING', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-PENDING',
|
||
sourceSummary: {
|
||
emailSubject: 'Pending mail', filename: 'pending-mail.eml', documentId: null,
|
||
documentCount: 2, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: null,
|
||
},
|
||
aggregateChildren: [recognizedLeaf, pendingLeaf],
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [root], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const pendingRow = wrapper.get('[data-testid="shipping-processing-file-INTAKE:EML-PENDING-live-PLAN:EML-PENDING:missing.pdf"]');
|
||
expect(pendingRow.text()).toContain('missing.pdf');
|
||
expect(pendingRow.text()).toContain('待识别');
|
||
expect(pendingRow.find('button').exists()).toBe(false);
|
||
});
|
||
|
||
it('counts only stage-filtered EML leaves in the batch status heading', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'INTAKE:MIXED-STAGES', group: 'processing', status_label: 'extracting',
|
||
title: 'mixed-stages.eml', file_count: 2, run_no: 'RUN-MIXED-STAGES', can_append: false,
|
||
}]);
|
||
const orderReviewLeaf = buildWorkItem('DOCUMENT:401', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STAGES',
|
||
sourceSummary: { ...buildWorkItem('DOCUMENT:401').sourceSummary, documentId: 401, filename: 'review.pdf' },
|
||
uiState: {
|
||
status: 'waiting_human', stage: 'waiting_review', lifecycleStage: 'order_review',
|
||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const freightLeaf = buildWorkItem('DOCUMENT:402', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STAGES',
|
||
sourceSummary: { ...buildWorkItem('DOCUMENT:402').sourceSummary, documentId: 402, filename: 'upload.xlsx' },
|
||
uiState: {
|
||
status: 'running', stage: 'freight_uploading', lifecycleStage: 'freight_upload',
|
||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const root = buildWorkItem('INTAKE:MIXED-STAGES', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STAGES',
|
||
aggregateChildren: [orderReviewLeaf, freightLeaf],
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [root], workbenchMode: true, lifecycleFilter: 'order_review' },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// 阶段卡与列表标题必须消费同一批可见叶子,不能把同一 EML 的其它阶段附件混入。
|
||
expect(wrapper.get('[data-testid="shipping-processing-group-processing"]').text()).toContain('1 个文件');
|
||
expect(wrapper.get('[data-testid="shipping-processing-group-processing"]').text()).not.toContain('2 个文件');
|
||
});
|
||
|
||
it('keeps backend processing rows visible while matching work items are still unavailable', async () => {
|
||
const processingLeaf = buildWorkItem('DOCUMENT:610', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-PROCESSING-SNAPSHOT',
|
||
sourceSummary: { ...buildWorkItem('DOCUMENT:610').sourceSummary, documentId: 610, filename: 'processing.pdf' },
|
||
uiState: {
|
||
status: 'running', stage: 'document_parsing', lifecycleStage: 'intake_parse',
|
||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const projection = projectionWithGroups(
|
||
{ total_tasks: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||
{
|
||
failed: [], waiting_human: [],
|
||
processing: [{
|
||
user_task_no: 'OT-PROCESSING-SNAPSHOT', group: 'processing', status_label: 'processing',
|
||
title: 'processing.eml', file_count: 1, run_no: 'RUN-PROCESSING-SNAPSHOT', can_append: false,
|
||
aggregateChildren: [processingLeaf],
|
||
}],
|
||
completed: [], cancelled: [], archived: [],
|
||
},
|
||
);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// 状态分组先到达时,须以同次响应的叶子快照保留处理中附件。
|
||
const group = wrapper.get('[data-testid="shipping-processing-group-processing"]');
|
||
expect(group.text()).toContain('处理中 · 1 个文件');
|
||
expect(group.text()).toContain('processing.pdf');
|
||
});
|
||
|
||
it('shows a mixed-status EML once per PDF status without mixing completed files', async () => {
|
||
const completedLeaf = buildWorkItem('DOCUMENT:501', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STATUS',
|
||
sourceSummary: { ...buildWorkItem('DOCUMENT:501').sourceSummary, documentId: 501, filename: 'done.pdf' },
|
||
uiState: {
|
||
status: 'completed', stage: 'completed', lifecycleStage: 'upload_complete',
|
||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const processingLeaf = buildWorkItem('DOCUMENT:502', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STATUS',
|
||
sourceSummary: { ...buildWorkItem('DOCUMENT:502').sourceSummary, documentId: 502, filename: 'running.pdf' },
|
||
uiState: {
|
||
status: 'running', stage: 'freight_upload', lifecycleStage: 'freight_upload',
|
||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||
},
|
||
});
|
||
const root = buildWorkItem('INTAKE:MIXED-STATUS', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-MIXED-STATUS',
|
||
sourceSummary: { ...buildWorkItem('INTAKE:MIXED-STATUS').sourceSummary, filename: 'mixed.eml', documentId: null },
|
||
aggregateChildren: [completedLeaf, processingLeaf],
|
||
});
|
||
const task = {
|
||
user_task_no: 'OT-MIXED-STATUS', title: 'mixed.eml', file_count: 1, run_no: 'RUN-MIXED-STATUS', can_append: false,
|
||
aggregateSummary: { intakeNo: 'SNI-MIXED-STATUS', total: 2, in_group: 1 },
|
||
};
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 2, processing: 1, needs_action: 0, completed: 1, history: 0 },
|
||
{
|
||
failed: [], waiting_human: [],
|
||
processing: [{ ...task, group: 'processing', status_label: 'processing', aggregateChildren: [processingLeaf] }],
|
||
completed: [{ ...task, group: 'completed', status_label: 'completed', aggregateChildren: [completedLeaf] }],
|
||
cancelled: [], archived: [],
|
||
},
|
||
),
|
||
workItems: [root], workbenchMode: true,
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(wrapper.get('[data-testid="shipping-processing-group-processing"]').text()).toContain('running.pdf');
|
||
expect(wrapper.get('[data-testid="shipping-processing-group-processing"]').text()).not.toContain('done.pdf');
|
||
expect(wrapper.get('[data-testid="shipping-processing-group-processing"]').text()).toContain('本组 1/共 2 个文件');
|
||
await wrapper.get('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
expect(wrapper.get('[data-testid="shipping-processing-history-completed"]').text()).toContain('done.pdf');
|
||
expect(wrapper.get('[data-testid="shipping-processing-history-completed"]').text()).not.toContain('running.pdf');
|
||
expect(wrapper.get('[data-testid="shipping-processing-history-completed"]').text()).toContain('本组 1/共 2 个文件');
|
||
});
|
||
|
||
it('keeps an EML attachment when it has a linked child order task', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'INTAKE:EML-WITH-CHILD-OT', group: 'processing', status_label: 'extracting',
|
||
title: 'mail.eml', file_count: 2, run_no: 'RUN-EML-WITH-CHILD-OT', can_append: false,
|
||
}]);
|
||
const firstAttachment = buildWorkItem('OT-EML-WITH-CHILD-OT', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-WITH-CHILD-OT',
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'first.pdf', documentId: 266,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-FIRST',
|
||
},
|
||
childOrderTasks: [{
|
||
orderTaskNo: 'OT-EML-WITH-CHILD-OT-C1', status: 'blocked', stage: 'inventory_matching',
|
||
customerName: null, poNumber: 'PO-SECOND', lastActivityAt: null,
|
||
}],
|
||
});
|
||
const secondAttachment = buildWorkItem('OT-EML-WITH-CHILD-OT-C1', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-WITH-CHILD-OT',
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'second.pdf', documentId: 267,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-SECOND',
|
||
},
|
||
});
|
||
const liveEmlRoot = buildWorkItem('INTAKE:EML-WITH-CHILD-OT', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-WITH-CHILD-OT',
|
||
sourceSummary: {
|
||
emailSubject: 'Mail', filename: 'mail.eml', documentId: null,
|
||
documentCount: 2, parsedDocumentCount: 2, candidateCount: 2,
|
||
customerName: null, poNumber: null,
|
||
},
|
||
aggregateChildren: [firstAttachment, secondAttachment],
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [liveEmlRoot], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="shipping-processing-file-DOC-266"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-file-DOC-267"]').exists()).toBe(true);
|
||
expect(wrapper.text()).toContain('处理中 · 2 个文件');
|
||
});
|
||
|
||
it('renders needs_action / processing groups and collapsible processing records with three subsections', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection: buildProjection() },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="shipping-conversation-processing-card"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-group-failed"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-group-processing"]').exists()).toBe(true);
|
||
// 状态组与对话流一致,未展开附件时仍按后端 file_count 统计。
|
||
expect(wrapper.text()).toContain('异常 · 2 个文件');
|
||
expect(wrapper.text()).toContain('处理中 · 1 个文件');
|
||
expect(wrapper.text()).toContain('刚刚创建');
|
||
|
||
// 处理记录默认折叠;标题按文件数而非 EML / 任务行数统计。
|
||
const historyGroup = wrapper.find('[data-testid="shipping-processing-group-history"]');
|
||
expect(historyGroup.exists()).toBe(true);
|
||
expect(historyGroup.text()).toContain('处理记录 · 3 个文件');
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-body"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-DONE"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-HIST"]').exists()).toBe(false);
|
||
|
||
await wrapper.find('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-body"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-completed"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-versions"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-cancelled"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-DONE"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-HIST"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-CANCEL"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-completed"]').text()).toContain('已完成');
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-versions"]').text()).toContain('历史版本');
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-cancelled"]').text()).toContain('已取消');
|
||
});
|
||
|
||
it('shows history more badge when summary.history exceeds returned history length', async () => {
|
||
const projection = buildProjection();
|
||
projection.summary.history = 14;
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// UI-03:折叠态即可看到「还有 N 条」。
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-more"]').text()).toContain('还有 12 条');
|
||
await wrapper.find('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-truncated"]').text())
|
||
.toContain('仅展示最近 2 条,另有 12 条未显示');
|
||
});
|
||
|
||
it('falls back to generic truncated hint when hasMoreHistory but no reliable hidden count', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: buildProjection(),
|
||
hasMoreHistory: true,
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-more"]').exists()).toBe(false);
|
||
await wrapper.find('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-history-truncated"]').text())
|
||
.toContain('列表已截断,仅展示最近任务');
|
||
});
|
||
|
||
it('keeps processing-record cards read-only without primary CTA or progress', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: buildProjection(),
|
||
workItems: [
|
||
buildWorkItem('OT-DONE', { status: 'completed', stage: 'completed' }),
|
||
],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
await wrapper.find('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
await flushPromises();
|
||
|
||
const doneCard = wrapper.find('[data-testid="shipping-processing-task-OT-DONE"]');
|
||
expect(doneCard.find('[data-testid="sidebar-progress-inline"]').exists()).toBe(false);
|
||
expect(doneCard.find('[data-testid="shipping-processing-task-actions"]').exists()).toBe(false);
|
||
expect(doneCard.find('[data-testid="shipping-processing-action-view_result"]').exists()).toBe(false);
|
||
expect(doneCard.find('[data-testid="shipping-processing-action-cancel_task"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('uses expand-files as the only detail entry when canExpandFileDetails', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 1, processing: 0, needs_action: 1, completed: 0, history: 0 }, {
|
||
failed: [{
|
||
user_task_no: 'OT-MULTI',
|
||
group: 'needs_action',
|
||
status_label: 'pending_review',
|
||
title: null,
|
||
display_kind: 'multi_document_task',
|
||
document_names: ['4518838152.pdf', '4518838154.pdf'],
|
||
file_count: 2,
|
||
run_no: 'RUN-MULTI',
|
||
can_append: false,
|
||
available_actions: ['view_details', 'cancel_task'],
|
||
}], waiting_human: [], processing: [], completed: [], cancelled: [], archived: [],
|
||
}),
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.text()).toContain('本次订单文件处理');
|
||
expect(wrapper.text()).toContain('2 个 PDF');
|
||
expect(wrapper.text()).toContain('主文件:4518838152.pdf');
|
||
const titleEl = wrapper.find('[data-testid="shipping-processing-task-OT-MULTI"] .text-sm.font-semibold');
|
||
expect(titleEl.text()).toContain('本次订单文件处理');
|
||
expect(titleEl.text()).not.toContain('4518838152.pdf');
|
||
|
||
// UI-02:有文件对象时不双开「查看详情」与「展开文件详情」。
|
||
expect(wrapper.find('[data-testid="shipping-processing-expand-files"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-action-view_details"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-action-cancel_task"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-overflow-actions"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('shows view_details when task cannot expand file details, and keeps cancel as overflow', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 1, processing: 0, needs_action: 1, completed: 0, history: 0 }, {
|
||
failed: [{
|
||
user_task_no: 'OT-SINGLE',
|
||
group: 'needs_action',
|
||
status_label: 'pending_review',
|
||
file_count: 1,
|
||
run_no: 'RUN-SINGLE',
|
||
can_append: false,
|
||
available_actions: ['view_details', 'cancel_task'],
|
||
objects: [],
|
||
}], waiting_human: [], processing: [], completed: [], cancelled: [], archived: [],
|
||
}),
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-expand-files"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-action-view_details"]').exists()).toBe(false);
|
||
// 无文件对象时取消可直接挂在卡上(低频文字链,非主 CTA)。
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-overflow-actions"]').exists()).toBe(false);
|
||
expect(wrapper.find('[data-testid="shipping-processing-action-cancel_task"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('shows multi-document title from authoritative projection without workflow fallback', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 1, total_files: 2, processing: 0, needs_action: 1, completed: 0, history: 0 }, {
|
||
failed: [{
|
||
user_task_no: 'OT-MULTI',
|
||
group: 'needs_action',
|
||
status_label: 'pending_review',
|
||
title: null,
|
||
display_kind: 'multi_document_task',
|
||
document_names: ['4518838152.pdf', '4518838154.pdf'],
|
||
file_count: 2,
|
||
run_no: 'RUN-MULTI',
|
||
can_append: false,
|
||
available_actions: ['view_details', 'cancel_task'],
|
||
objects: [],
|
||
}], waiting_human: [], processing: [], completed: [], cancelled: [], archived: [],
|
||
}),
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.text()).toContain('本次订单文件处理');
|
||
expect(wrapper.text()).toContain('2 个 PDF');
|
||
const titleEl = wrapper.find('[data-testid="shipping-processing-task-OT-MULTI"] .text-sm.font-semibold');
|
||
expect(titleEl.text()).toContain('本次订单文件处理');
|
||
expect(titleEl.text()).not.toContain('4518838152.pdf');
|
||
});
|
||
|
||
it('uses unified order file processing title instead of internal OT number', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 1, processing: 1, needs_action: 0, completed: 0, history: 0 }, {
|
||
failed: [], waiting_human: [], processing: [{
|
||
user_task_no: 'OT-20260803-A13F95D2',
|
||
group: 'processing',
|
||
status_label: 'processing',
|
||
title: null,
|
||
file_count: 1,
|
||
run_no: 'SNER-X',
|
||
can_append: false,
|
||
}], completed: [], cancelled: [], archived: [],
|
||
}),
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.text()).toContain('本次订单文件处理');
|
||
expect(wrapper.text()).not.toContain('20260803-A13F95D2');
|
||
});
|
||
|
||
it('selects a task locally without writing focus or viewed events', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection: buildProjection() },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
await wrapper.find('[data-testid="shipping-processing-task-OT-NEED"] button').trigger('click');
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]').attributes('data-focused')).toBe('1');
|
||
expect(wrapper.emitted('focus')).toBeUndefined();
|
||
expect(wrapper.emitted('viewed')).toBeUndefined();
|
||
expect(wrapper.emitted('expandFiles')).toBeUndefined();
|
||
});
|
||
|
||
it('does not show a view-result action for completed records', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: {
|
||
...projectionWithGroups(
|
||
{ total_tasks: 1, processing: 0, needs_action: 0, completed: 1, history: 0 }, {
|
||
failed: [], waiting_human: [], processing: [], completed: [{
|
||
user_task_no: 'OT-DETAIL', group: 'completed', status_label: 'completed',
|
||
file_count: 1, run_no: 'RUN-DETAIL', can_append: false,
|
||
available_actions: ['view_details'],
|
||
}], cancelled: [], archived: [],
|
||
},
|
||
),
|
||
focused_task_no: null,
|
||
recent_task_no: null,
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
await wrapper.find('[data-testid="shipping-processing-history-toggle"]').trigger('click');
|
||
|
||
expect(wrapper.find('[data-testid="shipping-processing-action-view_result"]').exists()).toBe(false);
|
||
expect(wrapper.emitted('taskAction')).toBeUndefined();
|
||
expect(wrapper.emitted('viewed')).toBeUndefined();
|
||
});
|
||
|
||
it('marks an unrecognized Excel attachment as ignored but keeps a pending PDF recognizable', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
user_task_no: 'INTAKE:EML-EXCEL', group: 'processing', status_label: 'extracting',
|
||
title: 'mail.eml', file_count: 2, run_no: 'RUN-EML-EXCEL', can_append: false,
|
||
aggregateChildren: [],
|
||
}]);
|
||
const pendingPdf = buildWorkItem('PLAN:EML-EXCEL:pending', {
|
||
workItemType: 'order_intake', sourceType: 'eml', rootOrderTaskNo: null,
|
||
sourceSummary: { emailSubject: null, filename: 'pending.pdf', documentId: null, documentCount: 0, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null },
|
||
facts: { recognized: false, planState: 'selected_pending' }, uiState: undefined,
|
||
});
|
||
const ignoredExcel = buildWorkItem('PLAN:EML-EXCEL:report', {
|
||
workItemType: 'order_intake', sourceType: 'eml', rootOrderTaskNo: null,
|
||
sourceSummary: { emailSubject: null, filename: 'report.xlsx', documentId: null, documentCount: 0, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null },
|
||
facts: { recognized: false, planState: 'selected_pending' }, uiState: undefined,
|
||
});
|
||
const root = buildWorkItem('INTAKE:EML-EXCEL', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-EXCEL',
|
||
aggregateChildren: [pendingPdf, ignoredExcel],
|
||
});
|
||
projection.status_groups!.processing![0]!.aggregateChildren = [pendingPdf, ignoredExcel];
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [root], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const processingGroup = wrapper.get('[data-testid="shipping-processing-group-processing"]');
|
||
expect(processingGroup.text()).toContain('pending.pdf');
|
||
expect(processingGroup.text()).not.toContain('report.xlsx');
|
||
expect(wrapper.get('[data-testid="shipping-processing-file-INTAKE:EML-EXCEL-live-PLAN:EML-EXCEL:pending"]').text()).toContain('待识别');
|
||
const ignoredGroup = wrapper.get('[data-testid="shipping-processing-group-ignored"]');
|
||
expect(ignoredGroup.text()).toContain('已忽略 · 1 个文件');
|
||
expect(wrapper.find('[data-testid="shipping-processing-ignored-body"]').exists()).toBe(false);
|
||
await ignoredGroup.get('[data-testid="shipping-processing-ignored-toggle"]').trigger('click');
|
||
const excelRow = ignoredGroup.get('[data-testid="shipping-processing-file-INTAKE:EML-EXCEL-live-PLAN:EML-EXCEL:report"]');
|
||
expect(excelRow.text()).toContain('已忽略');
|
||
expect(excelRow.text()).not.toContain('待识别');
|
||
});
|
||
|
||
it('keeps an ignored Excel row when its EML parent originates from completed', async () => {
|
||
const ignoredExcel = buildWorkItem('PLAN:EML-COMPLETED:report', {
|
||
workItemType: 'order_intake', sourceType: 'eml', rootOrderTaskNo: null,
|
||
sourceSummary: { emailSubject: null, filename: 'report.xlsx', documentId: null, documentCount: 0, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null },
|
||
facts: { recognized: false, planState: 'selected_pending' }, uiState: undefined,
|
||
});
|
||
const root = buildWorkItem('INTAKE:EML-COMPLETED', {
|
||
sourceType: 'eml', rootOrderTaskNo: 'OT-EML-COMPLETED',
|
||
aggregateChildren: [ignoredExcel],
|
||
});
|
||
const projection = projectionWithGroups(
|
||
{ total_tasks: 1, processing: 0, needs_action: 0, completed: 1, history: 0 },
|
||
{
|
||
failed: [], waiting_human: [], processing: [],
|
||
completed: [{
|
||
user_task_no: 'INTAKE:EML-COMPLETED', group: 'completed', status_label: 'completed',
|
||
title: 'mail.eml', file_count: 1, run_no: 'RUN-EML-COMPLETED', can_append: false,
|
||
aggregateChildren: [ignoredExcel],
|
||
}],
|
||
cancelled: [], archived: [],
|
||
},
|
||
);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [root], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const ignoredGroup = wrapper.get('[data-testid="shipping-processing-group-ignored"]');
|
||
expect(ignoredGroup.text()).toContain('已忽略 · 1 个文件');
|
||
expect(wrapper.find('[data-testid="shipping-processing-ignored-body"]').exists()).toBe(false);
|
||
await ignoredGroup.get('[data-testid="shipping-processing-ignored-toggle"]').trigger('click');
|
||
expect(ignoredGroup.get('[data-testid="shipping-processing-file-INTAKE:EML-COMPLETED-live-PLAN:EML-COMPLETED:report"]').text()).toContain('report.xlsx');
|
||
});
|
||
|
||
it('applies visible focus ring on needs_action card when focused', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: {
|
||
...buildProjection(),
|
||
focused_task_no: 'OT-NEED',
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
const needCard = wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]');
|
||
expect(needCard.attributes('data-focused')).toBe('1');
|
||
expect(needCard.classes().join(' ')).toContain('ring-brand-400');
|
||
const other = wrapper.find('[data-testid="shipping-processing-task-OT-PROC"]');
|
||
expect(other.attributes('data-focused')).toBe('0');
|
||
expect(other.classes().join(' ')).not.toContain('ring-brand-400');
|
||
});
|
||
|
||
it('emits expandFiles / collapseFiles when toggling file details', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: {
|
||
...buildProjection(),
|
||
status_groups: {
|
||
...buildProjection().status_groups!,
|
||
failed: [{
|
||
...buildProjection().status_groups!.failed[0],
|
||
available_actions: ['view_details', 'open_review', 'cancel_task'],
|
||
}],
|
||
},
|
||
},
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-expand-files"]').exists()).toBe(false);
|
||
});
|
||
|
||
it('renders twenty processing tasks in one top-level container', async () => {
|
||
const processing = Array.from({ length: 20 }, (_, index) => ({
|
||
user_task_no: `OT-${index}`,
|
||
group: 'processing' as const,
|
||
status_label: 'extracting',
|
||
file_count: 1,
|
||
run_no: `RUN-${index}`,
|
||
can_append: false,
|
||
}));
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 20, processing: 20, needs_action: 0, history: 0 },
|
||
{ failed: [], waiting_human: [], processing, completed: [], cancelled: [], archived: [] },
|
||
),
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.findAll('article[data-testid^="shipping-processing-task-"]')).toHaveLength(20);
|
||
expect(wrapper.findAll('[data-testid="shipping-conversation-processing-card"]')).toHaveLength(1);
|
||
});
|
||
|
||
it('renders an EML order_intake in the unified failed group rather than the removed intake side path', async () => {
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection: projectionWithGroups(
|
||
{ total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 }, {
|
||
failed: [{
|
||
user_task_no: 'SNI-1',
|
||
group: 'needs_action',
|
||
userGroup: 'failed',
|
||
status_label: 'failed',
|
||
title: 'mail.eml',
|
||
file_count: 1,
|
||
run_no: null,
|
||
can_append: false,
|
||
}], waiting_human: [], processing: [], completed: [], cancelled: [], archived: [],
|
||
}),
|
||
workItems: [{
|
||
workItemType: 'order_intake',
|
||
workItemNo: 'SNI-1',
|
||
sourceType: 'eml',
|
||
rootOrderTaskNo: null,
|
||
shippingNoticeNo: null,
|
||
conversationId: 'conv-1',
|
||
submissionNo: 'SOS-1',
|
||
intakeNo: 'SNI-1',
|
||
status: 'failed',
|
||
userGroup: 'failed',
|
||
stage: 'document_parsing',
|
||
progressVersion: 1,
|
||
lastActivityAt: '2026-08-04T12:00:00Z',
|
||
currentGate: {
|
||
gateCode: 'intake_document_parse',
|
||
status: 'blocked',
|
||
nextActionCode: 'retry_parse',
|
||
blockingReasonCode: 'SHIPPING_NOTICE.INTAKE_PARSE_FAILED',
|
||
attemptNo: 2,
|
||
},
|
||
availableActions: ['view_details', 'retry_parse'],
|
||
uiState: {
|
||
status: 'failed',
|
||
stage: 'document_parsing',
|
||
lifecycleStage: 'intake_parse',
|
||
lifecycleEntries: [],
|
||
blocking_reason: { code: 'SHIPPING_NOTICE.INTAKE_PARSE_FAILED' },
|
||
primary_action: { code: 'retry_parse', i18nKey: null, parameters: {}, executionMode: 'immediate' },
|
||
secondary_actions: [],
|
||
},
|
||
sourceSummary: {
|
||
emailSubject: null,
|
||
filename: 'po.pdf',
|
||
documentCount: 1,
|
||
parsedDocumentCount: 0,
|
||
candidateCount: 0,
|
||
customerName: null,
|
||
poNumber: null,
|
||
failureReasonCode: 'SHIPPING_NOTICE.INTAKE_PARSE_FAILED',
|
||
parseAttemptCount: 2,
|
||
assetStatus: 'ready',
|
||
},
|
||
childOrderTasks: [],
|
||
}],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
expect(wrapper.find('[data-testid="shipping-processing-group-failed"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-SNI-1"]').exists()).toBe(true);
|
||
expect(wrapper.find('[data-testid="shipping-processing-group-order-intake"]').exists()).toBe(false);
|
||
// Intake retry_parse 与 Case reparse 对用户统一展示为“重新解析”;
|
||
// 后端 action_code 仍保留不同对象边界与执行接口。
|
||
expect(wrapper.text()).toContain('重新解析');
|
||
});
|
||
|
||
it('keeps a human Gate action visible before and after selecting its task', async () => {
|
||
const projection = buildProjection();
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection,
|
||
workItems: [
|
||
buildWorkItem('OT-NEED', {
|
||
status: 'waiting_review',
|
||
stage: 'waiting_review',
|
||
currentGate: {
|
||
gateCode: 'inventory_matching',
|
||
nextActionCode: 'open_inventory_match_review',
|
||
blockingReasonCode: 'inventory_match_not_ready',
|
||
},
|
||
availableActions: ['open_inventory_match_review'],
|
||
uiState: {
|
||
status: 'waiting_human',
|
||
stage: 'waiting_review',
|
||
lifecycleStage: 'order_review',
|
||
lifecycleEntries: [],
|
||
blocking_reason: { code: 'inventory_match_not_ready' },
|
||
primary_action: { code: 'open_inventory_match_review', i18nKey: null, parameters: {}, executionMode: 'immediate' },
|
||
secondary_actions: [],
|
||
},
|
||
}),
|
||
buildWorkItem('OT-PROC', {
|
||
stage: 'inventory_matching',
|
||
}),
|
||
],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(wrapper.findAll('[data-testid="sidebar-progress-inline"]')).toHaveLength(2);
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]').text()).toContain('待人工处理');
|
||
expect(wrapper.find('[data-testid="shipping-processing-task-OT-PROC"]').text()).toContain('通知准备');
|
||
expect(wrapper.findAll('[data-testid="shipping-processing-task-actions"]')).toHaveLength(0);
|
||
const task = wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]');
|
||
expect(task.find('[data-testid="unified-action-primary"]').exists()).toBe(true);
|
||
expect(task.find('[data-testid="unified-action-primary"]').text()).toContain('open_inventory_match_review');
|
||
|
||
await task.find('button').trigger('click');
|
||
await flushPromises();
|
||
|
||
// 点击仅改变焦点;同一 Gate 的恢复入口必须继续可见。
|
||
expect(task.attributes('data-focused')).toBe('1');
|
||
expect(task.find('[data-testid="unified-action-primary"]').exists()).toBe(true);
|
||
});
|
||
|
||
it('maps internal review_case_draft status to a user-facing review label', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'failed', [{
|
||
...projection.status_groups!.failed[0],
|
||
status_label: 'review_case_draft',
|
||
}]);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// 旧聚合卡不再显示内部 Case 状态;工作台文件行才展示后端 ui_state。
|
||
expect(wrapper.text()).not.toContain('review_case_draft');
|
||
expect(wrapper.text()).not.toContain('review_case_draft');
|
||
});
|
||
|
||
it('renders a compact V3 file row with named lifecycle entries', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
...projection.status_groups!.processing[0],
|
||
user_task_no: 'OT-LIFECYCLE',
|
||
run_no: 'RUN-LIFECYCLE',
|
||
file_count: 1,
|
||
}]);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection,
|
||
workbenchMode: true,
|
||
workItems: [buildWorkItem('OT-LIFECYCLE', {
|
||
runNo: 'RUN-LIFECYCLE',
|
||
caseNo: 'CASE-LIFECYCLE',
|
||
sourceSummary: {
|
||
emailSubject: null,
|
||
filename: 'lifecycle.pdf',
|
||
documentId: 9,
|
||
documentCount: 1,
|
||
parsedDocumentCount: 1,
|
||
candidateCount: 1,
|
||
customerName: null,
|
||
poNumber: 'PO-LIFECYCLE',
|
||
},
|
||
uiState: {
|
||
status: 'running',
|
||
stage: 'inventory_match',
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ 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: [],
|
||
},
|
||
})],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const row = wrapper.find('[data-testid="shipping-processing-file-DOC-9"]');
|
||
expect(row.exists()).toBe(true);
|
||
expect(row.text()).toContain('lifecycle.pdf');
|
||
expect(row.text()).toContain('PO:PO-LIFECYCLE');
|
||
expect(row.text()).toContain('通知准备');
|
||
expect(row.text()).toContain('当前阶段:通知准备');
|
||
});
|
||
|
||
it('keeps the file action slot for a real action but not for duplicate lifecycle navigation', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
...projection.status_groups!.processing[0],
|
||
user_task_no: 'OT-FILE-ACTION', run_no: 'RUN-FILE-ACTION', file_count: 1,
|
||
}]);
|
||
const navigationOnly = buildWorkItem('OT-FILE-ACTION', {
|
||
runNo: 'RUN-FILE-ACTION',
|
||
sourceSummary: { ...buildWorkItem('OT-FILE-ACTION').sourceSummary, documentId: 31 },
|
||
uiState: {
|
||
status: 'waiting_human', stage: 'order_review', lifecycleStage: 'order_review',
|
||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
blocking_reason: null,
|
||
primary_action: {
|
||
code: 'open_order_review', i18nKey: null, parameters: {}, executionMode: 'navigate',
|
||
targetSurface: 'order_lifecycle_workbench', targetLifecycleStage: 'order_review',
|
||
},
|
||
secondary_actions: [],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [navigationOnly], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const row = wrapper.get('[data-testid="shipping-processing-file-DOC-31"]');
|
||
expect(row.text()).not.toContain('进入订单复核');
|
||
|
||
await wrapper.setProps({
|
||
workItems: [buildWorkItem('OT-FILE-ACTION', {
|
||
runNo: 'RUN-FILE-ACTION',
|
||
sourceSummary: { ...buildWorkItem('OT-FILE-ACTION').sourceSummary, documentId: 31 },
|
||
uiState: {
|
||
status: 'waiting_human', stage: 'order_review', lifecycleStage: 'order_review',
|
||
lifecycleEntries: [{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
|
||
blocking_reason: null,
|
||
primary_action: {
|
||
code: 'create_draft', i18nKey: null, parameters: {}, executionMode: 'navigate',
|
||
targetSurface: 'order_lifecycle_workbench', targetLifecycleStage: 'order_review',
|
||
},
|
||
secondary_actions: [],
|
||
},
|
||
})],
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(row.text()).toContain('创建草稿');
|
||
await row.find('button').trigger('click');
|
||
expect(wrapper.emitted('projectionAction')?.[0]?.[0]).toMatchObject({
|
||
item: { actionCode: 'create_draft' },
|
||
});
|
||
});
|
||
|
||
it('fails closed when a lifecycle entry has an unknown backend state', async () => {
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'processing', [{
|
||
...projection.status_groups!.processing[0],
|
||
user_task_no: 'OT-LIFECYCLE-UNKNOWN',
|
||
run_no: 'RUN-LIFECYCLE-UNKNOWN',
|
||
file_count: 1,
|
||
}]);
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: {
|
||
projection,
|
||
workbenchMode: true,
|
||
workItems: [buildWorkItem('OT-LIFECYCLE-UNKNOWN', {
|
||
runNo: 'RUN-LIFECYCLE-UNKNOWN',
|
||
sourceSummary: {
|
||
emailSubject: null,
|
||
filename: 'unknown-entry.pdf',
|
||
documentId: 10,
|
||
documentCount: 1,
|
||
parsedDocumentCount: 1,
|
||
candidateCount: 1,
|
||
customerName: null,
|
||
poNumber: 'PO-UNKNOWN',
|
||
},
|
||
uiState: {
|
||
status: 'running',
|
||
stage: 'inventory_match',
|
||
lifecycleStage: 'fulfillment_prep',
|
||
lifecycle_entries: [
|
||
{ code: 'order_review', state: 'paused', targetSurface: 'order_lifecycle_workbench' },
|
||
] as unknown as ShippingProcessingProjection['uiState']['lifecycleEntries'],
|
||
blocking_reason: null,
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
})],
|
||
},
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
const row = wrapper.find('[data-testid="shipping-processing-file-DOC-10"]');
|
||
expect(row.findAll('button')).toHaveLength(0);
|
||
});
|
||
|
||
it('shows a specific blocking reason once per waiting-human card without header duplication', async () => {
|
||
// v4 去重:具体原因由文件行页脚独家承载;任务卡头不再重复同一句。
|
||
// ui_state 挂在任务条目上(与后端 EML 聚合下发形态一致:任务级为代表子项原因)。
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'waiting_human', [{
|
||
user_task_no: 'OT-REASON-ONCE', group: 'waiting_human', status_label: 'pending_review',
|
||
file_count: 1, run_no: 'RUN-REASON-ONCE', can_append: false,
|
||
uiState: {
|
||
status: 'waiting_human',
|
||
stage: 'order_review',
|
||
blocking_reason: { code: 'customer_unresolved', message: '客户尚未确认' },
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
objects: [{
|
||
kind: 'document', object_key: 'DOC-REASON', label: 'reason.pdf', filename: 'reason.pdf',
|
||
document_id: 91, root_document_id: 91, status_label: 'pending_review',
|
||
}],
|
||
}]);
|
||
const workItem = buildWorkItem('OT-REASON-ONCE', {
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'reason.pdf', documentId: 91,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-REASON',
|
||
},
|
||
status: 'waiting_human',
|
||
uiState: {
|
||
status: 'waiting_human',
|
||
stage: 'order_review',
|
||
blocking_reason: { code: 'customer_unresolved', message: '客户尚未确认' },
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [workItem], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
// 关键断言:具体原因全文只出现一次,且带「阻塞原因:」前缀落在文件行页脚。
|
||
const matches = wrapper.text().match(/客户尚未确认/g) || [];
|
||
expect(matches.length).toBe(1);
|
||
expect(wrapper.text()).toContain('阻塞原因:客户尚未确认');
|
||
});
|
||
|
||
it('hides the blocker line when the backend only provides a generic fallback reason', async () => {
|
||
// v4:未知原因码不得渲染成「当前步骤需要人工处理」空话;状态芯片已表达待人工。
|
||
const projection = buildProjection();
|
||
setStatusGroup(projection, 'waiting_human', [{
|
||
user_task_no: 'OT-REASON-GENERIC', group: 'waiting_human', status_label: 'pending_review',
|
||
file_count: 1, run_no: 'RUN-REASON-GENERIC', can_append: false,
|
||
objects: [{
|
||
kind: 'document', object_key: 'DOC-GENERIC', label: 'generic.pdf', filename: 'generic.pdf',
|
||
document_id: 92, root_document_id: 92, status_label: 'pending_review',
|
||
}],
|
||
}]);
|
||
const workItem = buildWorkItem('OT-REASON-GENERIC', {
|
||
sourceSummary: {
|
||
emailSubject: null, filename: 'generic.pdf', documentId: 92,
|
||
documentCount: 1, parsedDocumentCount: 1, candidateCount: 1,
|
||
customerName: null, poNumber: 'PO-GENERIC',
|
||
},
|
||
status: 'waiting_human',
|
||
uiState: {
|
||
status: 'waiting_human',
|
||
stage: 'order_review',
|
||
blocking_reason: { code: 'mystery_internal_code' },
|
||
primary_action: null,
|
||
secondary_actions: [],
|
||
},
|
||
});
|
||
const wrapper = mount(ShippingConversationProcessingCard, {
|
||
props: { projection, workItems: [workItem], workbenchMode: true },
|
||
global: { plugins: [i18n] },
|
||
});
|
||
await flushPromises();
|
||
|
||
expect(wrapper.text()).not.toContain('阻塞原因');
|
||
expect(wrapper.text()).not.toContain('当前步骤需要人工处理');
|
||
});
|
||
});
|