1
- using System . Threading . Tasks ;
1
+ using System . Linq ;
2
+ using System . Threading . Tasks ;
2
3
using Bunit ;
3
4
using FluentAssertions ;
4
5
using LinkDotNet . Blog . TestUtilities ;
@@ -26,6 +27,7 @@ public async Task ShouldShowAllBlogPostsWithLatestOneFirst()
26
27
ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
27
28
ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
28
29
var cut = ctx . RenderComponent < Index > ( ) ;
30
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
29
31
30
32
var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
31
33
@@ -46,13 +48,67 @@ public async Task ShouldOnlyShowPublishedPosts()
46
48
ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
47
49
ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
48
50
var cut = ctx . RenderComponent < Index > ( ) ;
51
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
49
52
50
53
var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
51
54
52
55
blogPosts . Should ( ) . HaveCount ( 1 ) ;
53
56
blogPosts [ 0 ] . Find ( ".description h1" ) . InnerHtml . Should ( ) . Be ( "Published" ) ;
54
57
}
55
58
59
+ [ Fact ]
60
+ public async Task ShouldOnlyLoadTenEntities ( )
61
+ {
62
+ await CreatePublishedBlogPosts ( 11 ) ;
63
+ using var ctx = new TestContext ( ) ;
64
+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
65
+ ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
66
+ ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
67
+ var cut = ctx . RenderComponent < Index > ( ) ;
68
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
69
+
70
+ var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
71
+
72
+ blogPosts . Count . Should ( ) . Be ( 10 ) ;
73
+ }
74
+
75
+ [ Fact ]
76
+ public async Task ShouldLoadNextBatchOnClick ( )
77
+ {
78
+ await CreatePublishedBlogPosts ( 11 ) ;
79
+ using var ctx = new TestContext ( ) ;
80
+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
81
+ ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
82
+ ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
83
+ var cut = ctx . RenderComponent < Index > ( ) ;
84
+
85
+ cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
86
+
87
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count == 1 ) ;
88
+ var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
89
+ blogPosts . Count . Should ( ) . Be ( 1 ) ;
90
+ }
91
+
92
+ [ Fact ]
93
+ public async Task ShouldLoadPreviousBatchOnClick ( )
94
+ {
95
+ await CreatePublishedBlogPosts ( 11 ) ;
96
+ using var ctx = new TestContext ( ) ;
97
+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
98
+ ctx . Services . AddScoped < IRepository > ( _ => BlogPostRepository ) ;
99
+ ctx . Services . AddScoped ( _ => CreateSampleAppConfiguration ( ) ) ;
100
+ var cut = ctx . RenderComponent < Index > ( ) ;
101
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
102
+ cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
103
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count == 1 ) ;
104
+
105
+ cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:first-child a" ) . Click ( ) ;
106
+
107
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count > 1 ) ;
108
+ var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
109
+ blogPosts . Count . Should ( ) . Be ( 10 ) ;
110
+ }
111
+
56
112
private static AppConfiguration CreateSampleAppConfiguration ( )
57
113
{
58
114
return new ( )
@@ -66,5 +122,14 @@ private static AppConfiguration CreateSampleAppConfiguration()
66
122
} ,
67
123
} ;
68
124
}
125
+
126
+ private async Task CreatePublishedBlogPosts ( int amount )
127
+ {
128
+ for ( var i = 0 ; i < amount ; i ++ )
129
+ {
130
+ var blogPost = new BlogPostBuilder ( ) . IsPublished ( ) . Build ( ) ;
131
+ await BlogPostRepository . StoreAsync ( blogPost ) ;
132
+ }
133
+ }
69
134
}
70
135
}
0 commit comments