37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
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');
|
||
|
||
// UI 重新设计:窗口不透明(transparent:false + backgroundColor 空间底色),根背景应为不透明的 L0 空间色
|
||
test('窗口不透明:根背景为 L0 空间底色(alpha=1,非透明)', 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 });
|
||
await page.waitForTimeout(500);
|
||
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=1,非 rgba(...,0) / transparent)
|
||
const m = rootBg!.match(/rgba\(([\d.]+),\s*([\d.]+),\s*([\d.]+),\s*([\d.]+)\)|^rgb\(([\d.]+),\s*([\d.]+),\s*([\d.]+)\)$/);
|
||
expect(m).not.toBeNull();
|
||
// 不透明:要么是 rgb(...)(隐式 alpha=1),要么 rgba alpha=1
|
||
if (rootBg!.startsWith('rgba')) {
|
||
const alpha = parseFloat(m![4]);
|
||
expect(alpha).toBe(1);
|
||
} else {
|
||
expect(rootBg!.startsWith('rgb(')).toBe(true);
|
||
}
|
||
await app.close();
|
||
}); |