feat(M2): FR-E3 行内格式补齐——工具栏行内代码(toggleCode/Ctrl+E)+清除格式(unsetAllMarks)按钮;editor-inline E2E 1 项

This commit is contained in:
hunter-dev
2026-08-26 13:05:11 +08:00
parent c4af03adce
commit 78843ce5cc
2 changed files with 71 additions and 0 deletions
@@ -20,6 +20,8 @@ export function EditorToolbar() {
<T title="加粗 Ctrl+B" onClick={cmd(e => e.chain().focus().toggleBold().run())} disabled={d}>B</T>
<T title="斜体 Ctrl+I" onClick={cmd(e => e.chain().focus().toggleItalic().run())} disabled={d}>I</T>
<T title="删除线 Alt+Shift+5" onClick={cmd(e => e.chain().focus().toggleStrike().run())} disabled={d}>S</T>
<T title="行内代码 Ctrl+E" onClick={cmd(e => e.chain().focus().toggleCode().run())} disabled={d}><span style={{ fontFamily: 'monospace' }}>code</span></T>
<T title="清除格式" onClick={cmd(e => e.chain().focus().unsetAllMarks().run())} disabled={d}>T×</T>
<T title="引用 Ctrl+Shift+Q" onClick={cmd(e => e.chain().focus().toggleBlockquote().run())} disabled={d}>❝</T>
<span style={{ width: 1, background: '#333', height: 20, margin: '0 4px' }} />
<T title="一级标题 Ctrl+1" onClick={cmd(e => e.chain().focus().toggleHeading({ level: 1 }).run())} disabled={d}>H1</T>
@@ -0,0 +1,69 @@
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');
// 加粗 -> <strong>
await a.page.keyboard.press('Control+A');
await a.page.locator('button[title="加粗 Ctrl+B"]').click();
expect(await html()).toContain('<strong>');
// 清除格式 -> 移除 <strong>
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('<strong>');
expect(afterClearBold).not.toContain('<code>');
// 行内代码 -> <code>
await editor.click();
await a.page.keyboard.press('Control+A');
await a.page.locator('button[title="行内代码 Ctrl+E"]').click();
expect(await html()).toContain('<code>');
// 清除格式 -> 移除 <code>
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('<code>');
expect(afterClearCode).not.toContain('<strong>');
await a.app.close();
});