Skip to content

Commit 1f5c535

Browse files
flow direction test
1 parent 9895a9e commit 1f5c535

File tree

6 files changed

+247
-6
lines changed

6 files changed

+247
-6
lines changed

src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Android.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.Maui.Controls;
55
using Microsoft.Maui.Handlers;
66
using Xunit;
7+
using Microsoft.Maui.Dispatching;
78

89
namespace Microsoft.Maui.DeviceTests
910
{
@@ -141,5 +142,35 @@ public async Task RotationConsistent()
141142
var platformRotation = await InvokeOnMainThreadAsync(() => PlatformEditor.Rotation);
142143
Assert.Equal(expected, platformRotation);
143144
}
145+
146+
[Theory]
147+
[InlineData(true, FlowDirection.LeftToRight, Android.Views.TextAlignment.ViewStart)]
148+
[InlineData(true, FlowDirection.RightToLeft, Android.Views.TextAlignment.ViewStart)]
149+
[InlineData(false, FlowDirection.LeftToRight, Android.Views.TextAlignment.ViewStart)]
150+
[InlineData(false, FlowDirection.RightToLeft, Android.Views.TextAlignment.ViewStart)]
151+
[Description("The Editor's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
152+
public async Task EditorAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, Android.Views.TextAlignment expectedAlignment)
153+
{
154+
var editor = new Editor { Text = "Checking flow direction" };
155+
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };
156+
157+
if (isExplicit)
158+
{
159+
editor.FlowDirection = flowDirection;
160+
}
161+
else
162+
{
163+
contentPage.FlowDirection = flowDirection;
164+
}
165+
166+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
167+
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
168+
{
169+
var textField = GetPlatformControl(handler);
170+
return textField.TextAlignment;
171+
});
172+
173+
Assert.Equal(expectedAlignment, nativeAlignment);
174+
}
144175
}
145176
}

src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.Windows.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
#nullable enable
2+
using Xunit;
3+
using System;
4+
using System.ComponentModel;
25
using System.Threading.Tasks;
6+
using Microsoft.Maui.Controls;
7+
using Microsoft.Maui.Dispatching;
38
using Microsoft.Maui.Handlers;
49
using Microsoft.UI.Xaml.Controls;
10+
using WFlowDirection = Microsoft.UI.Xaml.FlowDirection;
11+
using WTextAlignment = Microsoft.UI.Xaml.TextAlignment;
512

613
namespace Microsoft.Maui.DeviceTests
714
{
@@ -32,5 +39,54 @@ static int GetPlatformCursorPosition(EditorHandler editorHandler) =>
3239

3340
static int GetPlatformSelectionLength(EditorHandler editorHandler) =>
3441
GetPlatformControl(editorHandler).SelectionLength;
42+
43+
private async Task<Tuple<WTextAlignment, WFlowDirection>> GetEditorAlignmentAndFlowDirection(bool isExplicit, FlowDirection flowDirection)
44+
{
45+
var editor = new Editor { Text = " تسجيل الدخول" };
46+
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };
47+
48+
if (isExplicit)
49+
{
50+
editor.FlowDirection = flowDirection;
51+
}
52+
else
53+
{
54+
contentPage.FlowDirection = flowDirection;
55+
}
56+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
57+
var (nativeAlignment, nativeFlowDirection) = await contentPage.Dispatcher.DispatchAsync(() =>
58+
{
59+
var textField = GetPlatformControl(handler);
60+
return (textField.TextAlignment, textField.FlowDirection);
61+
});
62+
return new Tuple<WTextAlignment, WFlowDirection>(nativeAlignment, nativeFlowDirection);
63+
}
64+
65+
[Fact]
66+
[Description("The Editor's text alignment and flow direction should match the expected values when FlowDirection is explicitly set to RightToLeft.")]
67+
public async Task EditorAlignmentMatchesFlowDirectionRtlExplicit()
68+
{
69+
var results = await GetEditorAlignmentAndFlowDirection(true, FlowDirection.RightToLeft);
70+
Assert.Equal(WTextAlignment.Left, results.Item1);
71+
Assert.Equal(WFlowDirection.RightToLeft, results.Item2);
72+
}
73+
74+
[Fact]
75+
[Description("The Editor's text alignment and flow direction should match the expected values when FlowDirection is explicitly set to LeftToRight.")]
76+
public async Task EditorAlignmentMatchesFlowDirectionLtrExplicit()
77+
{
78+
var results = await GetEditorAlignmentAndFlowDirection(true, FlowDirection.LeftToRight);
79+
Assert.Equal(WTextAlignment.Left, results.Item1);
80+
Assert.Equal(WFlowDirection.LeftToRight, results.Item2);
81+
}
82+
83+
[Fact]
84+
[Description("The Editor's text alignment and flow direction should match the expected values when FlowDirection is implicitly set to LeftToRight.")]
85+
public async Task EditorAlignmentMatchesFlowDirectionLtrImplicit()
86+
{
87+
var results = await GetEditorAlignmentAndFlowDirection(false, FlowDirection.LeftToRight);
88+
Assert.Equal(WTextAlignment.Left, results.Item1);
89+
Assert.Equal(WFlowDirection.LeftToRight, results.Item2);
90+
}
3591
}
3692
}

