Develop (#25)
核心功能新增 工具套件扩展 JSON 工具(差异比较、格式化、转 YAML/TOML、压缩) Base64 转换器(文本/文件/图像编解码) Markdown ↔ HTML 双向转换 JWT 解析器 文本统计工具 二维码生成/解析(替换库以减小体积) 表单工具(已移除) 表单映射、智能填充、高亮定位功能已移除 架构与工程改进 技术栈升级 引入 @webext-core/messaging 重构消息通信 添加 @dnd-kit 支持功能列表拖拽排序 引入 i18next 实现中英文国际化 使用 MUI 主题系统替代硬编码样式,支持暗色模式 代码质量 统一组件导出为默认导出 提取公共组件(TextInputArea、SwitchButtonGroup、PageHeader、DecodeResultPaper) 使用 useStorageState 钩子统一管理存储状态 添加 PageErrorBoundary 页面级错误边界 实现组件懒加载优化首屏性能 关键重构 路由系统重构 — 支持独立标签页模式,合并路由与功能配置 状态管理优化 — 存储状态增加快照机制、验证器和防抖处理 剪贴板与打印工具 — 统一为 async/await 形式,修复重复触发问题 存储清理器 — 使用 TextEncoder 准确计算 UTF-8 字节数,支持 TB 单位 测试与 CI 测试覆盖 — 为新增工具、公共组件、边界场景补充单元测试 CI 精简 — 移除 Firefox 测试,仅保留 Chrome;修正类型检查命令
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatSize, isRestrictedUrl } from '@/utils/storageCleaner';
|
||||
import { clearCookies, formatSize, isRestrictedUrl } from '@/utils/storageCleaner';
|
||||
|
||||
describe('storageCleaner utils', () => {
|
||||
describe('isRestrictedUrl', () => {
|
||||
@@ -80,4 +80,54 @@ describe('storageCleaner utils', () => {
|
||||
expect(formatSize(1025)).toBe('1.0 KB');
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearCookies', () => {
|
||||
it('should strip leading dot from cookie domain when removing cookies', async () => {
|
||||
const mockCookies = [
|
||||
{ name: 'session', domain: '.example.com', path: '/', secure: true, storeId: '0' },
|
||||
{ name: 'auth', domain: '.example.com', path: '/api', secure: false, storeId: '0' },
|
||||
];
|
||||
(chrome.cookies.getAll as any).mockResolvedValue(mockCookies);
|
||||
(chrome.cookies.remove as any).mockResolvedValue(undefined);
|
||||
|
||||
const result = await clearCookies('https://example.com');
|
||||
|
||||
expect(result).toEqual({ success: true, count: 2 });
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'https://example.com/',
|
||||
name: 'session',
|
||||
storeId: '0',
|
||||
});
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'http://example.com/api',
|
||||
name: 'auth',
|
||||
storeId: '0',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle domains without leading dot', async () => {
|
||||
const mockCookies = [
|
||||
{ name: 'pref', domain: 'sub.example.com', path: '/path', secure: true, storeId: '0' },
|
||||
];
|
||||
(chrome.cookies.getAll as any).mockResolvedValue(mockCookies);
|
||||
(chrome.cookies.remove as any).mockResolvedValue(undefined);
|
||||
|
||||
const result = await clearCookies('https://sub.example.com');
|
||||
|
||||
expect(result).toEqual({ success: true, count: 1 });
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'https://sub.example.com/path',
|
||||
name: 'pref',
|
||||
storeId: '0',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when operation fails', async () => {
|
||||
(chrome.cookies.getAll as any).mockRejectedValue(new Error('Permission denied'));
|
||||
|
||||
const result = await clearCookies('https://example.com');
|
||||
|
||||
expect(result).toEqual({ success: false, error: 'Error: Permission denied' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user