Skip to content

Commit 3ae9b51

Browse files
committed
Fixed tests, so that they wait for the async operation
1 parent 223645f commit 3ae9b51

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/Admin/DraftBlogPostPageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Linq;
2+
using System.Threading.Tasks;
23
using Bunit;
34
using FluentAssertions;
45
using LinkDotNet.Blog.TestUtilities;
@@ -23,6 +24,8 @@ public async Task ShouldOnlyShowPublishedPosts()
2324
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
2425
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
2526
var cut = ctx.RenderComponent<DraftBlogPosts>();
27+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
28+
2629

2730
var blogPosts = cut.FindComponents<ShortBlogPost>();
2831

LinkDotNet.Blog.IntegrationTests/Web/Pages/IndexTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Linq;
2+
using System.Threading.Tasks;
23
using Bunit;
34
using FluentAssertions;
45
using LinkDotNet.Blog.TestUtilities;
@@ -26,6 +27,7 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst()
2627
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
2728
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
2829
var cut = ctx.RenderComponent<Index>();
30+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
2931

3032
var blogPosts = cut.FindComponents<ShortBlogPost>();
3133

@@ -46,6 +48,7 @@ public async Task ShouldOnlyShowPublishedPosts()
4648
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
4749
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
4850
var cut = ctx.RenderComponent<Index>();
51+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
4952

5053
var blogPosts = cut.FindComponents<ShortBlogPost>();
5154

@@ -62,6 +65,7 @@ public async Task ShouldOnlyLoadTenEntities()
6265
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
6366
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
6467
var cut = ctx.RenderComponent<Index>();
68+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
6569

6670
var blogPosts = cut.FindComponents<ShortBlogPost>();
6771

@@ -80,6 +84,7 @@ public async Task ShouldLoadNextBatchOnClick()
8084

8185
cut.FindComponent<BlogPostNavigation>().Find("li:last-child a").Click();
8286

87+
cut.WaitForState(() => cut.FindAll(".blog-card").Count == 1);
8388
var blogPosts = cut.FindComponents<ShortBlogPost>();
8489
blogPosts.Count.Should().Be(1);
8590
}
@@ -93,6 +98,7 @@ public async Task ShouldLoadPreviousBatchOnClick()
9398
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
9499
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
95100
var cut = ctx.RenderComponent<Index>();
101+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
96102
cut.FindComponent<BlogPostNavigation>().Find("li:last-child a").Click();
97103

98104
cut.FindComponent<BlogPostNavigation>().Find("li:first-child a").Click();

0 commit comments

Comments
 (0)