!3550 test(#I623MW): add unit test for Select/TableColumn

* test: 增加 ShowCopyColumnTooltip 单元测试
* test: 增加 ShowCopyColumn 单元测试
* test: 增加 OnBeforeSelectedItemChange 单元测试
* test: 修复编译失败
This commit is contained in:
Argo 2022-11-20 15:46:40 +00:00
parent 00e96291fc
commit 1a79ac519a
3 changed files with 100 additions and 0 deletions

View File

@ -170,6 +170,36 @@ public class SwalTest : SwalTestBase
cut.Contains("I am auto hide");
var alert = cut.FindComponent<SweetAlert>();
alert.Dispose();
// 带确认框的 Select
cut.SetParametersAndRender(pb =>
{
pb.AddChildContent<Select<string>>(pb =>
{
pb.Add(a => a.Items, new List<SelectedItem>()
{
new SelectedItem("1", "Test1"),
new SelectedItem("2", "Test2") { IsDisabled = true }
});
pb.Add(a => a.OnBeforeSelectedItemChange, item => Task.FromResult(true));
pb.Add(a => a.OnSelectedItemChanged, item => Task.CompletedTask);
pb.Add(a => a.SwalFooter, "test-swal-footer");
});
});
Task.Run(() => cut.InvokeAsync(() => cut.FindComponent<Select<string>>().Instance.ConfirmSelectedItem(0)));
tick = DateTime.Now;
while (!cut.Markup.Contains("test-swal-footer"))
{
Thread.Sleep(100);
if (DateTime.Now > tick.AddSeconds(1))
{
break;
}
}
button = cut.Find(".btn-danger");
cut.InvokeAsync(() => button.Click());
cut.InvokeAsync(() => modal.Instance.CloseCallback());
}
private class MockSwalTest : ComponentBase

View File

@ -791,6 +791,74 @@ public class TableTest : TableTestBase
}
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void ShowCopyColumn_Ok(bool showCopy)
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(pb =>
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 1));
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(1, "Field", "Name");
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.AddAttribute(3, "ShowCopyColumn", showCopy);
builder.CloseComponent();
});
});
});
if (showCopy)
{
cut.Contains("col-copy");
}
else
{
cut.DoesNotContain("col-copy");
}
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void ShowCopyColumnTooltip_Ok(bool showCopyTooltip)
{
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
{
pb.AddChildContent<Table<Foo>>(pb =>
{
pb.Add(a => a.RenderMode, TableRenderMode.Table);
pb.Add(a => a.ShowCopyColumnTooltip, showCopyTooltip);
pb.Add(a => a.CopyColumnTooltipText, "test-copy-column-tooltip");
pb.Add(a => a.Items, Foo.GenerateFoo(localizer, 1));
pb.Add(a => a.TableColumns, foo => builder =>
{
builder.OpenComponent<TableColumn<Foo, string>>(0);
builder.AddAttribute(1, "Field", "Name");
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Name", typeof(string)));
builder.AddAttribute(3, "ShowCopyColumn", true);
builder.CloseComponent();
});
});
});
if (showCopyTooltip)
{
cut.Contains("test-copy-column-tooltip");
}
else
{
cut.DoesNotContain("test-copy-column-tooltip");
}
}
[Theory]
[InlineData(true)]
[InlineData(false)]

View File

@ -110,4 +110,6 @@ internal class MockTableColumn : ITableColumn
public string? GroupName { get; set; }
public int GroupOrder { get; set; }
public bool ShowCopyColumn { get; set; }
}