mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-05 13:39:39 +08:00
!3550 test(#I623MW): add unit test for Select/TableColumn
* test: 增加 ShowCopyColumnTooltip 单元测试 * test: 增加 ShowCopyColumn 单元测试 * test: 增加 OnBeforeSelectedItemChange 单元测试 * test: 修复编译失败
This commit is contained in:
parent
00e96291fc
commit
1a79ac519a
@ -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
|
||||
|
@ -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)]
|
||||
|
@ -110,4 +110,6 @@ internal class MockTableColumn : ITableColumn
|
||||
public string? GroupName { get; set; }
|
||||
|
||||
public int GroupOrder { get; set; }
|
||||
|
||||
public bool ShowCopyColumn { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user