sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import { createInstance } from 'i18next';
|
||||
import { LANGUAGE_CODES } from '../../i18n/catalog.js';
|
||||
import {
|
||||
commissionLabel,
|
||||
commissionLabels,
|
||||
commissionLevelName,
|
||||
commissionActorName,
|
||||
} from './labels.js';
|
||||
|
||||
const resources = Object.fromEntries(
|
||||
LANGUAGE_CODES.map((code) => [
|
||||
code,
|
||||
JSON.parse(
|
||||
readFileSync(
|
||||
new URL(`../../i18n/locales/${code}.json`, import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
|
||||
test('audit operators show account names, distinguish system actions and missing accounts', () => {
|
||||
const t = (key) => key;
|
||||
assert.equal(
|
||||
commissionActorName(t, { actor_id: 5, actor_username: 'admin.account' }),
|
||||
'admin.account',
|
||||
);
|
||||
assert.equal(commissionActorName(t, { actor_id: 0 }), '系统');
|
||||
assert.equal(commissionActorName(t, { actor_id: '0' }), '系统');
|
||||
assert.equal(commissionActorName(t, { actor_id: 99 }), '未知用户');
|
||||
assert.equal(commissionActorName(t, {}), '未知用户');
|
||||
});
|
||||
|
||||
test('commission labels follow the selected language and preserve custom values', async () => {
|
||||
const i18n = createInstance();
|
||||
await i18n.init({
|
||||
lng: 'zh',
|
||||
resources,
|
||||
fallbackLng: false,
|
||||
keySeparator: false,
|
||||
nsSeparator: false,
|
||||
});
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'default'), '默认');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'standard'), '标准');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'premium'), '高级');
|
||||
assert.equal(commissionLabel(i18n.t, 'operation', 'fee_set'), '录入手续费');
|
||||
for (const [action, expected] of Object.entries({
|
||||
ADJ_CREATED: '创建调整单',
|
||||
ADJ_UPDATED: '修改调整单',
|
||||
ADJ_DELETED: '作废调整单',
|
||||
BILL_CREATED: '新增',
|
||||
BILL_ISSUED: '正式出账',
|
||||
FEE_ENTERED: '录入手续费',
|
||||
PAID_REGISTERED: '登记已打款',
|
||||
PARTNER_CONFIRMED: '伙伴确认',
|
||||
PARTNER_REJECTED: '伙伴驳回',
|
||||
AUTO_CONFIRMED: '逾期视同确认',
|
||||
BLOCK_DETECTED: '出账阻断',
|
||||
BLOCK_CLEARED: '解除出账阻断',
|
||||
DEADLINE_CHANGED: '修改确认截止日期',
|
||||
RECALC: '刷新金额',
|
||||
})) {
|
||||
assert.equal(commissionLabel(i18n.t, 'operation', action), expected);
|
||||
}
|
||||
await i18n.changeLanguage('en');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'default'), 'Default');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'premium'), 'Premium');
|
||||
assert.equal(commissionLabel(i18n.t, 'status', 'active'), 'Active');
|
||||
assert.equal(commissionLabel(i18n.t, 'operation', 'fee_set'), 'Set fee');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'VIP-custom'), 'VIP-custom');
|
||||
assert.equal(
|
||||
commissionLabel(i18n.t, 'operation', 'new_action'),
|
||||
'new_action',
|
||||
);
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'toString'), 'toString');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', null), '-');
|
||||
assert.equal(
|
||||
commissionLevelName(i18n.t, { key: 'default', name: 'default' }),
|
||||
'Default',
|
||||
);
|
||||
assert.equal(
|
||||
commissionLevelName(i18n.t, { key: 'default', name: '定制等级' }),
|
||||
'定制等级',
|
||||
);
|
||||
await i18n.changeLanguage('zh-TW');
|
||||
assert.equal(commissionLabel(i18n.t, 'level', 'default'), '預設');
|
||||
});
|
||||
|
||||
test('every supported language has non-empty commission enum translations', () => {
|
||||
for (const code of LANGUAGE_CODES) {
|
||||
for (const labels of Object.values(commissionLabels)) {
|
||||
for (const key of Object.values(labels)) {
|
||||
assert.ok(
|
||||
resources[code].translation[key]?.trim(),
|
||||
`${code} is missing ${key}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('commission page translations retain interpolation variables in every language', () => {
|
||||
const source = ['index.jsx', 'operations.jsx']
|
||||
.map((file) => readFileSync(new URL(`./${file}`, import.meta.url), 'utf8'))
|
||||
.join('\n');
|
||||
const keys = new Set(
|
||||
[...source.matchAll(/\bt\('([^']+)'/gu)].map((match) => match[1]),
|
||||
);
|
||||
const variables = (text) =>
|
||||
[...text.matchAll(/\{\{(\w+)\}\}/gu)].map((match) => match[1]).sort();
|
||||
for (const code of LANGUAGE_CODES) {
|
||||
for (const key of keys) {
|
||||
const translated = resources[code].translation[key];
|
||||
assert.ok(translated?.trim(), `${code} is missing ${key}`);
|
||||
assert.deepEqual(
|
||||
variables(translated),
|
||||
variables(key),
|
||||
`${code}: ${key}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user