文件
OmniCard/admin/tests/nfc-rules.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

130 行
6.0 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 rulesPagePath = path.join(adminRoot, 'src/pages/nfc/rules/index.tsx');
const rulesLocalePath = path.join(adminRoot, 'src/pages/nfc/rules/locale/index.ts');
const routesPath = path.join(adminRoot, 'src/routes.ts');
const mainLocalePath = path.join(adminRoot, 'src/locale/index.ts');
test('1. nfc/rules 页面必须与后端 /admin/nfc/rule 接口契约完全匹配', () => {
assert.ok(fs.existsSync(rulesPagePath), 'NFC 场景路由规则页面必须存在');
const content = fs.readFileSync(rulesPagePath, 'utf-8');
assert.ok(
content.includes('admin/nfc/rule/page'),
'必须请求 POST /api/admin/nfc/rule/page'
);
assert.ok(
content.includes('admin/nfc/rule/add'),
'必须请求 POST /api/admin/nfc/rule/add'
);
assert.ok(
content.includes('admin/nfc/rule/update'),
'必须请求 POST /api/admin/nfc/rule/update'
);
assert.ok(
content.includes('admin/nfc/rule/delete'),
'必须请求 POST /api/admin/nfc/rule/delete'
);
assert.ok(
content.includes('admin/nfc/rule/resolveScene'),
'必须支持调用 POST /api/admin/nfc/rule/resolveScene 进行场景解析'
);
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('Message.success'), '成功必须使用 Arco Message.success');
assert.ok(
!content.includes('Mock.js') && !content.includes("from 'mockjs'"),
'禁止用 Mock.js 假数据冒充成功'
);
assert.ok(!/\bany\b/.test(content), '页面中禁止使用 any');
});
test('2. nfc/rules 必须复用 Arco 组件、设计 Token 与场景路由契约', () => {
const content = fs.readFileSync(rulesPagePath, 'utf-8');
// Arco 组件
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('TimePicker'), '必须使用 Arco TimePicker');
assert.ok(content.includes('Select'), '必须使用 Arco Select');
assert.ok(content.includes('Switch'), '必须使用 Arco Switch');
assert.ok(content.includes('Tag'), '必须使用 Arco Tag');
assert.ok(content.includes('Popconfirm'), '必须使用 Arco Popconfirm');
assert.ok(
content.includes("from '@arco-design/web-react'"),
'必须从 @arco-design/web-react 引入组件'
);
assert.ok(!content.includes('<Pagination'), '禁止手写分页器,必须使用 Table 自带分页');
// 契约复用
assert.ok(content.includes('NFCSceneRule'), '必须使用 NFCSceneRule 类型');
assert.ok(content.includes('NFCSceneMode'), '必须使用 NFCSceneMode 类型');
assert.ok(content.includes("from '@/types/omni'"), '必须复用 admin/src/types/omni.ts');
// 场景字段
assert.ok(content.includes('startTime'), '必须支持时段 startTime');
assert.ok(content.includes('endTime'), '必须支持时段 endTime');
assert.ok(content.includes('countryCode'), '必须支持地理国家 countryCode');
assert.ok(content.includes('weekdays'), '必须支持生效星期 weekdays');
assert.ok(content.includes('targetCardId'), '必须支持目标名片 targetCardId');
assert.ok(content.includes('sceneMode'), '必须支持场景模式 sceneMode');
assert.ok(content.includes('deviceId'), '必须支持设备 ID deviceId');
// 设计 Token 与单主 CTA 约束
assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors token');
assert.ok(!/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码颜色代码');
assert.ok(
(content.match(/type="primary"/g) || []).length === 1,
'一屏只允许 1 个主 CTA (type="primary")'
);
// 禁止 emoji
const emojiRegex = /[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u;
assert.ok(!emojiRegex.test(content), '页面严禁包含 emoji');
});
test('3. nfc/rules 路由与国际化配置必须完整', () => {
// 检查 routes.ts
assert.ok(fs.existsSync(routesPath), 'routes.ts 必须存在');
const routesContent = fs.readFileSync(routesPath, 'utf-8');
assert.ok(
routesContent.includes("key: 'nfc/rules'"),
'routes.ts 中必须注册 key: nfc/rules'
);
assert.ok(
routesContent.includes("name: 'menu.nfc.rules'"),
'routes.ts 中必须声明 name: menu.nfc.rules'
);
// 检查主语言包
assert.ok(fs.existsSync(mainLocalePath), '主语言包 index.ts 必须存在');
const mainLocaleContent = fs.readFileSync(mainLocalePath, 'utf-8');
assert.ok(
mainLocaleContent.includes("'menu.nfc.rules'"),
'主语言包必须包含 menu.nfc.rules 词条'
);
// 检查页面语言包
assert.ok(fs.existsSync(rulesLocalePath), '规则页面语言包必须存在');
const rulesLocaleContent = fs.readFileSync(rulesLocalePath, 'utf-8');
assert.ok(rulesLocaleContent.includes("'en-US'"), '页面语言包必须包含英文案');
assert.ok(rulesLocaleContent.includes("'zh-CN'"), '页面语言包必须包含中文案');
assert.ok(rulesLocaleContent.includes('nfcRules.request.fail'), '必须包含失败提示文案');
assert.ok(rulesLocaleContent.includes('nfcRules.columns.name'), '必须包含规则名称文案');
assert.ok(rulesLocaleContent.includes('nfcRules.columns.sceneMode'), '必须包含场景模式文案');
assert.ok(rulesLocaleContent.includes('nfcRules.columns.timeRange'), '必须包含生效时段文案');
assert.ok(rulesLocaleContent.includes('nfcRules.columns.countryCode'), '必须包含地理国家文案');
assert.ok(rulesLocaleContent.includes('nfcRules.action.create'), '必须包含新建规则文案');
assert.ok(rulesLocaleContent.includes('nfcRules.action.resolve'), '必须包含路由解析文案');
assert.ok(!/\bany\b/.test(rulesLocaleContent), 'locale 禁止使用 any');
});