From fef28097cc0d29ff46780d901148fb97cf283284 Mon Sep 17 00:00:00 2001 From: Joel Date: Mon, 24 Aug 2026 08:33:29 +0000 Subject: [PATCH] fix: preserve agent task editor focus when inserting commands (#41166) --- .../workflow/nodes/agent-v2/__tests__/panel.spec.tsx | 8 +++++--- .../nodes/agent-v2/components/agent-task-field.tsx | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/nodes/agent-v2/__tests__/panel.spec.tsx b/web/app/components/workflow/nodes/agent-v2/__tests__/panel.spec.tsx index 25d39a0fe11..850a3e688bb 100644 --- a/web/app/components/workflow/nodes/agent-v2/__tests__/panel.spec.tsx +++ b/web/app/components/workflow/nodes/agent-v2/__tests__/panel.spec.tsx @@ -3,6 +3,7 @@ import type { AgentV2NodeType } from '../types' import type { PromptEditorProps } from '@/app/components/base/prompt-editor' import type { NodePanelProps } from '@/app/components/workflow/types' import { act, fireEvent, render, screen, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' import { BlockEnum } from '@/app/components/workflow/types' import { FlowType } from '@/types/common' import { AgentV2Panel } from '../panel' @@ -1230,7 +1231,8 @@ describe('agent/panel', () => { expect(screen.queryByText('Clarification Drafter')).not.toBeInTheDocument() }) - it('updates agent task and opens prompt insertion shortcuts', () => { + it('updates agent task and opens prompt insertion shortcuts', async () => { + const user = userEvent.setup() render( { screen.queryByRole('button', { name: 'workflow.nodes.agent.task.mention' }), ).not.toBeInTheDocument() - fireEvent.focus(editor) + await user.click(editor) - fireEvent.click(screen.getByRole('button', { name: 'workflow.nodes.agent.task.insert' })) + await user.click(screen.getByRole('button', { name: 'workflow.nodes.agent.task.insert' })) expect(mockEditorFocus).toHaveBeenCalled() expect(mockInsertNodes.mock.calls[0]?.[0]?.[0]?.getTextContent()).toBe('/') expect( diff --git a/web/app/components/workflow/nodes/agent-v2/components/agent-task-field.tsx b/web/app/components/workflow/nodes/agent-v2/components/agent-task-field.tsx index 86457d4e12b..cb3b3e5ee7c 100644 --- a/web/app/components/workflow/nodes/agent-v2/components/agent-task-field.tsx +++ b/web/app/components/workflow/nodes/agent-v2/components/agent-task-field.tsx @@ -36,6 +36,7 @@ function AgentTaskToolbar({ taskLength, onInsert }: { taskLength: number; onInse