Files
syops/frontend/src/features/shipping-progress/gateReasonLabel.spec.ts
T

67 lines
2.8 KiB
TypeScript

/**
* features/shipping-progress/gateReasonLabel.spec.ts
* 用途:验收「当前需要」文案优先级 C(blockingReason → nextAction)。
* 依赖:Vitest、gateReasonLabel。
* 逻辑:有 reason 用 gateReasons;仅有 action 用 processGate.actions;均无则空串。
*/
import { describe, expect, it } from 'vitest';
import { resolveCurrentNeedLabel, resolveGateReasonLabel } from './gateReasonLabel';
function makeI18n(messages: Record<string, string>) {
return {
te: (key: string) => Object.prototype.hasOwnProperty.call(messages, key),
t: (key: string) => messages[key] || key,
};
}
describe('gateReasonLabel', () => {
it('resolveGateReasonLabel prefers shippingProcessing.gateReasons', () => {
const i18n = makeI18n({
'chat.shippingProcessing.gateReasons.customer_unresolved': '确认客户',
'chat.shippingProcessing.gateReasons.generic': '需要处理',
});
expect(resolveGateReasonLabel('customer_unresolved', i18n)).toBe('确认客户');
});
it('resolveGateReasonLabel uses the existing Process Gate reason label', () => {
const i18n = makeI18n({
'workspace.shippingNotice.processGate.reasons.inventory_shortage_review_required': '存在库存缺口,需要人工处理',
'chat.shippingProcessing.gateReasons.generic': '需要处理',
});
// 当前任务卡和进度条必须共用该映射,不能把后端原因码直接展示给用户。
expect(resolveGateReasonLabel('inventory_shortage_review_required', i18n)).toBe('存在库存缺口,需要人工处理');
});
it('resolveCurrentNeedLabel uses blockingReasonCode first', () => {
const i18n = makeI18n({
'chat.shippingProcessing.gateReasons.customer_unresolved': '确认客户',
'workspace.shippingNotice.processGate.actions.confirm_customer': '确认客户(动作)',
'chat.shippingProcessing.gateReasons.generic': '需要处理',
});
expect(resolveCurrentNeedLabel({
blockingReasonCode: 'customer_unresolved',
nextActionCode: 'confirm_customer',
}, i18n)).toBe('确认客户');
});
it('resolveCurrentNeedLabel falls back to nextActionCode when reason missing', () => {
const i18n = makeI18n({
'workspace.shippingNotice.processGate.actions.retry_freight_upload_rpa': '重试货代上传',
'chat.shippingProcessing.gateReasons.generic': '需要处理',
});
expect(resolveCurrentNeedLabel({
blockingReasonCode: null,
nextActionCode: 'retry_freight_upload_rpa',
}, i18n)).toBe('重试货代上传');
});
it('resolveCurrentNeedLabel returns empty when gate empty', () => {
const i18n = makeI18n({
'chat.shippingProcessing.gateReasons.generic': '需要处理',
});
expect(resolveCurrentNeedLabel(null, i18n)).toBe('');
expect(resolveCurrentNeedLabel({ blockingReasonCode: '', nextActionCode: '' }, i18n)).toBe('');
});
});