文件
OmniCard/admin/tests/ai-translation.test.ts
wikiboss eec259a3a7 feat: 完成全系统30个功能点开发与E2E全链路验收 (8轮调度32个子代理闭环)
- 模块一: 出海案例作品集、博客动态发布、人名发音语音条、RTL阿语多语言切换
- 模块二: AI顾问人设配置、行业术语库润色、RAG切片沙盒调试、流式会话与意向留资卡片
- 模块三: 全球访客雷达大屏、多维加权意向算分、外部CRM对接推送、团队公海池流转
- 模块四: 移动端NFC安全挂失、NFC动态路由规则配置、动态防伪验签、展会制卡Zip批量导出
- 模块五: 组织架构与名片分配、移动端个人中心设置、离职交接与历史线索迁移、安全审计日志
- 模块六: Stripe国际信用卡订阅Webhook、独立二级域名与SSL检测、坐席配额预警、多币种发票
- 模块七: 纸质名片OCR解析入库、国际商务日程RFC 5545 ICS日历、微官网离线SWR预加载、展会实时排行榜大屏
- 模块八: 全球出海SEO OpenGraph元标签注入与社交爬虫探测、30点端到端全链路业务流集成测试套件
2026-09-20 23:47:47 +08:00

121 行
5.7 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import defaultI18n from '../src/locale/index.ts';
const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const translationPagePath = path.join(adminRoot, 'src/pages/ai/translation/index.tsx');
const translationLocalePath = path.join(adminRoot, 'src/pages/ai/translation/locale/index.ts');
const routesPath = path.join(adminRoot, 'src/routes.ts');
test('1. 路由与主词典必须注册 ai/translation 与 menu.ai.translation', () => {
assert.ok(fs.existsSync(routesPath), 'routes.ts 必须存在');
const routesContent = fs.readFileSync(routesPath, 'utf-8');
assert.ok(
routesContent.includes("'ai/translation'") || routesContent.includes('"ai/translation"'),
'routes.ts 必须注册 key 为 ai/translation 的路由'
);
assert.ok(
routesContent.includes("'menu.ai.translation'") || routesContent.includes('"menu.ai.translation"'),
'routes.ts 必须注册 name 为 menu.ai.translation'
);
assert.ok(defaultI18n['en-US']['menu.ai.translation'], '主词典 en-US 必须包含 menu.ai.translation');
assert.ok(defaultI18n['zh-CN']['menu.ai.translation'], '主词典 zh-CN 必须包含 menu.ai.translation');
});
test('2. ai/translation 国际化语言包必须包含中英文案且零 any', () => {
assert.ok(fs.existsSync(translationLocalePath), '翻译页面语言包必须存在');
const localeContent = fs.readFileSync(translationLocalePath, 'utf-8');
assert.ok(localeContent.includes("'en-US'"), '必须包含 en-US 词条');
assert.ok(localeContent.includes("'zh-CN'"), '必须包含 zh-CN 词条');
assert.ok(localeContent.includes('aiTranslation.playground.submit'), '必须包含试炼器提交按钮文案');
assert.ok(localeContent.includes('aiTranslation.glossary.action.add'), '必须包含术语库添加按钮文案');
assert.ok(localeContent.includes('aiTranslation.glossary.columns.sourceTerm'), '必须包含源术语表头文案');
assert.ok(localeContent.includes('aiTranslation.glossary.columns.targetTerm'), '必须包含目标术语表头文案');
assert.ok(!/\bany\b/.test(localeContent), 'locale 文件禁止使用 any');
});
test('3. ai/translation 页面必须实现实时润色与术语库管理,使用 Arco 组件与规范 API', () => {
assert.ok(fs.existsSync(translationPagePath), '润色中心页面必须存在');
const content = fs.readFileSync(translationPagePath, 'utf-8');
// Arco 组件库引入
assert.ok(
content.includes("from '@arco-design/web-react'"),
'必须从 @arco-design/web-react 引入组件'
);
assert.ok(content.includes('Table'), '必须使用 Arco Table');
assert.ok(content.includes('Form'), '必须使用 Arco Form');
assert.ok(content.includes('Modal'), '必须使用 Arco Modal');
assert.ok(content.includes('Select'), '必须使用 Arco Select');
assert.ok(content.includes('Tag'), '必须使用 Arco Tag');
assert.ok(content.includes('Input'), '必须使用 Arco Input');
assert.ok(content.includes('Popconfirm'), '必须使用 Arco Popconfirm');
assert.ok(content.includes('Upload'), '必须使用 Arco Upload 实现批量导入');
// 接口请求
assert.ok(
content.includes('/api/admin/ai/localize/localize') || content.includes('admin/ai/localize/localize'),
'必须调用润色接口 /api/admin/ai/localize/localize'
);
assert.ok(
content.includes('admin/ai/glossary/page'),
'必须请求术语库分页接口 /api/admin/ai/glossary/page'
);
assert.ok(
content.includes('admin/ai/glossary/add'),
'必须请求术语库新增接口 /api/admin/ai/glossary/add'
);
assert.ok(
content.includes('admin/ai/glossary/update'),
'必须请求术语库更新接口 /api/admin/ai/glossary/update'
);
assert.ok(
content.includes('admin/ai/glossary/delete'),
'必须请求术语库删除接口 /api/admin/ai/glossary/delete'
);
assert.ok(
content.includes('admin/ai/glossary/batchImport'),
'必须请求术语库批量导入接口 /api/admin/ai/glossary/batchImport'
);
// 业务契约复用与规范
assert.ok(
content.includes("from '@/types/omni'"),
'必须复用 admin/src/types/omni.ts 中的契约类型'
);
assert.ok(content.includes('AiGlossaryItem'), '必须使用 AiGlossaryItem 契约类型');
assert.ok(
content.includes('code === 1000') || content.includes('code ===1000'),
'必须按 Cool-Admin code === 1000 规范判断响应成功'
);
assert.ok(content.includes('Message.error'), '错误提示必须使用 Arco Message.error');
assert.ok(!content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js 假数据冒充成功');
assert.ok(!content.includes('<Pagination'), '禁止手写分页器,必须使用 Table 自带分页');
});
test('4. 必须遵守瑞士国际主义设计规范与 Token 约束 (零 emoji, 零 any, 零硬编码颜色)', () => {
const content = fs.readFileSync(translationPagePath, 'utf-8');
assert.ok(!/\bany\b/.test(content), '页面严禁使用 any 类型');
assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors token');
assert.ok(!/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码 HEX 颜色');
// 禁止 emoji (常见 emoji Unicode 范围)
const emojiRegex = /[\u{1F300}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u;
assert.ok(!emojiRegex.test(content), '页面禁止包含任何 emoji 表情符号');
// 确保只有一个主 CTA (type="primary")
const primaryButtonMatches = content.match(/type="primary"/g) || [];
assert.equal(
primaryButtonMatches.length,
1,
'瑞士国际主义风格约束:整屏只允许 1 个主 CTA (type="primary")'
);
});