fix(sender-e2e): stabilize template delete e2e case#317
fix(sender-e2e): stabilize template delete e2e case#317hexqi merged 3 commits intoopentiny:developfrom
Conversation
WalkthroughReplaced manual cursor/keypress sequences in template-deletion tests with a new helper-driven operation ( Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Playwright Test
participant PageHelper as template-helper
participant WinAPI as window.__senderTestApi
participant Sender as sender component (ProseMirror)
participant EditorDOM as Editor DOM
Test->>PageHelper: call pressDeleteBeforeTemplate(0)
PageHelper->>WinAPI: page.evaluate -> pressDeleteBeforeTemplate(0)
WinAPI->>Sender: moveCursorBeforeTemplate(0) (walk doc.descendants)
Sender->>EditorDOM: set selection / focus at position before template
WinAPI->>EditorDOM: synthesize keydown Delete (bubbling, cancelable)
EditorDOM-->>WinAPI: dispatchEvent result (canceled or not)
WinAPI-->>PageHelper: return boolean success
PageHelper-->>Test: assert returned true, optionally poll normalized text
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Package Previewpnpm add https://pkg.pr.new/@opentiny/tiny-robot@961233c pnpm add https://pkg.pr.new/@opentiny/tiny-robot-kit@961233c pnpm add https://pkg.pr.new/@opentiny/tiny-robot-svgs@961233c commit: 961233c |
452ef54 to
3c19a1b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/test/src/sender/index.vue (1)
7-14: Return structured results from__senderTestApi.This hook is a good stabilization strategy, but
falsecurrently conflates “editor unavailable”, “template index not found”, “cursor placement failed”, and “Delete not handled”. That leavespackages/test/src/sender/helpers/template-helper.ts:128-133with only a genericexpected false to be truewhen something regresses. Returning{ ok, reason }here would keep the deterministic path and make the next failure much faster to triage.💡 Possible adjustment
declare global { interface Window { __senderTestApi?: { - moveCursorBeforeTemplate: (index: number) => boolean - pressDeleteBeforeTemplate: (index: number) => boolean + moveCursorBeforeTemplate: (index: number) => { ok: boolean; reason?: string } + pressDeleteBeforeTemplate: (index: number) => { ok: boolean; reason?: string } } } } const moveCursorBeforeTemplate = (index: number) => { const exposedEditor = senderRef.value?.editor const editor = exposedEditor?.value ?? exposedEditor - if (!editor) return false + if (!editor) return { ok: false, reason: 'editor is unavailable' } let currentIndex = 0 let templatePosition: number | null = null @@ - if (templatePosition === null) return false + if (templatePosition === null) { + return { ok: false, reason: `template index ${index} was not found` } + } editor.commands.setTextSelection(templatePosition) editor.commands.focus(templatePosition) - return editor.state.selection.$from.nodeAfter?.type?.name === 'templateBlock' + const ok = editor.state.selection.$from.nodeAfter?.type?.name === 'templateBlock' + return ok ? { ok } : { ok: false, reason: 'cursor was not placed before the template' } } const pressDeleteBeforeTemplate = (index: number) => { const exposedEditor = senderRef.value?.editor const editor = exposedEditor?.value ?? exposedEditor - if (!editor || !moveCursorBeforeTemplate(index)) return false + if (!editor) return { ok: false, reason: 'editor is unavailable' } + + const moveResult = moveCursorBeforeTemplate(index) + if (!moveResult.ok) return moveResult const deleteEvent = new KeyboardEvent('keydown', { key: 'Delete', bubbles: true, cancelable: true, }) - return editor.view.dom.dispatchEvent(deleteEvent) === false + const ok = editor.view.dom.dispatchEvent(deleteEvent) === false + return ok ? { ok } : { ok: false, reason: `Delete before template ${index} was not handled` } }Also applies to: 170-209
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/test/src/sender/index.vue` around lines 7 - 14, The test hook __senderTestApi currently returns boolean from moveCursorBeforeTemplate and pressDeleteBeforeTemplate which conflates multiple failure modes; change the Window.__senderTestApi type to return a structured result { ok: boolean, reason?: string } for both functions, update all call sites (including the helpers that currently assert true around moveCursorBeforeTemplate and pressDeleteBeforeTemplate) to handle the object by checking result.ok and surface or assert result.reason on failure, and adjust any tests or assertions in the template-helper functions to expect and propagate the structured {ok, reason} instead of a bare boolean so failures report the precise cause.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/test/src/sender/index.vue`:
- Around line 7-14: The test hook __senderTestApi currently returns boolean from
moveCursorBeforeTemplate and pressDeleteBeforeTemplate which conflates multiple
failure modes; change the Window.__senderTestApi type to return a structured
result { ok: boolean, reason?: string } for both functions, update all call
sites (including the helpers that currently assert true around
moveCursorBeforeTemplate and pressDeleteBeforeTemplate) to handle the object by
checking result.ok and surface or assert result.reason on failure, and adjust
any tests or assertions in the template-helper functions to expect and propagate
the structured {ok, reason} instead of a bare boolean so failures report the
precise cause.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 69929036-a0e7-4c4c-9b00-41613dc27ff4
📒 Files selected for processing (3)
packages/test/src/sender/helpers/template-helper.tspackages/test/src/sender/index.vuepackages/test/src/sender/specs/template/delete.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/test/src/sender/specs/template/delete.spec.ts
🧹 Preview Cleaned UpThe preview deployment has been removed. |

一、问题背景
Sender 模板块删除场景中的 TC-DL-06 在 CI 环境下存在偶发失败。根因是该用例原先依赖 Home + ArrowRight 这类键盘步进方式来定位光标,再通过外层键盘事件触发 Delete,对浏览器选区行为和执行时序较为敏感,在不同环境下容易出现光标未准确落位的问题,从而导致未命中预期的模板块删除逻辑。
二、 优化方向
本次优化将“光标定位 + Delete 触发”收敛为基于 Sender 内部 editor 的浏览器侧原子操作,不再依赖外层键盘步进来猜测光标位置。这样可以更稳定地命中模板块左侧删除场景,降低 ProseMirror/Tiptap 选区差异带来的 flaky 风险,同时保留该测试场景的覆盖。
变更内容
Delete场景的测试实现,不再依赖Home + ArrowRight这类对浏览器选区行为敏感的键盘步进。template-helper中补充对应的稳定辅助方法和文本断言能力,用于提升模板块边界场景下的断言可靠性。TC-DL-05、恢复并稳定TC-DL-06的实现,使其更贴近模板块删除逻辑的真实触发路径。三、 当前现状
验证情况
pnpm -F tiny-robot-test test -- --workers=1 src/sender/specs/template/delete.spec.tsCI=1、单 worker 模式下连续运行 5 轮template/delete.spec.ts,均通过CI=1、单 worker 模式下运行src/sender/specs,70 passedpnpm -F tiny-robot-test test,79 passed运行截图
【git-action】
【本地】
整体测试

相关测试

Summary by CodeRabbit