Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing UniformGridLayout items-per-line evaluation #4994

Merged
merged 2 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 95 additions & 2 deletions dev/Repeater/InteractionTests/RepeaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public static void ClassInitialize(TestContext testContext)
TestEnvironment.Initialize(testContext);
}

[TestCleanup]
public void TestCleanup()
{
TestCleanupHelper.Cleanup();
}

[TestMethod]
public void VerifyUniformGridLayoutDoesNotCreateHoles()
{
Expand Down Expand Up @@ -68,9 +74,96 @@ public void VerifyUniformGridLayoutDoesNotCreateHoles()
}
}

public void TestCleanup()
[TestMethod]
public void VerifyUniformGridLayoutScrolling()
{
TestCleanupHelper.Cleanup();
using (var setup = new TestSetupHelper("ItemsRepeater Tests"))
{
// Open page
FindElement.ByName("UniformGridLayoutDemo").Click();

// Set ScrollViewer HorizontalScrollBarVisibility to Disabled.
Log.Comment("Retrieving CmbScrollViewerHorizontalScrollBarVisibility");
UIObject CmbScrollViewerHorizontalScrollBarVisibilityUIObject = FindElement.ByName("CmbScrollViewerHorizontalScrollBarVisibility");
ComboBox CmbScrollViewerHorizontalScrollBarVisibility = new ComboBox(CmbScrollViewerHorizontalScrollBarVisibilityUIObject);
Verify.IsNotNull(CmbScrollViewerHorizontalScrollBarVisibility, "Verifying that CmbScrollViewerHorizontalScrollBarVisibility ComboBox was found");

Log.Comment("Changing ScrollViewer HorizontalScrollBarVisibility to Disabled");
CmbScrollViewerHorizontalScrollBarVisibility.SelectItemByName("Disabled");
Log.Comment("Selection is now {0}", CmbScrollViewerHorizontalScrollBarVisibility.Selection[0].Name);

// Set ScrollViewer MaxWidth to 500.
Log.Comment("Retrieving ScrollViewerMaxWidth");
UIObject ScrollViewerMaxWidthUIObject = FindElement.ByName("ScrollViewerMaxWidth");
Edit ScrollViewerMaxWidthTextBox = new Edit(ScrollViewerMaxWidthUIObject);
Verify.IsNotNull(ScrollViewerMaxWidthTextBox, "Verifying that ScrollViewerMaxWidth Edit was found");
ScrollViewerMaxWidthTextBox.SetValue("500");
Wait.ForIdle();
Log.Comment("ScrollViewerMaxWidth: " + ScrollViewerMaxWidthTextBox.Value);

Log.Comment("Retrieving SetScrollViewerMaxWidth");
UIObject SetScrollViewerMaxWidthUIObject = FindElement.ByName("SetScrollViewerMaxWidth");
Button SetScrollViewerMaxWidthButton = new Button(SetScrollViewerMaxWidthUIObject);
Verify.IsNotNull(SetScrollViewerMaxWidthUIObject, "Verifying that SetScrollViewerMaxWidth Button was found");
Log.Comment("Updating ScrollViewerMaxWidth");
SetScrollViewerMaxWidthButton.Invoke();
Wait.ForIdle();

// Set UniformGridLayout ItemsStretch to Fill.
Log.Comment("Retrieving CmbUniformGridLayoutItemsStretch");
UIObject CmbUniformGridLayoutItemsStretchUIObject = FindElement.ByName("CmbUniformGridLayoutItemsStretch");
ComboBox CmbUniformGridLayoutItemsStretch = new ComboBox(CmbUniformGridLayoutItemsStretchUIObject);
Verify.IsNotNull(CmbUniformGridLayoutItemsStretch, "Verifying that CmbUniformGridLayoutItemsStretch ComboBox was found");

Log.Comment("Changing UniformGridLayout ItemsStretch to Fill");
CmbUniformGridLayoutItemsStretch.SelectItemByName("Fill");
Log.Comment("Selection is now {0}", CmbUniformGridLayoutItemsStretch.Selection[0].Name);

// Set UniformGridLayout MinColumnSpacing to 50.
Log.Comment("Retrieving UniformGridLayoutMinColumnSpacing");
UIObject UniformGridLayoutMinColumnSpacingUIObject = FindElement.ByName("UniformGridLayoutMinColumnSpacing");
Edit UniformGridLayoutMinColumnSpacingTextBox = new Edit(UniformGridLayoutMinColumnSpacingUIObject);
Verify.IsNotNull(UniformGridLayoutMinColumnSpacingTextBox, "Verifying that UniformGridLayoutMinColumnSpacing Edit was found");
UniformGridLayoutMinColumnSpacingTextBox.SetValue("50");
Wait.ForIdle();
Log.Comment("UniformGridLayoutMinColumnSpacing: " + UniformGridLayoutMinColumnSpacingTextBox.Value);

Log.Comment("Retrieving SetUniformGridLayoutMinColumnSpacing");
UIObject SetUniformGridLayoutMinColumnSpacingUIObject = FindElement.ByName("SetUniformGridLayoutMinColumnSpacing");
Button SetUniformGridLayoutMinColumnSpacingButton = new Button(SetUniformGridLayoutMinColumnSpacingUIObject);
Verify.IsNotNull(SetUniformGridLayoutMinColumnSpacingUIObject, "Verifying that SetUniformGridLayoutMinColumnSpacing Button was found");
Log.Comment("Updating UniformGridLayoutMinColumnSpacing");
SetUniformGridLayoutMinColumnSpacingButton.Invoke();
Wait.ForIdle();

// Set ScrollViewer VerticalOffset to 1000.
Log.Comment("Retrieving ScrollViewerVerticalOffset");
UIObject ScrollViewerVerticalOffsetUIObject = FindElement.ByName("ScrollViewerVerticalOffset");
Edit ScrollViewerVerticalOffsetTextBox = new Edit(ScrollViewerVerticalOffsetUIObject);
Verify.IsNotNull(ScrollViewerVerticalOffsetTextBox, "Verifying that ScrollViewerVerticalOffset Edit was found");
ScrollViewerVerticalOffsetTextBox.SetValue("1000");
Wait.ForIdle();
Log.Comment("ScrollViewerVerticalOffset: " + ScrollViewerVerticalOffsetTextBox.Value);

Log.Comment("Retrieving SetScrollViewerVerticalOffset");
UIObject SetScrollViewerVerticalOffsetUIObject = FindElement.ByName("SetScrollViewerVerticalOffset");
Button SetScrollViewerVerticalOffsetButton = new Button(SetScrollViewerVerticalOffsetUIObject);
Verify.IsNotNull(SetScrollViewerVerticalOffsetUIObject, "Verifying that SetScrollViewerVerticalOffset Button was found");
Log.Comment("Scrolling to ScrollViewer VerticalOffset 1000 by invoking SetScrollViewerVerticalOffset Button");
SetScrollViewerVerticalOffsetButton.Invoke();
Wait.ForIdle();

Log.Comment("Retrieving GetScrollViewerVerticalOffset");
UIObject GetScrollViewerVerticalOffsetUIObject = FindElement.ByName("GetScrollViewerVerticalOffset");
Button GetScrollViewerVerticalOffsetButton = new Button(GetScrollViewerVerticalOffsetUIObject);
Verify.IsNotNull(GetScrollViewerVerticalOffsetUIObject, "Verifying that GetScrollViewerVerticalOffset Button was found");
Log.Comment("Retrieving ScrollViewer VerticalOffset by invoking GetScrollViewerVerticalOffset Button");
GetScrollViewerVerticalOffsetButton.Invoke();
Wait.ForIdle();
Log.Comment("ScrollViewerVerticalOffset: " + ScrollViewerVerticalOffsetTextBox.Value);

Verify.AreEqual("1000", ScrollViewerVerticalOffsetTextBox.Value, "Verifying that final ScrollViewer VerticalOffset is requested 1000.");
}
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion dev/Repeater/TestUI/RepeaterTestUIPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<TextBox x:Name="lineSpacing" Text="10"></TextBox>
<TextBlock>LineAlignment</TextBlock>
<TextBlock>(Start/Center/End/SpaceEvenly/SpaceAround/SpaceBetween)</TextBlock>
<TextBox x:Name="lineAlingment" Text="Start"></TextBox>
<TextBox x:Name="lineAlignment" Text="Start"></TextBox>
<ToggleSwitch x:Name="orientation" OnContent="Horizontal" OffContent="Vertical">Scroll Orientation</ToggleSwitch>
</StackPanel>
<StackPanel Orientation="Horizontal">
Expand Down
4 changes: 2 additions & 2 deletions dev/Repeater/TestUI/RepeaterTestUIPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private VirtualizingLayout GetGridLayout()
MinItemHeight = 150,
MinRowSpacing = double.Parse(itemSpacing.Text),
MinColumnSpacing = double.Parse(lineSpacing.Text),
ItemsJustification = (UniformGridLayoutItemsJustification)Enum.Parse(typeof(UniformGridLayoutItemsJustification), lineAlingment.Text),
ItemsJustification = (UniformGridLayoutItemsJustification)Enum.Parse(typeof(UniformGridLayoutItemsJustification), lineAlignment.Text),
Orientation = orientation.IsOn ? Orientation.Vertical: Orientation.Horizontal,
};
}
Expand All @@ -272,7 +272,7 @@ private VirtualizingLayout GetFlowLayout()
{
MinRowSpacing = double.Parse(itemSpacing.Text),
MinColumnSpacing = double.Parse(lineSpacing.Text),
LineAlignment = (FlowLayoutLineAlignment)Enum.Parse(typeof(FlowLayoutLineAlignment), lineAlingment.Text),
LineAlignment = (FlowLayoutLineAlignment)Enum.Parse(typeof(FlowLayoutLineAlignment), lineAlignment.Text),
Orientation = orientation.IsOn ? Orientation.Vertical : Orientation.Horizontal,
};
}
Expand Down
10 changes: 5 additions & 5 deletions dev/Repeater/TestUI/Samples/BasicDemo.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<Page
<local:TestPage
x:Class="MUXControlsTestApp.Samples.BasicDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MUXControlsTestApp"
xmlns:controls="using:Microsoft.UI.Xaml.Controls">