src/Controls/tests/DeviceTests/Elements/Editor/EditorTests.iOS.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System.Linq;
1+
using UIKit;
2+
using Xunit;
3+
using System.Linq;
24
using System.Threading.Tasks;
35
using Microsoft.Maui.Controls;
6+
using Microsoft.Maui.Dispatching;
47
using Microsoft.Maui.Handlers;
58
using Microsoft.Maui.Hosting;
69
using Microsoft.Maui.Platform;
7-
using Xunit;
810
using static Microsoft.Maui.DeviceTests.AssertHelpers;
11+
using System.ComponentModel;
912

1013
namespace Microsoft.Maui.DeviceTests
1114
{
@@ -48,7 +51,7 @@ Task<float> GetPlatformOpacity(EditorHandler editorHandler)
4851
return InvokeOnMainThreadAsync(() =>
4952
{
5053
var nativeView = GetPlatformControl(editorHandler);
51-
return (float)nativeView.Alpha;
54+
return (float)nativeView.Alpha;
5255
});
5356
}
5457

@@ -94,5 +97,34 @@ await CreateHandlerAndAddToWindow(contentPage, async () =>
9497
});
9598
}
9699
}
100+
101+
[Theory]
102+
[InlineData(true, FlowDirection.LeftToRight, UITextAlignment.Left)]
103+
[InlineData(true, FlowDirection.RightToLeft, UITextAlignment.Right)]
104+
[InlineData(false, FlowDirection.LeftToRight, UITextAlignment.Left)]
105+
[Description("The Editor's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
106+
public async Task EditorAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, UITextAlignment expectedAlignment)
107+
{
108+
var editor = new Editor { Text = "Checking flow direction" };
109+
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };
110+
111+
if (isExplicit)
112+
{
113+
editor.FlowDirection = flowDirection;
114+
}
115+
else
116+
{
117+
contentPage.FlowDirection = flowDirection;
118+
}
119+
120+
var handler = await CreateHandlerAsync<EditorHandler>(editor);
121+
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
122+
{
123+
var textField = GetPlatformControl(handler);
124+
return textField.TextAlignment;
125+
});
126+
127+
Assert.Equal(expectedAlignment, nativeAlignment);
128+
}
97129
}
98130
}

src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Android.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading.Tasks;
33
using AndroidX.AppCompat.Widget;
44
using Microsoft.Maui.Controls;
5+
using Microsoft.Maui.Dispatching;
56
using Microsoft.Maui.Handlers;
67
using Xunit;
78

@@ -155,5 +156,35 @@ public async Task RotationConsistent()
155156
var platformRotation = await InvokeOnMainThreadAsync(() => platformEntry.Rotation);
156157
Assert.Equal(expected, platformRotation);
157158
}
159+
160+
[Theory]
161+
[InlineData(true, FlowDirection.LeftToRight, Android.Views.TextAlignment.ViewStart)]
162+
[InlineData(true, FlowDirection.RightToLeft, Android.Views.TextAlignment.ViewStart)]
163+
[InlineData(false, FlowDirection.LeftToRight, Android.Views.TextAlignment.ViewStart)]
164+
[InlineData(false, FlowDirection.RightToLeft, Android.Views.TextAlignment.ViewStart)]
165+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
166+
public async Task EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, Android.Views.TextAlignment expectedAlignment)
167+
{
168+
var entry = new Entry { Text = "Checking flow direction", HorizontalTextAlignment = TextAlignment.Start };
169+
var contentPage = new ContentPage { Title = "Flow Direction", Content = entry };
170+
171+
if (isExplicit)
172+
{
173+
entry.FlowDirection = flowDirection;
174+
}
175+
else
176+
{
177+
contentPage.FlowDirection = flowDirection;
178+
}
179+
180+
var handler = await CreateHandlerAsync<EntryHandler>(entry);
181+
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
182+
{
183+
var textField = GetPlatformControl(handler);
184+
return textField.TextAlignment;
185+
});
186+
187+
Assert.Equal(expectedAlignment, nativeAlignment);
188+
}
158189
}
159190
}

src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.Windows.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#nullable enable
2+
using Xunit;
3+
using System.ComponentModel;
24
using System.Threading.Tasks;
5+
using Microsoft.Maui.Controls;
6+
using Microsoft.Maui.Dispatching;
37
using Microsoft.Maui.Handlers;
48
using Microsoft.UI.Xaml.Controls;
9+
using WTextAlignment = Microsoft.UI.Xaml.TextAlignment;
510

