Skip to content

Commit

Permalink
Merge pull request #4392 from unoplatform/mergify/bp/release/beta/3.1…
Browse files Browse the repository at this point in the history
…/pr-4200

[iOS] CommandBar: fixed height regression (bp #4200)
  • Loading branch information
jeromelaban authored Oct 27, 2020
2 parents cef0e22 + b545916 commit 274c895
Show file tree
Hide file tree
Showing 31 changed files with 788 additions and 464 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public partial class UnoSamples_Tests : SampleControlUITestBase
[ActivePlatforms(Platform.Android, Platform.iOS)]
public void CommandBar_LongTitle_Validation()
{
Run("Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_LongTitle");

var isLandscape = GetIsCurrentRotationLandscape("ThePage");

try
{
Run("Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_LongTitle");

_app.WaitForElement(_app.Marked("TextBlockWidthTest"));

Expand All @@ -41,7 +44,15 @@ public void CommandBar_LongTitle_Validation()
}
finally
{
_app.SetOrientationLandscape();
// Reset orientation to original value
if (isLandscape)
{
_app.SetOrientationLandscape();
}
else
{
_app.SetOrientationPortrait();
}
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions src/SamplesApp/SamplesApp.UITests/SampleControlUITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,40 @@ internal IAppRect GetScreenDimensions()
}
}

private class PhysicalRect : IAppRect
{
public PhysicalRect(IAppRect logicalRect, double scaling)
{
var s = (float)scaling;
Bottom = logicalRect.Bottom * s;
Right = logicalRect.Right * s;
CenterY = logicalRect.CenterY * s;
CenterX = logicalRect.CenterX * s;
Y = logicalRect.Y * s;
X = logicalRect.X * s;
Height = logicalRect.Height * s;
Width = logicalRect.Width * s;
}

public float Width { get; }
public float Height { get; }
public float X { get; }
public float Y { get; }
public float CenterX { get; }
public float CenterY { get; }
public float Right { get; }
public float Bottom { get; }
}

public IAppRect ToPhysicalRect(IAppRect logicalRect)
{
if (logicalRect is PhysicalRect p)
{
return p;
}
return new PhysicalRect(logicalRect, GetDisplayScreenScaling());
}

internal double GetDisplayScreenScaling()
{
if (_scaling == null)
Expand Down Expand Up @@ -318,5 +352,24 @@ internal PointF GetRectCenterScaled(string elementName)
var rect = _app.GetRect(elementName);
return GetScaledCenter(rect);
}

protected bool GetIsCurrentRotationLandscape(string elementName)
{
if (!GetSupportsRotation())
{
return true;
}

var sampleRect = _app.GetRect(elementName);
var b = sampleRect.Width > sampleRect.Height;
return b;
}

protected static bool GetSupportsRotation()
{
var currentPlatform = AppInitializer.GetLocalPlatform();
var supportsRotation = currentPlatform == Platform.Android || currentPlatform == Platform.iOS;
return supportsRotation;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;
using Uno.UITests.Helpers;

namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.CommandBarTests
{
Expand All @@ -28,6 +30,100 @@ public void NativeCommandBar_Automated()
_app.WaitForText(result, "Clicked!");
}

[Test]
[AutoRetry]
public async Task NativeCommandBar_Size()
{
Run("Uno.UI.Samples.Content.UITests.CommandBar.CommandBar_Dynamic");

const string rootElementName = "RootPanel";
_app.WaitForElement(rootElementName);

var supportsRotation = GetSupportsRotation();

var isLandscape = GetIsCurrentRotationLandscape(rootElementName);
var currentModeIsLandscape = isLandscape;


async Task ToggleOrientation()
{
if (currentModeIsLandscape)
{
_app.SetOrientationPortrait();
}
else
{
_app.SetOrientationLandscape();
}

currentModeIsLandscape = !currentModeIsLandscape;

_app.WaitFor(()=> GetIsCurrentRotationLandscape(rootElementName) == currentModeIsLandscape);

await Task.Delay(125); // A delay ia required after rotation for the test to succeed
}

try
{
var firstScreenShot = TakeScreenshot("FirstOrientation");

var firstCommandBarRect = _app.GetRect("TheCommandBar");
var firstYellowBorderRect = _app.GetRect("TheBorder");
firstCommandBarRect.Bottom.Should().Be(firstYellowBorderRect.Y);

var firstCommandBarPhysicalRect = ToPhysicalRect(firstCommandBarRect);


var x1 = firstCommandBarPhysicalRect.X + (firstCommandBarPhysicalRect.Width * 0.75f);
ImageAssert.HasColorAt(firstScreenShot, x1, firstCommandBarPhysicalRect.Bottom - 1, Color.Red);

if(!supportsRotation)
{
return; // We're on a platform not supporting rotations.
}

await ToggleOrientation();

var secondScreenShot = TakeScreenshot("SecondOrientation");

var secondCommandBarRect = _app.GetRect("TheCommandBar");
var secondYellowBorderRect = _app.GetRect("TheBorder");
secondCommandBarRect.Bottom.Should().Be(secondYellowBorderRect.Y);

var secondCommandBarPhysicalRect = ToPhysicalRect(secondCommandBarRect);

var x2 = secondCommandBarPhysicalRect.X + (secondCommandBarPhysicalRect.Width * 0.75f);
ImageAssert.HasColorAt(secondScreenShot, x2, secondCommandBarPhysicalRect.Bottom - 1, Color.Red);

await ToggleOrientation();

var thirdScreenShot = TakeScreenshot("thirdOrientation");

var thirdCommandBarRect = _app.GetRect("TheCommandBar");
var thirdYellowBorderRect = _app.GetRect("TheBorder");
thirdCommandBarRect.Bottom.Should().Be(thirdYellowBorderRect.Y);

var thirdCommandBarPhysicalRect = ToPhysicalRect(thirdCommandBarRect);

var x3 = thirdCommandBarPhysicalRect.X + (thirdCommandBarPhysicalRect.Width * 0.75f);
ImageAssert.HasColorAt(thirdScreenShot, x3, thirdCommandBarPhysicalRect.Bottom - 1, Color.Red);
}
finally
{
// Reset orientation to original value
if (isLandscape)
{
_app.SetOrientationLandscape();
}
else
{
_app.SetOrientationPortrait();
}

_app.WaitFor(() => GetIsCurrentRotationLandscape(rootElementName) == isLandscape);
}
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android)]
Expand Down
1 change: 1 addition & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,7 @@
<DependentUpon>ControlStateViewer.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)ValueConverters\BoolNegationValueConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ValueConverters\FromNullableBoolToCustomValueConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ValueConverters\StringConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_ApplicationModel\Calls\PhoneCallManagerTests.xaml.cs">
<DependentUpon>PhoneCallManagerTests.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using Windows.UI.Xaml.Data;

