Skip to content

Commit a39a354

Browse files
committed
test: 更新单元测试
1 parent f49f2fd commit a39a354

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private async Task SearchTextChanged(string val)
391391
/// <inheritdoc/>
392392
/// </summary>
393393
/// <returns></returns>
394-
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, nameof(ConfirmSelectedItem));
394+
protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, new { ConfirmMethodCallback = nameof(ConfirmSelectedItem), SearchMethodCallback = nameof(TriggerOnSearch) });
395395

396396
/// <summary>
397397
/// 客户端回车回调方法
@@ -408,6 +408,18 @@ public async Task ConfirmSelectedItem(int index)
408408
}
409409
}
410410

411+
/// <summary>
412+
/// 客户端搜索栏回调方法
413+
/// </summary>
414+
/// <param name="searchText"></param>
415+
/// <returns></returns>
416+
[JSInvokable]
417+
public async Task TriggerOnSearch(string searchText)
418+
{
419+
await SearchTextChanged(searchText);
420+
StateHasChanged();
421+
}
422+
411423
/// <summary>
412424
/// 下拉框选项点击时调用此方法
413425
/// </summary>

test/UnitTest/Components/SelectGenericTest.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ namespace UnitTest.Components;
1313

1414
public class SelectGenericTest : BootstrapBlazorTestBase
1515
{
16-
[Fact]
17-
public void SeletectedItem_Ok()
18-
{
19-
var item = new SelectedItem(null!, "Text");
20-
Assert.Equal(item.Value, string.Empty);
21-
}
22-
2316
[Fact]
2417
public async Task OnSearchTextChanged_Null()
2518
{
@@ -42,7 +35,7 @@ await ctx.InvokeAsync(async () =>
4235
await ctx.Instance.ConfirmSelectedItem(0);
4336

4437
// 搜索 T
45-
ctx.Find(".search-text").Input("T");
38+
await ctx.Instance.TriggerOnSearch("T");
4639
await ctx.Instance.ConfirmSelectedItem(0);
4740
});
4841

@@ -68,9 +61,9 @@ await ctx.InvokeAsync(async () =>
6861
});
6962
});
7063

71-
await ctx.InvokeAsync(() =>
64+
await ctx.InvokeAsync(async () =>
7265
{
73-
ctx.Find(".search-text").Input("T");
66+
await ctx.Instance.TriggerOnSearch("T");
7467
});
7568
cut.DoesNotContain("Test2");
7669
}

test/UnitTest/Components/SelectTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ await ctx.InvokeAsync(async () =>
3535
await ctx.Instance.ConfirmSelectedItem(0);
3636

3737
// 搜索 T
38-
ctx.Find(".search-text").Input("T");
38+
await ctx.Instance.TriggerOnSearch("T");
3939
await ctx.Instance.ConfirmSelectedItem(0);
4040
});
4141

@@ -61,9 +61,9 @@ await ctx.InvokeAsync(async () =>
6161
});
6262
});
6363

64-
await ctx.InvokeAsync(() =>
64+
await ctx.InvokeAsync(async () =>
6565
{
66-
ctx.Find(".search-text").Input("T");
66+
await ctx.Instance.TriggerOnSearch("T");
6767
});
6868
cut.DoesNotContain("Test2");
6969
}
@@ -663,7 +663,7 @@ public async Task IsVirtualize_Items_Clearable_Ok()
663663
// 期望 UI 显示值为默认值
664664
// 期望 下拉框为全数据
665665
var input = cut.Find(".search-text");
666-
await cut.InvokeAsync(() => input.Input("2"));
666+
await cut.InvokeAsync(() => cut.Instance.TriggerOnSearch("2"));
667667

668668
// 下拉框仅显示一个选项 Test2
669669
var items = cut.FindAll(".dropdown-item");
@@ -721,7 +721,7 @@ public async Task IsVirtualize_OnQueryAsync_Clearable_Ok()
721721
// 期望 UI 显示值为默认值
722722
// 期望 下拉框为全数据
723723
var input = cut.Find(".search-text");
724-
await cut.InvokeAsync(() => input.Input("2"));
724+
await cut.InvokeAsync(() => cut.Instance.TriggerOnSearch("2"));
725725

726726
// 下拉框仅显示一个选项 Test2
727727
var items = cut.FindAll(".dropdown-item");

0 commit comments

Comments
 (0)