83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
/**
|
|
* features/shipping-notice/shippingI18nParity.spec.ts
|
|
* 用途:验证货代发货通知业务域在四种语言中的文案键保持一致。
|
|
* 依赖:admin/chat/workspace 四语言 JSON;只检查货代业务子树,不受其他历史业务域影响。
|
|
* 逻辑:递归收集叶子键并比较集合;覆盖 Schema/库存/聊天通知/会话摘要/工作台待办。
|
|
*/
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import adminEn from '@/locales/en/admin.json';
|
|
import adminTh from '@/locales/th/admin.json';
|
|
import adminZhCn from '@/locales/zh-CN/admin.json';
|
|
import adminZhTw from '@/locales/zh-TW/admin.json';
|
|
import chatEn from '@/locales/en/chat.json';
|
|
import chatTh from '@/locales/th/chat.json';
|
|
import chatZhCn from '@/locales/zh-CN/chat.json';
|
|
import chatZhTw from '@/locales/zh-TW/chat.json';
|
|
import workspaceEn from '@/locales/en/workspace.json';
|
|
import workspaceTh from '@/locales/th/workspace.json';
|
|
import workspaceZhCn from '@/locales/zh-CN/workspace.json';
|
|
import workspaceZhTw from '@/locales/zh-TW/workspace.json';
|
|
|
|
type LocaleTree = Record<string, unknown>;
|
|
|
|
const leafKeys = (value: unknown, prefix = ''): string[] => {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return [prefix];
|
|
return Object.entries(value as LocaleTree).flatMap(([key, child]) => (
|
|
leafKeys(child, prefix ? `${prefix}.${key}` : key)
|
|
));
|
|
};
|
|
|
|
const expectSameKeys = (trees: LocaleTree[]) => {
|
|
const expected = leafKeys(trees[0]).sort();
|
|
trees.slice(1).forEach((tree) => expect(leafKeys(tree).sort()).toEqual(expected));
|
|
};
|
|
|
|
describe('shipping notice i18n parity', () => {
|
|
it('keeps admin order schema keys aligned', () => {
|
|
expectSameKeys([
|
|
adminZhCn.shippingOrderSchema as LocaleTree,
|
|
adminZhTw.shippingOrderSchema as LocaleTree,
|
|
adminEn.shippingOrderSchema as LocaleTree,
|
|
adminTh.shippingOrderSchema as LocaleTree,
|
|
]);
|
|
});
|
|
|
|
it('keeps admin inventory configuration keys aligned', () => {
|
|
expectSameKeys([
|
|
adminZhCn.shippingInventory as LocaleTree,
|
|
adminZhTw.shippingInventory as LocaleTree,
|
|
adminEn.shippingInventory as LocaleTree,
|
|
adminTh.shippingInventory as LocaleTree,
|
|
]);
|
|
});
|
|
|
|
it('keeps chat shipping notice keys aligned', () => {
|
|
expectSameKeys([
|
|
chatZhCn.shippingNotice as LocaleTree,
|
|
chatZhTw.shippingNotice as LocaleTree,
|
|
chatEn.shippingNotice as LocaleTree,
|
|
chatTh.shippingNotice as LocaleTree,
|
|
]);
|
|
});
|
|
|
|
it('keeps chat shipping session summary keys aligned', () => {
|
|
expectSameKeys([
|
|
chatZhCn.shippingSessionSummary as LocaleTree,
|
|
chatZhTw.shippingSessionSummary as LocaleTree,
|
|
chatEn.shippingSessionSummary as LocaleTree,
|
|
chatTh.shippingSessionSummary as LocaleTree,
|
|
]);
|
|
});
|
|
|
|
it('keeps workspace shipping notice keys aligned', () => {
|
|
expectSameKeys([
|
|
workspaceZhCn.shippingNotice as LocaleTree,
|
|
workspaceZhTw.shippingNotice as LocaleTree,
|
|
workspaceEn.shippingNotice as LocaleTree,
|
|
workspaceTh.shippingNotice as LocaleTree,
|
|
]);
|
|
});
|
|
});
|