55 lines
2.2 KiB
TypeScript
55 lines
2.2 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');
|
|
|
|
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 };
|
|
}
|
|
|
|
async function newDoc(a: { page: any; invoke: any }, title: string) {
|
|
await a.page.getByRole('button', { name: /新建文档/ }).click();
|
|
await a.page.getByPlaceholder(/输入文档标题/).fill(title);
|
|
await a.page.getByPlaceholder(/输入文档标题/).press('Enter');
|
|
await expect(a.page.getByTestId('tabbar').getByText(title, { exact: true })).toBeVisible({ timeout: 10000 });
|
|
}
|
|
|
|
// FR-E12:斜杠菜单插入公式块 + KaTeX 渲染
|
|
test('FR-E12:斜杠菜单插入公式块 + KaTeX 渲染', async () => {
|
|
const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-e12-'));
|
|
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 });
|
|
await newDoc(a, '公式测试');
|
|
|
|
await a.page.locator('.ProseMirror').click();
|
|
await a.page.keyboard.type('/');
|
|
await a.page.waitForTimeout(300);
|
|
// 斜杠菜单应出现
|
|
await a.page.getByText('公式', { exact: true }).click();
|
|
|
|
// 应插入 mathBlock 节点
|
|
await expect(a.page.locator('.ProseMirror .math-block')).toHaveCount(1, { timeout: 5000 });
|
|
|
|
// 在公式源码区输入 LaTeX
|
|
const source = a.page.locator('.ProseMirror .math-source');
|
|
await source.click();
|
|
await a.page.keyboard.type('c = \\sqrt{a^2 + b^2}');
|
|
|
|
// KaTeX 预览区应渲染出 .katex 元素
|
|
await expect(a.page.locator('.ProseMirror .math-preview .katex')).toHaveCount(1, { timeout: 8000 });
|
|
|
|
await a.app.close();
|
|
});
|