Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#nullable enable
using Xunit;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.UI.Xaml.Controls;
using WFlowDirection = Microsoft.UI.Xaml.FlowDirection;
using WTextAlignment = Microsoft.UI.Xaml.TextAlignment;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -41,5 +48,35 @@ Task<bool> GetPlatformIsVisible(EditorHandler editorHandler)
return nativeView.Visibility == Microsoft.UI.Xaml.Visibility.Visible;
});
}
//src/Compatibility/Core/tests/WinUI/FlowDirectionTests.cs
[Theory]
[InlineData(true, FlowDirection.RightToLeft, WTextAlignment.Left, WFlowDirection.RightToLeft)]
[InlineData(true, FlowDirection.LeftToRight, WTextAlignment.Left, WFlowDirection.LeftToRight)]
[InlineData(false, FlowDirection.LeftToRight, WTextAlignment.Left, WFlowDirection.LeftToRight)]
[Description("The Editor's text alignment and flow direction should match the expected values when FlowDirection is applied explicitly or implicitly.")]
public async Task EditorAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, WTextAlignment expectedAlignment, WFlowDirection expectedFlowDirection)
{
var editor = new Editor { Text = " تسجيل الدخول" };
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };

if (isExplicit)
{
editor.FlowDirection = flowDirection;
}
else
{
contentPage.FlowDirection = flowDirection;
}

var handler = await CreateHandlerAsync<EditorHandler>(editor);
var (nativeAlignment, nativeFlowDirection) = await contentPage.Dispatcher.DispatchAsync(() =>
{
var textField = GetPlatformControl(handler);
return (textField.TextAlignment, textField.FlowDirection);
});

Assert.Equal(expectedAlignment, nativeAlignment);
Assert.Equal(expectedFlowDirection, nativeFlowDirection);
}
}
}
39 changes: 36 additions & 3 deletions src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using System.Linq;
using UIKit;
using Xunit;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
using Xunit;
using static Microsoft.Maui.DeviceTests.AssertHelpers;
using System.ComponentModel;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -48,7 +51,7 @@ Task<float> GetPlatformOpacity(EditorHandler editorHandler)
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(editorHandler);
return (float)nativeView.Alpha;
return (float)nativeView.Alpha;
});
}

Expand Down Expand Up @@ -103,5 +106,35 @@ await CreateHandlerAndAddToWindow(contentPage, async () =>
});
}
}

//src/Compatibility/Core/tests/iOS/FlowDirectionTests.cs
[Theory]
[InlineData(true, FlowDirection.LeftToRight, UITextAlignment.Left)]
[InlineData(true, FlowDirection.RightToLeft, UITextAlignment.Right)]
[InlineData(false, FlowDirection.LeftToRight, UITextAlignment.Left)]
[Description("The Editor's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
public async Task EditorAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, UITextAlignment expectedAlignment)
{
var editor = new Editor { Text = "Checking flow direction" };
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };

if (isExplicit)
{
editor.FlowDirection = flowDirection;
}
else
{
contentPage.FlowDirection = flowDirection;
}

var handler = await CreateHandlerAsync<EditorHandler>(editor);
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
{
var textField = GetPlatformControl(handler);
return textField.TextAlignment;
});

Assert.Equal(expectedAlignment, nativeAlignment);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#nullable enable
using Xunit;
using System.ComponentModel;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.UI.Xaml.Controls;
using WTextAlignment = Microsoft.UI.Xaml.TextAlignment;

namespace Microsoft.Maui.DeviceTests
{
Expand Down Expand Up @@ -41,5 +46,35 @@ Task<bool> GetPlatformIsVisible(EntryHandler entryHandler)
return nativeView.Visibility == Microsoft.UI.Xaml.Visibility.Visible;
});
}
//src/Compatibility/Core/tests/WinUI/FlowDirectionTests.cs
[Theory]
[InlineData(true, FlowDirection.LeftToRight, WTextAlignment.Left)]
[InlineData(true, FlowDirection.RightToLeft, WTextAlignment.Left)]
[InlineData(false, FlowDirection.LeftToRight, WTextAlignment.Left)]
[InlineData(false, FlowDirection.RightToLeft, WTextAlignment.Left)]
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly.")]
public async Task EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, WTextAlignment expectedAlignment)
{
var entry = new Entry { Text = "Checking flow direction", HorizontalTextAlignment = TextAlignment.Start };
var contentPage = new ContentPage { Title = "Flow Direction", Content = entry };

if (isExplicit)
{
entry.FlowDirection = flowDirection;
}
else
{
contentPage.FlowDirection = flowDirection;
}

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
{
var textField = GetPlatformControl(handler);
return textField.TextAlignment;
});

Assert.Equal(expectedAlignment, nativeAlignment);
}
}
}
42 changes: 37 additions & 5 deletions src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System.Linq;
using UIKit;
using Xunit;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.DeviceTests.TestCases;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
using UIKit;
using Xunit;
using static Microsoft.Maui.DeviceTests.AssertHelpers;

namespace Microsoft.Maui.DeviceTests
Expand Down Expand Up @@ -44,13 +46,13 @@ static int GetPlatformSelectionLength(EntryHandler entryHandler)

return -1;
}