<Page.Resources>
<local:TestPage.Resources>
<controls:RecyclePool x:Key="RecyclePool" />
<DataTemplate x:Key="odd" x:DataType="x:String">
<Button Content="{x:Bind}" Foreground="Red" Width="100" Height="100" />
Expand All @@ -21,7 +22,7 @@
<StaticResource x:Key="even" ResourceKey="even" />
</controls:RecyclingElementFactory.Templates>
</controls:RecyclingElementFactory>
</Page.Resources>
</local:TestPage.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
Expand All @@ -31,7 +32,6 @@
</Grid.RowDefinitions>

<StackPanel>
<Button x:Name="goBackButton">Back</Button>
<Button Click="OnAddRecipeButton_Click" AutomationProperties.Name="InsertAtStartButton">Insert item at start</Button>
<TextBlock x:Name="InsertAtStartChildCountLabel" AutomationProperties.Name="InsertAtStartChildCountLabel" Text="0"/>
</StackPanel>
Expand Down Expand Up @@ -82,4 +82,4 @@
</controls:ItemsRepeater>
</-->
</Grid>
</Page>
</local:TestPage>
4 changes: 1 addition & 3 deletions dev/Repeater/TestUI/Samples/BasicDemo.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
using System.Collections.ObjectModel;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using RecyclingElementFactory = Microsoft.UI.Xaml.Controls.RecyclingElementFactory;
using SelectTemplateEventArgs = Microsoft.UI.Xaml.Controls.SelectTemplateEventArgs;

