Files
MyNote/apps/desktop/tests/e2e/transparency-check.spec.ts
T

37 lines
1.9 KiB
TypeScript
Raw 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');
// 透明主题真透明:bgPrimary=transparent 时根背景必须是 alpha=0(配合主进程 transparent:true + backgroundColor:#00000000 + backgroundMaterial:'none' 即可透出下层软件)
test('透明主题:根背景 alpha=0(真透明,可见下层软件)', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-tr-'));
const ud = nodePath.join(tmp, 'ud'); const v = nodePath.join(tmp, 'v');
await fs.mkdir(ud, { recursive: true }); await fs.mkdir(v, { recursive: true });
const app = await electron.launch({ args: ['--user-data-dir=' + ud, MAIN_JS] });
const page = await app.firstWindow();
await page.waitForLoadState('domcontentloaded');
await page.evaluate(({ root }) => (globalThis as any).dsh.invoke('vault:switch', { root }), { root: v });
// 应用透明主题的 CSS 变量(bgPrimary='transparent'),并移除背景图遮罩
await page.evaluate(() => {
const el = document.documentElement;
el.style.setProperty('--bg-primary', 'transparent');
el.style.setProperty('--bg-secondary', 'rgba(20,20,28,0.5)');
el.style.setProperty('--text-primary', '#ddd');
document.querySelectorAll('div[style*="background-image"]').forEach((n: any) => n.remove());
});
await page.waitForTimeout(400);
const rootBg = await page.evaluate(() => {
const root = document.querySelector('#root > div') as HTMLElement;
if (!root) return null;
return getComputedStyle(root).backgroundColor;
});
console.log('ROOT_BG', rootBg);
expect(rootBg).not.toBeNull();
// 透明背景应为 alpha=0(rgba(0,0,0,0) 或 transparent)
expect(rootBg).toMatch(/rgba\(0, 0, 0, 0\)|transparent/i);
await app.close();
});