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 }; } // FR-E3 行内格式:加粗/斜体/删除线/行内代码/清除格式 工具栏按钮 test('FR-E3:行内代码 + 清除格式 工具栏按钮生效', async () => { const tmp = await fs.mkdtemp(nodePath.join(os.tmpdir(), 'hn-e3-')); 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 a.page.getByRole('button', { name: /新建文档/ }).click(); await a.page.getByPlaceholder(/输入文档标题/).fill('行内格式'); await a.page.getByPlaceholder(/输入文档标题/).press('Enter'); await expect(a.page.getByTestId('tabbar').getByText('行内格式', { exact: true })).toBeVisible({ timeout: 10000 }); const editor = a.page.locator('.ProseMirror'); const html = () => a.page.evaluate(() => (document.querySelector('.ProseMirror') as HTMLElement)?.innerHTML ?? ''); // 输入文本 await editor.click(); await a.page.keyboard.type('hello world'); // 加粗 -> await a.page.keyboard.press('Control+A'); await a.page.locator('button[title="加粗 Ctrl+B"]').click(); expect(await html()).toContain(''); // 清除格式 -> 移除 await editor.click(); await a.page.keyboard.press('Control+A'); await a.page.locator('button[title="清除格式"]').click(); const afterClearBold = await html(); expect(afterClearBold).not.toContain(''); expect(afterClearBold).not.toContain(''); // 行内代码 -> await editor.click(); await a.page.keyboard.press('Control+A'); await a.page.locator('button[title="行内代码 Ctrl+E"]').click(); expect(await html()).toContain(''); // 清除格式 -> 移除 await editor.click(); await a.page.keyboard.press('Control+A'); await a.page.locator('button[title="清除格式"]').click(); const afterClearCode = await html(); expect(afterClearCode).not.toContain(''); expect(afterClearCode).not.toContain(''); await a.app.close(); });