From a1545320d01454cd3d166fac3e9fbe8dd0b68201 Mon Sep 17 00:00:00 2001 From: Gabriel Vazquez Jr Date: Fri, 4 Sep 2020 15:45:47 -0700 Subject: [PATCH] Pager: Add Auto Display Mode functionality (#3239) * Added Auto mode behavior. * Modified auto display mode tests * Changed threshold value for auto display mode and removed magic numbers. * Added test to check auto display mode threshold boundry Co-authored-by: Gabriel Vazquez --- dev/Pager/InteractionTests/PagerTests.cs | 50 ++++++++++++++++++- .../PagerTestsPageElements.cs | 6 +++ .../PrototypePager/PrototypePager.Events.cs | 5 +- dev/Pager/PrototypePager/PrototypePager.cs | 3 +- dev/Pager/TestUI/PagerPage.xaml | 2 +- dev/Pager/TestUI/PagerPage.xaml.cs | 17 +++++++ 6 files changed, 79 insertions(+), 4 deletions(-) diff --git a/dev/Pager/InteractionTests/PagerTests.cs b/dev/Pager/InteractionTests/PagerTests.cs index ab85be9f1b..d49db562bc 100644 --- a/dev/Pager/InteractionTests/PagerTests.cs +++ b/dev/Pager/InteractionTests/PagerTests.cs @@ -34,6 +34,7 @@ public class PagerTests { PagerTestsPageElements elements; int previousPage = -1; + int AutoDisplayModeThresholdValue = 10; delegate void SetButtonVisibilityModeFunction(ButtonVisibilityModes mode); [ClassInitialize] @@ -529,6 +530,32 @@ public void ChangingDisplayModeTest() SetNumberPanelDisplayMode(); VerifyNumberPanelDisplayMode(); + + ChangeNumberOfPages(); + VerifyNumberOfPages("100"); + + SetAutoDisplayMode(); + VerifyAutoDisplayMode(); + + ChangeNumberOfPages(); + VerifyNumberOfPages("5"); + + VerifyAutoDisplayMode(); + + IncrementNumberOfPages(4); + VerifyNumberOfPages("9"); + + VerifyAutoDisplayMode(); + + IncrementNumberOfPages(1); + VerifyNumberOfPages("10"); + + VerifyAutoDisplayMode(); + + IncrementNumberOfPages(1); + VerifyNumberOfPages("11"); + + VerifyAutoDisplayMode(); } } @@ -580,7 +607,7 @@ int GetPreviousPageAsInt() { return Convert.ToInt32(GetPreviousPage()); } - string GetPreviousPage() + string GetPreviousPage() { return elements.GetPreviousPageTextBlock().GetText(); } @@ -599,6 +626,14 @@ void ChangeNumberOfPages() InputHelper.LeftClick(elements.GetNumberOfPagesSetterButton()); } + void IncrementNumberOfPages(int numberOfPagesToAdd) + { + for (int i = 0; i < numberOfPagesToAdd; i++) + { + InputHelper.LeftClick(elements.GetIncreaseNumberOfPagesButton()); + } + } + void VerifyNumberOfPages(string expectedPages) { Verify.AreEqual(expectedPages, elements.GetNumberOfPagesTextBlock().GetText()); @@ -812,6 +847,19 @@ void VerifyDisplayMode(DisplayModes mode) switch (mode) { case DisplayModes.Auto: + if (Convert.ToInt32(elements.GetNumberOfPagesTextBlock().GetText()) < AutoDisplayModeThresholdValue) + { + VerifyComboBoxEnabled(); + VerifyNumberBoxDisabled(); + VerifyNumberPanelDisabled(); + } + else + { + VerifyNumberBoxEnabled(); + VerifyComboBoxDisabled(); + VerifyNumberPanelDisabled(); + } + break; case DisplayModes.ComboBox: VerifyComboBoxEnabled(); VerifyNumberBoxDisabled(); diff --git a/dev/Pager/InteractionTests/PagerTestsPageElements.cs b/dev/Pager/InteractionTests/PagerTestsPageElements.cs index fcffdec0e3..c5c8e8de3d 100644 --- a/dev/Pager/InteractionTests/PagerTestsPageElements.cs +++ b/dev/Pager/InteractionTests/PagerTestsPageElements.cs @@ -229,6 +229,12 @@ public TextBlock GetPreviousPageTextBlock() } private TextBlock PreviousPageTextBlock; + public Button GetIncreaseNumberOfPagesButton() + { + return GetElement(ref IncreaseNumberOfPagesButton, "IncreaseNumberOfPagesButton"); + } + private Button IncreaseNumberOfPagesButton; + private T GetElement(ref T element, string elementName) where T : UIObject { if (element == null) diff --git a/dev/Pager/PrototypePager/PrototypePager.Events.cs b/dev/Pager/PrototypePager/PrototypePager.Events.cs index 8802319fa4..ee6836e89e 100644 --- a/dev/Pager/PrototypePager/PrototypePager.Events.cs +++ b/dev/Pager/PrototypePager/PrototypePager.Events.cs @@ -96,6 +96,7 @@ private void OnNumberOfPagesChanged() } DisablePageButtonsOnEdge(); + OnPagerDisplayModeChanged(); } private void OnComboBoxSelectionChanged() @@ -113,10 +114,12 @@ private void OnPagerDisplayModeChanged() { switch (this.PagerDisplayMode) { + case PagerDisplayModes.Auto: + VisualStateManager.GoToState(this, NumberOfPages < AutoDisplayModeNumberOfPagesThreshold ? ComboBoxVisibleVisualState : NumberBoxVisibleVisualState, false); + break; case PagerDisplayModes.NumberBox: VisualStateManager.GoToState(this, NumberBoxVisibleVisualState, false); break; - case PagerDisplayModes.Auto: case PagerDisplayModes.ComboBox: VisualStateManager.GoToState(this, ComboBoxVisibleVisualState, false); break; diff --git a/dev/Pager/PrototypePager/PrototypePager.cs b/dev/Pager/PrototypePager/PrototypePager.cs index a6556d4ce0..a55647a3d3 100644 --- a/dev/Pager/PrototypePager/PrototypePager.cs +++ b/dev/Pager/PrototypePager/PrototypePager.cs @@ -33,10 +33,11 @@ public enum ButtonVisibilityMode { Auto, AlwaysVisible, HiddenOnEdge, None, } private ItemsRepeater PagerNumberPanel; private Rectangle NumberPanelCurrentPageIdentifier; + private static int AutoDisplayModeNumberOfPagesThreshold = 10; // This integer determines when to switch between NumberBoxDisplayMode and ComboBoxDisplayMode private static int MaxNumberOfElementsInRepeater = 7; private static int NumberPanelMiddleStateStartIndex = 5; private int NumberPanelEndStateStartIndex; - + private static IconElement LeftEllipse = new SymbolIcon(Symbol.More); private static IconElement RightEllipse = new SymbolIcon(Symbol.More); diff --git a/dev/Pager/TestUI/PagerPage.xaml b/dev/Pager/TestUI/PagerPage.xaml index 4d38857f6f..2ca2468b59 100644 --- a/dev/Pager/TestUI/PagerPage.xaml +++ b/dev/Pager/TestUI/PagerPage.xaml @@ -88,7 +88,7 @@