文件
OmniCard/admin/tests/routes-menu.test.ts

80 行
2.5 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 layoutPath = path.join(adminRoot, 'src/layout.tsx');
const routesPath = path.join(adminRoot, 'src/routes.ts');
const CORE_BIZ_MODULES = [
'dashboard',
'card',
'crm',
'ai',
'nfc',
'team',
'settings-biz',
];
const REMOVED_DEMO_MODULES = [
'visualization',
'list',
'form',
'profile',
'result',
'user',
];
test('1. 核心业务菜单必须保留在侧边栏正常展示', () => {
const content = fs.readFileSync(routesPath, 'utf-8');
for (const key of CORE_BIZ_MODULES) {
assert.ok(
content.includes(`key: '${key}'`),
`routes.ts 必须存在核心业务模块: ${key}`
);
}
assert.ok(
!/key:\s*'dashboard'[\s\S]{0,80}ignore:\s*true/.test(content),
'dashboard 不得被 ignore'
);
});
test('2. Arco Pro Demo 模块必须从路由中移除,且 monitor / 个人中心不得再出现', () => {
const content = fs.readFileSync(routesPath, 'utf-8');
for (const key of REMOVED_DEMO_MODULES) {
assert.ok(
!content.includes(`key: '${key}'`),
`与需求无关的模板模块 ${key} 必须从 routes.ts 删除`
);
}
assert.ok(
!content.includes("key: 'dashboard/monitor'"),
'直播监控 Demo 必须从路由删除'
);
assert.ok(
!content.includes("key: 'user/info'"),
'个人中心 Demo 必须从路由删除'
);
});
test('3. layout 不得再为 ignore Demo 注册可访问路由,未知地址走 404', () => {
const content = fs.readFileSync(layoutPath, 'utf-8');
assert.ok(content.includes('KEEP_IGNORED_ROUTES'), '必须显式白名单详情/异常页');
assert.ok(content.includes('crm/lead-profile'), '线索画像必须仍可直达');
assert.ok(
content.includes("./pages/exception/404"),
'未知路由必须落到 404'
);
assert.ok(content.includes("'card'"), "layout.tsx 必须为 'card' 模块配置图标");
assert.ok(content.includes("'crm'"), "layout.tsx 必须为 'crm' 模块配置图标");
assert.ok(content.includes("'ai'"), "layout.tsx 必须为 'ai' 模块配置图标");
assert.ok(content.includes("'nfc'"), "layout.tsx 必须为 'nfc' 模块配置图标");
assert.ok(content.includes("'team'"), "layout.tsx 必须为 'team' 模块配置图标");
assert.ok(
content.includes("'settings-biz'"),
"layout.tsx 必须为 'settings-biz' 模块配置图标"
);
});