文件
OmniCard/admin/tests/card-builder.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

119 行
4.8 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 { routes } from '../src/routes.ts';
import defaultI18n from '../src/locale/index.ts';
const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const builderPagePath = path.join(adminRoot, 'src/pages/card/builder/index.tsx');
const builderLocalePath = path.join(
adminRoot,
'src/pages/card/builder/locale/index.ts'
);
function flattenRouteKeys(items: typeof routes): string[] {
return items.flatMap((item) => [
item.key,
...(item.children ? flattenRouteKeys(item.children) : []),
]);
}
test('1. routes.ts 已注册 card/builder,对应 pages/card/builder', () => {
const keys = flattenRouteKeys(routes);
assert.ok(keys.includes('card/builder'), '应存在路由 key: card/builder');
const cardGroup = routes.find((item) => item.key === 'card');
assert.ok(
cardGroup?.children?.some(
(child) =>
child.key === 'card/builder' && child.name === 'menu.card.builder'
),
'card 分组下应有 menu.card.builder / card/builder'
);
assert.ok(fs.existsSync(builderPagePath), '必须存在 pages/card/builder/index.tsx');
});
test('2. locale 必须包含 menu.card.builder 中英文案', () => {
assert.equal(defaultI18n['en-US']['menu.card.builder'], 'Bento Builder');
assert.equal(defaultI18n['zh-CN']['menu.card.builder'], 'Bento 搭建器');
});
test('3. builder 必须请求 getBlocksByCardId / batchSaveLayout 并支持 colSpan', () => {
const content = fs.readFileSync(builderPagePath, 'utf-8');
assert.ok(
content.includes('getBlocksByCardId'),
'必须请求 POST /api/admin/card/bento/getBlocksByCardId'
);
assert.ok(
content.includes('batchSaveLayout'),
'必须请求 POST /api/admin/card/bento/batchSaveLayout'
);
assert.ok(content.includes('colSpan'), '必须读写 colSpan');
assert.ok(content.includes('rowSpan'), '必须读写 rowSpan');
assert.ok(
content.includes('{ cardId: Number(id) }'),
'拉取块必须提交 { cardId: Number(id) }'
);
assert.ok(
content.includes('code === 1000') || content.includes('code ===1000'),
'必须按 Cool-Admin code === 1000 判断成功'
);
});
test('4. builder 必须覆盖 hero/case/article 等 Bento 类型', () => {
const content = fs.readFileSync(builderPagePath, 'utf-8');
assert.ok(content.includes('hero'), '组件库必须包含 hero');
assert.ok(content.includes('case'), '组件库必须包含 case');
assert.ok(content.includes('article'), '组件库必须包含 article');
assert.ok(content.includes('social'), '组件库必须包含 social');
assert.ok(content.includes('video'), '组件库必须包含 video');
assert.ok(content.includes('form'), '组件库必须包含 form');
assert.ok(content.includes('BentoBlock'), '必须复用 BentoBlock 类型');
assert.ok(content.includes('BentoBlockType'), '必须复用 BentoBlockType 类型');
});
test('5. builder 必须用 query id、Arco 三栏与单一保存 CTA', () => {
const content = fs.readFileSync(builderPagePath, 'utf-8');
assert.ok(content.includes('useLocation'), '名片 id 必须来自 useLocation');
assert.ok(
content.includes('query-string') || content.includes('queryString'),
'必须用 query-string 解析 id'
);
assert.ok(content.includes('Layout'), '必须使用 Arco Layout');
assert.ok(content.includes('Input.TextArea'), '必须使用 Input.TextArea');
assert.ok(content.includes('Tabs'), '必须使用 Arco Tabs');
assert.ok(
content.includes("from '@arco-design/web-react'"),
'必须从 @arco-design/web-react 引入组件'
);
assert.ok(
content.includes("from '@/style/tokens'"),
'颜色必须引用 admin/src/style/tokens'
);
assert.ok(content.includes('cardBuilder.save') || content.includes('保存排版'), '必须提供保存排版主 CTA');
assert.ok(content.includes('Empty') || content.includes('cardBuilder.empty'), '缺 id 必须 Empty 提示');
assert.ok(content.includes('/card/list'), '缺 id 必须提示回资产库');
assert.ok(!/\bany\b/.test(content), '禁止使用 any');
assert.ok(
!/[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test(content),
'禁止使用 emoji'
);
});
test('6. builder 页面文案走 i18n 且无 emoji', () => {
assert.ok(fs.existsSync(builderLocalePath), '必须存在 builder locale');
const localeContent = fs.readFileSync(builderLocalePath, 'utf-8');
assert.ok(localeContent.includes('cardBuilder.save'), '必须有保存排版词条');
assert.ok(localeContent.includes('cardBuilder.empty'), '必须有缺 id 空状态词条');
assert.ok(
!/[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test(localeContent),
'locale 禁止使用 emoji'
);
assert.ok(!/\bany\b/.test(localeContent), 'locale 禁止使用 any');
});