Skip to content

Commit a968517

Browse files
committed
!3768 test(#I6AT8P): add unit test for table search OnSearchKeyup method
* test: 增加 OnSearchKeyUp 单元测试
1 parent 760a932 commit a968517

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

test/UnitTest/Components/TableTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,42 @@ public async Task ShowSearch_Ok()
305305
await cut.InvokeAsync(() => searchButton.Click());
306306
}
307307

308+
[Fact]
309+
public void OnSearchKeyup_Ok()
310+
{
311+
var resetSearch = false;
312+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
313+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
314+
{
315+
pb.AddChildContent<Table<Foo>>(pb =>
316+
{
317+
pb.Add(a => a.RenderMode, TableRenderMode.Table);
318+
pb.Add(a => a.ShowToolbar, true);
319+
pb.Add(a => a.ShowSearch, true);
320+
pb.Add(a => a.ShowSearchText, true);
321+
pb.Add(a => a.ShowSearchTextTooltip, false);
322+
pb.Add(a => a.SearchMode, SearchMode.Top);
323+
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 2));
324+
pb.Add(a => a.TableColumns, foo => builder =>
325+
{
326+
builder.OpenComponent<TableColumn<Foo, string>>(0);
327+
builder.AddAttribute(1, "Field", "Name");
328+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
329+
builder.CloseComponent();
330+
});
331+
pb.Add(a => a.OnResetSearchAsync, foo =>
332+
{
333+
resetSearch = true;
334+
return Task.CompletedTask;
335+
});
336+
});
337+
});
338+
var searchBox = cut.Find(".table-toolbar-search");
339+
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Enter" }));
340+
cut.InvokeAsync(() => searchBox.KeyUp(new KeyboardEventArgs() { Key = "Escape" }));
341+
Assert.True(resetSearch);
342+
}
343+
308344
[Fact]
309345
public async Task ShowAdvancedSearch_Ok()
310346
{

0 commit comments

Comments
 (0)