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'; const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const financialPagePath = path.join(adminRoot, 'src/pages/dashboard/financial/index.tsx'); const financialLocalePath = path.join(adminRoot, 'src/pages/dashboard/financial/locale/index.ts'); const mainLocalePath = path.join(adminRoot, 'src/locale/index.ts'); const routesPath = path.join(adminRoot, 'src/routes.ts'); const EMOJI_RE = /[\u{1F300}-\u{1F5FF}\u{1F600}-\u{1F64F}\u{1F680}-\u{1F6FF}\u{1F700}-\u{1F77F}\u{1F780}-\u{1F7FF}\u{1F800}-\u{1F8FF}\u{1F900}-\u{1F9FF}\u{1FA00}-\u{1FA6F}\u{1FA70}-\u{1FAFF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u; test('1. routes.ts 必须在 dashboard 下注册 dashboard/financial 且未被 ignore', () => { const content = fs.readFileSync(routesPath, 'utf-8'); assert.ok(content.includes("key: 'dashboard/financial'"), '必须注册 dashboard/financial'); assert.ok( !/key:\s*'dashboard\/financial'[\s\S]{0,80}ignore:\s*true/.test(content), 'financial 路由必须在侧边栏正常展示' ); }); test('2. 主词典与多语言包必须包含 menu.dashboard.financial 翻译', () => { const content = fs.readFileSync(mainLocalePath, 'utf-8'); assert.ok( content.includes("'menu.dashboard.financial'"), '主词典必须包含 menu.dashboard.financial 词条' ); }); test('3. dashboard/financial 页面必须存在,且具备 COO/CFO 视角切换与 API 对接', () => { assert.ok(fs.existsSync(financialPagePath), '必须存在 financial/index.tsx 页面'); const content = fs.readFileSync(financialPagePath, 'utf-8'); // 必须请求商业化分析接口 assert.ok( content.includes('/admin/team/billing/analytics') || content.includes('team/billing/analytics'), '必须调用 /admin/team/billing/analytics 统计接口' ); // 必须具备运营官 (coo) 与财务官 (cfo) 双视角 assert.ok( content.includes("'coo'") && content.includes("'cfo'"), '页面必须支持 coo 与 cfo 视角状态切换' ); assert.ok(!content.includes('14500'), '禁止硬编码演示 MRR'); assert.ok(!content.includes('Vanguard Global'), '禁止硬编码演示账单'); // 必须使用 Arco 核心组件 assert.ok(content.includes('@arco-design/web-react'), '必须引入 Arco Design'); assert.ok(content.includes('Table'), '必须包含 Table 表格展示账目流水'); assert.ok(content.includes('Statistic'), '必须包含 Statistic 核心指标统计组件'); assert.ok(content.includes('Card'), '必须使用 Card 卡片容器'); }); test('4. dashboard/financial 必须遵循瑞士国际主义设计规范、Token 与零 any、零 emoji 约束', () => { const pageContent = fs.readFileSync(financialPagePath, 'utf-8'); const localeContent = fs.readFileSync(financialLocalePath, 'utf-8'); // 零 any assert.ok(!/\bany\b/.test(pageContent), '页面中严禁使用 any 类型'); assert.ok(!/\bany\b/.test(localeContent), '语言包中严禁使用 any 类型'); // 零 emoji assert.ok(!EMOJI_RE.test(pageContent), '页面中严禁使用 emoji 符号'); assert.ok(!EMOJI_RE.test(localeContent), '语言包中严禁使用 emoji 符号'); // 单一主 CTA (如导出对账单按钮为唯一的 type="primary") const primaryButtons = pageContent.match(/type=["']primary["']/g) || []; assert.ok( primaryButtons.length <= 1, `一屏只允许最多 1 个主 CTA 按钮,当前包含: ${primaryButtons.length}` ); }); test('5. 专属语言包 financial/locale/index.ts 必须完备覆盖 COO 与 CFO 专业词汇', () => { assert.ok(fs.existsSync(financialLocalePath), '必须存在 financial/locale/index.ts'); const localeContent = fs.readFileSync(financialLocalePath, 'utf-8'); // 核心字段涵盖 assert.ok(localeContent.includes('cooView'), '必须包含运营官视角词条'); assert.ok(localeContent.includes('cfoView'), '必须包含财务官视角词条'); assert.ok(localeContent.includes('mrr'), '必须包含 MRR 词条'); assert.ok(localeContent.includes('totalInvoiced'), '必须包含开票总额词条'); assert.ok(localeContent.includes('agingAnalysis'), '必须包含账龄分析词条'); });