using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared; namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Shared; /// /// Unit tests for the helper introduced for /// windowed pagination that keeps the rendered button count /// bounded regardless of total page count. /// public class PagerWindowTests { /// Verifies that a small page count returns every page with no ellipsis. [Fact] public void Build_SmallPageCount_ReturnsEveryPage_NoEllipsis() { var pages = PagerWindow.Build(currentPage: 3, totalPages: 5); Assert.Equal(new[] { 1, 2, 3, 4, 5 }, pages); } /// Verifies that a large page count yields a bounded window that includes the first and last pages. [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."); } /// Verifies that a large page count inserts an ellipsis for each gap in the window. [Fact] public void Build_LargePageCount_InsertsEllipsisForGaps() { // 0 is the ellipsis sentinel. var pages = PagerWindow.Build(currentPage: 100, totalPages: 200); Assert.Contains(0, pages); } /// Verifies that a current page near the start produces no leading ellipsis. [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]); } /// Verifies that an out-of-range current page is clamped into the valid range. [Fact] public void Build_ClampsOutOfRangeCurrentPage() { var pages = PagerWindow.Build(currentPage: 999, totalPages: 200); Assert.Contains(200, pages); Assert.True(pages.Count <= 12); } /// Verifies that a non-positive total page count returns an empty window. /// The non-positive total page count under test. [Theory] [InlineData(0)] [InlineData(-3)] public void Build_NonPositiveTotalPages_ReturnsEmpty(int totalPages) { Assert.Empty(PagerWindow.Build(currentPage: 1, totalPages: totalPages)); } }