Skip to content

Commit 856525a

Browse files
committed
test: 增加单元测试
1 parent c1cd3e5 commit 856525a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/UnitTest/Components/ButtonTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,45 @@ public void ShareButton_Ok()
452452
Assert.Equal("test-share-title", cut.Instance.ShareContext?.Title);
453453
Assert.Equal("www.blazor.zone", cut.Instance.ShareContext?.Url);
454454
}
455+
456+
[Fact]
457+
public async Task ToogleButton_Ok()
458+
{
459+
var active = false;
460+
var bindActive = false;
461+
var clickWithoutRender = false;
462+
var clicked = false;
463+
var tcs = new TaskCompletionSource();
464+
var cut = Context.RenderComponent<ToggleButton>(pb =>
465+
{
466+
pb.Add(a => a.IsActive, false);
467+
pb.Add(a => a.IsActiveChanged, EventCallback.Factory.Create<bool>(this, b =>
468+
{
469+
active = b;
470+
bindActive = true;
471+
}));
472+
pb.Add(a => a.OnClickWithoutRender, () =>
473+
{
474+
clickWithoutRender = true;
475+
return Task.CompletedTask;
476+
});
477+
pb.Add(a => a.OnClick, () =>
478+
{
479+
clicked = true;
480+
return Task.CompletedTask;
481+
});
482+
pb.Add(a => a.OnToggleAsync, async isActive =>
483+
{
484+
await Task.Delay(10);
485+
active = isActive;
486+
tcs.TrySetResult();
487+
});
488+
});
489+
var button = cut.Find("button");
490+
await cut.InvokeAsync(() => button.Click());
491+
await tcs.Task;
492+
Assert.True(active);
493+
Assert.True(clickWithoutRender);
494+
Assert.True(clicked);
495+
}
455496
}

0 commit comments

Comments
 (0)