Skip to content

Commit 8ecb7fc

Browse files
authored
Fix InvalidOperationException when deleting connections from UI (#73)
1 parent 91fcc16 commit 8ecb7fc

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/NodeDev.Blazor/Components/GraphCanvas.razor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,11 @@ public void RemoveLinkFromGraphCanvas(Connection source, Connection destination)
580580
DisableConnectionUpdate = true;
581581
try
582582
{
583-
Diagram.Links.Remove(Diagram.Links.First(x => (x.Source.Model as GraphPortModel)?.Connection == source && (x.Target.Model as GraphPortModel)?.Connection == destination));
583+
var link = Diagram.Links.FirstOrDefault(x => (x.Source.Model as GraphPortModel)?.Connection == source && (x.Target.Model as GraphPortModel)?.Connection == destination);
584+
if (link != null)
585+
{
586+
Diagram.Links.Remove(link);
587+
}
584588
}
585589
finally
586590
{

src/NodeDev.EndToEndTests/Features/NodeManipulation.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Scenario: Disconnect and reconnect nodes
3434
When I connect the 'Entry' 'Exec' output to the 'Return' 'Exec' input
3535
Then I take a screenshot named 'reconnected'
3636

37+
Scenario: Delete connection between Entry and Return nodes
38+
Given I load the default project
39+
And I open the 'Main' method in the 'Program' class
40+
When I delete the connection between 'Entry' 'Exec' output and 'Return' 'Exec' input
41+
Then There should be no console errors
42+
And I take a screenshot named 'connection-deleted'
43+
3744
Scenario: Open method and check for browser errors
3845
Given I load the default project
3946
When I check for console errors

src/NodeDev.EndToEndTests/Pages/HomePage.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 });

src/NodeDev.EndToEndTests/StepDefinitions/NodeManipulationStepDefinitions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,22 @@ public async Task ThenTheGraphCanvasShouldBeVisible()
205205

206206
Console.WriteLine("✓ Graph canvas is visible");
207207
}
208+
209+
[When("I delete the connection between {string} {string} output and {string} {string} input")]
210+
public async Task WhenIDeleteTheConnectionBetweenOutputAndInput(string sourceNode, string sourcePort, string targetNode, string targetPort)
211+
{
212+
Console.WriteLine($"Deleting connection: {sourceNode}.{sourcePort} (output) -> {targetNode}.{targetPort} (input)");
213+
214+
// Take screenshot before
215+
await HomePage.TakeScreenshot($"/tmp/before-delete-connection-{Guid.NewGuid()}.png");
216+
217+
// Delete the connection
218+
await HomePage.DeleteConnection(sourceNode, sourcePort, targetNode, targetPort);
219+
220+
// Take screenshot after
221+
await HomePage.TakeScreenshot($"/tmp/after-delete-connection-{Guid.NewGuid()}.png");
222+
223+
// Wait for UI to update
224+
await Task.Delay(200);
225+
}
208226
}

0 commit comments

Comments
 (0)