Skip to content

Commit

Permalink
Fixed tests, so that they wait for the async operation
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Jul 14, 2021
1 parent 223645f commit 3ae9b51
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Bunit;
using FluentAssertions;
using LinkDotNet.Blog.TestUtilities;
Expand All @@ -23,6 +24,8 @@ public async Task ShouldOnlyShowPublishedPosts()
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
var cut = ctx.RenderComponent<DraftBlogPosts>();
cut.WaitForState(() => cut.FindAll(".blog-card").Any());


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

Expand Down
8 changes: 7 additions & 1 deletion LinkDotNet.Blog.IntegrationTests/Web/Pages/IndexTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Bunit;
using FluentAssertions;
using LinkDotNet.Blog.TestUtilities;
Expand Down Expand Up @@ -26,6 +27,7 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst()
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
ctx.Services.AddScoped(_ => CreateSampleAppConfiguration());
var cut = ctx.RenderComponent<Index>();
cut.WaitForState(() => cut.FindAll(".blog-card").Any());

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

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

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

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

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

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

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

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

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

0 comments on commit 3ae9b51

Please sign in to comment.