From e7da213f93f11b1f78a69a113c55a548b0e877ef Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:53:37 +0800 Subject: [PATCH] fix(web): name workflow debug actions (#40273) --- .../__tests__/debug-and-preview.spec.tsx | 95 +++++++++++++++++++ .../panel/debug-and-preview/index.tsx | 16 ++-- 2 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 web/app/components/workflow/panel/debug-and-preview/__tests__/debug-and-preview.spec.tsx diff --git a/web/app/components/workflow/panel/debug-and-preview/__tests__/debug-and-preview.spec.tsx b/web/app/components/workflow/panel/debug-and-preview/__tests__/debug-and-preview.spec.tsx new file mode 100644 index 00000000000..8e1cf322c6e --- /dev/null +++ b/web/app/components/workflow/panel/debug-and-preview/__tests__/debug-and-preview.spec.tsx @@ -0,0 +1,95 @@ +import type { Ref } from 'react' +import { screen } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { useImperativeHandle } from 'react' +import { renderWorkflowComponent } from '@/app/components/workflow/__tests__/workflow-test-env' +import DebugAndPreview from '../index' + +const mockHandleRestart = vi.fn() +const mockHandleNodeCancelRunningStatus = vi.fn() +const mockHandleEdgeCancelRunningStatus = vi.fn() + +vi.mock('reactflow', () => ({ + useNodes: () => [ + { + data: { + type: 'start', + variables: [{ label: 'Topic', variable: 'topic' }], + }, + id: 'start', + }, + ], +})) + +vi.mock('../../../hooks/use-workflow-panel-interactions', () => ({ + useWorkflowInteractions: () => ({ + handleCancelDebugAndPreviewPanel: vi.fn(), + }), +})) + +vi.mock('../../../hooks/use-nodes-interactions-without-sync', () => ({ + useNodesInteractionsWithoutSync: () => ({ + handleNodeCancelRunningStatus: mockHandleNodeCancelRunningStatus, + }), +})) + +vi.mock('../../../hooks/use-edges-interactions-without-sync', () => ({ + useEdgesInteractionsWithoutSync: () => ({ + handleEdgeCancelRunningStatus: mockHandleEdgeCancelRunningStatus, + }), +})) + +vi.mock('../../../nodes/_base/hooks/use-resize-panel', () => ({ + useResizePanel: () => ({ + containerRef: vi.fn(), + triggerRef: vi.fn(), + }), +})) + +vi.mock('../../../persistence/local-storage-options', () => ({ + useSetDebugPreviewPanelWidth: () => vi.fn(), +})) + +vi.mock('../chat-wrapper', () => ({ + default: function MockChatWrapper({ ref }: { ref: Ref<{ handleRestart: () => void }> }) { + useImperativeHandle(ref, () => ({ handleRestart: mockHandleRestart })) + return
Chat
+ }, +})) + +describe('DebugAndPreview', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('exposes and invokes the restart action by name', async () => { + const user = userEvent.setup() + renderWorkflowComponent(, { + initialStoreState: { + previewPanelWidth: 400, + }, + }) + + await user.click(screen.getByRole('button', { name: /operation\.refresh/ })) + + expect(mockHandleNodeCancelRunningStatus).toHaveBeenCalledTimes(1) + expect(mockHandleEdgeCancelRunningStatus).toHaveBeenCalledTimes(1) + expect(mockHandleRestart).toHaveBeenCalledTimes(1) + }) + + it('exposes the user input field toggle state by name', async () => { + const user = userEvent.setup() + renderWorkflowComponent(, { + initialStoreState: { + previewPanelWidth: 400, + }, + }) + const toggle = screen.getByRole('button', { name: /panel\.userInputField/ }) + + expect(toggle).toHaveAttribute('aria-pressed', 'true') + + await user.click(toggle) + + expect(toggle).toHaveAttribute('aria-pressed', 'false') + }) +}) diff --git a/web/app/components/workflow/panel/debug-and-preview/index.tsx b/web/app/components/workflow/panel/debug-and-preview/index.tsx index 5425ed00fd4..a6e5e3cd5e9 100644 --- a/web/app/components/workflow/panel/debug-and-preview/index.tsx +++ b/web/app/components/workflow/panel/debug-and-preview/index.tsx @@ -33,6 +33,8 @@ const DebugAndPreview = () => { const startNode = nodes.find((node) => node.data.type === BlockEnum.Start) const variables = startNode?.data.variables || [] const visibleVariables = variables + const restartLabel = t(($) => $['operation.refresh'], { ns: 'common' }) + const userInputFieldLabel = t(($) => $['panel.userInputField'], { ns: 'workflow' }) const [showConversationVariableModal, setShowConversationVariableModal] = useState(false) @@ -94,12 +96,12 @@ const DebugAndPreview = () => { handleRestartChat()}> - + handleRestartChat()}> + } /> - {t(($) => $['operation.refresh'], { ns: 'common' })} + {restartLabel} {visibleVariables.length > 0 && (
@@ -107,16 +109,16 @@ const DebugAndPreview = () => { setExpanded(!expanded)} > - +