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 }; } // FR-A5:GPU 探测 + 性能优先开关 test('FR-A5:GPU 探测 + 性能优先开关持久化', async () => { const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-a5-')); const userData = nodePath.join(tmp, 'userdata'); const vault = nodePath.join(tmp, 'vault'); await fs.mkdir(userData, { recursive: true }); await fs.mkdir(vault, { recursive: true }); const a = await launch(userData); await a.invoke('vault:switch', { root: vault }); // GPU info IPC 应可用 const gpu = await a.invoke('gpu:info', null as any); expect(gpu).toBeTruthy(); expect(typeof gpu.softwareRendering).toBe('boolean'); // 打开设置 -> 其他页 await a.page.getByTitle('设置').click(); await expect(a.page.getByText('设置', { exact: true })).toBeVisible({ timeout: 5000 }); await a.page.getByRole('button', { name: '其他' }).click(); // 性能优先开关应可见 await expect(a.page.getByText('性能优先')).toBeVisible({ timeout: 5000 }); // GPU 信息应显示 await expect(a.page.getByText(/GPU:/)).toBeVisible({ timeout: 5000 }); // 开启性能优先——通过 data-testid 定位 toggle const perfToggle = a.page.getByTestId('perf-toggle'); await perfToggle.click(); // 关闭设置面板 await a.page.keyboard.press('Escape'); await a.page.waitForTimeout(500); // 重开应用验证持久化 await a.app.close(); const a2 = await launch(userData); await a2.invoke('vault:switch', { root: vault }); await a2.page.getByTitle('设置').click(); await a2.page.getByRole('button', { name: '其他' }).click(); // perfMode 应已持久化(toggle 为开启状态) const toggleBg = await a2.page.getByTestId('perf-toggle').evaluate((el: HTMLButtonElement) => el.style.background); // 开启时 background 应为 var(--accent) 或对应值 expect(toggleBg).toContain('accent'); await a2.app.close(); });