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(' { 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")' ); });