Skip to content

Commit 0f7be01

Browse files
ArgoZhangice6github-actions[bot]
authored
test(Dropdown): add unit test improve code coverage (#5323)
* refactor: update html element tag name * test: 更新单元测试 Co-Authored-By: ice6 <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c19f3ab commit 0f7be01

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/BootstrapBlazor/Components/Dropdown/Dropdown.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<BootstrapLabel for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
99
}
1010
<div @attributes="@AdditionalAttributes" id="@Id" class="@DirectionClassName">
11-
<DynamicElement type="button" class="@ButtonClassName" data-bs-toggle="@DropdownToggle" disabled="@Disabled"
11+
<DynamicElement TagName="button" type="button" class="@ButtonClassName" data-bs-toggle="@DropdownToggle" disabled="@Disabled"
1212
TriggerClick="ShowSplit" OnClick="OnClickButton">
1313
@if (ButtonTemplate == null)
1414
{

test/UnitTest/Components/DropdownTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,29 @@ namespace UnitTest.Components;
88
public class DropdownTest : BootstrapBlazorTestBase
99
{
1010
[Fact]
11-
public void ShowSplit_OK()
11+
public async Task ShowSplit_OK()
1212
{
13+
var clicked = false;
14+
var clickedWithoutRender = false;
1315
var cut = Context.RenderComponent<Dropdown<EnumEducation>>(pb =>
1416
{
1517
pb.Add(a => a.ShowSplit, true);
18+
pb.Add(a => a.OnClick, () =>
19+
{
20+
clicked = true;
21+
});
22+
pb.Add(a => a.OnClickWithoutRender, () =>
23+
{
24+
clickedWithoutRender = true;
25+
return Task.CompletedTask;
26+
});
1627
});
1728
Assert.Contains(" dropdown-toggle-split", cut.Markup);
29+
30+
var button = cut.Find("button");
31+
await cut.InvokeAsync(() => button.Click());
32+
Assert.True(clicked);
33+
Assert.True(clickedWithoutRender);
1834
}
1935

2036
[Fact]

0 commit comments

Comments
 (0)