Skip to content

Commit

Permalink
Merge pull request #338 from ITU-BDSA2024-GROUP10/fix-bugs-with-page-…
Browse files Browse the repository at this point in the history
…buttons

Fix bugs with page buttons
  • Loading branch information
anthoncastillo authored Nov 27, 2024
2 parents ce780b0 + 3f3a8ad commit 33a6a12
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,48 @@
var lastPageNumber = ViewBag.LastPageNumber as int? ?? 1;
}

<div style="display: flex; align-items: baseline;" class="page-buttons">
@if (currentPageNumber > 1)
@if (lastPageNumber > 0)
{
if (currentPageNumber > lastPageNumber)
{
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-right: 8px;" href="@targetPageUrl?page=@(currentPageNumber - 1)">&lt; Prev</a>
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-right: 8px;"
href="@targetPageUrl?page=@lastPageNumber">&lt; Go to cheeps</a>
}
@if (currentPageNumber != 1)
else
{
<a style="margin: 5px" href="@targetPageUrl?page=1">1</a>
@if (currentPageNumber != 2)
{
<p style="margin: 5px">..</p>
<a style="margin: 5px" href="@targetPageUrl?page=@(currentPageNumber - 1)">@(currentPageNumber - 1)</a>
}
}
<p style="margin: 5px">@currentPageNumber</p>
@if (currentPageNumber != lastPageNumber)
{
@if (currentPageNumber != lastPageNumber-1)
{
<a style="margin: 5px" href="@targetPageUrl?page=@(currentPageNumber + 1)">@(currentPageNumber + 1)</a>
<p style="margin: 5px">..</p>
}
<a style="margin: 5px" href="@targetPageUrl?page=@lastPageNumber">@lastPageNumber</a>
}
@if (currentPageNumber < lastPageNumber)
{
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-left: 8px;" href="@targetPageUrl?page=@(currentPageNumber + 1)">Next &gt;</a>
<div style="display: flex; align-items: baseline;" class="page-buttons">
@if (currentPageNumber > 1)
{
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-right: 8px;"
href="@targetPageUrl?page=@(currentPageNumber - 1)">&lt; Prev</a>
}
@if (currentPageNumber != 1)
{
<a style="margin: 5px" href="@targetPageUrl?page=1">1</a>
@if (currentPageNumber != 2)
{
<p style="margin: 5px">..</p>
<a style="margin: 5px"
href="@targetPageUrl?page=@(currentPageNumber - 1)">@(currentPageNumber - 1)</a>
}
}
<p style="margin: 5px">@currentPageNumber</p>
@if (currentPageNumber != lastPageNumber)
{
@if (currentPageNumber != lastPageNumber - 1)
{
<a style="margin: 5px"
href="@targetPageUrl?page=@(currentPageNumber + 1)">@(currentPageNumber + 1)</a>
<p style="margin: 5px">..</p>
}

<a style="margin: 5px" href="@targetPageUrl?page=@lastPageNumber">@lastPageNumber</a>
}
@if (currentPageNumber < lastPageNumber)
{
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-left: 8px;"
href="@targetPageUrl?page=@(currentPageNumber + 1)">Next &gt;</a>
}
</div>
}
</div>
}
2 changes: 1 addition & 1 deletion Chirp/src/Chirp.Web/Pages/UserTimeline.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

@if (Model.Cheeps.Any())
{
@await Component.InvokeAsync("CheepList", new { cheeps = Model.Cheeps, targetPage = $"/{routeName}" })
@await Component.InvokeAsync("PageButtons", new { currentPageNumber = Model.PageNumber, lastPageNumber = Model.LastPageNumber, targetPageUrl = $"/{routeName}" })
@await Component.InvokeAsync("CheepList", new { cheeps = Model.Cheeps, targetPage = $"/{routeName}" })
}
else
{
Expand Down
68 changes: 67 additions & 1 deletion Chirp/test/PlaywrightTests/UITests/PageButtonsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,60 @@ namespace PlaywrightTests.UITests;
public class PageButtonsTests : PageTestWithRazorPlaywrightWebApplicationFactory
{
[Test]
public async Task FormatingTest()
public async Task FormatingTest_OnePage()
{
//arrange
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager())
.WithDefault()
.Create();
await GenerateCheeps(testAuthor.author, 32*1);

await Page.GotoAsync("/?page=1");
await Expect(Page.Locator("body")).Not.ToContainTextAsync("Next >");
}

[Test]
public async Task FormatingTest_TwoPages()
{
//arrange
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager())
.WithDefault()
.Create();
await GenerateCheeps(testAuthor.author, 32*2);

//first
await Page.GotoAsync("/?page=1");
await Expect(Page.Locator("body")).ToContainTextAsync("1 2 Next >");

//second
await Page.GotoAsync("/?page=2");
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 2");
}

[Test]
public async Task FormatingTest_ThreePages()
{
//arrange
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager())
.WithDefault()
.Create();
await GenerateCheeps(testAuthor.author, 32*3);

//first
await Page.GotoAsync("/?page=1");
await Expect(Page.Locator("body")).ToContainTextAsync("1 2 .. 3 Next >");

//second
await Page.GotoAsync("/?page=2");
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 2 3 Next >");

//third
await Page.GotoAsync("/?page=3");
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 .. 2 3");
}

[Test]
public async Task FormatingTest_FivePages()
{
//arrange
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager())
Expand Down Expand Up @@ -52,4 +105,17 @@ public async Task PageNumbersAreClickable()
await Page.GetByRole(AriaRole.Link, new() { Name = "5" }).First.ClickAsync();
Assert.That(Page.Url, Is.EqualTo($"{RazorBaseUrl}/?page=5"));
}

[Test]
public async Task CurrentPageIsBeyondLastPage()
{
//arrange
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager())
.WithDefault()
.Create();
await GenerateCheeps(testAuthor.author, 32*5);

await Page.GotoAsync("/?page=6");
await Expect(Page.Locator("body")).ToContainTextAsync("< Go to cheeps");
}
}

0 comments on commit 33a6a12

Please sign in to comment.