Files
syops/frontend/src/features/shipping-progress/progressWindow.spec.ts
T
hugoandCursor 84a881b554 feat(shipping-notice): 落地 XFA 统一视觉拆分确认门禁与处理投影收敛
闭合拆分预览令牌单次消费、样本 checksum 绑定与确认审计;正式提取改为 bindings-only。
同步统一标注工作台交互,并补齐进度投影/任务中心与迁移文档。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-06 10:21:25 +08:00

122 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* features/shipping-progress/progressWindow.spec.ts
* 用途:验收密度窗口切分、stageNodes 优先与范围摘要。
*/
import { describe, expect, it } from 'vitest';
import type { ShippingProcessingProjection } from '@/features/chat/types/shipping.api.types';
import {
buildProgressRangeHint,
buildProgressWindow,
buildReviewProgressDomainSummary,
computeProgressWindowRange,
resolveStageNodeStatus,
stageAbsoluteIndex,
} from './progressWindow';
function baseProjection(
overrides: Partial<ShippingProcessingProjection> = {},
): ShippingProcessingProjection {
return {
workItemType: 'order_task',
workItemNo: 'OT-1',
sourceType: 'eml',
rootOrderTaskNo: 'OT-1',
shippingNoticeNo: null,
conversationId: 'c1',
submissionNo: 'SOS-1',
intakeNo: 'SNI-1',
status: 'blocked',
stage: 'inventory_source_resolving',
progressVersion: 1,
lastActivityAt: '2026-08-05T00:00:00Z',
currentGate: null,
availableActions: [],
sourceSummary: {
emailSubject: null,
filename: 'a.pdf',
documentCount: 1,
parsedDocumentCount: 1,
candidateCount: 1,
customerName: null,
poNumber: null,
},
childOrderTasks: [],
...overrides,
};
}
describe('progressWindow', () => {
it('anchors inventory_source_resolving at index 7', () => {
expect(stageAbsoluteIndex('inventory_source_resolving')).toBe(7);
});
it('workbench shows all 15 stages', () => {
const nodes = buildProgressWindow(baseProjection({ sourceType: 'eml' }), 'workbench');
expect(nodes).toHaveLength(15);
expect(nodes[7]?.isCurrent).toBe(true);
expect(nodes[7]?.status).toBe('blocked');
});
it('chat window stays within 3–5 visible nodes', () => {
const nodes = buildProgressWindow(baseProjection(), 'chat');
expect(nodes.length).toBeGreaterThanOrEqual(3);
expect(nodes.length).toBeLessThanOrEqual(5);
expect(nodes.some((n) => n.isCurrent)).toBe(true);
});
it('marks EML-only stages skipped for direct_pdf', () => {
const status = resolveStageNodeStatus({
absoluteIndex: 1,
currentIndex: 7,
projectionStatus: 'processing',
sourceType: 'direct_pdf',
stage: 'email_parsing',
});
expect(status).toBe('skipped');
});
it('centers window around current index', () => {
const { start, end } = computeProgressWindowRange(7, 'right', 15);
expect(end - start).toBe(6);
expect(start).toBeLessThanOrEqual(7);
expect(end).toBeGreaterThan(7);
});
it('prefers backend stageNodes status over index heuristic', () => {
const nodes = buildProgressWindow(baseProjection({
stage: 'inventory_source_resolving',
status: 'processing',
stageNodes: [
{ stage: 'upload_received', absoluteIndex: 0, status: 'passed' },
{ stage: 'inventory_source_resolving', absoluteIndex: 7, status: 'failed' },
],
}), 'workbench');
expect(nodes[7]?.status).toBe('failed');
});
it('buildProgressRangeHint returns done/total and current label key', () => {
const hint = buildProgressRangeHint(baseProjection({
stage: 'waiting_review',
status: 'waiting_review',
}), 'review');
expect(hint).not.toBeNull();
expect(hint!.currentLabelKey).toBe('chat.shippingProcessing.stage.waiting_review');
expect(hint!.total).toBeGreaterThan(0);
expect(hint!.done).toBeGreaterThanOrEqual(0);
});
it('buildReviewProgressDomainSummary maps waiting_review into order_confirm blocked', () => {
const domains = buildReviewProgressDomainSummary(baseProjection({
stage: 'waiting_review',
status: 'blocked',
}));
expect(domains).toHaveLength(5);
expect(domains[0]?.state).toBe('passed');
expect(domains[1]?.state).toBe('passed');
expect(domains[2]?.key).toBe('order_confirm');
expect(domains[2]?.state).toBe('blocked');
expect(domains[3]?.state).toBe('pending');
});
});