From a8a1e89f8aa48bca98eda22854c7bf5a180d1a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Fri, 19 Jun 2026 09:47:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=94=AE=E5=90=8D=E7=A7=B0=E5=B9=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20README=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将功能键 'jsonDiff' 更新为 'jsonTools',以更准确地反映其功能。 - 删除不再使用的 README.md 文件,清理项目结构。 - 更新相关测试用例以反映功能键名称的变化。 --- src/config/README.md | 44 ------------------- src/config/__tests__/features.test.ts | 29 ++++++------ src/config/features.tsx | 2 +- .../__tests__/RouterProvider.test.tsx | 12 ++--- src/types/storage.d.ts | 2 +- 5 files changed, 22 insertions(+), 67 deletions(-) delete mode 100644 src/config/README.md diff --git a/src/config/README.md b/src/config/README.md deleted file mode 100644 index ced4dcb..0000000 --- a/src/config/README.md +++ /dev/null @@ -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) diff --git a/src/config/__tests__/features.test.ts b/src/config/__tests__/features.test.ts index aff96db..07cdecb 100644 --- a/src/config/__tests__/features.test.ts +++ b/src/config/__tests__/features.test.ts @@ -9,11 +9,11 @@ import { describe('features', () => { describe('FEATURES', () => { - it('should have 10 features defined', () => { + it('应该有10个功能定义', () => { expect(FEATURES).toHaveLength(10); }); - it('should have all required properties for each feature', () => { + it('应该有每个功能的所有必需属性', () => { FEATURES.forEach((feature) => { expect(feature).toHaveProperty('key'); expect(feature).toHaveProperty('label'); @@ -29,7 +29,6 @@ describe('features', () => { expect(feature.components).toHaveProperty('sidepanel'); expect(feature.components).toHaveProperty('tab'); - // Optional UI properties for non-hidden features if (feature.key !== 'dashboard') { expect(feature).toHaveProperty('icon'); 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 uniqueKeys = new Set(keys); expect(uniqueKeys.size).toBe(keys.length); @@ -46,14 +45,14 @@ describe('features', () => { }); describe('getFeatureByKey', () => { - it('should return dashboard feature', () => { + it('应该返回dashboard功能', () => { const feature = getFeatureByKey('dashboard'); expect(feature).toBeDefined(); expect(feature?.key).toBe('dashboard'); expect(feature?.label).toBe('仪表盘'); }); - it('should return timestamp feature', () => { + it('应该返回时间戳功能', () => { const feature = getFeatureByKey('timestamp'); expect(feature).toBeDefined(); expect(feature?.key).toBe('timestamp'); @@ -61,21 +60,21 @@ describe('features', () => { expect(feature?.themeColorKey).toBeDefined(); }); - it('should return storageCleaner feature', () => { + it('应该返回存储清理功能', () => { const feature = getFeatureByKey('storageCleaner'); expect(feature).toBeDefined(); expect(feature?.key).toBe('storageCleaner'); expect(feature?.label).toBe('存储清理'); }); - it('should return undefined for invalid key', () => { + it('应该返回undefined用于无效的key', () => { const feature = getFeatureByKey('invalid' as any); expect(feature).toBeUndefined(); }); }); describe('getDefaultVisibleFeatureKeys', () => { - it('should return only visible features', () => { + it('应该返回仅可见的功能', () => { const visibleKeys = getDefaultVisibleFeatureKeys(); visibleKeys.forEach((key) => { const feature = getFeatureByKey(key); @@ -83,7 +82,7 @@ describe('features', () => { }); }); - it('should include dashboard, timestamp, storageCleaner, qrCode', () => { + it('应该包含仪表盘、时间戳、存储清理、二维码', () => { const visibleKeys = getDefaultVisibleFeatureKeys(); expect(visibleKeys).toContain('dashboard'); expect(visibleKeys).toContain('timestamp'); @@ -93,7 +92,7 @@ describe('features', () => { }); describe('getAllFeatureKeys', () => { - it('should return all feature keys', () => { + it('应该返回所有功能key', () => { const allKeys = getAllFeatureKeys(); expect(allKeys).toHaveLength(10); expect(allKeys).toContain('dashboard'); @@ -102,7 +101,7 @@ describe('features', () => { expect(allKeys).toContain('qrCode'); expect(allKeys).toContain('textStatistics'); expect(allKeys).toContain('jwt'); - expect(allKeys).toContain('jsonDiff'); + expect(allKeys).toContain('jsonTools'); expect(allKeys).toContain('base64Converter'); expect(allKeys).toContain('rightClickRestorer'); expect(allKeys).toContain('testDataGenerator'); @@ -110,19 +109,19 @@ describe('features', () => { }); describe('getDefaultPageOrder', () => { - it('should exclude dashboard from page order', () => { + it('应该排除仪表盘从页面顺序', () => { const pageOrder = getDefaultPageOrder(); expect(pageOrder).not.toContain('dashboard'); }); - it('should include timestamp, storageCleaner, qrCode in page order', () => { + it('应该包含时间戳、存储清理、二维码在页面顺序', () => { const pageOrder = getDefaultPageOrder(); expect(pageOrder).toContain('timestamp'); expect(pageOrder).toContain('storageCleaner'); expect(pageOrder).toContain('qrCode'); }); - it('should have 9 items in page order', () => { + it('应该有9个项目在页面顺序', () => { const pageOrder = getDefaultPageOrder(); expect(pageOrder).toHaveLength(9); }); diff --git a/src/config/features.tsx b/src/config/features.tsx index f82b90d..d98d397 100644 --- a/src/config/features.tsx +++ b/src/config/features.tsx @@ -119,7 +119,7 @@ export const FEATURES: FeatureConfig[] = [ }, }, { - key: 'jsonDiff', + key: 'jsonTools', label: 'JSON 工具', description: '差异比较、格式化、YAML/TOML 转换及压缩', themeColorKey: 'primary', diff --git a/src/providers/__tests__/RouterProvider.test.tsx b/src/providers/__tests__/RouterProvider.test.tsx index 7550582..76fda0d 100644 --- a/src/providers/__tests__/RouterProvider.test.tsx +++ b/src/providers/__tests__/RouterProvider.test.tsx @@ -156,7 +156,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; const oldPageOrder = [ 'timestamp', @@ -164,7 +164,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; (storageUtil.get as any).mockImplementation((key: string, defaultValue: any) => { @@ -196,7 +196,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; const oldPageOrder = [ 'timestamp', @@ -204,7 +204,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; localStorage.setItem('snapshot/app/visiblePages', JSON.stringify(oldVisiblePages)); localStorage.setItem('snapshot/app/pageOrder', JSON.stringify(oldPageOrder)); @@ -250,7 +250,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; const oldPageOrder = [ 'timestamp', @@ -258,7 +258,7 @@ describe('RouterProvider', () => { 'qrCode', 'textStatistics', 'jwt', - 'jsonDiff', + 'jsonTools', ]; await act(async () => { diff --git a/src/types/storage.d.ts b/src/types/storage.d.ts index 88b7bbd..c430178 100644 --- a/src/types/storage.d.ts +++ b/src/types/storage.d.ts @@ -8,7 +8,7 @@ export type PageType = | 'qrCode' // 二维码工具 | 'textStatistics' // 文本统计工具 | 'jwt' // JWT 解析工具 - | 'jsonDiff' // JSON 差异比较工具 + | 'jsonTools' // JSON 工具 | 'base64Converter' // Base64 转换器工具 | 'rightClickRestorer' // 右键菜单恢复工具 | 'testDataGenerator'; // 测试数据生成器工具