@@ -254,6 +254,41 @@ public async Task ConnectPorts(string sourceNodeName, string sourcePortName, str
254254 await Task . Delay ( 200 ) ; // Wait for connection to be established
255255 }
256256
257+ public async Task DeleteConnection ( string sourceNodeName , string sourcePortName , string targetNodeName , string targetPortName )
258+ {
259+ Console . WriteLine ( $ "Deleting connection: { sourceNodeName } .{ sourcePortName } -> { targetNodeName } .{ targetPortName } ") ;
260+
261+ // In Blazor.Diagrams, connections are rendered as SVG paths
262+ // We need to click on the connection to select it, then press Delete
263+
264+ // Get source and target port positions
265+ var sourcePort = GetGraphPort ( sourceNodeName , sourcePortName , isInput : false ) ;
266+ await sourcePort . WaitForVisible ( ) ;
267+
268+ var targetPort = GetGraphPort ( targetNodeName , targetPortName , isInput : true ) ;
269+ await targetPort . WaitForVisible ( ) ;
270+
271+ var sourceBox = await sourcePort . BoundingBoxAsync ( ) ;
272+ var targetBox = await targetPort . BoundingBoxAsync ( ) ;
273+
274+ if ( sourceBox == null || targetBox == null )
275+ throw new Exception ( "Could not get bounding boxes for ports" ) ;
276+
277+ // Calculate midpoint between source and target
278+ var midX = ( float ) ( sourceBox . X + sourceBox . Width / 2 + targetBox . X + targetBox . Width / 2 ) / 2 ;
279+ var midY = ( float ) ( sourceBox . Y + sourceBox . Height / 2 + targetBox . Y + targetBox . Height / 2 ) / 2 ;
280+
281+ Console . WriteLine ( $ "Clicking on connection midpoint: ({ midX } , { midY } )") ;
282+
283+ // Click on the connection to select it
284+ await _user . Mouse . ClickAsync ( midX , midY ) ;
285+ await Task . Delay ( 100 ) ;
286+
287+ // Press Delete key to remove the connection
288+ await _user . Keyboard . PressAsync ( "Delete" ) ;
289+ await Task . Delay ( 100 ) ;
290+ }
291+
257292 public async Task TakeScreenshot ( string fileName )
258293 {
259294 await _user . ScreenshotAsync ( new ( ) { Path = fileName } ) ;
0 commit comments