From 241182740ba2f18367fe89b93967d6566c49fbc7 Mon Sep 17 00:00:00 2001 From: Caio Pizzol Date: Mon, 13 Jul 2026 16:01:51 -0300 Subject: [PATCH] fix(super-editor): verify comment selection feedback settles (IT-1278) --- .../comment/comments-plugin.test.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.test.js b/packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.test.js index 7aef9b791f..4129557c3d 100644 --- a/packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.test.js +++ b/packages/super-editor/src/editors/v1/extensions/comment/comments-plugin.test.js @@ -766,6 +766,30 @@ describe('CommentsPlugin state', () => { expect(editor.emit).not.toHaveBeenCalled(); }); + it('settles when the selected event is echoed back to the plugin', () => { + const { view, editor } = createPluginStateEnvironment(); + + editor.emit.mockImplementation((event, update) => { + if (event === 'commentsUpdate' && update.type === comments_module_events.SELECTED) { + setActiveComment(view, update.activeCommentId); + } + }); + + setActiveComment(view, 'comment-1'); + setActiveComment(view, 'comment-2'); + setActiveComment(view, 'comment-3'); + + vi.runAllTimers(); + + expect(editor.emit).toHaveBeenCalledTimes(1); + expect(editor.emit).toHaveBeenCalledWith('commentsUpdate', { + type: comments_module_events.SELECTED, + activeCommentId: 'comment-3', + }); + expect(CommentsPluginKey.getState(view.state).activeThreadId).toBe('comment-3'); + expect(vi.getTimerCount()).toBe(0); + }); + it('does not emit when the editor is destroyed before a deferred notification runs', () => { const { view, editor } = createPluginStateEnvironment();