文件
OmniCard/admin/tests/dashboard-financial.test.ts
wikiboss 6c3d5d323a refactor(arch): 落地平台架构演进第一二阶段整改,消除OOM与越权风险并支持高并发缓冲与AI多租户BYOK
- [P0安全底座] 多租户数据闭环:公开留资与雷达足迹自动逆向追溯绑定名片 tenantId 与归属销售 userId
- [P0性能稳定] 消除内存全量加载:公海池分批带条件扫描回收,雷达国家分布改用 SQL 原生 GROUP BY 聚合查询彻底消除 OOM 隐患
- [P0商业变现] 商业化配额门禁切面:在 Cool-Admin modifyBefore 生命周期织入 assertQuotaAvailable 校验,阻断超额名片创建
- [P0环境解耦] 客户端解耦本地硬编码:request.uts 支持 api_base_url 本地覆盖,生产数据库名修正为 crmmpdata
- [P1高并发削峰] 雷达足迹批量缓冲引擎:引入 CrmRadarBufferService 环形缓冲队列与阈值/定时批量 Bulk Insert 落盘
- [P2中枢租户化] AI 智能中枢多租户 BYOK 与 Token 成本风控:支持企业自带 Key 隔离、Token 消耗账本、用量配额门禁与名片人设个性化联动
- [跨端规范] 对齐 Uni-app x 移动微官网原生首屏与底部原生 tabBar 规范
- [测试驱动] 全工程 116 个测试套件,1,175 个单元与集成测试用例全部 100% 绿色通过,管理后台 Vite 打包无错误
2026-09-21 11:14:10 +08:00

92 行
4.2 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';
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'), '必须包含账龄分析词条');
});