Skip to content

Commit 09ea869

Browse files
AndrewKeepCodingArlodotexe
authored andcommitted
Add tests for WrapPanel
1 parent 2a8c651 commit 09ea869

12 files changed

Lines changed: 262 additions & 71 deletions

components/Primitives/tests/Primitives.Tests.projitems

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@
3333
<Compile Include="$(MSBuildThisFileDirectory)Test_UniformGrid_FreeSpots.cs" />
3434
<Compile Include="$(MSBuildThisFileDirectory)Test_UniformGrid_RowColDefinitions.cs" />
3535
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_BasicLayout.cs" />
36-
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_Infinity.cs" />
36+
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_StretchChild.cs" />
3737
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_Visibility.cs" />
3838
<Compile Include="$(MSBuildThisFileDirectory)UniformGrid\AutoLayoutFixedElementZeroZeroSpecialPage.xaml.cs">
3939
<DependentUpon>AutoLayoutFixedElementZeroZeroSpecialPage.xaml</DependentUpon>
4040
</Compile>
41-
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelSample.xaml.cs">
42-
<DependentUpon>WrapPanelSample.xaml</DependentUpon>
41+
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\HorizontalWrapPanelInsideParentWithInfinityWidth.xaml.cs">
42+
<DependentUpon>HorizontalWrapPanelInsideParentWithInfinityWidth.xaml</DependentUpon>
43+
</Compile>
44+
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\HorizontalWrapPanelInsideParentWithLimitedWidth.xaml.cs">
45+
<DependentUpon>HorizontalWrapPanelInsideParentWithLimitedWidth.xaml</DependentUpon>
46+
</Compile>
47+
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithInfinityHeight.xaml.cs">
48+
<DependentUpon>VerticalWrapPanelInsideParentWithInfinityHeight.xaml</DependentUpon>
49+
</Compile>
50+
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithLimitedHeight.xaml.cs">
51+
<DependentUpon>VerticalWrapPanelInsideParentWithLimitedHeight.xaml</DependentUpon>
4352
</Compile>
4453
</ItemGroup>
4554
<ItemGroup>
@@ -51,7 +60,19 @@
5160
<SubType>Designer</SubType>
5261
<Generator>MSBuild:Compile</Generator>
5362
</Page>
54-
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelSample.xaml">
63+
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\HorizontalWrapPanelInsideParentWithInfinityWidth.xaml">
64+
<SubType>Designer</SubType>
65+
<Generator>MSBuild:Compile</Generator>
66+
</Page>
67+
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\HorizontalWrapPanelInsideParentWithLimitedWidth.xaml">
68+
<SubType>Designer</SubType>
69+
<Generator>MSBuild:Compile</Generator>
70+
</Page>
71+
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithInfinityHeight.xaml">
72+
<SubType>Designer</SubType>
73+
<Generator>MSBuild:Compile</Generator>
74+
</Page>
75+
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithLimitedHeight.xaml">
5576
<SubType>Designer</SubType>
5677
<Generator>MSBuild:Compile</Generator>
5778
</Page>

