From ec3a7ad5e581c004799f9977aa0eaebf80d9ddd5 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Tue, 1 Mar 2022 19:42:24 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20SwitchButton=20?= =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/UnitTest/Components/SwitchButtonTest.cs | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 test/UnitTest/Components/SwitchButtonTest.cs diff --git a/test/UnitTest/Components/SwitchButtonTest.cs b/test/UnitTest/Components/SwitchButtonTest.cs new file mode 100644 index 000000000..de38dc77e --- /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); + } +} -- Gitee