namespace UITests.Shared.ValueConverters
namespace UITests.ValueConverters
{
public class BoolNegationValueConverter : IValueConverter
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Globalization;
using Windows.UI.Xaml.Data;

namespace UITests.ValueConverters
{
public class FromNullableBoolToCustomValueConverter : IValueConverter
{
public object NullOrFalseValue { get; set; }
public object TrueValue { get; set; }

public object Convert(object value, Type targetType, object parameter, string language)
{
if (value == null || !System.Convert.ToBoolean(value, CultureInfo.InvariantCulture))
{
return NullOrFalseValue;
}
else
{
return TrueValue;
}
}

public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotSupportedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<UserControl x:Class="UITests.Shared.Windows_Devices.HingeAngleSensorTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<UserControl
x:Class="UITests.Shared.Windows_Devices.HingeAngleSensorTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
<valueconverters:BoolNegationValueConverter x:Key="BoolNegation" />
Expand Down
15 changes: 7 additions & 8 deletions src/SamplesApp/UITests.Shared/Windows_Devices/LampTests.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<Page
x:Class="UITests.Shared.Windows_Devices.LampTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
x:Class="UITests.Shared.Windows_Devices.LampTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<UserControl.Resources>
<valueconverters:BoolNegationValueConverter x:Key="BoolNegation" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<UserControl
x:Class="UITests.Shared.Windows_Devices.MagnetometerTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
x:Class="UITests.Shared.Windows_Devices.MagnetometerTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
<valueconverters:BoolNegationValueConverter x:Key="BoolNegation" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<UserControl
x:Class="UITests.Shared.Windows_Devices.PedometerTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_Devices"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.Shared.ValueConverters"
x:Class="UITests.Shared.Windows_Devices.PedometerTests"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:valueconverters="using:UITests.ValueConverters"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
d:DesignHeight="300"
d:DesignWidth="400">

<UserControl.Resources>
<valueconverters:BoolNegationValueConverter x:Key="BoolNegation" />
Expand Down
Loading

0 comments on commit 274c895

Please sign in to comment.