feat(centralui): KeysetPager reusable cursor-pagination component (T35b)

This commit is contained in:
Joseph Doherty
2026-06-18 19:28:15 -04:00
parent 4755ceee81
commit 6a34ed9ed6
2 changed files with 118 additions and 0 deletions
@@ -0,0 +1,24 @@
@* Reusable keyset (cursor) pagination button bar — purely presentational.
All cursor/navigation logic lives in the consuming page via callbacks. *@
<div class="d-flex align-items-center gap-2">
<button class="btn btn-outline-secondary btn-sm"
data-test="keyset-prev"
disabled="@(!CanGoBack || Disabled)"
@onclick="OnPrevious">Previous</button>
<span data-test="keyset-summary">Page @PageNumber · @RowCount rows</span>
<button class="btn btn-outline-secondary btn-sm"
data-test="keyset-next"
disabled="@(!HasNextPage || Disabled)"
@onclick="OnNext">Next</button>
</div>
@code {
[Parameter] public int PageNumber { get; set; } = 1;
[Parameter] public int RowCount { get; set; }
[Parameter] public bool CanGoBack { get; set; }
[Parameter] public bool HasNextPage { get; set; }
[Parameter] public bool Disabled { get; set; }
[Parameter] public EventCallback OnPrevious { get; set; }
[Parameter] public EventCallback OnNext { get; set; }
}
@@ -0,0 +1,94 @@
using Bunit;
using Microsoft.AspNetCore.Components;
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
/// <summary>
/// Component tests for <see cref="KeysetPager"/> — the purely-presentational
/// cursor-pagination button bar shared by SiteCallsReport and AuditResultsGrid.
/// </summary>
public class KeysetPagerTests : BunitContext
{
[Fact]
public void PrevDisabled_WhenCannotGoBack()
{
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.CanGoBack, false)
.Add(p => p.HasNextPage, true));
var prev = cut.Find("[data-test='keyset-prev']");
Assert.NotNull(prev.GetAttribute("disabled"));
}
[Fact]
public void NextDisabled_WhenNoNextPage()
{
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.CanGoBack, true)
.Add(p => p.HasNextPage, false));
var next = cut.Find("[data-test='keyset-next']");
Assert.NotNull(next.GetAttribute("disabled"));
}
[Fact]
public void Prev_Click_InvokesOnPrevious()
{
var fired = false;
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.CanGoBack, true)
.Add(p => p.HasNextPage, false)
.Add(p => p.OnPrevious,
EventCallback.Factory.Create(this, () => { fired = true; })));
cut.Find("[data-test='keyset-prev']").Click();
Assert.True(fired);
}
[Fact]
public void Next_Click_InvokesOnNext()
{
var fired = false;
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.CanGoBack, false)
.Add(p => p.HasNextPage, true)
.Add(p => p.OnNext,
EventCallback.Factory.Create(this, () => { fired = true; })));
cut.Find("[data-test='keyset-next']").Click();
Assert.True(fired);
}
[Fact]
public void Summary_RendersPageAndRows()
{
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.PageNumber, 3)
.Add(p => p.RowCount, 42));
var summary = cut.Find("[data-test='keyset-summary']");
Assert.Contains("Page 3", summary.TextContent);
Assert.Contains("42 rows", summary.TextContent);
}
[Fact]
public void BothDisabled_WhenDisabled()
{
var cut = Render<KeysetPager>(ps => ps
.Add(p => p.CanGoBack, true)
.Add(p => p.HasNextPage, true)
.Add(p => p.Disabled, true));
var prev = cut.Find("[data-test='keyset-prev']");
var next = cut.Find("[data-test='keyset-next']");
Assert.NotNull(prev.GetAttribute("disabled"));
Assert.NotNull(next.GetAttribute("disabled"));
}
}