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

52 lines
2.4 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 };
}
// 红色波浪线修复:编辑器 contenteditable 必须关闭 Chromium 拼写检查(spellcheck=false)
test('编辑器关闭拼写检查(去除红色波浪线)', async () => {
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-sp-'));
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 a = await launch(ud);
await a.invoke('vault:switch', { root: v });
await a.page.getByRole('button', { name: /新建文档/ }).click();
await a.page.getByPlaceholder(/输入文档标题/).fill('SpellTest');
await a.page.getByPlaceholder(/输入文档标题/).press('Enter');
await expect(a.page.getByTestId('tabbar').getByText('SpellTest', { exact: true })).toBeVisible({ timeout: 10000 });
const ed = a.page.locator('.ProseMirror');
await ed.click();
await a.page.keyboard.type('WordPress caddy gitea Lsky');
await a.page.waitForTimeout(300);
// 主编辑器 spellcheck 属性必须为 false(Chromium 据此关闭红色波浪线)
const sc = await a.page.locator('.ProseMirror').getAttribute('spellcheck');
console.log('SPELLCHECK', sc);
expect(sc).toBe('false');
// CSS 兜底样式存在:spelling-error / grammar-error 无红色波浪下划线
const cssOk = await a.page.evaluate(() => {
const sheets = Array.from(document.styleSheets);
for (const s of sheets) {
try {
const rules = Array.from((s as CSSStyleSheet).cssRules);
for (const r of rules) {
const css = (r as CSSStyleRule).cssText || '';
if (css.includes('spelling-error') && css.includes('text-decoration')) return true;
}
} catch { /* cross-origin */ }
}
return false;
});
console.log('CSS_FALLBACK', cssOk);
await a.app.close();
});