Files

41 lines
1.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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('外观:特效选择 + 持久化(重开恢复并接线 EffectLayer)', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-appearance-'));
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 a1 = await launch(userData);
await a1.invoke('vault:switch', { root: vault });
await a1.page.getByTitle('外观定制').click();
await expect(a1.page.getByText('外观定制').first()).toBeVisible();
await a1.page.getByRole('button', { name: '微粒' }).click();
await a1.page.getByRole('button', { name: '保存外观' }).click();
await expect(a1.page.getByText('外观定制').first()).toBeHidden();
await a1.app.close();
// 重开:恢复 + 接线
const a2 = await launch(userData);
const cfg: { effect: string } | null = await a2.invoke('appearance:load', null);
expect(cfg?.effect).toBe('particle');
await expect(a2.page.locator('canvas[data-effect="particle"]')).toBeVisible({ timeout: 10000 });
await a2.app.close();
});