1+ import { ReactNode } from 'react'
12import { Position } from 'reactflow'
23
3- import { render } from '@testing-library/react'
4+ import { render , RenderOptions } from '@testing-library/react'
45
56import { ConnectionLine } from './ConnectionLine'
67
8+ const SvgWrapper = ( { children } : { children : ReactNode } ) => < svg > { children } </ svg >
9+
10+ const renderInSvg = ( ui : React . ReactElement , options ?: Omit < RenderOptions , 'wrapper' > ) => render ( ui , { wrapper : SvgWrapper , ...options } )
11+
712// --- Mocks ---
813let mockConnectionHandleId : string | null = null
914
@@ -39,72 +44,72 @@ describe('ConnectionLine', () => {
3944 describe ( 'edge label visibility' , ( ) => {
4045 it ( 'should not render edge label for regular nodes' , ( ) => {
4146 mockConnectionHandleId = 'llmAgentflow_output_0'
42- const { queryByTestId } = render ( < ConnectionLine { ...defaultProps } /> )
47+ const { queryByTestId } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
4348 expect ( queryByTestId ( 'edge-label-renderer' ) ) . not . toBeInTheDocument ( )
4449 } )
4550
4651 it ( 'should render edge label for conditionAgentflow nodes' , ( ) => {
4752 mockConnectionHandleId = 'conditionAgentflow_output-0'
48- const { getByTestId } = render ( < ConnectionLine { ...defaultProps } /> )
53+ const { getByTestId } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
4954 expect ( getByTestId ( 'edge-label-renderer' ) ) . toBeInTheDocument ( )
5055 } )
5156
5257 it ( 'should render edge label for conditionAgentAgentflow nodes' , ( ) => {
5358 mockConnectionHandleId = 'conditionAgentAgentflow_output-0'
54- const { getByTestId } = render ( < ConnectionLine { ...defaultProps } /> )
59+ const { getByTestId } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
5560 expect ( getByTestId ( 'edge-label-renderer' ) ) . toBeInTheDocument ( )
5661 } )
5762
5863 it ( 'should render edge label for humanInputAgentflow nodes' , ( ) => {
5964 mockConnectionHandleId = 'humanInputAgentflow_output-0'
60- const { getByTestId } = render ( < ConnectionLine { ...defaultProps } /> )
65+ const { getByTestId } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
6166 expect ( getByTestId ( 'edge-label-renderer' ) ) . toBeInTheDocument ( )
6267 } )
6368 } )
6469
6570 describe ( 'edge label content' , ( ) => {
6671 it ( 'should show numeric label for condition nodes' , ( ) => {
6772 mockConnectionHandleId = 'conditionAgentflow_output-2'
68- const { getByText } = render ( < ConnectionLine { ...defaultProps } /> )
73+ const { getByText } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
6974 expect ( getByText ( '2' ) ) . toBeInTheDocument ( )
7075 } )
7176
7277 it ( 'should show "0" when condition handle has no numeric suffix' , ( ) => {
7378 mockConnectionHandleId = 'conditionAgentflow_output-0'
74- const { getByText } = render ( < ConnectionLine { ...defaultProps } /> )
79+ const { getByText } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
7580 expect ( getByText ( '0' ) ) . toBeInTheDocument ( )
7681 } )
7782
7883 it ( 'should show "proceed" for humanInput first output (index 0)' , ( ) => {
7984 mockConnectionHandleId = 'humanInputAgentflow_output-0'
80- const { getByText } = render ( < ConnectionLine { ...defaultProps } /> )
85+ const { getByText } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
8186 expect ( getByText ( 'proceed' ) ) . toBeInTheDocument ( )
8287 } )
8388
8489 it ( 'should show "reject" for humanInput second output (index 1)' , ( ) => {
8590 mockConnectionHandleId = 'humanInputAgentflow_output-1'
86- const { getByText } = render ( < ConnectionLine { ...defaultProps } /> )
91+ const { getByText } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
8792 expect ( getByText ( 'reject' ) ) . toBeInTheDocument ( )
8893 } )
8994
9095 it ( 'should handle NaN suffix by defaulting to "0"' , ( ) => {
9196 mockConnectionHandleId = 'conditionAgentflow_output-notanumber'
92- const { getByText } = render ( < ConnectionLine { ...defaultProps } /> )
97+ const { getByText } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
9398 expect ( getByText ( '0' ) ) . toBeInTheDocument ( )
9499 } )
95100 } )
96101
97102 describe ( 'edge color' , ( ) => {
98103 it ( 'should use the color from AGENTFLOW_ICONS for known nodes' , ( ) => {
99104 mockConnectionHandleId = 'conditionAgentflow_output-0'
100- const { container } = render ( < ConnectionLine { ...defaultProps } /> )
105+ const { container } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
101106 const path = container . querySelector ( 'path.animated' )
102107 expect ( path ) . toHaveAttribute ( 'stroke' , '#FF6B6B' )
103108 } )
104109
105110 it ( 'should render path element for any connection' , ( ) => {
106111 mockConnectionHandleId = 'llmAgentflow_output_0'
107- const { container } = render ( < ConnectionLine { ...defaultProps } /> )
112+ const { container } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
108113 const path = container . querySelector ( 'path.animated' )
109114 expect ( path ) . toBeInTheDocument ( )
110115 expect ( path ) . toHaveAttribute ( 'stroke' , '#45B7D1' )
@@ -113,7 +118,7 @@ describe('ConnectionLine', () => {
113118
114119 it ( 'should handle null connectionHandleId gracefully' , ( ) => {
115120 mockConnectionHandleId = null
116- const { container } = render ( < ConnectionLine { ...defaultProps } /> )
121+ const { container } = renderInSvg ( < ConnectionLine { ...defaultProps } /> )
117122 expect ( container . querySelector ( 'g' ) ) . toBeInTheDocument ( )
118123 } )
119124} )
0 commit comments