Files
syops/frontend/src/features/admin/modules/freight-rpa/movementFieldLabels.spec.ts
T
hugoandCursor 4c2a7e2a23 feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-22 00:48:37 +08:00

50 lines
2.7 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/admin/modules/freight-rpa/movementFieldLabels.spec.ts
* 用途:锁定库存解析管理页「标准异动字段」标签映射与后端 MOVEMENT_FIELDS 契约一致。
* 依赖:vitest、四语言 locales 下各 admin.json。
* 逻辑:页面用 `movementFields.${item.code}` 动态取标签,code 集合由后端目录接口
* (movement_contract.MOVEMENT_FIELDS)在运行期下发,静态 i18n 工具查不出缺键——
* 后端扩字段而语言包未同步时,界面会把原始 key(如 admin.freightRpa.
* movementFields.order_type)直接渲染给用户(2026-10-15 实测回归)。
*/
import { describe, expect, it } from 'vitest';
import zhCN from '@/locales/zh-CN/admin.json';
import zhTW from '@/locales/zh-TW/admin.json';
import en from '@/locales/en/admin.json';
import th from '@/locales/th/admin.json';
// 后端权威契约:backend/app/services/in_transit_transfer/movement_contract.py MOVEMENT_FIELDS。
// ⚠️ 后端追加/删除异动字段时,必须同步此列表与四语言包 movementFields(i18n 四语言红线)。
const BACKEND_MOVEMENT_FIELD_CODES = [
'doc_no', 'line_no', 'in_out_flag', 'material_code', 'material_name',
'warehouse_code', 'storage_code', 'lot_no', 'quantity', 'movement_date', 'unit',
'line_seq', 'specification', 'order_type', 'odm_id', 'odm_name', 'carton_id', 'pallet_id',
'external_doc_no', 'external_line_no',
] as const;
const LABEL_MAPS: Record<string, Record<string, string>> = {
'zh-CN': (zhCN as Record<string, any>).freightRpa.movementFields,
'zh-TW': (zhTW as Record<string, any>).freightRpa.movementFields,
en: (en as Record<string, any>).freightRpa.movementFields,
th: (th as Record<string, any>).freightRpa.movementFields,
};
describe('movementFieldLabels', () => {
it('四语言 movementFields 与后端 MOVEMENT_FIELDS 契约逐键对齐', () => {
for (const [locale, labels] of Object.entries(LABEL_MAPS)) {
const codes = Object.keys(labels);
// 关键断言:不缺键(缺键=界面渲染原始 key)、不多键(多键=契约外死键误导维护者)。
expect(codes.sort(), `${locale} 缺键/多键`).toEqual([...BACKEND_MOVEMENT_FIELD_CODES].sort());
// 关键断言:每个标签都是非空真实文案,防止键在但值为空。
for (const code of codes) expect(labels[code].trim().length, `${locale}.${code}`).toBeGreaterThan(0);
}
});
it('四语言之间标签键集互相同步(防单语言先行漂移)', () => {
const keySets = Object.values(LABEL_MAPS).map((labels) => Object.keys(labels).sort());
// 关键断言:任一语言补键时必须四语言同时补齐。
for (const keySet of keySets.slice(1)) expect(keySet).toEqual(keySets[0]);
});
});