Task<float> GetPlatformOpacity(EntryHandler entryHandler)
{
return InvokeOnMainThreadAsync(() =>
{
var nativeView = GetPlatformControl(entryHandler);
return (float)nativeView.Alpha;
return (float)nativeView.Alpha;
});
}

Expand Down Expand Up @@ -332,5 +334,35 @@ await CreateHandlerAndAddToWindow(contentPage, async () =>
});
}
}

//src/Compatibility/Core/tests/iOS/FlowDirectionTests.cs
[Theory]
[InlineData(true, FlowDirection.LeftToRight, UITextAlignment.Left)]
[InlineData(true, FlowDirection.RightToLeft, UITextAlignment.Right)]
[InlineData(false, FlowDirection.LeftToRight, UITextAlignment.Left)]
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
public async Task EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, UITextAlignment expectedAlignment)
{
var entry = new Entry { Text = "Checking flow direction", HorizontalTextAlignment = TextAlignment.Start };
var contentPage = new ContentPage { Title = "Flow Direction", Content = entry };

if (isExplicit)
{
entry.FlowDirection = flowDirection;
}
else
{
contentPage.FlowDirection = flowDirection;
}

var handler = await CreateHandlerAsync<EntryHandler>(entry);
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
{
var textField = GetPlatformControl(handler);
return textField.TextAlignment;
});

Assert.Equal(expectedAlignment, nativeAlignment);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Handlers.Compatibility;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Platform;
Expand Down Expand Up @@ -65,5 +67,29 @@ public async Task TranslucentNavigationBar(bool enabled)
var translucent = await GetValueAsync(navPage, (handler) => (handler.ViewController as UINavigationController).NavigationBar.Translucent);
Assert.Equal(enabled, translucent);
}

//src/Compatibility/Core/tests/iOS/NavigationTests.cs
[Fact]
[Description("Multiple calls to NavigationRenderer.Dispose shouldn't crash")]
public async Task NavigationRendererDoubleDisposal()
{
SetupBuilder();

var root = new ContentPage()
{
Title = "root",
Content = new Label { Text = "Hello" }
};

await root.Dispatcher.DispatchAsync(() =>
{
var navPage = new NavigationPage(root);
var handler = CreateHandler(navPage);

// Calling Dispose more than once should be fine
(handler as NavigationRenderer).Dispose();
(handler as NavigationRenderer).Dispose();
});
}
}
}
37 changes: 37 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Page/PageTests.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using Xunit;
using AView = Android.Views.View;
using AndroidX.Fragment.App;

namespace Microsoft.Maui.DeviceTests
{
public partial class PageTests : ControlsHandlerTestBase
{
//src/Compatibility/Core/tests/Android/EmbeddingTests.cs
[Fact(DisplayName = "Can Create Platform View From ContentPage")]
public async Task CanCreatePlatformViewFromContentPage()
{

var contentPage = new ContentPage { Title = "Embedded Page" };
var handler = CreateHandler<PageHandler>(contentPage);
var mauiContext = handler.MauiContext;

await contentPage.Dispatcher.DispatchAsync(() =>
{

AView platformView = contentPage.ToPlatform(mauiContext);
if (platformView is FragmentContainerView containerView)
{
var activity = mauiContext.Context as AndroidX.Fragment.App.FragmentActivity;
var fragmentManager = activity.SupportFragmentManager;
var fragment = fragmentManager.FindFragmentById(containerView.Id);
Assert.NotNull(fragment);
}
});
}
}
}
21 changes: 21 additions & 0 deletions src/Controls/tests/DeviceTests/Elements/Page/PageTests.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using Microsoft.Maui.Dispatching;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Hosting;
using UIKit;
using Xunit;

namespace Microsoft.Maui.DeviceTests
Expand Down Expand Up @@ -40,5 +43,23 @@ await CreateHandlerAndAddToWindow<IWindowHandler>(shell, (handler) =>
}
});
}

//src/Compatibility/Core/tests/iOS/EmbeddingTests.cs
[Fact(DisplayName = "Can Create Platform View From ContentPage")]
public async Task CanCreateViewControllerFromContentPage()
{
var contentPage = new ContentPage { Title = "Embedded Page" };
await contentPage.Dispatcher.DispatchAsync(async () =>
{
var handler = CreateHandler<PageHandler>(contentPage);
var mauiContext = handler.MauiContext;

await contentPage.Dispatcher.DispatchAsync(() =>
{
UIViewController viewController = contentPage.ToUIViewController(mauiContext);
Assert.NotNull(viewController);
});
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using CoreGraphics;
using Microsoft.Maui.Controls;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Handlers;
Expand Down Expand Up @@ -40,6 +41,22 @@ public async Task StrokeColorInitializesCorrectly()
Assert.Equal(expectedValue, values.PlatformViewValue);
}

//src/Compatibility/Core/tests/iOS/ImageButtonTests.cs
[Fact]
[Trait("Category", "ImageButton")]
public async Task CreatedWithCorrectButtonType()
{
var imageButton = new ImageButton();
var handler = await CreateHandlerAsync(imageButton);

var buttonType = await InvokeOnMainThreadAsync(() =>
{
var uiButton = GetPlatformImageButton(handler);
return uiButton.ButtonType;
});

Assert.NotEqual(UIButtonType.Custom, buttonType);
}
UIButton GetPlatformImageButton(ImageButtonHandler imageButtonHandler) =>
imageButtonHandler.PlatformView;

Expand Down