Skip to content

Commit 7f92482

Browse files
authored
WI00697921-NCN-Removing_last_node_from_Workflow_Relationship_Designer_throws_exception (#31)
WI00697921 - NCN - Removing the last node from Workflow Relationship Designer throws an exception
2 parents f4e4b46 + 0f8d6d0 commit 7f92482

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/Blazor.Diagrams/Components/DiagramCanvas.razor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Blazor.Diagrams.Components;
1010

11-
public partial class DiagramCanvas : IDisposable
11+
public partial class DiagramCanvas : IAsyncDisposable
1212
{
1313
private DotNetObjectReference<DiagramCanvas>? _reference;
1414
private bool _shouldRender;
@@ -28,15 +28,15 @@ public partial class DiagramCanvas : IDisposable
2828

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

31-
public void Dispose()
31+
public async ValueTask DisposeAsync()
3232
{
3333
BlazorDiagram.Changed -= OnDiagramChanged;
3434

3535
if (_reference == null)
3636
return;
3737

3838
if (elementReference.Id != null)
39-
_ = JSRuntime.UnobserveResizes(elementReference);
39+
await JSRuntime.UnobserveResizes(elementReference);
4040

4141
_reference.Dispose();
4242
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Blazor.Diagrams.Components;
2+
using Blazor.Diagrams.Core.Geometry;
3+
using Bunit;
4+
using Xunit;
5+
6+
namespace Blazor.Diagrams.Tests.Components
7+
{
8+
public class DiagramCanvasTests
9+
{
10+
[Fact]
11+
public void Behavior_WhenDisposing_ShouldUnsubscribeToResizes()
12+
{
13+
// Arrange
14+
JSRuntimeInvocationHandler call;
15+
using (var ctx = new TestContext())
16+
{
17+
ctx.JSInterop.Setup<Rectangle>("ZBlazorDiagrams.getBoundingClientRect", _ => true);
18+
call = ctx.JSInterop.SetupVoid("ZBlazorDiagrams.unobserve", _ => true).SetVoidResult();
19+
20+
// Act
21+
var cut = ctx.RenderComponent<DiagramCanvas>(p => p.Add(n => n.BlazorDiagram, new BlazorDiagram()));
22+
}
23+
24+
// Assert
25+
call.VerifyInvoke("ZBlazorDiagrams.unobserve", calledTimes: 1);
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)