components/Primitives/tests/Test_WrapPanel_Infinity.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using CommunityToolkit.Tests;
6+
using CommunityToolkit.Tooling.TestGen;
7+
using CommunityToolkit.WinUI.Controls;
8+
9+
namespace PrimitivesTests;
10+
11+
[TestClass]
12+
public partial class Test_WrapPanel_StretchChild : VisualUITestBase
13+
{
14+
/// <summary>
15+
/// When a WrapPanel is inside a parent with infinite width, the last child cannot stretch to fill the remaining space.
16+
/// Instead, it should measure to its desired size.
17+
/// </summary>
18+
[TestCategory("WrapPanel")]
19+
[UIThreadTestMethod]
20+
public void VerticalWrapPanelInsideParentWithInfinityHeightTest(VerticalWrapPanelInsideParentWithInfinityHeight page)
21+
{
22+
var wrapPanel = page.FindDescendant<WrapPanel>();
23+
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
24+
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
25+
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");
26+
27+
foreach (var child in wrapPanel.Children.Cast<FrameworkElement>())
28+
{
29+
double expectedHeight = child.DesiredSize.Height;
30+
Assert.AreEqual(expectedHeight, child.ActualHeight, "Child height not as expected.");
31+
}
32+
}
33+
34+
/// <summary>
35+
/// When a WrapPanel is inside a parent with limited height, the last child with Stretch alignment should fill the remaining space.
36+
/// </summary>
37+
[TestCategory("WrapPanel")]
38+
[UIThreadTestMethod]
39+
public void VerticalWrapPanelInsideParentWithLimitedHeightTest(VerticalWrapPanelInsideParentWithLimitedHeight page)
40+
{
41+
var wrapPanel = page.FindDescendant<WrapPanel>();
42+
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
43+
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
44+
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");
45+
46+
var precedingChildren = wrapPanel.Children.Cast<FrameworkElement>().Take(wrapPanel.Children.Count - 1);
47+
48+
foreach (var child in precedingChildren)
49+
{
50+
double expectedHeight = child.DesiredSize.Height;
51+
Assert.AreEqual(expectedHeight, child.ActualHeight, "Preceding child height not as expected.");
52+
}
53+
54+
var lastChild = wrapPanel.Children.Cast<FrameworkElement>().Last();
55+
double lastChildExpectedHeight = wrapPanel.ActualHeight - precedingChildren.Sum(child => child.ActualHeight);
56+
Assert.AreEqual(lastChildExpectedHeight, lastChild.ActualHeight, "Last child height not as expected.");
57+
}
58+
59+
/// <summary>
60+
/// When a WrapPanel is inside a parent with infinite width, the last child cannot stretch to fill the remaining space.
61+
/// Instead, it should measure to its desired size.
62+
/// </summary>
63+
[TestCategory("WrapPanel")]
64+
[UIThreadTestMethod]
65+
public void HorizontalWrapPanelInsideParentWithInfinityWidthTest(HorizontalWrapPanelInsideParentWithInfinityWidth page)
66+
{
67+
var wrapPanel = page.FindDescendant<WrapPanel>();
68+
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
69+
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
70+
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");
71+
72+
foreach (var child in wrapPanel.Children.Cast<FrameworkElement>())
73+
{
74+
double expectedWidth = child.DesiredSize.Width;
75+
Assert.AreEqual(expectedWidth, child.ActualWidth, "Preceding child width not as expected.");
76+
}
77+
}
78+
79+
/// <summary>
80+
/// When a WrapPanel is inside a parent with limited width, the last child with Stretch alignment should fill the remaining space.
81+
/// </summary>
82+
/// <param name="page"></param>
83+
[TestCategory("WrapPanel")]
84+
[UIThreadTestMethod]
85+
public void HorizontalWrapPanelInsideParentWithLimitedWidthTest(HorizontalWrapPanelInsideParentWithLimitedWidth page)
86+
{
87+
var wrapPanel = page.FindDescendant<WrapPanel>();
88+
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
89+
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
90+
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");
91+
92+
var precedingChildren = wrapPanel.Children.Cast<FrameworkElement>().Take(wrapPanel.Children.Count - 1);
93+
94+
foreach (var child in precedingChildren)
95+
{
96+
double expectedWidth = child.DesiredSize.Width;
97+
Assert.AreEqual(expectedWidth, child.ActualWidth, "Child width not as expected.");
98+
}
99+
100+
var lastChild = wrapPanel.Children.Cast<FrameworkElement>().Last();
101+
double lastChildExpectedWidth = wrapPanel.ActualWidth - precedingChildren.Sum(child => child.ActualWidth);
102+
Assert.AreEqual(lastChildExpectedWidth, lastChild.ActualWidth, "Last child width not as expected.");
103+
}
104+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Page
2+
x:Class="PrimitivesTests.HorizontalWrapPanelInsideParentWithInfinityWidth"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:PrimitivesTests"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="Auto" />
15+
</Grid.ColumnDefinitions>
16+
<controls:WrapPanel Orientation="Horizontal" StretchChild="Last">
17+
<Button HorizontalAlignment="Stretch" Content="Child 1" />
18+
<Button HorizontalAlignment="Stretch" Content="Child 2" />
19+
<Button HorizontalAlignment="Stretch" Content="Last Child" />
20+
</controls:WrapPanel>
21+
</Grid>
22+
23+
</Page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace PrimitivesTests;
6+
7+
public sealed partial class HorizontalWrapPanelInsideParentWithInfinityWidth : Page
8+
{
9+
public HorizontalWrapPanelInsideParentWithInfinityWidth()
10+
{
11+
this.InitializeComponent();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Page
2+
x:Class="PrimitivesTests.HorizontalWrapPanelInsideParentWithLimitedWidth"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:PrimitivesTests"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid>
13+
<Grid.ColumnDefinitions>
14+
<ColumnDefinition Width="*" />
15+
</Grid.ColumnDefinitions>
16+
<controls:WrapPanel Orientation="Horizontal" StretchChild="Last">
17+
<Button HorizontalAlignment="Stretch" Content="Child 1" />
18+
<Button HorizontalAlignment="Stretch" Content="Child 2" />
19+
<Button HorizontalAlignment="Stretch" Content="Last Child" />
20+
</controls:WrapPanel>
21+
</Grid>
22+
23+
</Page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace PrimitivesTests;
6+
7+
public sealed partial class HorizontalWrapPanelInsideParentWithLimitedWidth : Page
8+
{
9+
public HorizontalWrapPanelInsideParentWithLimitedWidth()
10+
{
11+
this.InitializeComponent();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Page
2+
x:Class="PrimitivesTests.VerticalWrapPanelInsideParentWithInfinityHeight"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:PrimitivesTests"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid>
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="Auto" />
15+
</Grid.RowDefinitions>
16+
<controls:WrapPanel Orientation="Vertical" StretchChild="Last">
17+
<Button VerticalAlignment="Stretch" Content="Child 1" />
18+
<Button VerticalAlignment="Stretch" Content="Child 2" />
19+
<Button VerticalAlignment="Stretch" Content="Last Child" />
20+
</controls:WrapPanel>
21+
</Grid>
22+
23+
</Page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace PrimitivesTests;
6+
7+
public sealed partial class VerticalWrapPanelInsideParentWithInfinityHeight : Page
8+
{
9+
public VerticalWrapPanelInsideParentWithInfinityHeight()
10+
{
11+
this.InitializeComponent();
12+
}
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Page
2+
x:Class="PrimitivesTests.VerticalWrapPanelInsideParentWithLimitedHeight"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:PrimitivesTests"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid>
13+
<Grid.RowDefinitions>
14+
<RowDefinition Height="*" />
15+
</Grid.RowDefinitions>
16+
<controls:WrapPanel Orientation="Vertical" StretchChild="Last">
17+
<Button VerticalAlignment="Stretch" Content="Child 1" />
18+
<Button VerticalAlignment="Stretch" Content="Child 2" />
19+
<Button VerticalAlignment="Stretch" Content="Last Child" />
20+
</controls:WrapPanel>
21+
</Grid>
22+
23+
</Page>

0 commit comments

Comments
 (0)