Skip to content

Commit 62022a0

Browse files
ArgoZhangAxxbis
andcommitted
test: 更新单元测试
Co-Authored-By: ZhYan <[email protected]>
1 parent 61ce633 commit 62022a0

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

test/UnitTest/Components/TableTest.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7665,6 +7665,106 @@ public async Task GetValue_LookupServiceKey()
76657665

76667666
var table = cut.FindComponent<MockTable>();
76677667
await cut.InvokeAsync(() => table.Instance.QueryAsync());
7668+
7669+
col.SetParametersAndRender(pb =>
7670+
{
7671+
pb.Add(a => a.ShowTips, true);
7672+
pb.Add(a => a.Lookup, null);
7673+
pb.Add(a => a.LookupService, new MockLookupServiceAsync());
7674+
});
7675+
await cut.InvokeAsync(() => table.Instance.QueryAsync());
7676+
cut.WaitForElement("[data-bs-original-title=\"LookupService-Test-True-async\"]");
7677+
}
7678+
7679+
[Fact]
7680+
public async Task GetValue_LookupServiceKey_Null()
7681+
{
7682+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
7683+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
7684+
{
7685+
pb.AddChildContent<MockTable>(pb =>
7686+
{
7687+
pb.Add(a => a.OnQueryAsync, OnQueryAsync(localizer));
7688+
pb.Add(a => a.TableColumns, foo => builder =>
7689+
{
7690+
builder.OpenComponent<TableColumn<Foo, bool>>(0);
7691+
builder.AddAttribute(1, "Field", true);
7692+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Complete", typeof(bool)));
7693+
builder.AddAttribute(3, "LookupServiceKey", "null");
7694+
builder.AddAttribute(4, "LookupServiceData", true);
7695+
builder.AddAttribute(5, "ShowTips", true);
7696+
builder.AddAttribute(6, "LookupService", new MockLookupServiceAsync());
7697+
builder.CloseComponent();
7698+
});
7699+
});
7700+
});
7701+
7702+
var table = cut.FindComponent<MockTable>();
7703+
await cut.InvokeAsync(() => table.Instance.QueryAsync());
7704+
cut.WaitForElement("[data-bs-original-title=\"True\"]");
7705+
}
7706+
7707+
[Fact]
7708+
public async Task GetValue_LookupServiceKey_NullText()
7709+
{
7710+
var localizer = Context.Services.GetRequiredService<IStringLocalizer<Foo>>();
7711+
var cut = Context.RenderComponent<BootstrapBlazorRoot>(pb =>
7712+
{
7713+
pb.AddChildContent<MockTable>(pb =>
7714+
{
7715+
pb.Add(a => a.OnQueryAsync, OnQueryAsync(localizer));
7716+
pb.Add(a => a.TableColumns, foo => builder =>
7717+
{
7718+
builder.OpenComponent<TableColumn<Foo, bool>>(0);
7719+
builder.AddAttribute(1, "Field", true);
7720+
builder.AddAttribute(2, "FieldExpression", Utility.GenerateValueExpression(foo, "Complete", typeof(bool)));
7721+
builder.AddAttribute(3, "LookupServiceKey", "null-text");
7722+
builder.AddAttribute(4, "LookupServiceData", true);
7723+
builder.AddAttribute(5, "ShowTips", true);
7724+
builder.AddAttribute(6, "LookupService", new MockLookupServiceAsync());
7725+
builder.CloseComponent();
7726+
});
7727+
});
7728+
});
7729+
7730+
var table = cut.FindComponent<MockTable>();
7731+
await cut.InvokeAsync(() => table.Instance.QueryAsync());
7732+
cut.WaitForElement("[data-bs-original-title=\"True\"]");
7733+
}
7734+
class MockLookupServiceAsync : LookupServiceBase
7735+
{
7736+
public override IEnumerable<SelectedItem>? GetItemsByKey(string? key, object? data) => null;
7737+
7738+
public override async Task<IEnumerable<SelectedItem>?> GetItemsByKeyAsync(string? key, object? data)
7739+
{
7740+
await Task.Delay(300);
7741+
7742+
IEnumerable<SelectedItem>? ret = null;
7743+
7744+
if (key == "test")
7745+
{
7746+
ret = new SelectedItem[]
7747+
{
7748+
new("True", "LookupService-Test-True-async"),
7749+
new("False", "LookupService-Test-False-async")
7750+
};
7751+
}
7752+
7753+
if (key == "null")
7754+
{
7755+
ret = null;
7756+
}
7757+
7758+
if (key == "null-text")
7759+
{
7760+
ret = new SelectedItem[]
7761+
{
7762+
new("Fake-True", "Fake-True"),
7763+
new("Fake-False", "Fake-False")
7764+
};
7765+
}
7766+
return ret;
7767+
}
76687768
}
76697769

76707770
[Fact]

0 commit comments

Comments
 (0)