-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
FlowDirectionTests.cs
104 lines (91 loc) · 3.93 KB
/
FlowDirectionTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Threading.Tasks;
using NUnit.Framework;
using WTextAlignment = Windows.UI.Xaml.TextAlignment;
using WFlowDirection = Windows.UI.Xaml.FlowDirection;
using System;
namespace Xamarin.Forms.Platform.UAP.UnitTests
{
public class FlowDirectionTests : PlatformTestFixture
{
[TestCase(true, FlowDirection.LeftToRight, Category = "FlowDirection,Entry", ExpectedResult = WTextAlignment.Left)]
[TestCase(true, FlowDirection.RightToLeft, Category = "FlowDirection,Entry", ExpectedResult = WTextAlignment.Right)]
[TestCase(false, FlowDirection.LeftToRight, Category = "FlowDirection,Entry", ExpectedResult = WTextAlignment.Left)]
[TestCase(false, FlowDirection.RightToLeft, Category = "FlowDirection,Entry", ExpectedResult = WTextAlignment.Right)]
public async Task<WTextAlignment> EntryAlignmentMatchesFlowDirection(bool isExplicit, FlowDirection flowDirection)
{
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 nativeAlignment = await Device.InvokeOnMainThreadAsync(() => {
if (!isExplicit)
{
GetRenderer(contentPage);
}
var textField = GetNativeControl(entry);
return textField.TextAlignment;
});
return nativeAlignment;
}
async Task<Tuple<WTextAlignment, WFlowDirection>> GetEditorAlignmentAndFlowDirection(bool isExplicit, FlowDirection flowDirection)
{
var editor = new Editor { Text = " تسجيل الدخول" };
var contentPage = new ContentPage { Title = "Flow Direction", Content = editor };
if (isExplicit)
{
editor.FlowDirection = flowDirection;
}
else
{
contentPage.FlowDirection = flowDirection;
}
var (nativeAlignment, nativeFlowDirection) = await Device.InvokeOnMainThreadAsync(() => {
if (!isExplicit)
{
GetRenderer(contentPage);
}
var textField = GetNativeControl(editor);
return (textField.TextAlignment, textField.FlowDirection);
});
return new Tuple<WTextAlignment, WFlowDirection>(nativeAlignment, nativeFlowDirection);
}
// The Left TextAlignment seems counterintuitive, but for the Editor the FlowDirection
// is going to automatically handle the alignment anyway.
// The important thing is that the TextAlignment is *not* set to DetectFromContent,
// as that will override our FlowDirection settings if they don't agree
[Test, Category("Editor"), Category("FlowDirection")]
public async Task EditorAlignmentMatchesFlowDirectionRtlExplicit()
{
var results = await GetEditorAlignmentAndFlowDirection(true, FlowDirection.RightToLeft);
Assert.That(results.Item1, Is.EqualTo(WTextAlignment.Left));
Assert.That(results.Item2, Is.EqualTo(WFlowDirection.RightToLeft));
}
[Test, Category("Editor"), Category("FlowDirection")]
public async Task EditorAlignmentMatchesFlowDirectionLtrExplicit()
{
var results = await GetEditorAlignmentAndFlowDirection(true, FlowDirection.LeftToRight);
Assert.That(results.Item1, Is.EqualTo(WTextAlignment.Left));
Assert.That(results.Item2, Is.EqualTo(WFlowDirection.LeftToRight));
}
[Test, Category("Editor"), Category("FlowDirection")]
public async Task EditorAlignmentMatchesFlowDirectionRtlImplicit()
{
var results = await GetEditorAlignmentAndFlowDirection(false, FlowDirection.RightToLeft);
Assert.That(results.Item1, Is.EqualTo(WTextAlignment.Left));
Assert.That(results.Item2, Is.EqualTo(WFlowDirection.RightToLeft));
}
[Test, Category("Editor"), Category("FlowDirection")]
public async Task EditorAlignmentMatchesFlowDirectionLtrImplicit()
{
var results = await GetEditorAlignmentAndFlowDirection(false, FlowDirection.LeftToRight);
Assert.That(results.Item1, Is.EqualTo(WTextAlignment.Left));
Assert.That(results.Item2, Is.EqualTo(WFlowDirection.LeftToRight));
}
}
}