Files
PathEditor/e2e/tests/search-clean.spec.ts
T
Serendipity e5b348bb9b fix: e2e 类型声明 + ESLint 覆盖 e2e + backup 路径校验 + DX 脚本
- e2e/global.d.ts: Window.__TAURI_INTERNALS__ 类型声明
- e2e search-clean: 未使用参数 _args 前缀
- tsconfig.test.json: include e2e/
- CI: ESLint 扫描范围扩展到 e2e/
- backup_registry: 拒绝写入系统目录 (C:\Windows\, C:\Program Files\)
- package.json: 新增 lint:fix / format 脚本

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 23:23:51 +08:00

52 lines
1.8 KiB
TypeScript

import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
window.__TAURI_INTERNALS__ = {
invoke: async (cmd, _args) => {
switch (cmd) {
case 'check_admin': return true;
case 'load_system_paths': return ['C:\\\\Windows', 'invalid_path', 'C:\\\\Temp'];
case 'load_user_paths': return [];
case 'load_disabled_state': return { system: [], user: [] };
case 'save_system_paths': return undefined;
case 'save_user_paths': return undefined;
case 'save_disabled_state': return undefined;
case 'backup_registry': return '';
case 'broadcast_env_change': return undefined;
case 'validate_path': return false;
case 'expand_env_vars': return '';
case 'read_text_file': return '';
case 'get_appdata_dir': return '';
default: return undefined;
}
}
};
});
await page.goto('/');
});
test('搜索过滤后清理无效路径', async ({ page }) => {
// 初始 3 条路径
await page.waitForTimeout(500);
await expect(page.locator('table tbody tr')).toHaveCount(3);
// 搜索 "Windows"
const searchInput = page.locator('input[placeholder]');
await searchInput.fill('Windows');
await page.waitForTimeout(300);
await expect(page.locator('table tbody tr')).toHaveCount(1);
// 清除搜索
await searchInput.fill('');
await page.waitForTimeout(300);
await expect(page.locator('table tbody tr')).toHaveCount(3);
// 点击"一键清理"按钮
await page.click('text=一键清理');
await page.waitForTimeout(300);
// is_valid_path_format 只校验格式,不检查存在性
// "invalid_path" 格式无效被移除,C:\Windows 和 C:\Temp 格式有效保留
await expect(page.locator('table tbody tr')).toHaveCount(2);
});