diff --git a/test/UnitTest/Components/SwitchButtonTest.cs b/test/UnitTest/Components/SwitchButtonTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..de38dc77e7cae189571511740c2c8c08cd5d72c9 --- /dev/null +++ b/test/UnitTest/Components/SwitchButtonTest.cs @@ -0,0 +1,36 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using Microsoft.AspNetCore.Components.Web; + +namespace UnitTest.Components; + +public class SwitchButtonTest : TestBase +{ + [Fact] + public void Toggle_Ok() + { + var state = false; + var clicked = false; + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.OnText, "Test_OnTest"); + pb.Add(a => a.OffText, "Test_OffTest"); + pb.Add(a => a.ToggleState, false); + pb.Add(a => a.ToggleStateChanged, EventCallback.Factory.Create(this, v => + { + state = v; + })); + pb.Add(a => a.OnClick, EventCallback.Factory.Create(this, e => + { + clicked = true; + })); + }); + cut.Contains("Test_OffTest"); + + // Click + cut.InvokeAsync(() => cut.Find("a").Click()); + Assert.True(clicked); + } +}