Skip to content

Commit 898d8f1

Browse files
committed
test: 更新单元测试
1 parent a25b6dc commit 898d8f1

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

test/UnitTest/Components/MessageTest.cs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

66
using Microsoft.AspNetCore.Components.Web;
7+
using Microsoft.Extensions.Options;
78

89
namespace UnitTest.Components;
910

@@ -57,10 +58,8 @@ await cut.InvokeAsync(() =>
5758
Assert.NotNull(alert.Id);
5859

5960
var message = cut.FindComponent<Message>();
60-
await message.Instance.Dismiss(alert.Id);
61+
await cut.InvokeAsync(() => message.Instance.Dismiss(alert.Id));
6162
Assert.True(dismiss);
62-
63-
await cut.InvokeAsync(() => message.Instance.Clear());
6463
}
6564

6665
[Fact]
@@ -98,7 +97,7 @@ await cut.InvokeAsync(() => service.Show(new MessageOption()
9897

9998
await cut.Instance.Dismiss(alert.Id);
10099
await cut.Instance.Dismiss("test_id");
101-
await cut.InvokeAsync(() => cut.Instance.Clear());
100+
await cut.InvokeAsync(() => cut.Instance.Clear(alert.Id));
102101

103102
await cut.InvokeAsync(() => service.Show(new MessageOption()
104103
{
@@ -133,4 +132,44 @@ await cut.InvokeAsync(() => service.Show(new MessageOption()
133132
ShowMode = MessageShowMode.Single
134133
}, cut.Instance));
135134
}
135+
136+
[Fact]
137+
public async Task ForceDelay_Ok()
138+
{
139+
var service = Context.Services.GetRequiredService<MessageService>();
140+
var cut = Context.RenderComponent<Message>();
141+
var option = new MessageOption()
142+
{
143+
Content = "Test Content",
144+
IsAutoHide = false,
145+
ShowDismiss = true,
146+
Icon = "fa-solid fa-font-awesome",
147+
ForceDelay = true,
148+
Delay = 2000
149+
};
150+
await cut.InvokeAsync(() => service.Show(option, cut.Instance));
151+
Assert.Contains("data-bb-delay=\"2000\"", cut.Markup);
152+
153+
var alert = cut.Find(".alert");
154+
Assert.NotNull(alert);
155+
Assert.NotNull(alert.Id);
156+
await cut.InvokeAsync(() => cut.Instance.Clear(alert.Id));
157+
158+
option.ForceDelay = false;
159+
await cut.InvokeAsync(() => service.Show(option, cut.Instance));
160+
Assert.Contains("data-bb-delay=\"4000\"", cut.Markup);
161+
await cut.InvokeAsync(() => cut.Instance.Clear(alert.Id));
162+
163+
// 更新 Options 值
164+
var options = Context.Services.GetRequiredService<IOptionsMonitor<BootstrapBlazorOptions>>();
165+
options.CurrentValue.MessageDelay = 1000;
166+
await cut.InvokeAsync(() => service.Show(option, cut.Instance));
167+
Assert.Contains("data-bb-delay=\"1000\"", cut.Markup);
168+
await cut.InvokeAsync(() => cut.Instance.Clear(alert.Id));
169+
170+
options.CurrentValue.MessageDelay = 0;
171+
await cut.InvokeAsync(() => service.Show(option, cut.Instance));
172+
Assert.Contains("data-bb-delay=\"1000\"", cut.Markup);
173+
await cut.InvokeAsync(() => cut.Instance.Clear(alert.Id));
174+
}
136175
}

0 commit comments

Comments
 (0)