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 defaultI18n from '../src/locale/index.ts'; const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const auditPagePath = path.join(adminRoot, 'src/pages/settings/audit-logs/index.tsx'); const auditLocalePath = path.join( adminRoot, 'src/pages/settings/audit-logs/locale/index.ts' ); const routesPath = path.join(adminRoot, 'src/routes.ts'); function readPage(): string { assert.ok(fs.existsSync(auditPagePath), '安全审计日志页面文件必须存在'); return fs.readFileSync(auditPagePath, 'utf-8'); } test('1. 路由配置中必须包含 settings/audit-logs 并在主语言包中声明菜单词条', () => { assert.ok(fs.existsSync(routesPath), 'routes.ts 必须存在'); const routesContent = fs.readFileSync(routesPath, 'utf-8'); assert.ok( routesContent.includes("'settings/audit-logs'") || routesContent.includes('"settings/audit-logs"'), 'routes.ts 必须注册 settings/audit-logs' ); assert.ok( routesContent.includes('menu.settings.auditLogs'), 'routes.ts 必须使用 menu.settings.auditLogs 作为国际化 key' ); assert.equal( defaultI18n['en-US']['menu.settings.auditLogs'], 'Audit Logs', 'en-US 主词典必须包含 menu.settings.auditLogs' ); assert.ok( defaultI18n['zh-CN']['menu.settings.auditLogs'] === '安全审计' || defaultI18n['zh-CN']['menu.settings.auditLogs'] === '审计日志', 'zh-CN 主词典必须包含 menu.settings.auditLogs' ); }); test('2. settings/audit-logs 页面必须采用 Arco Table, DatePicker, Select, Tag, Input 等官方组件', () => { const content = readPage(); assert.ok(content.includes('Table'), '必须使用 Arco Table'); assert.ok(content.includes('DatePicker'), '必须使用 Arco DatePicker'); assert.ok(content.includes('Select'), '必须使用 Arco Select'); assert.ok(content.includes('Tag'), '必须使用 Arco Tag'); assert.ok(content.includes('Input'), '必须使用 Arco Input/Input.Search'); assert.ok( content.includes("from '@arco-design/web-react'"), '必须从 @arco-design/web-react 引入组件' ); assert.ok( content.includes('admin/base/audit/page') || content.includes('/api/admin/base/audit/page'), '必须请求 POST /api/admin/base/audit/page' ); assert.ok( content.includes('code === 1000') || content.includes('code ===1000'), '必须按 Cool-Admin code === 1000 判断成功' ); }); test('3. 严格遵循瑞士国际主义风格、单一主 CTA、引用设计 Token,且零 any、零 emoji', () => { const content = readPage(); // 单一主 CTA: 统计 type="primary" const primaryButtons = content.match(/type=["']primary["']/g) || []; assert.equal( primaryButtons.length, 1, '页面必须严格保持单一主 CTA (仅有 1 个 type="primary")' ); // 严格 Token 引用,禁止硬编码颜色与纯黑 assert.ok(content.includes('lightColors'), '必须引用 lightColors token'); assert.ok( !/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码 HEX 颜色值' ); assert.ok(!content.includes('#000'), '禁止纯黑 #000'); // 零 any assert.ok(!/\bany\b/.test(content), '页面严禁使用 any'); // 零 emoji assert.ok( !/[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test(content), '页面严禁包含 emoji' ); }); test('4. settings/audit-logs 语言包必须包含中英文案且零 emoji、零 any', () => { assert.ok(fs.existsSync(auditLocalePath), '审计日志语言包文件必须存在'); const localeContent = fs.readFileSync(auditLocalePath, 'utf-8'); assert.ok(localeContent.includes("'en-US'"), '必须包含英文词典'); assert.ok(localeContent.includes("'zh-CN'"), '必须包含中文词典'); assert.ok( localeContent.includes('menu.settings.auditLogs'), '必须声明 menu.settings.auditLogs' ); assert.ok(!/\bany\b/.test(localeContent), '语言包严禁使用 any'); assert.ok( !/[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}]/u.test( localeContent ), '语言包严禁包含 emoji' ); });