1
- using System . Linq ;
1
+ using System ;
2
+ using System . Linq ;
2
3
using System . Threading . Tasks ;
3
4
using Bunit ;
4
5
using FluentAssertions ;
8
9
using LinkDotNet . Blog . Web ;
9
10
using LinkDotNet . Blog . Web . Shared ;
10
11
using LinkDotNet . Blog . Web . Shared . Services ;
12
+ using Microsoft . AspNetCore . Components ;
11
13
using Microsoft . Extensions . DependencyInjection ;
12
14
using Moq ;
13
15
using Toolbelt . Blazor . HeadElement ;
@@ -74,7 +76,7 @@ public async Task ShouldOnlyLoadTenEntities()
74
76
}
75
77
76
78
[ Fact ]
77
- public async Task ShouldLoadNextBatchOnClick ( )
79
+ public async Task ShouldGoToNextPageOnNextClick ( )
78
80
{
79
81
await CreatePublishedBlogPosts ( 11 ) ;
80
82
using var ctx = new TestContext ( ) ;
@@ -84,28 +86,42 @@ public async Task ShouldLoadNextBatchOnClick()
84
86
85
87
cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
86
88
87
- cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count == 1 ) ;
88
- var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
89
- blogPosts . Count . Should ( ) . Be ( 1 ) ;
89
+ var navigationManager = ctx . Services . GetService < NavigationManager > ( ) ;
90
+ cut . WaitForState ( ( ) => navigationManager . Uri . Contains ( "/2" ) ) ;
91
+ navigationManager . Uri . Should ( ) . Contain ( "/2" ) ;
90
92
}
91
93
92
94
[ Fact ]
93
- public async Task ShouldLoadPreviousBatchOnClick ( )
95
+ public async Task ShouldGoToPreviousPageOnPreviousClick ( )
94
96
{
95
97
await CreatePublishedBlogPosts ( 11 ) ;
96
98
using var ctx = new TestContext ( ) ;
97
99
ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
98
100
RegisterComponents ( ctx ) ;
99
- var cut = ctx . RenderComponent < Index > ( ) ;
100
- cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
101
- cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:last-child a" ) . Click ( ) ;
102
- cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count == 1 ) ;
101
+ var cut = ctx . RenderComponent < Index > (
102
+ p => p . Add ( s => s . Page , 2 ) ) ;
103
103
104
104
cut . FindComponent < BlogPostNavigation > ( ) . Find ( "li:first-child a" ) . Click ( ) ;
105
105
106
- cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Count > 1 ) ;
106
+ var navigationManager = ctx . Services . GetService < NavigationManager > ( ) ;
107
+ cut . WaitForState ( ( ) => navigationManager . Uri . Contains ( "/1" ) ) ;
108
+ navigationManager . Uri . Should ( ) . Contain ( "/1" ) ;
109
+ }
110
+
111
+ [ Fact ]
112
+ public async Task ShouldLoadOnlyItemsInPage ( )
113
+ {
114
+ await CreatePublishedBlogPosts ( 11 ) ;
115
+ using var ctx = new TestContext ( ) ;
116
+ ctx . JSInterop . Mode = JSRuntimeMode . Loose ;
117
+ RegisterComponents ( ctx ) ;
118
+
119
+ var cut = ctx . RenderComponent < Index > (
120
+ p => p . Add ( s => s . Page , 2 ) ) ;
121
+
122
+ cut . WaitForState ( ( ) => cut . FindAll ( ".blog-card" ) . Any ( ) ) ;
107
123
var blogPosts = cut . FindComponents < ShortBlogPost > ( ) ;
108
- blogPosts . Count . Should ( ) . Be ( 10 ) ;
124
+ blogPosts . Should ( ) . HaveCount ( 1 ) ;
109
125
}
110
126
111
127
[ Fact ]
0 commit comments