Skip to content

Commit

Permalink
Pager: Add Auto Display Mode functionality (#3239)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Gabriel Vazquez Jr and Gabriel Vazquez authored Sep 4, 2020
1 parent d6b4251 commit a154532
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
50 changes: 49 additions & 1 deletion dev/Pager/InteractionTests/PagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class PagerTests
{
PagerTestsPageElements elements;
int previousPage = -1;
int AutoDisplayModeThresholdValue = 10;
delegate void SetButtonVisibilityModeFunction(ButtonVisibilityModes mode);

[ClassInitialize]
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -580,7 +607,7 @@ int GetPreviousPageAsInt()
{
return Convert.ToInt32(GetPreviousPage());
}
string GetPreviousPage()
string GetPreviousPage()
{
return elements.GetPreviousPageTextBlock().GetText();
}
Expand All @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions dev/Pager/InteractionTests/PagerTestsPageElements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ public TextBlock GetPreviousPageTextBlock()
}
private TextBlock PreviousPageTextBlock;

public Button GetIncreaseNumberOfPagesButton()
{
return GetElement(ref IncreaseNumberOfPagesButton, "IncreaseNumberOfPagesButton");
}
private Button IncreaseNumberOfPagesButton;

private T GetElement<T>(ref T element, string elementName) where T : UIObject
{
if (element == null)
Expand Down
5 changes: 4 additions & 1 deletion dev/Pager/PrototypePager/PrototypePager.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ private void OnNumberOfPagesChanged()
}

DisablePageButtonsOnEdge();
OnPagerDisplayModeChanged();
}

private void OnComboBoxSelectionChanged()
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion dev/Pager/PrototypePager/PrototypePager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion dev/Pager/TestUI/PagerPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</ComboBox>

<Button x:Name="NumberOfPagesSetterButton" Content="Set NumberOfPages to 100" Grid.Row="4" Click="NumberOfPagesSetterButtonClicked"/>

<Button x:Name="IncreaseNumberOfPagesButton" Content="Increase NumberOfPages by 1" Grid.Row="5" Click="IncreaseNumberOfPagesButtonClicked"/>
</Grid>
<Grid Grid.Column="1" Margin="5">
<Grid.ColumnDefinitions>
Expand Down
17 changes: 17 additions & 0 deletions dev/Pager/TestUI/PagerPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@ private void NumberOfPagesSetterButtonClicked(object sender, RoutedEventArgs arg
TestPager.NumberOfPages = 5;
NumberOfPagesSetterButton.Content = "Set NumberOfPages to 100";
}

NumberBoxVisibilityCheckBox.IsChecked = TestPager.NumberBoxDisplayTestHook.Visibility == Visibility.Visible;
ComboBoxVisibilityCheckBox.IsChecked = TestPager.ComboBoxDisplayTestHook.Visibility == Visibility.Visible;
NumberPanelVisibilityCheckBox.IsChecked = TestPager.NumberPanelDisplayTestHook.Visibility == Visibility.Visible;
NumberBoxIsEnabledCheckBox.IsChecked = TestPager.NumberBoxDisplayTestHook.IsEnabled;
ComboBoxIsEnabledCheckBox.IsChecked = TestPager.ComboBoxDisplayTestHook.IsEnabled;
}

private void IncreaseNumberOfPagesButtonClicked(object sender, RoutedEventArgs args)
{
TestPager.NumberOfPages += 1;

NumberBoxVisibilityCheckBox.IsChecked = TestPager.NumberBoxDisplayTestHook.Visibility == Visibility.Visible;
ComboBoxVisibilityCheckBox.IsChecked = TestPager.ComboBoxDisplayTestHook.Visibility == Visibility.Visible;
NumberPanelVisibilityCheckBox.IsChecked = TestPager.NumberPanelDisplayTestHook.Visibility == Visibility.Visible;
NumberBoxIsEnabledCheckBox.IsChecked = TestPager.NumberBoxDisplayTestHook.IsEnabled;
ComboBoxIsEnabledCheckBox.IsChecked = TestPager.ComboBoxDisplayTestHook.IsEnabled;
}

private void OnPageChanged(PrototypePager sender, PageChangedEventArgs args)
Expand Down

0 comments on commit a154532

Please sign in to comment.