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 builderPagePath = path.join(adminRoot, 'src/pages/card/builder/index.tsx'); const builderLocalePath = path.join( adminRoot, 'src/pages/card/builder/locale/index.ts' ); const routesPath = path.join(adminRoot, 'src/routes.ts'); const mainLocalePath = path.join(adminRoot, 'src/locale/index.ts'); test('1. routes.ts 已注册 card/builder,对应 pages/card/builder', () => { const content = fs.readFileSync(routesPath, 'utf-8'); assert.ok(content.includes("key: 'card/builder'"), '应存在路由 key: card/builder'); assert.ok(content.includes("name: 'menu.card.builder'"), '应存在 menu.card.builder'); assert.ok(fs.existsSync(builderPagePath), '必须存在 pages/card/builder/index.tsx'); }); test('2. locale 必须包含 menu.card.builder 中英文案', () => { const content = fs.readFileSync(mainLocalePath, 'utf-8'); assert.ok(content.includes("'menu.card.builder': 'Bento Builder'"), '英文 menu.card.builder'); assert.ok(content.includes("'menu.card.builder': 'Bento 搭建器'"), '中文 menu.card.builder'); }); 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'); }); test('7. builder 支持无 ID 自动拉取名片列表、名片切换器与多环境预览 (Dark / RTL)', () => { const content = fs.readFileSync(builderPagePath, 'utf-8'); assert.ok( content.includes('/api/admin/card/info/page'), '必须支持拉取名片列表 /api/admin/card/info/page' ); assert.ok( content.includes('cardBuilder.switchCard') || content.includes('cardOptions'), '必须支持名片切换器' ); assert.ok( content.includes('previewMode') || content.includes('themeMode') || content.includes('isDark'), '必须支持暗黑/浅色模式视口切换' ); assert.ok( content.includes('isRtl') || content.includes('rtl'), '必须支持 RTL 排版镜像切换' ); });