Skip to content

Commit 5ca7fba

Browse files
committed
test: 增加单元测试
1 parent 423ce90 commit 5ca7fba

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/UnitTest/Components/ListViewTest.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public void Items_Ok()
1414
{
1515
pb.Add(a => a.BodyTemplate, p => builder => builder.AddContent(0, $"{p.ImageUrl}-{p.Description}-{p.Category}"));
1616
});
17-
cut.Markup.Contains("listview-body");
17+
cut.Contains("listview-body");
1818
}
1919

2020
[Fact]
@@ -24,7 +24,7 @@ public void Height_Ok()
2424
{
2525
pb.Add(a => a.Height, "50vh");
2626
});
27-
cut.Markup.Contains("style=\"height: 50vh;\"");
27+
cut.Contains("style=\"height: 50vh;\"");
2828
}
2929

3030
[Fact]
@@ -293,6 +293,32 @@ public void OnCollapseChanged_Ok()
293293
});
294294
}
295295

296+
[Fact]
297+
public void EmptyTemplate_Ok()
298+
{
299+
var cut = Context.RenderComponent<ListView<Product>>(pb =>
300+
{
301+
pb.Add(a => a.OnQueryAsync, option =>
302+
{
303+
var ret = new QueryData<Product>()
304+
{
305+
Items = [],
306+
TotalCount = 0
307+
};
308+
return Task.FromResult(ret);
309+
});
310+
pb.Add(a => a.EmptyTemplate, builder => builder.AddContent(0, "empty-template"));
311+
});
312+
cut.Contains("empty-template");
313+
314+
cut.SetParametersAndRender(pb =>
315+
{
316+
pb.Add<RenderFragment?>(a => a.EmptyTemplate, null);
317+
pb.Add(a => a.EmptyText, "text-empty");
318+
});
319+
cut.Contains("text-empty");
320+
}
321+
296322
private class Product
297323
{
298324
public string? ImageUrl { get; set; }

0 commit comments

Comments
 (0)