Skip to content

Commit 12b4071

Browse files
committed
test: 增加单元测试
1 parent 23a50fb commit 12b4071

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/UnitTest/Components/DrawerTest.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ public void ChildContent_Ok()
106106
Assert.NotNull(button);
107107
}
108108

109+
[Fact]
110+
public void BodyContext_Ok()
111+
{
112+
var cut = Context.RenderComponent<Drawer>(builder =>
113+
{
114+
builder.Add(a => a.BodyContext, "test-body-context");
115+
builder.Add(a => a.ChildContent, s =>
116+
{
117+
s.OpenComponent<MockContent>(0);
118+
s.CloseComponent();
119+
});
120+
});
121+
122+
var component = cut.FindComponent<MockContent>();
123+
Assert.NotNull(component);
124+
125+
Assert.Equal("test-body-context", component.Instance.GetBodyContext());
126+
}
127+
109128
[Fact]
110129
public void ShowBackdrop_Ok()
111130
{
@@ -141,4 +160,13 @@ public void Position_Ok()
141160
});
142161
cut.Contains("--bb-drawer-position: absolute;");
143162
}
163+
164+
class MockContent : ComponentBase
165+
{
166+
[CascadingParameter(Name = "BodyContext")]
167+
[NotNull]
168+
private object? BodyContext { get; set; }
169+
170+
public string? GetBodyContext() => BodyContext.ToString();
171+
}
144172
}

0 commit comments

Comments
 (0)