Skip to content

Commit 2132144

Browse files
committed
test: 更新单元测试
1 parent d916476 commit 2132144

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

test/UnitTest/Components/TableTest.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5507,6 +5507,88 @@ public async Task OnSaveAsync_Ok()
55075507
Assert.True(afterModify);
55085508
}
55095509

5510+
[Fact]
5511+
public async Task OnAfterCancelSaveAsync_EditForm()
5512+
{
5513+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
5514+
var items = Foo.GenerateFoo(localizer, 2);
5515+
var afterCancelSave = false;
5516+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
5517+
{
5518+
pb.AddChildContent<Table<Foo>>(pb =>
5519+
{
5520+
pb.Add(a => a.RenderMode, TableRenderMode.Table);
5521+
pb.Add(a => a.Items, items);
5522+
pb.Add(a => a.IsMultipleSelect, true);
5523+
pb.Add(a => a.ShowToolbar, true);
5524+
pb.Add(a => a.ShowExtendButtons, true);
5525+
pb.Add(a => a.EditMode, EditMode.EditForm);
5526+
pb.Add(a => a.OnAfterCancelSaveAsync, () =>
5527+
{
5528+
afterCancelSave = true;
5529+
return Task.CompletedTask;
5530+
});
5531+
pb.Add(a => a.TableColumns, foo => builder =>
5532+
{
5533+
builder.OpenComponent<TableColumn<Foo, string>>(0);
5534+
builder.AddAttribute(1, "Field", "Name");
5535+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
5536+
builder.CloseComponent();
5537+
});
5538+
});
5539+
});
5540+
5541+
// test edit button
5542+
var button = cut.FindAll("tbody tr button");
5543+
await cut.InvokeAsync(() => button[0].Click());
5544+
5545+
// 取消按钮
5546+
var cancelButton = cut.Find(".form-footer .btn-secondary");
5547+
await cut.InvokeAsync(() => cancelButton.Click());
5548+
Assert.True(afterCancelSave);
5549+
}
5550+
5551+
[Fact]
5552+
public async Task OnAfterCancelSaveAsync_InCell()
5553+
{
5554+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
5555+
var items = Foo.GenerateFoo(localizer, 2);
5556+
var afterCancelSave = false;
5557+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
5558+
{
5559+
pb.AddChildContent<Table<Foo>>(pb =>
5560+
{
5561+
pb.Add(a => a.RenderMode, TableRenderMode.Table);
5562+
pb.Add(a => a.Items, items);
5563+
pb.Add(a => a.IsMultipleSelect, true);
5564+
pb.Add(a => a.ShowToolbar, true);
5565+
pb.Add(a => a.ShowExtendButtons, true);
5566+
pb.Add(a => a.EditMode, EditMode.EditForm);
5567+
pb.Add(a => a.OnAfterCancelSaveAsync, () =>
5568+
{
5569+
afterCancelSave = true;
5570+
return Task.CompletedTask;
5571+
});
5572+
pb.Add(a => a.TableColumns, foo => builder =>
5573+
{
5574+
builder.OpenComponent<TableColumn<Foo, string>>(0);
5575+
builder.AddAttribute(1, "Field", "Name");
5576+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
5577+
builder.CloseComponent();
5578+
});
5579+
});
5580+
});
5581+
5582+
// test edit button
5583+
var button = cut.FindAll("tbody tr button");
5584+
await cut.InvokeAsync(() => button[0].Click());
5585+
5586+
// 取消按钮
5587+
button = cut.FindAll("tbody tr button");
5588+
await cut.InvokeAsync(() => button[1].Click());
5589+
Assert.True(afterCancelSave);
5590+
}
5591+
55105592
[Fact]
55115593
public async Task OnAfterCancelSaveAsync_Popup()
55125594
{

0 commit comments

Comments
 (0)