105 行
5.0 KiB
TypeScript
105 行
5.0 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 defaultI18n from '../src/locale/index.ts';
|
|
|
|
const adminRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const knowledgePagePath = path.join(adminRoot, 'src/pages/ai/knowledge/index.tsx');
|
|
const knowledgeLocalePath = path.join(adminRoot, 'src/pages/ai/knowledge/locale/index.ts');
|
|
|
|
test('1. ai/knowledge 页面必须请求 knowledge/page 与 add,并使用 Arco Table/Form/Modal', () => {
|
|
assert.ok(fs.existsSync(knowledgePagePath), '知识库页面必须存在');
|
|
const content = fs.readFileSync(knowledgePagePath, 'utf-8');
|
|
|
|
assert.ok(
|
|
content.includes('admin/ai/knowledge/page'),
|
|
'必须请求 POST /api/admin/ai/knowledge/page'
|
|
);
|
|
assert.ok(
|
|
content.includes('admin/ai/knowledge/add'),
|
|
'必须请求 POST /api/admin/ai/knowledge/add'
|
|
);
|
|
assert.ok(content.includes('Table'), '必须使用 Arco Table');
|
|
assert.ok(content.includes('Form'), '必须使用 Arco Form');
|
|
assert.ok(content.includes('Modal'), '必须使用 Arco Modal');
|
|
assert.ok(
|
|
content.includes("from '@arco-design/web-react'"),
|
|
'必须从 @arco-design/web-react 引入组件'
|
|
);
|
|
assert.ok(content.includes('AiKnowledgeDoc'), '必须使用 AiKnowledgeDoc 类型');
|
|
assert.ok(
|
|
content.includes('code === 1000') || content.includes('code ===1000'),
|
|
'必须按 Cool-Admin code === 1000 判断成功'
|
|
);
|
|
assert.ok(content.includes('Message.error'), '失败必须使用 Arco Message.error');
|
|
assert.ok(!content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js 假数据冒充成功');
|
|
assert.ok(!/\bany\b/.test(content), '禁止使用 any');
|
|
});
|
|
|
|
test('2. ai/knowledge 必须支持筛选、摘要列、编辑删除与空状态主 CTA', () => {
|
|
const content = fs.readFileSync(knowledgePagePath, 'utf-8');
|
|
|
|
assert.ok(content.includes("from '@/types/omni'"), '必须复用 admin/src/types/omni.ts');
|
|
assert.ok(content.includes('lightColors'), '颜色必须引用 lightColors token');
|
|
assert.ok(!/#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})\b/.test(content), '禁止硬编码颜色');
|
|
|
|
assert.ok(content.includes('title'), '必须展示 title');
|
|
assert.ok(content.includes('cardId'), '必须展示并筛选 cardId');
|
|
assert.ok(content.includes('locale'), '必须展示并筛选 locale');
|
|
assert.ok(content.includes('keyWord'), '筛选必须支持 keyWord');
|
|
assert.ok(content.includes('content'), '必须展示 content 摘要');
|
|
|
|
assert.ok(
|
|
content.includes('admin/ai/knowledge/update'),
|
|
'编辑必须请求 POST /api/admin/ai/knowledge/update'
|
|
);
|
|
assert.ok(
|
|
content.includes('admin/ai/knowledge/delete'),
|
|
'删除必须请求 POST /api/admin/ai/knowledge/delete'
|
|
);
|
|
assert.ok(content.includes('Popconfirm'), '删除必须使用 Arco Popconfirm');
|
|
assert.ok(content.includes('Upload'), '可选文本导入必须使用 Arco Upload');
|
|
assert.ok(
|
|
content.includes('readAsText') || content.includes('FileReader'),
|
|
'Upload 只允许把文本读进 content'
|
|
);
|
|
assert.ok(
|
|
!content.includes('oss') && !content.includes('OSS'),
|
|
'禁止手写 OSS 上传'
|
|
);
|
|
|
|
assert.ok(content.includes('type="primary"'), '必须有一个主 CTA');
|
|
assert.ok(
|
|
content.includes('aiKnowledge.action.add') || content.includes('aiKnowledge.empty'),
|
|
'空状态必须复用新增 CTA 文案'
|
|
);
|
|
assert.ok(
|
|
content.includes('noDataElement') || content.includes('aiKnowledge.empty'),
|
|
'必须提供空状态'
|
|
);
|
|
assert.ok(!content.includes('<Pagination'), '禁止手写分页器,必须使用 Table 自带分页');
|
|
assert.ok(!content.includes('Mock.js') && !content.includes("from 'mockjs'"), '禁止用 Mock.js');
|
|
assert.ok(!/\bany\b/.test(content), '禁止使用 any');
|
|
});
|
|
|
|
test('3. ai/knowledge locale 必须包含 menu.ai.knowledge 与中英文案', () => {
|
|
assert.ok(fs.existsSync(knowledgeLocalePath), '知识库语言包必须存在');
|
|
const content = fs.readFileSync(knowledgeLocalePath, 'utf-8');
|
|
|
|
assert.ok(content.includes("'menu.ai.knowledge'"), '页面语言包必须包含 menu.ai.knowledge');
|
|
assert.ok(content.includes("'en-US'"), '必须包含英文案');
|
|
assert.ok(content.includes("'zh-CN'"), '必须包含中文案');
|
|
assert.ok(content.includes('aiKnowledge.request.fail'), '必须包含失败提示文案');
|
|
assert.ok(content.includes('aiKnowledge.action.add'), '必须包含新增主 CTA 文案');
|
|
assert.ok(content.includes('aiKnowledge.empty'), '必须包含空状态文案');
|
|
assert.ok(content.includes('aiKnowledge.filter.cardId'), '必须包含 cardId 筛选文案');
|
|
assert.ok(content.includes('aiKnowledge.filter.locale'), '必须包含 locale 筛选文案');
|
|
assert.ok(content.includes('aiKnowledge.filter.keyWord'), '必须包含 keyWord 筛选文案');
|
|
assert.ok(!/\bany\b/.test(content), 'locale 禁止使用 any');
|
|
|
|
assert.equal(defaultI18n['en-US']['menu.ai.knowledge'], 'Knowledge');
|
|
assert.equal(defaultI18n['zh-CN']['menu.ai.knowledge'], '知识库');
|
|
});
|