Skip to content

Commit 016bd9b

Browse files
committed
test: 更新单元测试
1 parent 1d0381e commit 016bd9b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/UnitTest/Components/TabTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Bunit.TestDoubles;
88
using Microsoft.AspNetCore.Components.Rendering;
99
using System.Reflection;
10+
using System.Threading.Tasks;
1011
using UnitTest.Misc;
1112

1213
namespace UnitTest.Components;
@@ -25,6 +26,46 @@ protected override void ConfigureServices(IServiceCollection services)
2526
});
2627
}
2728

29+
[Fact]
30+
public async Task ContextMenu_Ok()
31+
{
32+
var clicked = false;
33+
var cut = Context.RenderComponent<ContextMenuZone>(pb =>
34+
{
35+
pb.AddChildContent<Tab>(pb =>
36+
{
37+
pb.AddChildContent<TabItem>(pb =>
38+
{
39+
pb.Add(a => a.Text, "Tab1");
40+
pb.Add(a => a.Url, "/Index");
41+
pb.Add(a => a.Closable, true);
42+
pb.Add(a => a.Icon, "fa-solid fa-font-awesome");
43+
pb.Add(a => a.ChildContent, "Tab1-Content");
44+
});
45+
});
46+
pb.AddChildContent<ContextMenu>(pb =>
47+
{
48+
pb.AddChildContent<ContextMenuItem>(pb =>
49+
{
50+
pb.Add(a => a.Text, "test-close");
51+
pb.Add(a => a.OnClick, (context, item) =>
52+
{
53+
clicked = true;
54+
if (item is TabItem tabItem)
55+
{
56+
57+
}
58+
return Task.CompletedTask;
59+
});
60+
});
61+
});
62+
});
63+
64+
var item = cut.Find(".dropdown-menu .dropdown-item");
65+
await cut.InvokeAsync(() => item.Click());
66+
Assert.True(clicked);
67+
}
68+
2869
[Fact]
2970
public void ToolbarTemplate_Ok()
3071
{

0 commit comments

Comments
 (0)