diff --git a/test/UnitTest/Components/CheckboxListTest.cs b/test/UnitTest/Components/CheckboxListTest.cs index 999fbac81d3..92db69cc5f6 100644 --- a/test/UnitTest/Components/CheckboxListTest.cs +++ b/test/UnitTest/Components/CheckboxListTest.cs @@ -208,7 +208,7 @@ public void CheckboxItemClass_Ok() } [Fact] - public void StringValue_Ok() + public async Task StringValue_Ok() { var cut = Context.RenderComponent>(builder => { @@ -236,13 +236,13 @@ public void StringValue_Ok() }); }); // 字符串值选中事件 - var item = cut.Find(".form-check-input"); - item.Click(); + var item = cut.FindComponent>(); + await cut.InvokeAsync(item.Instance.TriggerClick); Assert.True(selected); } [Fact] - public void OnSelectedChanged_Ok() + public async Task OnSelectedChanged_Ok() { var selected = false; var foo = Foo.Generate(Localizer); @@ -257,8 +257,8 @@ public void OnSelectedChanged_Ok() }); }); - var item = cut.Find(".form-check-input"); - item.Click(); + var item = cut.FindComponent>(); + await cut.InvokeAsync(item.Instance.TriggerClick); Assert.True(selected); } @@ -274,7 +274,7 @@ public void EnumValue_Ok() } [Fact] - public void IntValue_Ok() + public async Task IntValue_Ok() { var ret = new List(); var selectedIntValues = new List { 1, 2 }; @@ -292,8 +292,8 @@ public void IntValue_Ok() return Task.CompletedTask; }); }); - var item = cut.Find(".form-check-input"); - item.Click(); + var item = cut.FindComponent>(); + await cut.InvokeAsync(item.Instance.TriggerClick); // 选中 2 Assert.Equal(2, ret.First()); diff --git a/test/UnitTest/Components/ConsoleTest.cs b/test/UnitTest/Components/ConsoleTest.cs index ef00230fbf7..a09d805f431 100644 --- a/test/UnitTest/Components/ConsoleTest.cs +++ b/test/UnitTest/Components/ConsoleTest.cs @@ -195,7 +195,7 @@ public void LightTitle_OK() } [Fact] - public void ClickAutoScroll_OK() + public async Task ClickAutoScroll_OK() { var cut = Context.RenderComponent(builder => { @@ -206,7 +206,8 @@ public void ClickAutoScroll_OK() builder.Add(a => a.ShowAutoScroll, true); }); - cut.Find(".card-footer input").Click(); + var item = cut.FindComponent>(); + await cut.InvokeAsync(item.Instance.TriggerClick); var res = cut.Instance.IsAutoScroll; Assert.False(res); } diff --git a/test/UnitTest/Components/TableDialogTest.cs b/test/UnitTest/Components/TableDialogTest.cs index 788a6266629..e867ca70555 100644 --- a/test/UnitTest/Components/TableDialogTest.cs +++ b/test/UnitTest/Components/TableDialogTest.cs @@ -62,8 +62,8 @@ public async Task EditAsync_Ok() var table = cut.FindComponent>(); // 选一个 - var input = cut.Find("tbody tr input"); - await cut.InvokeAsync(() => input.Click()); + var checkbox = cut.FindComponents>()[1]; + await cut.InvokeAsync(checkbox.Instance.TriggerClick); await cut.InvokeAsync(() => table.Instance.EditAsync()); cut.Contains("test-save"); @@ -128,7 +128,7 @@ public async Task EditAsync_Ok() await cut.InvokeAsync(() => table.Instance.AddAsync()); // 编辑弹窗逻辑 - input = cut.Find(".modal-body form input.form-control"); + var input = cut.Find(".modal-body form input.form-control"); await cut.InvokeAsync(() => input.Change("Test_Name")); form = cut.Find(".modal-body form"); @@ -362,8 +362,8 @@ public async Task Required_Ok() var modal = cut.FindComponent(); // 选一个 - var input = cut.Find("tbody tr input"); - await cut.InvokeAsync(() => input.Click()); + var item = cut.FindComponent>(); + await cut.InvokeAsync(item.Instance.TriggerClick); await cut.InvokeAsync(() => table.Instance.AddAsync()); var form = cut.Find(".modal-body form"); diff --git a/test/UnitTest/Components/TableDrawerTest.cs b/test/UnitTest/Components/TableDrawerTest.cs index 75a63c52350..a96d484eb76 100644 --- a/test/UnitTest/Components/TableDrawerTest.cs +++ b/test/UnitTest/Components/TableDrawerTest.cs @@ -43,8 +43,8 @@ public async Task EditAsync_Ok() var table = cut.FindComponent>(); // 选一个 - var input = cut.Find("tbody tr input"); - await cut.InvokeAsync(() => input.Click()); + var checkbox = cut.FindComponents>()[1]; + await cut.InvokeAsync(checkbox.Instance.TriggerClick); await cut.InvokeAsync(() => table.Instance.EditAsync()); // 编辑弹窗逻辑 @@ -102,8 +102,8 @@ public async Task EditAsync_Ok() { pb.Add(a => a.OnSaveAsync, (foo, itemType) => Task.FromResult(false)); }); - input = cut.Find("tbody tr input"); - await cut.InvokeAsync(() => input.Click()); + checkbox = cut.FindComponents>()[1]; + await cut.InvokeAsync(checkbox.Instance.TriggerClick); await cut.InvokeAsync(() => table.Instance.EditAsync()); form = cut.Find("form"); await cut.InvokeAsync(() => form.Submit()); @@ -119,7 +119,7 @@ public async Task EditAsync_Ok() await cut.InvokeAsync(() => table.Instance.AddAsync()); // 编辑弹窗逻辑 - input = cut.Find("form input.form-control"); + var input = cut.Find("form input.form-control"); await cut.InvokeAsync(() => input.Change("Test_Name")); form = cut.Find("form"); diff --git a/test/UnitTest/Components/TableTest.cs b/test/UnitTest/Components/TableTest.cs index d0e3dd92169..f6634013f5c 100644 --- a/test/UnitTest/Components/TableTest.cs +++ b/test/UnitTest/Components/TableTest.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone +using Bunit; using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web.Virtualization; @@ -758,9 +759,8 @@ public async Task ShowColumnList_Ok() }); cut.Contains("Test_Column_List"); - var item = cut.Find(".dropdown-item .form-check-input"); - await cut.InvokeAsync(() => item.Click()); - + var item = cut.FindComponents>()[0]; + await cut.InvokeAsync(item.Instance.TriggerClick); Assert.True(show); } @@ -2478,8 +2478,8 @@ public async Task CustomerToolbarButton_Ok() Assert.True(clickWithoutRender); // 选中一行 - var input = cut.Find("tbody tr input"); - await cut.InvokeAsync(() => input.Click()); + var input = cut.FindComponents>()[1]; + await cut.InvokeAsync(input.Instance.TriggerClick); button = cut.FindComponents