Skip to content

Commit

Permalink
WI00697921-NCN-Removing_last_node_from_Workflow_Relationship_Designer…
Browse files Browse the repository at this point in the history
…_throws_exception (#31)

WI00697921 - NCN - Removing the last node from Workflow Relationship Designer throws an exception
  • Loading branch information
LeonamAnjos authored Mar 21, 2024
2 parents f4e4b46 + 0f8d6d0 commit 7f92482
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Blazor.Diagrams.Components;

public partial class DiagramCanvas : IDisposable
public partial class DiagramCanvas : IAsyncDisposable
{
private DotNetObjectReference<DiagramCanvas>? _reference;
private bool _shouldRender;
Expand All @@ -28,15 +28,15 @@ public partial class DiagramCanvas : IDisposable

[Inject] public IJSRuntime JSRuntime { get; set; } = null!;

public void Dispose()
public async ValueTask DisposeAsync()
{
BlazorDiagram.Changed -= OnDiagramChanged;

if (_reference == null)
return;

if (elementReference.Id != null)
_ = JSRuntime.UnobserveResizes(elementReference);
await JSRuntime.UnobserveResizes(elementReference);

_reference.Dispose();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Blazor.Diagrams.Tests/Components/DiagramCanvasTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Blazor.Diagrams.Components;
using Blazor.Diagrams.Core.Geometry;
using Bunit;
using Xunit;

namespace Blazor.Diagrams.Tests.Components
{
public class DiagramCanvasTests
{
[Fact]
public void Behavior_WhenDisposing_ShouldUnsubscribeToResizes()
{
// Arrange
JSRuntimeInvocationHandler call;
using (var ctx = new TestContext())
{
ctx.JSInterop.Setup<Rectangle>("ZBlazorDiagrams.getBoundingClientRect", _ => true);
call = ctx.JSInterop.SetupVoid("ZBlazorDiagrams.unobserve", _ => true).SetVoidResult();

// Act
var cut = ctx.RenderComponent<DiagramCanvas>(p => p.Add(n => n.BlazorDiagram, new BlazorDiagram()));
}

// Assert
call.VerifyInvoke("ZBlazorDiagrams.unobserve", calledTimes: 1);
}
}
}

0 comments on commit 7f92482

Please sign in to comment.