文件
OmniCard/admin/tests/admin-layout-page-shell.test.ts

64 行
3.0 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'path';
import { fileURLToPath } from 'node:url';
const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
function read(relPath: string): string {
return fs.readFileSync(path.join(adminRoot, relPath), 'utf-8');
}
test('1. PageShell 必须提供统一页头 / 筛选卡 / 内容卡', () => {
const shell = read('src/components/PageShell/index.tsx');
const styles = read('src/components/PageShell/style/index.module.less');
assert.ok(shell.includes('export function PageShell'), '必须导出 PageShell');
assert.ok(shell.includes('export function PageHeader'), '必须导出 PageHeader');
assert.ok(shell.includes('export function FilterCard'), '必须导出 FilterCard');
assert.ok(shell.includes('export function ContentCard'), '必须导出 ContentCard');
assert.ok(shell.includes("from '@arco-design/web-react'"), '必须复用 Arco Card');
assert.ok(!/\bany\b/.test(shell), '禁止使用 any');
assert.ok(styles.includes('1200px'), '内容区最大宽度必须是 1200px');
assert.ok(styles.includes('720px'), '表单窄栏必须是 720px');
assert.ok(styles.includes('16px'), '卡片圆角必须是 16px');
});
test('2. 全局骨架禁止 1100 最小宽,内边距必须走 24/24/32', () => {
const layout = read('src/style/layout.module.less');
assert.ok(!layout.includes('min-width: @layout-max-width'), 'Navbar/Content 不得锁 1100 最小宽');
assert.ok(layout.includes('padding: 24px 24px 32px'), '内容区内边距必须是 24 24 32');
assert.ok(layout.includes('32px'), '折叠按钮热区不得小于 32');
});
test('3. 主题切换必须把 Omni token 注入 :root', () => {
const theme = read('src/utils/changeTheme.ts');
assert.ok(theme.includes('getCssVariables'), 'changeTheme 必须注入 getCssVariables');
assert.ok(theme.includes('document.documentElement'), '必须写到 documentElement');
});
test('4. 列表页必须拆成页头 / 筛选 / 表格三层,不再套一张全宽 Card', () => {
const pages = [
'src/pages/card/list/index.tsx',
'src/pages/crm/leads/index.tsx',
'src/pages/crm/radar-log/index.tsx',
'src/pages/nfc/devices/index.tsx',
];
for (const rel of pages) {
const content = read(rel);
assert.ok(content.includes('PageHeader'), `${rel} 必须使用 PageHeader`);
assert.ok(content.includes('FilterCard'), `${rel} 必须使用 FilterCard`);
assert.ok(content.includes('ContentCard'), `${rel} 必须使用 ContentCard`);
assert.ok(!content.includes('<Card title='), `${rel} 不得再用 Card.title 当页头`);
}
});
test('5. 表单设置页必须锁 720 窄栏', () => {
const tenant = read('src/pages/settings/tenant/index.tsx');
const handover = read('src/pages/team/handover/index.tsx');
assert.ok(tenant.includes('narrow') || tenant.includes('FormNarrow'), '域名页必须使用窄栏');
assert.ok(handover.includes('narrow') || handover.includes('FormNarrow'), '交接页必须使用窄栏');
});