Skip to content

Commit

Permalink
Add automated test
Browse files Browse the repository at this point in the history
  • Loading branch information
hartez committed May 18, 2023
1 parent d1a23c1 commit a54abef
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Layout/LayoutTests.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreGraphics;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
using Microsoft.VisualBasic;
using UIKit;
using Xunit;

namespace Microsoft.Maui.DeviceTests
Expand Down Expand Up @@ -162,5 +166,63 @@ void ValidateInputTransparentOnPlatformView(IView view)
Assert.True(view.InputTransparent == !value,
$"InputTransparent: {view.InputTransparent}. UserInteractionEnabled: {platformView.UserInteractionEnabled}");
}

async Task WaitForLayout(UIView view, CGRect initialFrame, int timeout)
{
int interval = 100;

while (timeout > 0)
{
if (view.Frame != initialFrame)
{
return;
}

await Task.Delay(interval);
timeout -= interval;
}
}

[Fact]
public async Task NestedLayoutsInRTLRemainOnScreen()
{
EnsureHandlerCreated((builder) =>
{
builder.ConfigureMauiHandlers(handler =>
{
handler.AddHandler(typeof(Button), typeof(ButtonHandler));
handler.AddHandler(typeof(Layout), typeof(LayoutHandler));
handler.AddHandler(typeof(Controls.ContentView), typeof(ContentViewHandler));
});
});

var level0 = new Controls.ContentView() { FlowDirection = FlowDirection.RightToLeft};
var level1 = new Grid() { HorizontalOptions = LayoutOptions.End, WidthRequest = 200 };
var level2 = new Grid() { HorizontalOptions = LayoutOptions.Start, WidthRequest = 200 };
var button = new Button() { Text = "Hello", HorizontalOptions = LayoutOptions.Start, WidthRequest = 100 };

level0.Content = level1;
level1.Add(level2);
level2.Add(button);

await AttachAndRun(level0, async (handler) =>
{
var root = handler.ToPlatform();
await WaitForLayout(root, CGRect.Empty, 5000);
UIKit.UIView nativeView = button.Handler.PlatformView as UIKit.UIView;
Assert.NotNull(nativeView);
// Work our way up the tree and verify that no one
// has a negative X position (which would make the view not
// show up on screen)
while (nativeView != null)
{
Assert.True(nativeView.Bounds.X >= 0);
nativeView = nativeView.Superview;
}
});
}
}
}

0 comments on commit a54abef

Please sign in to comment.