From ec42c83d4d1c14830abecc5f258503080ef7e308 Mon Sep 17 00:00:00 2001 From: anddrzejb Date: Wed, 20 Oct 2021 13:32:42 +0200 Subject: [PATCH 1/3] add SetVoidResult to Focus hanlders with tests --- .../FocusAsyncInvocationHandler.cs | 5 +++- .../Implementation/FocusOnNavigateHandler.cs | 4 ++- .../FocusAsyncInvocationHandlerTest.cs | 9 +++++++ .../FocusOnNavigateHandlerTest.cs | 25 +++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusAsyncInvocationHandler.cs b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusAsyncInvocationHandler.cs index d15e62aa0..bc9216caa 100644 --- a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusAsyncInvocationHandler.cs +++ b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusAsyncInvocationHandler.cs @@ -1,3 +1,4 @@ + #if NET5_0_OR_GREATER using System; using Microsoft.AspNetCore.Components; @@ -21,7 +22,9 @@ internal sealed class FocusAsyncInvocationHandler : JSRuntimeInvocationHandler /// internal FocusAsyncInvocationHandler() : base(inv => inv.Identifier.Equals(FocusIdentifier, StringComparison.Ordinal), isCatchAllHandler: false) - { } + { + SetVoidResult(); + } } } #endif diff --git a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusOnNavigateHandler.cs b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusOnNavigateHandler.cs index 9d06ea2b2..fb506c7dd 100644 --- a/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusOnNavigateHandler.cs +++ b/src/bunit.web/JSInterop/InvocationHandlers/Implementation/FocusOnNavigateHandler.cs @@ -20,7 +20,9 @@ internal sealed class FocusOnNavigateHandler : JSRuntimeInvocationHandler /// internal FocusOnNavigateHandler() : base(inv => inv.Identifier.Equals(Identifier, StringComparison.Ordinal), isCatchAllHandler: true) - { } + { + SetVoidResult(); + } } } #endif diff --git a/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs b/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs index 2e91b9422..c886cd2ed 100644 --- a/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs +++ b/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs @@ -31,14 +31,23 @@ public void Test002() invocations[1].Arguments[0].ShouldBeElementReferenceTo(inputs[1]); } + [Fact(DisplayName = "Will return completed task")] + public void Test003() + { + var cut = RenderComponent(); + Assert.True(cut.Instance.AfterFirstRender); + } + private class FocusingComponent : ComponentBase { private ElementReference elmRef; + internal bool AfterFirstRender { get; private set; } protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await elmRef.FocusAsync(); + AfterFirstRender = true; } } diff --git a/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusOnNavigateHandlerTest.cs b/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusOnNavigateHandlerTest.cs index bc7b4f6a3..246c9d71b 100644 --- a/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusOnNavigateHandlerTest.cs +++ b/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusOnNavigateHandlerTest.cs @@ -30,6 +30,31 @@ public void Test001() .Arguments[0] .ShouldBe(focusOnNavigateComponent.Instance.Selector); } + + [Fact(DisplayName = "Will return completed task")] + public void Test002() + { + var cut = RenderComponent(ps => ps + .Add(p => p.FoundTemplate, routeData => cps => cps + .Add(x => x.RouteData, routeData) + .Add(x => x.Selector, "h1"))); + + var focusOnNavigateComponent = cut.FindComponent(); + Assert.True(focusOnNavigateComponent.Instance.AfterFirstRender); + } + + private class FocusOnNavigateInternal : FocusOnNavigate + { + internal bool AfterFirstRender { get; private set; } + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + if (firstRender) + { + AfterFirstRender = true; + } + } + } } } #endif From 19697e2e3de690dbcb272df4ccceec58e2201753 Mon Sep 17 00:00:00 2001 From: anddrzejb Date: Wed, 20 Oct 2021 13:53:43 +0200 Subject: [PATCH 2/3] changelog update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215640d87..959b79cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,8 @@ List of added functionality in this release. - The `Click` and `DoubleClick` extension methods now set the `MouseEventArgs.Detail` property to `1` and `2` respectively by default, unless the user specifies something else. This makes the methods more correctly emulate how Blazor reports single or double clicks on an element in the browser. Thanks to [@David-Moreira](https://github.com/David-Moreira) for the help troubleshooting this issue. By [@egil](https://github.com/egil). +- `FocusAsync()` method handler on `ElementReference` and `` js handler return completed `Task` + ## [1.2.49] - 2021-08-09 ### Added From c866ded9653dc1493a573c66e7ed8472a03b9bd2 Mon Sep 17 00:00:00 2001 From: Andrzej Bakun Date: Wed, 20 Oct 2021 14:23:37 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Egil Hansen --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 959b79cdf..2e28cfab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,7 +35,7 @@ List of added functionality in this release. - The `Click` and `DoubleClick` extension methods now set the `MouseEventArgs.Detail` property to `1` and `2` respectively by default, unless the user specifies something else. This makes the methods more correctly emulate how Blazor reports single or double clicks on an element in the browser. Thanks to [@David-Moreira](https://github.com/David-Moreira) for the help troubleshooting this issue. By [@egil](https://github.com/egil). -- `FocusAsync()` method handler on `ElementReference` and `` js handler return completed `Task` +- `FocusAsync()` method handler on `ElementReference` and `` js handler return completed `Task`. By [@anddrzejb](https://github.com/anddrzejb). ## [1.2.49] - 2021-08-09