Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 28 13:50
    linkdotnet commented #694
  • Apr 28 13:48
    linkdotnet commented #694
  • Apr 28 13:41
    linkdotnet commented #694
  • Apr 28 13:40
    linkdotnet commented #694
  • Apr 28 13:32
    linkdotnet edited #695
  • Apr 28 13:31
    linkdotnet edited #695
  • Apr 28 13:28
    linkdotnet opened #695
  • Apr 28 12:59
    linkdotnet commented #694
  • Apr 28 11:37
    linkdotnet assigned #694
  • Apr 28 10:56
    dnfadmin commented #559
  • Apr 28 10:11
    linkdotnet commented #694
  • Apr 28 10:04
    egil commented #694
  • Apr 28 09:49
    linkdotnet commented #694
  • Apr 28 09:20
    egil commented #577
  • Apr 28 09:12
    egil labeled #694
  • Apr 28 09:12
    egil opened #694
  • Apr 28 09:07
    egil closed #691
  • Apr 28 09:06
    egil closed #693
  • Apr 28 09:06
    egil commented #693
  • Apr 28 06:52
    dnfadmin commented #561
gismofx
@gismofx
@egilhansen:matrix.org I'm having trouble making a minimal example, but the complete example is on my repo https://github.com/gismofx/MudBlazor/blob/77dd2c1d2ee12d868982a20795f59754f4eecfa4/src/MudBlazor.UnitTests/Components/AutocompleteTests.cs#L607
4 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, I'll see if I can get some time to look at this tomorrow. Mind just creating a QA in the bunit discussion forum so i don't forget. It's almost midnight here in Iceland so I'm off to bed
gismofx
@gismofx
ah! get sleep :) Thanks! I actually made a few changes in my local copy that I just pushed to my repo. I will make a post in bunit repo.
goodnight
Egil Hansen
@egilhansen:matrix.org
[m]
Great. And thank!
Egil Hansen
@egilhansen:matrix.org
[m]
hey friends, i'm live streaming some bUnit enhancement work right now. Come join at twitch.tv/egilhansen if you want to help out :)
Manuel Zelenka
@dev-in-disguise
Hey everyone!
Quick question regarding the nuget packages. Right now bunit and bunit.web are basically the same. Therefore the question in one of my projects arose: which of those nuget packages should we use when? Or rather: what was the reasoning behind having a bunit and a bunit.web package?
1 reply
Andrzej Bakun
@Andrzej2_gitlab
Hi guys! I think I have a weird problem. When I test a component that has await element.FocusAsync(), the code never continues. I am not really interested in catching focus event, but I don't understand why it gets stuck there and never continues. For net3.1 I have a JSInterop.SetupVoid("myfocusevent", _ => true).SetVoidResult() but I cannot find anywhere how to handle FocusAsync().
2 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Ok, there should be focusasync support builtin, but it does require you are using bunit's JSInterop and not injecting your own IJSRuntime
Andrzej Bakun
@Andrzej2_gitlab
I am using built in JSInterop. I also saw the link you posted. From what I can tell, this will help me to evaluate if FocusAsync() was called, but this is not what interests me. Unless the fact that I add the validation will also cause bUnit to register that js call?
Egil Hansen
@egilhansen:matrix.org
[m]
If you just want the focus async call to work, just don't set anything up.
Andrzej Bakun
@Andrzej2_gitlab

Anyway, I tried. It didn't work. But informed me that Bunit.JSInvokeCountExpectedException : VerifyInvoke failed: "Blazor._internal.domWrapper.focus" was not called the expected number of times.. So I added this line:

JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();

Solved my problem. But this is not intended, right?

