Skip to content

Commit

Permalink
Add Vertical Splitter tests to compliment bound tests for horizontal …
Browse files Browse the repository at this point in the history
…splitter
  • Loading branch information
michael-hawker committed Jun 24, 2021
1 parent ce16a2b commit 99b8ae5
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 7 deletions.
110 changes: 110 additions & 0 deletions UITests/UITests.Tests.Shared/Controls/GridSplitterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,105 @@ public async Task TestGridSplitterDragHorizontalPastMinimumAsync()
Verify.AreEqual(columnDefinitionEnd.MinWidth, columnDefinitionEnd.ActualWidth, "Column was not the minimum size expected.");
}

[TestMethod]
[TestPage("GridSplitterTestPage")]
public async Task TestGridSplitterDragHorizontalPastMaximumAsync()
{
var amount = 150;

var gridSplitter = FindElement.ById("GridSplitterHorizontal");

Verify.IsNotNull(gridSplitter, "Can't find Horizontal GridSplitter");

// Drag to the Left
InputHelper.DragDistance(gridSplitter, amount, Direction.East, 1000);

Wait.ForMilliseconds(1050);
Wait.ForIdle();

ColumnDefinition columnDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<ColumnDefinition>>("GridSplitterRoot", "ColumnDefinitions"))?.FirstOrDefault();

Wait.ForIdle();

Verify.AreEqual(columnDefinitionEnd.MaxWidth, columnDefinitionEnd.ActualWidth, "Column was not the maximum size expected.");
}

[TestMethod]
[TestPage("GridSplitterTestPage")]
public async Task TestGridSplitterDragVerticalAsync()
{
var amount = 50;
var tolerance = 10;

var grid = FindElement.ByName("GridSplitterRoot");
var gridSplitter = FindElement.ById("GridSplitterVertical");

Verify.IsNotNull(grid, "Can't find GridSplitterRoot");
Verify.IsNotNull(gridSplitter, "Can't find Vertical GridSplitter");

RowDefinition rowDefinitionStart = (await VisualTreeHelper.FindElementPropertyAsync<List<RowDefinition>>("GridSplitterRoot", "RowDefinitions"))?.FirstOrDefault();

Verify.IsNotNull(rowDefinitionStart, "Couldn't retrieve Row Definition");

// Drag to the Left
InputHelper.DragDistance(gridSplitter, amount, Direction.North, 1000);

Wait.ForMilliseconds(1050);
Wait.ForIdle();

RowDefinition rowDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<RowDefinition>>("GridSplitterRoot", "RowDefinitions"))?.FirstOrDefault();

Wait.ForIdle();

Verify.IsTrue(Math.Abs(rowDefinitionStart.ActualHeight - amount - rowDefinitionEnd.ActualHeight) <= tolerance, $"RowDefinition not in range expected {rowDefinitionStart.ActualHeight - amount} was {rowDefinitionEnd.ActualHeight}");
}

[TestMethod]
[TestPage("GridSplitterTestPage")]
public async Task TestGridSplitterDragVerticalPastMinimumAsync()
{
var amount = 150;

var gridSplitter = FindElement.ById("GridSplitterVertical");

Verify.IsNotNull(gridSplitter, "Can't find Vertical GridSplitter");

// Drag to the Left
InputHelper.DragDistance(gridSplitter, amount, Direction.North, 1000);

Wait.ForMilliseconds(1050);
Wait.ForIdle();

RowDefinition rowDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<RowDefinition>>("GridSplitterRoot", "RowDefinitions"))?.FirstOrDefault();

Wait.ForIdle();

Verify.AreEqual(rowDefinitionEnd.MinHeight, rowDefinitionEnd.ActualHeight, "Row was not the minimum size expected.");
}

[TestMethod]
[TestPage("GridSplitterTestPage")]
public async Task TestGridSplitterDragVerticalPastMaximumAsync()
{
var amount = 150;

var gridSplitter = FindElement.ById("GridSplitterVertical");

Verify.IsNotNull(gridSplitter, "Can't find Vertical GridSplitter");

// Drag to the Left
InputHelper.DragDistance(gridSplitter, amount, Direction.South, 1000);

Wait.ForMilliseconds(1050);
Wait.ForIdle();

RowDefinition rowDefinitionEnd = (await VisualTreeHelper.FindElementPropertyAsync<List<RowDefinition>>("GridSplitterRoot", "RowDefinitions"))?.FirstOrDefault();

Wait.ForIdle();

Verify.AreEqual(rowDefinitionEnd.MaxHeight, rowDefinitionEnd.ActualHeight, "Row was not the maximum size expected.");
}

private class ColumnDefinition
{
public GridLength Width { get; set; }
Expand All @@ -105,6 +204,17 @@ private class ColumnDefinition
public double MaxWidth { get; set; }
}

private class RowDefinition
{
public GridLength Height { get; set; }

public double ActualHeight { get; set; }

public double MinHeight { get; set; }

public double MaxHeight { get; set; }
}

private class GridLength
{
public int GridUnitType { get; set; } // 0 Auto, 1 Pixel, 2 Star
Expand Down
11 changes: 4 additions & 7 deletions UITests/UITests.Tests.Shared/Controls/GridSplitterTestPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
BorderBrush="{ThemeResource SystemControlHighlightChromeHighBrush}"
BorderThickness="0,0,1,1">
<Grid.RowDefinitions>
<RowDefinition MinHeight="100"
<RowDefinition Height="200"
MinHeight="100"
MaxHeight="300" />
<RowDefinition Height="200" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"
Expand Down Expand Up @@ -72,11 +73,7 @@
<controls:GridSplitter x:Name="GridSplitterHorizontal"
Grid.Column="1"
Width="16"
HorizontalAlignment="Left"
CursorBehavior="ChangeOnSplitterHover"
GripperCursor="Default"
ResizeBehavior="BasedOnAlignment"
ResizeDirection="Auto">
HorizontalAlignment="Left">
<!--<controls:GridSplitter.RenderTransform>
<TranslateTransform X="-8" />
</controls:GridSplitter.RenderTransform>-->
Expand Down

0 comments on commit 99b8ae5

Please sign in to comment.