611
namespace Microsoft.Maui.DeviceTests
712
{
@@ -32,5 +37,60 @@ static int GetPlatformCursorPosition(EntryHandler entryHandler) =>
3237

3338
static int GetPlatformSelectionLength(EntryHandler entryHandler) =>
3439
GetPlatformControl(entryHandler).SelectionLength;
40+
41+
public async Task<WTextAlignment> EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection)
42+
{
43+
var entry = new Entry { Text = "Checking flow direction", HorizontalTextAlignment = TextAlignment.Start };
44+
var contentPage = new ContentPage { Title = "Flow Direction", Content = entry };
45+
46+
if (isExplicit)
47+
{
48+
entry.FlowDirection = flowDirection;
49+
}
50+
else
51+
{
52+
contentPage.FlowDirection = flowDirection;
53+
}
54+
55+
var handler = await CreateHandlerAsync<EntryHandler>(entry);
56+
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
57+
{
58+
var textField = GetPlatformControl(handler);
59+
return textField.TextAlignment;
60+
});
61+
return nativeAlignment;
62+
}
63+
64+
[Fact]
65+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is explicitly set to LeftToRight.")]
66+
public async Task EntryAlignmentMatchesFlowDirectionLtrExplicit()
67+
{
68+
var results = await EntryAlignmentMatchesFlowDirection(true, FlowDirection.LeftToRight);
69+
Assert.Equal(WTextAlignment.Left, results);
70+
}
71+
72+
[Fact]
73+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is explicitly set to RightToLeft.")]
74+
public async Task EntryAlignmentMatchesFlowDirectionRtlExplicit()
75+
{
76+
var results = await EntryAlignmentMatchesFlowDirection(true, FlowDirection.RightToLeft);
77+
Assert.Equal(WTextAlignment.Left, results);
78+
}
79+
80+
[Fact]
81+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is implicitly set to LeftToRight.")]
82+
public async Task EntryAlignmentMatchesFlowDirectionLtrImplicit()
83+
{
84+
var results = await EntryAlignmentMatchesFlowDirection(false, FlowDirection.LeftToRight);
85+
Assert.Equal(WTextAlignment.Left, results);
86+
}
87+
88+
[Fact]
89+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is implicitly set to RightToLeft.")]
90+
public async Task EntryAlignmentMatchesFlowDirectionRtlImplicit()
91+
{
92+
var results = await EntryAlignmentMatchesFlowDirection(false, FlowDirection.RightToLeft);
93+
Assert.Equal(WTextAlignment.Left, results);
94+
}
3595
}
3696
}

src/Controls/tests/DeviceTests/Elements/Entry/EntryTests.iOS.cs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
using System.Linq;
1+
using UIKit;
2+
using Xunit;
3+
using System.ComponentModel;
4+
using System.Linq;
25
using System.Threading.Tasks;
36
using Microsoft.Maui.Controls;
47
using Microsoft.Maui.Controls.Handlers.Compatibility;
58
using Microsoft.Maui.DeviceTests.TestCases;
9+
using Microsoft.Maui.Dispatching;
610
using Microsoft.Maui.Handlers;
711
using Microsoft.Maui.Hosting;
812
using Microsoft.Maui.Platform;
9-
using UIKit;
10-
using Xunit;
1113
using static Microsoft.Maui.DeviceTests.AssertHelpers;
1214

1315
namespace Microsoft.Maui.DeviceTests
@@ -323,5 +325,34 @@ await CreateHandlerAndAddToWindow(contentPage, async () =>
323325
});
324326
}
325327
}
328+
329+
[Theory]
330+
[InlineData(true, FlowDirection.LeftToRight, UITextAlignment.Left)]
331+
[InlineData(true, FlowDirection.RightToLeft, UITextAlignment.Right)]
332+
[InlineData(false, FlowDirection.LeftToRight, UITextAlignment.Left)]
333+
[Description("The Entry's text alignment should match the expected alignment when FlowDirection is applied explicitly or implicitly")]
334+
public async Task EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection, UITextAlignment expectedAlignment)
335+
{
336+
var entry = new Entry { Text = "Checking flow direction", HorizontalTextAlignment = TextAlignment.Start };
337+
var contentPage = new ContentPage { Title = "Flow Direction", Content = entry };
338+
339+
if (isExplicit)
340+
{
341+
entry.FlowDirection = flowDirection;
342+
}
343+
else
344+
{
345+
contentPage.FlowDirection = flowDirection;
346+
}
347+
348+
var handler = await CreateHandlerAsync<EntryHandler>(entry);
349+
var nativeAlignment = await contentPage.Dispatcher.DispatchAsync(() =>
350+
{
351+
var textField = GetPlatformControl(handler);
352+
return textField.TextAlignment;
353+
});
354+
355+
Assert.Equal(expectedAlignment, nativeAlignment);
356+
}
326357
}
327358
}

0 commit comments

Comments
 (0)