From 78843ce5ccd043bfa68d0e97a085591855b505e0 Mon Sep 17 00:00:00 2001 From: hunter-dev Date: Wed, 26 Aug 2026 13:05:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(M2):=20FR-E3=20=E8=A1=8C=E5=86=85=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=A1=A5=E9=BD=90=E2=80=94=E2=80=94=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E6=A0=8F=E8=A1=8C=E5=86=85=E4=BB=A3=E7=A0=81(toggleCode/Ctrl+E?= =?UTF-8?q?)+=E6=B8=85=E9=99=A4=E6=A0=BC=E5=BC=8F(unsetAllMarks)=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=9Beditor-inline=20E2E=201=20=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/editor/EditorToolbar.tsx | 2 + apps/desktop/tests/e2e/editor-inline.spec.ts | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 apps/desktop/tests/e2e/editor-inline.spec.ts diff --git a/apps/desktop/src/renderer/features/editor/EditorToolbar.tsx b/apps/desktop/src/renderer/features/editor/EditorToolbar.tsx index ce75801..b942567 100644 --- a/apps/desktop/src/renderer/features/editor/EditorToolbar.tsx +++ b/apps/desktop/src/renderer/features/editor/EditorToolbar.tsx @@ -20,6 +20,8 @@ export function EditorToolbar() { e.chain().focus().toggleBold().run())} disabled={d}>B e.chain().focus().toggleItalic().run())} disabled={d}>I e.chain().focus().toggleStrike().run())} disabled={d}>S + e.chain().focus().toggleCode().run())} disabled={d}>code + e.chain().focus().unsetAllMarks().run())} disabled={d}>T× e.chain().focus().toggleBlockquote().run())} disabled={d}>❝ e.chain().focus().toggleHeading({ level: 1 }).run())} disabled={d}>H1 diff --git a/apps/desktop/tests/e2e/editor-inline.spec.ts b/apps/desktop/tests/e2e/editor-inline.spec.ts new file mode 100644 index 0000000..1a6fa7b --- /dev/null +++ b/apps/desktop/tests/e2e/editor-inline.spec.ts @@ -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'); + + // 加粗 -> + 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(); +});