test(Table): add unit test for table (#383)

* refactor: update pagination code

* test: update OnConfirm unit test
This commit is contained in:
Argo 2023-01-24 08:24:11 -08:00 committed by GitHub
parent 60ed1d7a7c
commit 374b62b5ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -732,7 +732,10 @@ public partial class Table<TItem>
// https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UJSL
PageIndex = Math.Max(1, Math.Min(PageIndex, int.Parse(Math.Ceiling((TotalCount - SelectedRows.Count) * 1d / PageItems).ToString())));
var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedRows.Count));
PageItems = Math.Min(PageItems, items.Any() ? items.Min() : PageItems);
if (items.Any())
{
PageItems = Math.Min(PageItems, items.Min());
}
}
SelectedRows.Clear();
await QueryAsync();

View File

@ -5191,7 +5191,7 @@ public class TableTest : TableTestBase
}
[Fact]
public async Task OnConfirm_Ok()
public void OnConfirm_Ok()
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
@ -5219,14 +5219,14 @@ public class TableTest : TableTestBase
var deleteButton = table.FindComponent<TableToolbarPopconfirmButton<Foo>>();
// 选一个
var input = cut.Find("tbody tr input");
await cut.InvokeAsync(() => input.Click());
await cut.InvokeAsync(() => deleteButton.Instance.OnConfirm());
cut.InvokeAsync(() => input.Click());
cut.InvokeAsync(() => deleteButton.Instance.OnConfirm());
table.SetParametersAndRender(pb =>
{
pb.Add(a => a.PageItemsSource, new int[] { 1, 2, 4, 8 });
});
await cut.InvokeAsync(() => deleteButton.Instance.OnConfirm());
cut.InvokeAsync(() => deleteButton.Instance.OnConfirm());
}
[Fact]
@ -6357,7 +6357,7 @@ public class TableTest : TableTestBase
return Task.FromResult(new QueryData<Foo>()
{
Items = items,
TotalCount = 80,
TotalCount = 5,
IsAdvanceSearch = isAdvanceSearch,
IsFiltered = isFilter,
IsSearch = isSearch,