Egil Hansen
@egilhansen:matrix.org
[m]
What blazor version?
Andrzej Bakun
@Andrzej2_gitlab
net6 rc1
Egil Hansen
@egilhansen:matrix.org
[m]
Hmm so that setupvoid call should already be added by default, so you should not need to do so. Only reason I can see it not working is if MS has changed the JS function being called
Can you share your entire test?
Andrzej Bakun
@Andrzej2_gitlab
Sure. Mind that this is work in progress, I hope to get rid of some of the await Task.Delay.
@using AntDesign.Core.JsInterop.Modules.Components
@inherits AntDesignTestBase
@code {
    public Select_Tags_Tests()
    {
        JSInterop.Setup<AntDesign.JsInterop.DomRect>(JSInteropConstants.GetBoundingClientRect, _ => true)
            .SetResult(new AntDesign.JsInterop.DomRect());                     
        JSInterop.Setup<HtmlElement>(JSInteropConstants.GetDomInfo, _ => true)
            .SetResult(new HtmlElement());
        JSInterop.SetupVoid(JSInteropConstants.AddPreventKeys, _ => true);        
        JSInterop.SetupVoid(JSInteropConstants.AddElementTo, _ => true);        
        #if !NET6_0_OR_GREATER
        JSInterop.SetupVoid(JSInteropConstants.Focus, _ => true).SetVoidResult();
        #else
        JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult();
        #endif        
    }

    [Fact]
    public async Task Single_tag_creation() //issue #1645
    {
        //Arrange

        JSInterop.Setup<OverlayPosition>(JSInteropConstants.OverlayComponentHelper.AddOverlayToContainer, _ => true)
            .SetResult(new OverlayPosition() { Top = 0, Left = 0, ZIndex = 5000, Placement = Placement.BottomLeft });               


        var cut = Render<AntDesign.Select<string, string>>(
        @<AntDesign.Select Mode="tags"
            TItemValue="string"
            TItem="string"        
            EnableSearch>
            <SelectOptions>                        
                <SelectOption TItemValue="string" TItem="string" Value="@("1")" Label="1" />            
            </SelectOptions>
    </AntDesign.Select>
    );
        //Act
        //overlay.
        var input = cut.Find("input.ant-select-selection-search-input");        

        input.Input("A"); //await element.FocusAsync() is called by Select here
        cut.WaitForState(() => cut.Instance.ActiveOption is not null);        


        await Task.Delay(100);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        input.Input("B");
        await Task.Delay(1);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        input.Input("C");
        await Task.Delay(1);
        input.KeyUp("ENTER");
        await Task.Delay(1);
        var addedTags = cut.FindAll("span.ant-select-selection-item-content")
            .Where(d => d.TextContent.Trim() == "B");
        //Assert
        addedTags.Should().HaveCount(1);
    }
}
input.Input("A") - await element.FocusAsync() is called by Select here
this test is passing in net5 & in net6 if I manually do the JSInterop.SetupVoid("Blazor._internal.domWrapper.focus", _ => true).SetVoidResult()
Egil Hansen
@egilhansen:matrix.org
[m]
Hmm that weird. You should not need that for .net 6
Andrzej Bakun
@Andrzej2_gitlab
Yeah, I thought so. I am being a bit of a nuisance today :smirk:
Anyway, I am at your disposal.
Egil Hansen
@egilhansen:matrix.org
[m]
Take a look at the test that verifies the FocusAsync support, and see if there are test cases that is missing:
https://github.com/bUnit-dev/bUnit/blob/main/tests/bunit.web.tests/JSInterop/InvocationHandlers/FocusAsyncInvocationHandlerTest.cs
The FocusingComponent is at the bottom of that file.
Andrzej Bakun
@Andrzej2_gitlab
Hmm...I am passing to FocusAsync a boolean. In my case it is default, at at some point I do it explicitly. Could that be it? The boolean stands for PreventDefault and is a part (at least was) of the overload on ElementReference.FocusAsync(bool preventDefault)
You don't seem to have that scenario in your tests
Egil Hansen
@egilhansen:matrix.org
[m]
Ahh i might be missing. If you want to add that it's probably a fairly simple PR 😉
Andrzej Bakun
@Andrzej2_gitlab
:smile: sure, I will try to do that. Let me first hook your repo to my project to play around a bit.
btw when I tried net6 rc2 I got a ton of errors with all SetupVoids not registering and wanting an interface (smth like IJSVoidResult but I am not sure). Did you get that kind of error?
Egil Hansen
@egilhansen:matrix.org
[m]
Yeah, it's fixed in the preview release of bunit
1.3.30-preview iirc
Andrzej Bakun
@Andrzej2_gitlab
Great! Any changes on my part or just update and forget?
Egil Hansen
@egilhansen:matrix.org
[m]
Update and forget i hope. Not planning on breaking changes.
Andrzej Bakun
@Andrzej2_gitlab
We rearly do I guess, but sometimes they are inevitable. Anyway, thanks for your help & have a good night!
Egil Hansen
@egilhansen:matrix.org
[m]
You too. If want to do a PR on this just create a issue first. Otherwise I'll take a look tomorrow during my twitch.tv/egilhansen stream.
Andrzej Bakun
@Andrzej2_gitlab
I will try. It is late here also, so it depends on my workload tomorrow.
Egil Hansen
@egilhansen:matrix.org
[m]
If you create an issue on it and I'll assign you. Then you can just report back if you don't have time.
Andrzej Bakun
@Andrzej2_gitlab
Ok, give me a minute
Ok, looking at the issue template, it may take me a bit more than a minute :disappointed:
Egil Hansen
@egilhansen:matrix.org
[m]
Don't need everything tonight, since i have all context from here.
Andrzej Bakun
@Andrzej2_gitlab
ok issue 522
Egil Hansen
@egilhansen:matrix.org
[m]
Thank you
gismofx
@gismofx
I'm testing a component and doing a button click, but it's not working... Not sure why...
<MudTable @ref="filteredTable" Items="states" Filter="new Func<string, bool>(FilterFunc)" RowsPerPage="@rows">
     <ToolBarContent>
        <MudText>Filtered Item Count: @FilteredItemCount</MudText>
        <MudSpacer />
        <MudTextField id="searchString" @bind-Value="searchString" Placeholder="Search"></MudTextField>
    </ToolBarContent>
    <RowTemplate>
        <MudTd>@context</MudTd>
    </RowTemplate> 
    <PagerContent>
        <MudTablePager />
    </PagerContent>
</MudTable>

<MudButton OnClick="@(() => ButtonClick())">Toggle Rows</MudButton>
test bit
            var testComponent = Context.RenderComponent<TablePagerChangeRowsPerPageTest>();
            var table = testComponent.FindComponent<MudTable<string>>().Instance;
            testComponent.Find("button").Click();
Andrzej Bakun
@Andrzej2_gitlab
To me it looks like you need to get the MudButton component, not the MudTable<string>
Egil Hansen
@egilhansen:matrix.org
[m]
What error message are you seeing @gismofx ?
Andrzej Bakun
@Andrzej2_gitlab

@egilhansen:matrix.org I think I found the problem. It wasn't what we thought it was yesterday. bUnit's interop was picking up the proper handler, but it was returning a task with status = WaitingForActivation. So my await element.FocusAsync() was never finishing. As a solution simplest for me to figure out, was to add SetVoidResult() into FocusAsyncInvocationHandler() constructor like this:

        internal FocusAsyncInvocationHandler()
            : base(inv => inv.Identifier.Equals(FocusIdentifier, StringComparison.Ordinal), isCatchAllHandler: false)
        {
            SetVoidResult();
        }

This solved my problem. However I am not sure if this is the way you'd like to have it solved. If yes, I can create a PR.

2 replies
Egil Hansen
@egilhansen:matrix.org
[m]
Let me think it though, but first thought is that it is the right solution.