Files
syops/frontend/src/features/chat/shipping/orderExtractionProgressDisplay.spec.ts
T

46 lines
2.2 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/chat/shipping/orderExtractionProgressDisplay.spec.ts
* 用途:校验进度展示纯函数不发明阶段码,并正确格式化耗时。
* 依赖:Vitest、orderExtractionProgressDisplay。
* 逻辑:覆盖空值、秒/分/小时格式,以及 stage key 回退路径。
*/
import { describe, expect, it } from 'vitest';
import {
formatOrderExtractionElapsed,
resolveOrderExtractionRunStageKey,
resolveOrderExtractionUserStageKey,
} from './orderExtractionProgressDisplay';
describe('orderExtractionProgressDisplay', () => {
it('formats elapsed seconds without inventing ETA', () => {
expect(formatOrderExtractionElapsed(null)).toBe('');
expect(formatOrderExtractionElapsed(12)).toBe('12s');
expect(formatOrderExtractionElapsed(75)).toBe('1m 15s');
expect(formatOrderExtractionElapsed(3600)).toBe('1h');
});
it('prefers user_visible_stage over document status for i18n keys', () => {
expect(resolveOrderExtractionUserStageKey('extracting', 'pending')).toBe(
'chat.shippingOrderExtractionUserStage.extracting',
);
expect(resolveOrderExtractionUserStageKey(null, 'routing')).toBe(
'chat.shippingOrderExtractionDocumentStatus.routing',
);
});
});
describe('resolveOrderExtractionRunStageKey(v2 输出不变契约)', () => {
it('与改造前页面内联字面量逐字一致', () => {
// 关键断言:有 stage → UserStage key(与原 `chat.shippingOrderExtractionUserStage.${stage}` 完全一致)
expect(resolveOrderExtractionRunStageKey('layout_parsing_started', 'processing'))
.toBe('chat.shippingOrderExtractionUserStage.layout_parsing_started');
expect(resolveOrderExtractionRunStageKey('review_required', 'review_required'))
.toBe('chat.shippingOrderExtractionUserStage.review_required');
// 关键断言:无 stage → CardTitle key(与原 `chat.shippingOrderExtractionCardTitle.${status}` 完全一致)
expect(resolveOrderExtractionRunStageKey(null, 'completed'))
.toBe('chat.shippingOrderExtractionCardTitle.completed');
expect(resolveOrderExtractionRunStageKey(undefined, 'failed'))
.toBe('chat.shippingOrderExtractionCardTitle.failed');
});
});