513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the <see cref="PagerWindow"/> helper introduced for
|
|
/// windowed pagination that keeps the rendered button count
|
|
/// bounded regardless of total page count.
|
|
/// </summary>
|
|
public class PagerWindowTests
|
|
{
|
|
/// <summary>Verifies that a small page count returns every page with no ellipsis.</summary>
|
|
[Fact]
|
|
public void Build_SmallPageCount_ReturnsEveryPage_NoEllipsis()
|
|
{
|
|
var pages = PagerWindow.Build(currentPage: 3, totalPages: 5);
|
|
|
|
Assert.Equal(new[] { 1, 2, 3, 4, 5 }, pages);
|
|
}
|
|
|
|
/// <summary>Verifies that a large page count yields a bounded window that includes the first and last pages.</summary>
|
|
[Fact]
|
|
public void Build_LargePageCount_IsBounded_AndIncludesFirstAndLast()
|
|
{
|
|
var pages = PagerWindow.Build(currentPage: 100, totalPages: 200);
|
|
|
|
Assert.Contains(1, pages);
|
|
Assert.Contains(200, pages);
|
|
Assert.Contains(100, pages);
|
|
// First, ellipsis, window of 5, ellipsis, last — never the full 200.
|
|
Assert.True(pages.Count <= 12, $"Expected a bounded window but got {pages.Count} entries.");
|
|
}
|
|
|
|
/// <summary>Verifies that a large page count inserts an ellipsis for each gap in the window.</summary>
|
|
[Fact]
|
|
public void Build_LargePageCount_InsertsEllipsisForGaps()
|
|
{
|
|
// 0 is the ellipsis sentinel.
|
|
var pages = PagerWindow.Build(currentPage: 100, totalPages: 200);
|
|
|
|
Assert.Contains(0, pages);
|
|
}
|
|
|
|
/// <summary>Verifies that a current page near the start produces no leading ellipsis.</summary>
|
|
[Fact]
|
|
public void Build_CurrentNearStart_NoLeadingEllipsis()
|
|
{
|
|
var pages = PagerWindow.Build(currentPage: 1, totalPages: 200);
|
|
|
|
// Pages 1..3 are contiguous from the start, so no ellipsis before them.
|
|
Assert.Equal(1, pages[0]);
|
|
Assert.NotEqual(0, pages[1]);
|
|
}
|
|
|
|
/// <summary>Verifies that an out-of-range current page is clamped into the valid range.</summary>
|
|
[Fact]
|
|
public void Build_ClampsOutOfRangeCurrentPage()
|
|
{
|
|
var pages = PagerWindow.Build(currentPage: 999, totalPages: 200);
|
|
|
|
Assert.Contains(200, pages);
|
|
Assert.True(pages.Count <= 12);
|
|
}
|
|
|
|
/// <summary>Verifies that a non-positive total page count returns an empty window.</summary>
|
|
/// <param name="totalPages">The non-positive total page count under test.</param>
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(-3)]
|
|
public void Build_NonPositiveTotalPages_ReturnsEmpty(int totalPages)
|
|
{
|
|
Assert.Empty(PagerWindow.Build(currentPage: 1, totalPages: totalPages));
|
|
}
|
|
}
|