Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WI00697921 - NCN - Removing last node from Workflow Relationship Designer throws exception #31

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading