Skip to content

Commit d2b0db5

Browse files
committed
Check if passed parameter is invalid
1 parent 3103eb1 commit d2b0db5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ public void ShouldSetAbsoluteUriForOgData(string givenUri, string expectedUri)
128128
cut.FindComponent<OgData>().Instance.AbsolutePreviewImageUrl.Should().Be(expectedUri);
129129
}
130130

131+
[Theory]
132+
[InlineData(null)]
133+
[InlineData(0)]
134+
[InlineData(-1)]
135+
public async Task ShouldSetPageToFirstIfOutOfRange(int? page)
136+
{
137+
await CreatePublishedBlogPosts(11);
138+
using var ctx = new TestContext();
139+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
140+
RegisterComponents(ctx);
141+
142+
var cut = ctx.RenderComponent<Index>(p => p.Add(
143+
i => i.Page, page));
144+
145+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
146+
cut.WaitForState(() => cut.FindAll(".blog-card").Count == 10);
147+
}
148+
131149
private static AppConfiguration CreateSampleAppConfiguration()
132150
{
133151
return new()

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242

4343
protected override async Task OnParametersSetAsync()
4444
{
45+
if (Page == null || Page < 1)
46+
{
47+
Page = 1;
48+
}
49+
4550
currentPage = await blogPostRepository.GetAllAsync(
4651
p => p.IsPublished,
4752
b => b.UpdatedDate,

0 commit comments

Comments
 (0)