namespace MUXControlsTestApp.Samples
{
public sealed partial class BasicDemo : Page
public sealed partial class BasicDemo : TestPage
{
public ObservableCollection<string> simpleStringsList = new ObservableCollection<string>();

public BasicDemo()
{
this.InitializeComponent();
goBackButton.Click += delegate { Frame.GoBack(); };
repeater.ItemTemplate = elementFactory;
var stack = repeater.Layout as StackLayout;
int numItems = (stack != null && stack.DisableVirtualization) ? 10 : 10000;
Expand Down
124 changes: 118 additions & 6 deletions dev/Repeater/TestUI/Samples/UniformGridLayoutDemo.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.UI.Xaml.Controls;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using RecyclingElementFactory = Microsoft.UI.Xaml.Controls.RecyclingElementFactory;
using SelectTemplateEventArgs = Microsoft.UI.Xaml.Controls.SelectTemplateEventArgs;

namespace MUXControlsTestApp.Samples
{
public sealed partial class UniformGridLayoutDemo : Page
public sealed partial class UniformGridLayoutDemo : TestPage
{
public IEnumerable<int> collection;

Expand All @@ -27,5 +23,121 @@ public void GetRepeaterActualHeightButtonClick(object sender, RoutedEventArgs e)
{
RepeaterActualHeightLabel.Text = UniformGridRepeater.ActualHeight.ToString();
}

private void GetUniformGridLayoutMinColumnSpacingButtonClick(object sender, RoutedEventArgs e)
{
UniformGridLayoutMinColumnSpacing.Text = (UniformGridRepeater.Layout as UniformGridLayout).MinColumnSpacing.ToString();
}

private void SetUniformGridLayoutMinColumnSpacingButtonClick(object sender, RoutedEventArgs e)
{
LayoutHelper.SetMinColumnSpacing(UniformGridRepeater.Layout, double.Parse(UniformGridLayoutMinColumnSpacing.Text));
}

private void GetUniformGridLayoutMinRowSpacingButtonClick(object sender, RoutedEventArgs e)
{
UniformGridLayoutMinRowSpacing.Text = (UniformGridRepeater.Layout as UniformGridLayout).MinRowSpacing.ToString();
}

private void SetUniformGridLayoutMinRowSpacingButtonClick(object sender, RoutedEventArgs e)
{
LayoutHelper.SetMinRowSpacing(UniformGridRepeater.Layout, double.Parse(UniformGridLayoutMinRowSpacing.Text));
}

private void GetUniformGridLayoutMinItemWidthButtonClick(object sender, RoutedEventArgs e)
{
UniformGridLayoutMinItemWidth.Text = (UniformGridRepeater.Layout as UniformGridLayout).MinItemWidth.ToString();
}

private void SetUniformGridLayoutMinItemWidthButtonClick(object sender, RoutedEventArgs e)
{
(UniformGridRepeater.Layout as UniformGridLayout).MinItemWidth = double.Parse(UniformGridLayoutMinItemWidth.Text);
}

private void GetUniformGridLayoutMinItemHeightButtonClick(object sender, RoutedEventArgs e)
{
UniformGridLayoutMinItemHeight.Text = (UniformGridRepeater.Layout as UniformGridLayout).MinItemHeight.ToString();
}

private void SetUniformGridLayoutMinItemHeightButtonClick(object sender, RoutedEventArgs e)
{
(UniformGridRepeater.Layout as UniformGridLayout).MinItemHeight = double.Parse(UniformGridLayoutMinItemHeight.Text);
}

private void GetScrollViewerMaxWidthButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewerMaxWidth.Text = ScrollViewer.MaxWidth.ToString();
}

private void SetScrollViewerMaxWidthButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewer.MaxWidth = double.Parse(ScrollViewerMaxWidth.Text);
}

private void GetScrollViewerMaxHeightButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewerMaxHeight.Text = ScrollViewer.MaxHeight.ToString();
}

private void SetScrollViewerMaxHeightButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewer.MaxHeight = double.Parse(ScrollViewerMaxHeight.Text);
}

private void GetScrollViewerHorizontalOffsetButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewerHorizontalOffset.Text = ScrollViewer.HorizontalOffset.ToString();
}

private void SetScrollViewerHorizontalOffsetButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewer.ChangeView(double.Parse(ScrollViewerHorizontalOffset.Text), null, null);
}

private void GetScrollViewerVerticalOffsetButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewerVerticalOffset.Text = ScrollViewer.VerticalOffset.ToString();
}

private void SetScrollViewerVerticalOffsetButtonClick(object sender, RoutedEventArgs e)
{
ScrollViewer.ChangeView(null, double.Parse(ScrollViewerVerticalOffset.Text), null);
}

private void CmbUniformGridLayoutItemsStretch_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (UniformGridRepeater != null)
{
var itemsStretch = (CmbUniformGridLayoutItemsStretch.SelectedItem as ComboBoxItem).Content.ToString();

LayoutHelper.SetItemsStretch(UniformGridRepeater.Layout, itemsStretch);
}
}

private void CmbUniformGridLayoutItemsJustification_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (UniformGridRepeater != null)
{
var itemsJustification = (CmbUniformGridLayoutItemsJustification.SelectedItem as ComboBoxItem).Content.ToString();

LayoutHelper.SetLineAlignment(UniformGridRepeater.Layout, itemsJustification);
}
}

private void CmbUniformGridLayoutOrientation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (UniformGridRepeater != null)
{
(UniformGridRepeater.Layout as UniformGridLayout).Orientation = CmbUniformGridLayoutOrientation.SelectedIndex == 0 ? Orientation.Vertical : Orientation.Horizontal;
}
}

private void CmbScrollViewerHorizontalScrollBarVisibility_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ScrollViewer != null)
{
ScrollViewer.HorizontalScrollBarVisibility = (ScrollBarVisibility)CmbScrollViewerHorizontalScrollBarVisibility.SelectedIndex;
}
}
}
}
Loading