feat: 快捷键录入重绑(FR-K3,keymap:load/save IPC+config.json,SettingsPanel 录入 UI+冲突检测,use-hotkeys 读 store 实时生效,重开恢复)

This commit is contained in:
hunter-dev
2026-08-24 23:48:17 +08:00
parent cf2600901b
commit 49c174851e
9 changed files with 166 additions and 36 deletions
+41
View File
@@ -0,0 +1,41 @@
import { test, expect } from '@playwright/test';
import { _electron as electron } from 'playwright';
import { promises as fs } from 'node:fs';
import nodePath from 'node:path';
import os from 'node:os';
const MAIN_JS = nodePath.join(process.cwd(), 'dist-electron/main/index.js');
async function launch(userData: string) {
const app = await electron.launch({ args: ['--user-data-dir=' + userData, MAIN_JS] });
const page = await app.firstWindow();
await page.waitForLoadState('domcontentloaded');
const invoke = (ch: string, args: any) => page.evaluate(({ ch, args }) => (globalThis as any).dsh.invoke(ch, args), { ch, args });
return { app, page, invoke };
}
test('keymap:录入重绑 + 持久化(重开恢复)', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-keymap-'));
const userData = nodePath.join(tmp, 'userdata');
const vault = nodePath.join(tmp, 'vault');
await fs.mkdir(userData, { recursive: true });
await fs.mkdir(vault, { recursive: true });
// 设置→快捷键→录入「新建文档」→ Ctrl+Q
const a1 = await launch(userData);
await a1.invoke('vault:switch', { root: vault });
await a1.page.getByTitle('设置').click();
await a1.page.getByRole('button', { name: '快捷键' }).click();
await a1.page.getByRole('button', { name: '录入' }).first().click();
await a1.page.keyboard.press('Control+q');
// 持久化断言
const km1: { id: string; combo: string }[] | null = await a1.invoke('keymap:load', null);
expect(km1?.find(x => x.id === 'newDoc')?.combo).toBe('ctrl+q');
await a1.app.close();
// 重开:恢复
const a2 = await launch(userData);
const km2: { id: string; combo: string }[] | null = await a2.invoke('keymap:load', null);
expect(km2?.find(x => x.id === 'newDoc')?.combo).toBe('ctrl+q');
await a2.app.close();
});