|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +namespace UnitTest.Components; |
| 7 | + |
| 8 | +/// <summary> |
| 9 | +/// Test for OtpInput component |
| 10 | +/// </summary> |
| 11 | +public class OtpInputTest : BootstrapBlazorTestBase |
| 12 | +{ |
| 13 | + [Fact] |
| 14 | + public void OtpInput_Ok() |
| 15 | + { |
| 16 | + var cut = Context.RenderComponent<OtpInput>(pb => |
| 17 | + { |
| 18 | + pb.Add(a => a.Value, "123"); |
| 19 | + pb.Add(a => a.Digits, 6); |
| 20 | + }); |
| 21 | + |
| 22 | + var items = cut.FindAll(".bb-opt-item"); |
| 23 | + Assert.Equal(6, items.Count); |
| 24 | + |
| 25 | + var item = items[0]; |
| 26 | + Assert.Equal("1", item.GetAttribute("value")); |
| 27 | + } |
| 28 | + |
| 29 | + [Fact] |
| 30 | + public void Readonly_Ok() |
| 31 | + { |
| 32 | + var cut = Context.RenderComponent<OtpInput>(pb => |
| 33 | + { |
| 34 | + pb.Add(a => a.IsReadonly, true); |
| 35 | + }); |
| 36 | + |
| 37 | + var item = cut.Find(".bb-opt-item"); |
| 38 | + Assert.Equal("<span class=\"bb-opt-item\"></span>", item.OuterHtml); |
| 39 | + |
| 40 | + cut.SetParametersAndRender(pb => |
| 41 | + { |
| 42 | + pb.Add(a => a.IsReadonly, false); |
| 43 | + }); |
| 44 | + item = cut.Find(".bb-opt-item"); |
| 45 | + Assert.Equal("<input type=\"number\" class=\"input-number-fix\" inputmode=\"numeric\" blazor:onchange=\"1\">", item.InnerHtml); |
| 46 | + |
| 47 | + cut.SetParametersAndRender(pb => |
| 48 | + { |
| 49 | + pb.Add(a => a.IsDisabled, true); |
| 50 | + }); |
| 51 | + item = cut.Find(".bb-opt-item"); |
| 52 | + Assert.Equal("<span class=\"bb-opt-item disabled\"></span>", item.OuterHtml); |
| 53 | + } |
| 54 | +} |
0 commit comments