-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from ITU-BDSA2024-GROUP10/update-the-page-but…
…tons Update the page buttons
- Loading branch information
Showing
11 changed files
with
124 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 27 additions & 9 deletions
36
Chirp/src/Chirp.Web/Pages/Shared/Components/PageButtons/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
@{ | ||
var targetPage = ViewBag.TargetPage as string ?? "/"; | ||
var pageNumber = ViewBag.PageNumber as int? ?? 1; | ||
var isLastPage = ViewBag.IsLastPage as bool? ?? false; | ||
var targetPageUrl = ViewBag.TargetPageUrl as string ?? "/"; | ||
var currentPageNumber = ViewBag.CurrentPageNumber as int? ?? 1; | ||
var lastPageNumber = ViewBag.LastPageNumber as int? ?? 1; | ||
} | ||
|
||
<div style="display: flex; align-items: center;"> | ||
@if (pageNumber > 1) | ||
<div style="display: flex; align-items: baseline;" class="page-buttons"> | ||
@if (currentPageNumber > 1) | ||
{ | ||
<a href="@targetPage?page=@(pageNumber - 1)">Previous</a> | ||
<a style="background-color: #cc6e6e; color: white; padding: 8px 16px; text-align: center; text-decoration: none; margin-right: 8px;" href="@targetPageUrl?page=@(currentPageNumber - 1)">< Prev</a> | ||
} | ||
<p style="margin: 10px">@pageNumber</p> | ||
@if (!isLastPage) | ||
@if (currentPageNumber != 1) | ||
{ | ||
<a href="@targetPage?page=@(pageNumber + 1)">Next</a> | ||
<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 ></a> | ||
} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.Playwright; | ||
using PlaywrightTests.Utils; | ||
using PlaywrightTests.Utils.PageTests; | ||
|
||
namespace PlaywrightTests.UITests; | ||
|
||
public class PageButtonsTests : PageTestWithRazorPlaywrightWebApplicationFactory | ||
{ | ||
[Test] | ||
public async Task FormatingTest() | ||
{ | ||
//arrange | ||
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager()) | ||
.WithDefault() | ||
.Create(); | ||
await GenerateCheeps(testAuthor.author, 32*5); | ||
|
||
//first | ||
await Page.GotoAsync("/?page=1"); | ||
await Expect(Page.Locator("body")).ToContainTextAsync("1 2 .. 5 Next >"); | ||
|
||
//second | ||
await Page.GotoAsync("/?page=2"); | ||
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 2 3 .. 5 Next >"); | ||
|
||
//middle | ||
await Page.GotoAsync("/?page=3"); | ||
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 .. 2 3 4 .. 5 Next >"); | ||
|
||
//second to last | ||
await Page.GotoAsync("/?page=4"); | ||
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 .. 3 4 5 Next >"); | ||
|
||
//end | ||
await Page.GotoAsync("/?page=5"); | ||
await Expect(Page.Locator("body")).ToContainTextAsync("< Prev 1 .. 4 5"); | ||
} | ||
|
||
[Test] | ||
public async Task PageNumbersAreClickable() | ||
{ | ||
//arrange | ||
var testAuthor = new TestAuthorBuilder(RazorFactory.GetUserManager()) | ||
.WithDefault() | ||
.Create(); | ||
await GenerateCheeps(testAuthor.author, 32*5); | ||
|
||
//first | ||
await Page.GotoAsync("/?page=1"); | ||
await Page.GetByRole(AriaRole.Link, new() { Name = "2" }).First.ClickAsync(); | ||
Assert.That(Page.Url, Is.EqualTo($"{RazorBaseUrl}/?page=2")); | ||
await Page.GetByRole(AriaRole.Link, new() { Name = "5" }).First.ClickAsync(); | ||
Assert.That(Page.Url, Is.EqualTo($"{RazorBaseUrl}/?page=5")); | ||
} | ||
} |