refactor: 更新功能键名称并移除 README 文件

- 将功能键 'jsonDiff' 更新为 'jsonTools',以更准确地反映其功能。
- 删除不再使用的 README.md 文件,清理项目结构。
- 更新相关测试用例以反映功能键名称的变化。
This commit is contained in:
雨霖铃
2026-06-19 09:47:08 +08:00
parent 9097c48b1f
commit a8a1e89f8a
5 changed files with 22 additions and 67 deletions
-44
View File
@@ -1,44 +0,0 @@
# config/
应用级配置目录,存放功能特性的注册中心。
## 文件说明
| 文件 | 用途 |
| -------------- | ---------------------------------------- |
| `features.tsx` | 核心配置文件,定义所有工具功能的注册信息 |
## features.tsx
`FEATURES` 数组是路由和功能元数据的**单一事实来源**,每个功能定义包含:
- `key`:页面类型标识(`PageType`
- `labelKey` / `descriptionKey`i18n 翻译键
- `themeColorKey`:主题色(`primary/success/warning/error/secondary/info`
- `icon`lucide-react 图标组件
- `defaultVisible`:默认是否可见
- `components`:三种渲染模式的懒加载组件(`popup``sidepanel``tab`
## 已注册功能(11 个)
| key | 图标 | 说明 |
| -------------------- | ----------------- | ----------------- |
| `dashboard` | — | 仪表盘首页 |
| `timestamp` | Clock | 时间戳转换工具 |
| `storageCleaner` | Database | 存储清理工具 |
| `qrCode` | QrCode | 二维码工具 |
| `textStatistics` | FileText | 文本统计工具 |
| `jwt` | Key | JWT 解析工具 |
| `jsonDiff` | GitCompareArrows | JSON 差异比较工具 |
| `base64Converter` | ArrowLeftRight | Base64 转换器 |
| `markdownToHtml` | Code | Markdown 转 HTML |
| `htmlToMarkdown` | File | HTML 转 Markdown |
| `rightClickRestorer` | MousePointerClick | 右键菜单恢复工具 |
## 导出函数
- `getFeatureByKey(key)` — 根据 key 获取功能配置
- `getDefaultVisibleFeatureKeys()` — 获取默认可见的功能 key 列表
- `getAllFeatureKeys()` — 获取所有功能 key 列表
- `getDefaultPageOrder()` — 获取默认页面排序(不含 dashboard)
- `getEntryPointType()` — 判断当前入口类型(popup/sidepanel/tab
+14 -15
View File
@@ -9,11 +9,11 @@ import {
describe('features', () => { describe('features', () => {
describe('FEATURES', () => { describe('FEATURES', () => {
it('should have 10 features defined', () => { it('应该有10个功能定义', () => {
expect(FEATURES).toHaveLength(10); expect(FEATURES).toHaveLength(10);
}); });
it('should have all required properties for each feature', () => { it('应该有每个功能的所有必需属性', () => {
FEATURES.forEach((feature) => { FEATURES.forEach((feature) => {
expect(feature).toHaveProperty('key'); expect(feature).toHaveProperty('key');
expect(feature).toHaveProperty('label'); expect(feature).toHaveProperty('label');
@@ -29,7 +29,6 @@ describe('features', () => {
expect(feature.components).toHaveProperty('sidepanel'); expect(feature.components).toHaveProperty('sidepanel');
expect(feature.components).toHaveProperty('tab'); expect(feature.components).toHaveProperty('tab');
// Optional UI properties for non-hidden features
if (feature.key !== 'dashboard') { if (feature.key !== 'dashboard') {
expect(feature).toHaveProperty('icon'); expect(feature).toHaveProperty('icon');
expect(feature).toHaveProperty('themeColorKey'); expect(feature).toHaveProperty('themeColorKey');
@@ -38,7 +37,7 @@ describe('features', () => {
}); });
}); });
it('should have unique keys for each feature', () => { it('应该有每个功能的唯一key', () => {
const keys = FEATURES.map((f) => f.key); const keys = FEATURES.map((f) => f.key);
const uniqueKeys = new Set(keys); const uniqueKeys = new Set(keys);
expect(uniqueKeys.size).toBe(keys.length); expect(uniqueKeys.size).toBe(keys.length);
@@ -46,14 +45,14 @@ describe('features', () => {
}); });
describe('getFeatureByKey', () => { describe('getFeatureByKey', () => {
it('should return dashboard feature', () => { it('应该返回dashboard功能', () => {
const feature = getFeatureByKey('dashboard'); const feature = getFeatureByKey('dashboard');
expect(feature).toBeDefined(); expect(feature).toBeDefined();
expect(feature?.key).toBe('dashboard'); expect(feature?.key).toBe('dashboard');
expect(feature?.label).toBe('仪表盘'); expect(feature?.label).toBe('仪表盘');
}); });
it('should return timestamp feature', () => { it('应该返回时间戳功能', () => {
const feature = getFeatureByKey('timestamp'); const feature = getFeatureByKey('timestamp');
expect(feature).toBeDefined(); expect(feature).toBeDefined();
expect(feature?.key).toBe('timestamp'); expect(feature?.key).toBe('timestamp');
@@ -61,21 +60,21 @@ describe('features', () => {
expect(feature?.themeColorKey).toBeDefined(); expect(feature?.themeColorKey).toBeDefined();
}); });
it('should return storageCleaner feature', () => { it('应该返回存储清理功能', () => {
const feature = getFeatureByKey('storageCleaner'); const feature = getFeatureByKey('storageCleaner');
expect(feature).toBeDefined(); expect(feature).toBeDefined();
expect(feature?.key).toBe('storageCleaner'); expect(feature?.key).toBe('storageCleaner');
expect(feature?.label).toBe('存储清理'); expect(feature?.label).toBe('存储清理');
}); });
it('should return undefined for invalid key', () => { it('应该返回undefined用于无效的key', () => {
const feature = getFeatureByKey('invalid' as any); const feature = getFeatureByKey('invalid' as any);
expect(feature).toBeUndefined(); expect(feature).toBeUndefined();
}); });
}); });
describe('getDefaultVisibleFeatureKeys', () => { describe('getDefaultVisibleFeatureKeys', () => {
it('should return only visible features', () => { it('应该返回仅可见的功能', () => {
const visibleKeys = getDefaultVisibleFeatureKeys(); const visibleKeys = getDefaultVisibleFeatureKeys();
visibleKeys.forEach((key) => { visibleKeys.forEach((key) => {
const feature = getFeatureByKey(key); const feature = getFeatureByKey(key);
@@ -83,7 +82,7 @@ describe('features', () => {
}); });
}); });
it('should include dashboard, timestamp, storageCleaner, qrCode', () => { it('应该包含仪表盘、时间戳、存储清理、二维码', () => {
const visibleKeys = getDefaultVisibleFeatureKeys(); const visibleKeys = getDefaultVisibleFeatureKeys();
expect(visibleKeys).toContain('dashboard'); expect(visibleKeys).toContain('dashboard');
expect(visibleKeys).toContain('timestamp'); expect(visibleKeys).toContain('timestamp');
@@ -93,7 +92,7 @@ describe('features', () => {
}); });
describe('getAllFeatureKeys', () => { describe('getAllFeatureKeys', () => {
it('should return all feature keys', () => { it('应该返回所有功能key', () => {
const allKeys = getAllFeatureKeys(); const allKeys = getAllFeatureKeys();
expect(allKeys).toHaveLength(10); expect(allKeys).toHaveLength(10);
expect(allKeys).toContain('dashboard'); expect(allKeys).toContain('dashboard');
@@ -102,7 +101,7 @@ describe('features', () => {
expect(allKeys).toContain('qrCode'); expect(allKeys).toContain('qrCode');
expect(allKeys).toContain('textStatistics'); expect(allKeys).toContain('textStatistics');
expect(allKeys).toContain('jwt'); expect(allKeys).toContain('jwt');
expect(allKeys).toContain('jsonDiff'); expect(allKeys).toContain('jsonTools');
expect(allKeys).toContain('base64Converter'); expect(allKeys).toContain('base64Converter');
expect(allKeys).toContain('rightClickRestorer'); expect(allKeys).toContain('rightClickRestorer');
expect(allKeys).toContain('testDataGenerator'); expect(allKeys).toContain('testDataGenerator');
@@ -110,19 +109,19 @@ describe('features', () => {
}); });
describe('getDefaultPageOrder', () => { describe('getDefaultPageOrder', () => {
it('should exclude dashboard from page order', () => { it('应该排除仪表盘从页面顺序', () => {
const pageOrder = getDefaultPageOrder(); const pageOrder = getDefaultPageOrder();
expect(pageOrder).not.toContain('dashboard'); expect(pageOrder).not.toContain('dashboard');
}); });
it('should include timestamp, storageCleaner, qrCode in page order', () => { it('应该包含时间戳、存储清理、二维码在页面顺序', () => {
const pageOrder = getDefaultPageOrder(); const pageOrder = getDefaultPageOrder();
expect(pageOrder).toContain('timestamp'); expect(pageOrder).toContain('timestamp');
expect(pageOrder).toContain('storageCleaner'); expect(pageOrder).toContain('storageCleaner');
expect(pageOrder).toContain('qrCode'); expect(pageOrder).toContain('qrCode');
}); });
it('should have 9 items in page order', () => { it('应该有9个项目在页面顺序', () => {
const pageOrder = getDefaultPageOrder(); const pageOrder = getDefaultPageOrder();
expect(pageOrder).toHaveLength(9); expect(pageOrder).toHaveLength(9);
}); });
+1 -1
View File
@@ -119,7 +119,7 @@ export const FEATURES: FeatureConfig[] = [
}, },
}, },
{ {
key: 'jsonDiff', key: 'jsonTools',
label: 'JSON 工具', label: 'JSON 工具',
description: '差异比较、格式化、YAML/TOML 转换及压缩', description: '差异比较、格式化、YAML/TOML 转换及压缩',
themeColorKey: 'primary', themeColorKey: 'primary',
@@ -156,7 +156,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
const oldPageOrder = [ const oldPageOrder = [
'timestamp', 'timestamp',
@@ -164,7 +164,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
(storageUtil.get as any).mockImplementation((key: string, defaultValue: any) => { (storageUtil.get as any).mockImplementation((key: string, defaultValue: any) => {
@@ -196,7 +196,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
const oldPageOrder = [ const oldPageOrder = [
'timestamp', 'timestamp',
@@ -204,7 +204,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
localStorage.setItem('snapshot/app/visiblePages', JSON.stringify(oldVisiblePages)); localStorage.setItem('snapshot/app/visiblePages', JSON.stringify(oldVisiblePages));
localStorage.setItem('snapshot/app/pageOrder', JSON.stringify(oldPageOrder)); localStorage.setItem('snapshot/app/pageOrder', JSON.stringify(oldPageOrder));
@@ -250,7 +250,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
const oldPageOrder = [ const oldPageOrder = [
'timestamp', 'timestamp',
@@ -258,7 +258,7 @@ describe('RouterProvider', () => {
'qrCode', 'qrCode',
'textStatistics', 'textStatistics',
'jwt', 'jwt',
'jsonDiff', 'jsonTools',
]; ];
await act(async () => { await act(async () => {
+1 -1
View File
@@ -8,7 +8,7 @@ export type PageType =
| 'qrCode' // 二维码工具 | 'qrCode' // 二维码工具
| 'textStatistics' // 文本统计工具 | 'textStatistics' // 文本统计工具
| 'jwt' // JWT 解析工具 | 'jwt' // JWT 解析工具
| 'jsonDiff' // JSON 差异比较工具 | 'jsonTools' // JSON 工具
| 'base64Converter' // Base64 转换器工具 | 'base64Converter' // Base64 转换器工具
| 'rightClickRestorer' // 右键菜单恢复工具 | 'rightClickRestorer' // 右键菜单恢复工具
| 'testDataGenerator'; // 测试数据生成器工具 | 'testDataGenerator'; // 测试数据生成器工具