|
| 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 | +public class TypedTest : BootstrapBlazorTestBase |
| 9 | +{ |
| 10 | + [Fact] |
| 11 | + public void Text_Ok() |
| 12 | + { |
| 13 | + var cut = Context.RenderComponent<Typed>(pb => |
| 14 | + { |
| 15 | + pb.Add(a => a.Text, "Test"); |
| 16 | + }); |
| 17 | + cut.MarkupMatches("<span diff:ignore></span>"); |
| 18 | + |
| 19 | + cut.SetParametersAndRender(pb => |
| 20 | + { |
| 21 | + pb.Add(a => a.Text, "Test1"); |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void Options_Ok() |
| 27 | + { |
| 28 | + var cut = Context.RenderComponent<Typed>(pb => |
| 29 | + { |
| 30 | + pb.Add(a => a.Options, new TypedOptions() { Text = ["test1", "test2"], TypeSpeed = 70 }); |
| 31 | + }); |
| 32 | + cut.MarkupMatches("<span diff:ignore></span>"); |
| 33 | + |
| 34 | + cut.SetParametersAndRender(pb => |
| 35 | + { |
| 36 | + pb.Add(a => a.Options, new TypedOptions() { Text = null, TypeSpeed = 70 }); |
| 37 | + }); |
| 38 | + cut.MarkupMatches("<span diff:ignore></span>"); |
| 39 | + |
| 40 | + cut.SetParametersAndRender(pb => |
| 41 | + { |
| 42 | + pb.Add(a => a.Options, new TypedOptions() { Text = ["test1", "test2", "test3"], TypeSpeed = 70 }); |
| 43 | + }); |
| 44 | + cut.MarkupMatches("<span diff:ignore></span>"); |
| 45 | + |
| 46 | + cut.SetParametersAndRender(pb => |
| 47 | + { |
| 48 | + pb.Add(a => a.Options, null); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + [Fact] |
| 53 | + public async Task TriggerComplete_Ok() |
| 54 | + { |
| 55 | + var triggered = false; |
| 56 | + Task onCompleteCallback() |
| 57 | + { |
| 58 | + triggered = true; |
| 59 | + return Task.CompletedTask; |
| 60 | + } |
| 61 | + var cut = Context.RenderComponent<Typed>(pb => |
| 62 | + { |
| 63 | + pb.Add(a => a.Options, new TypedOptions() { Text = ["test1", "test2"], TypeSpeed = 70 }); |
| 64 | + pb.Add(a => a.OnCompleteAsync, onCompleteCallback); |
| 65 | + }); |
| 66 | + cut.MarkupMatches("<span diff:ignore></span>"); |
| 67 | + |
| 68 | + await cut.InvokeAsync(() => cut.Instance.TriggerComplete()); |
| 69 | + Assert.True(triggered); |
| 70 | + } |
| 71 | + |
| 72 | + [Fact] |
| 73 | + public void TypedOptions_Ok() |
| 74 | + { |
| 75 | + // Arrange |
| 76 | + var options = new TypedOptions() |
| 77 | + { |
| 78 | + Text = ["test1", "test2"], |
| 79 | + TypeSpeed = 70, |
| 80 | + BackSpeed = 50, |
| 81 | + BackDelay = 200, |
| 82 | + Loop = true, |
| 83 | + LoopCount = 2, |
| 84 | + ShowCursor = true, |
| 85 | + CursorChar = "|", |
| 86 | + ContentType = "html", |
| 87 | + Shuffle = false, |
| 88 | + SmartBackspace = true |
| 89 | + }; |
| 90 | + |
| 91 | + // Assert |
| 92 | + Assert.NotNull(options.Text); |
| 93 | + Assert.Equal(2, options.Text.Count); |
| 94 | + Assert.Equal("test1", options.Text[0]); |
| 95 | + Assert.Equal("test2", options.Text[1]); |
| 96 | + Assert.Equal(70, options.TypeSpeed); |
| 97 | + Assert.Equal(50, options.BackSpeed); |
| 98 | + Assert.Equal(200, options.BackDelay); |
| 99 | + Assert.True(options.Loop); |
| 100 | + Assert.Equal(2, options.LoopCount); |
| 101 | + Assert.True(options.ShowCursor); |
| 102 | + Assert.False(options.Shuffle); |
| 103 | + Assert.True(options.SmartBackspace); |
| 104 | + Assert.Equal("|", options.CursorChar); |
| 105 | + Assert.Equal("html", options.ContentType); |
| 106 | + } |
| 107 | +} |
0 commit comments