feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -0,0 +1,318 @@
/**
* features/chat/components/shipping/ShippingConversationProcessingCard.spec.ts
* 用途:验收右侧任务分组卡——needs_action/processing 与短时反馈标签。
* 依赖:Vitest、Vue Test Utils、vue-i18n、ShippingConversationProcessingCard。
* 逻辑:构造 ConversationProcessingProjection;断言分组、焦点 emit;右侧不渲染 history。
*/
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 } 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 {
return {
summary: { total_tasks: 3, processing: 1, needs_action: 1, completed: 1, history: 0 },
focused_task_no: 'OT-PROC',
recent_task_no: 'OT-PROC',
needs_action: [{
user_task_no: 'OT-NEED',
group: 'needs_action',
status_label: 'pending_review',
file_count: 2,
run_no: 'RUN-NEED',
can_append: false,
recently_created: false,
}],
processing: [{
user_task_no: 'OT-PROC',
submission_ordinal: 2,
group: 'processing',
status_label: 'extracting',
file_count: 1,
run_no: 'RUN-PROC',
can_append: true,
recently_created: true,
focused: true,
}],
completed: [{
user_task_no: 'OT-DONE',
group: 'completed',
status_label: 'completed',
title: 'done.pdf',
file_count: 1,
run_no: 'RUN-DONE',
can_append: false,
available_actions: ['view_details'],
}],
history: [{
user_task_no: 'OT-HIST',
group: 'history',
status_label: 'completed',
file_count: 1,
run_no: 'RUN-HIST',
can_append: false,
viewed: true,
}],
};
}
describe('ShippingConversationProcessingCard', () => {
it('renders needs_action / processing / completed groups, hides history on the right panel', 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-needs_action"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-group-processing"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-group-completed"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-task-OT-PROC"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-task-OT-DONE"]').exists()).toBe(true);
expect(wrapper.text()).toContain('刚刚创建');
expect(wrapper.text()).toContain('已完成');
// UI-04:右侧不展示处理记录分组。
expect(wrapper.find('[data-testid="shipping-processing-group-history"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="shipping-processing-task-OT-HIST"]').exists()).toBe(false);
});
it('renders multi-PDF task title instead of first filename', async () => {
const wrapper = mount(ShippingConversationProcessingCard, {
props: {
projection: {
summary: { total_tasks: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
needs_action: [{
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'],
}],
processing: [],
completed: [],
history: [],
},
},
global: { plugins: [i18n] },
});
await flushPromises();
expect(wrapper.text()).toContain('订单识别任务');
expect(wrapper.text()).toContain('2 个 PDF');
expect(wrapper.text()).toContain('4518838152.pdf、4518838154.pdf');
expect(wrapper.text()).toContain('取消整个任务');
// 主标题不得单独伪装成首个 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('shows multi-document title from authoritative projection without workflow fallback', async () => {
const wrapper = mount(ShippingConversationProcessingCard, {
props: {
projection: {
summary: { total_tasks: 1, total_files: 2, processing: 0, needs_action: 1, completed: 0, history: 0 },
needs_action: [{
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: [],
}],
processing: [],
completed: [],
history: [],
},
},
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('falls back to unnamed PDF instead of internal OT number', async () => {
const wrapper = mount(ShippingConversationProcessingCard, {
props: {
projection: {
summary: { total_tasks: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
needs_action: [],
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: [],
history: [],
},
},
global: { plugins: [i18n] },
});
await flushPromises();
expect(wrapper.text()).toContain('未命名 PDF');
expect(wrapper.text()).not.toContain('20260803-A13F95D2');
});
it('emits focus only when selecting a task (not viewed)', 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.emitted('focus')?.[0]).toEqual(['OT-NEED']);
expect(wrapper.emitted('viewed')).toBeUndefined();
expect(wrapper.emitted('expandFiles')).toBeUndefined();
});
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"]');
// 关键断言:待操作聚焦卡必须有用户可见 ring,不能只写 data-focused。
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(),
needs_action: [{
...buildProjection().needs_action[0],
available_actions: ['view_details', 'open_review', 'cancel_task'],
}],
},
},
global: { plugins: [i18n] },
});
await flushPromises();
const taskRoot = wrapper.find('[data-testid="shipping-processing-task-OT-NEED"]');
const buttons = taskRoot.findAll('button');
// 最后一个按钮是展开/收起文件详情
await buttons[buttons.length - 1].trigger('click');
expect(wrapper.emitted('expandFiles')?.[0]?.[0]).toMatchObject({ user_task_no: 'OT-NEED' });
await buttons[buttons.length - 1].trigger('click');
expect(wrapper.emitted('collapseFiles')).toBeTruthy();
});
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: {
summary: { total_tasks: 20, processing: 20, needs_action: 0, history: 0 },
needs_action: [],
processing,
history: [],
},
},
global: { plugins: [i18n] },
});
await flushPromises();
expect(wrapper.findAll('[data-testid^="shipping-processing-task-"]')).toHaveLength(20);
expect(wrapper.findAll('[data-testid="shipping-conversation-processing-card"]')).toHaveLength(1);
});
it('renders pending order_intake work items above task groups', async () => {
const wrapper = mount(ShippingConversationProcessingCard, {
props: {
projection: null,
workItems: [{
workItemType: 'order_intake',
workItemNo: 'SNI-1',
sourceType: 'direct_pdf',
rootOrderTaskNo: null,
shippingNoticeNo: null,
conversationId: 'conv-1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: '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'],
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-order-intake"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-processing-intake-SNI-1"]').exists()).toBe(true);
expect(wrapper.text()).toContain('po.pdf');
// 关键断言:失败恢复元信息(原因 / Attempt / 资产)出现在材料卡。
expect(wrapper.find('[data-testid="shipping-processing-intake-recovery"]').exists()).toBe(true);
expect(wrapper.text()).toContain('SHIPPING_NOTICE.INTAKE_PARSE_FAILED');
await wrapper.find('[data-testid="shipping-processing-intake-action-retry_parse"]').trigger('click');
expect(wrapper.emitted('intakeAction')?.[0]?.[0]).toMatchObject({
action: 'retry_parse',
item: { workItemNo: 'SNI-1' },
});
});
});