Skip to content

Commit c72d510

Browse files
committed
test: 更新单元测试
1 parent 085985c commit c72d510

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

test/UnitTest/Components/TabTest.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ await cut.InvokeAsync(() => tab.AddTab(new Dictionary<string, object?>
261261
}
262262

263263
[Fact]
264-
public void AddTabByUrl_Ok()
264+
public async Task AddTabByUrl_Ok()
265265
{
266266
var navMan = Context.Services.GetRequiredService<FakeNavigationManager>();
267267
navMan.NavigateTo("/");
@@ -290,7 +290,7 @@ public void AddTabByUrl_Ok()
290290
});
291291

292292
navMan.NavigateTo("/");
293-
cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary<string, object?>
293+
await cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary<string, object?>
294294
{
295295
["Text"] = "Cat",
296296
["Url"] = "Cat"
@@ -299,10 +299,10 @@ public void AddTabByUrl_Ok()
299299
{
300300
pb.Add(a => a.ExcludeUrls, ["/Test"]);
301301
});
302-
cut.InvokeAsync(() => cut.Instance.CloseCurrentTab());
302+
await cut.InvokeAsync(() => cut.Instance.CloseCurrentTab());
303303

304304
// AddTab
305-
cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary<string, object?>
305+
await cut.InvokeAsync(() => cut.Instance.AddTab(new Dictionary<string, object?>
306306
{
307307
["Text"] = "Cat",
308308
["Url"] = null,
@@ -314,14 +314,16 @@ public void AddTabByUrl_Ok()
314314
Assert.NotNull(item);
315315
Assert.Equal("", item.Url);
316316

317-
cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
317+
await cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
318318
item = cut.Instance.GetActiveTab();
319319
Assert.NotNull(item);
320320
Assert.Equal("Cat", item.Url);
321321

322-
cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
322+
await cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
323323
item = cut.Instance.GetActiveTab();
324324
Assert.Null(item);
325+
326+
await cut.InvokeAsync(() => cut.Instance.CloseCurrentTab());
325327
}
326328

327329
[Fact]
@@ -534,26 +536,24 @@ public void AlwaysLoad_Ok()
534536
}
535537

536538
[Fact]
537-
public void ActiveTab_Ok()
539+
public async Task ActiveTab_Ok()
538540
{
539541
var cut = Context.RenderComponent<Tab>(pb =>
540542
{
541543
pb.Add(a => a.AdditionalAssemblies, new Assembly[] { GetType().Assembly });
542544
pb.Add(a => a.DefaultUrl, "/");
543545
});
544-
cut.InvokeAsync(() => cut.Instance.ActiveTab(0));
546+
await cut.InvokeAsync(() => cut.Instance.ActiveTab(0));
547+
545548
var item = cut.Instance.GetActiveTab();
546549
Assert.NotNull(item);
547-
cut.InvokeAsync(() =>
548-
{
549-
if (item != null)
550-
{
551-
cut.Instance.ActiveTab(item);
552-
}
553-
});
554-
cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
550+
551+
await cut.InvokeAsync(() => cut.Instance.ActiveTab(item));
552+
553+
// 移除标签导航到默认标签
554+
await cut.InvokeAsync(() => cut.Instance.RemoveTab(item!));
555555
item = cut.Instance.GetActiveTab();
556-
Assert.Null(item);
556+
Assert.NotNull(item);
557557
}
558558

559559
[Fact]

0 commit comments

Comments
 (0)