-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue1683.cs
205 lines (158 loc) · 5.55 KB
/
Issue1683.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using System.Collections.Generic;
using System.Linq;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using System.Diagnostics;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1683, "Auto Capitalization Implementation")]
public class Issue1683 : TestContentPage
{
const string kContainerId = "Container";
protected override void Init()
{
var layout = new StackLayout() { ClassId = kContainerId };
KeyboardFlags[] flags = new[]
{
KeyboardFlags.None,
KeyboardFlags.CapitalizeWord,
KeyboardFlags.CapitalizeSentence,
KeyboardFlags.CapitalizeCharacter,
KeyboardFlags.CapitalizeNone,
KeyboardFlags.All
};
List<Entry> entryViews = new List<Entry>();
List<Editor> editorViews = new List<Editor>();
List<InputView> inputViews = new List<InputView>();
KeyboardFlags spellCheckForUwp = KeyboardFlags.None;
if (Device.RuntimePlatform == Device.UWP)
{
spellCheckForUwp = KeyboardFlags.Spellcheck;
}
foreach (var flag in flags)
{
entryViews.Add(new EntryKeyboardFlags() { FlagsToTestFor = flag, Keyboard = Keyboard.Create(flag | spellCheckForUwp), ClassId = $"Entry{flag}" });
editorViews.Add(new EditorKeyboardFlags() { Keyboard = Keyboard.Create(flag | spellCheckForUwp), ClassId = $"Editor{flag}" });
}
entryViews.Add(new EntryKeyboardFlags() { ClassId = "EntryNoKeyboard" });
editorViews.Add(new EditorKeyboardFlags() { ClassId = "EditorNoKeyboard" });
inputViews.AddRange(entryViews);
inputViews.AddRange(editorViews);
inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRenderer" });
inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeSentence", FlagsToSet = KeyboardFlags.CapitalizeSentence, FlagsToTestFor = KeyboardFlags.CapitalizeSentence });
inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeWord", FlagsToSet = KeyboardFlags.CapitalizeWord, FlagsToTestFor = KeyboardFlags.CapitalizeWord });
if (Device.RuntimePlatform != Device.UWP)
{
inputViews.Add(new EntryKeyboardFlags() { ClassId = "CustomRendererCapitalizeCharacter", FlagsToSet = KeyboardFlags.CapitalizeCharacter });
}
if (Device.RuntimePlatform == Device.UWP)
{
layout.Children.Add(new Label() { Text = "Capitalization settings only work when using touch keyboard" });
layout.Children.Add(new Label() { Text = "Character doesn't do anything on UWP" });
}
else if (Device.RuntimePlatform == Device.iOS)
{
layout.Children.Add(new Label() { Text = "All will use Sentence" });
layout.Children.Add(new Label() { Text = "No Keyboard will use Sentence" });
}
else if (Device.RuntimePlatform == Device.Android)
{
layout.Children.Add(new Label() { Text = "All will use Sentence" });
layout.Children.Add(new Label() { Text = "No Keyboard will use None" });
}
foreach (InputView child in inputViews)
{
var inputs = new StackLayout()
{
Orientation = StackOrientation.Horizontal
};
if (child is Entry)
(child as Entry).Text = "All the Same.";
if (child is Editor)
(child as Editor).Text = "All the Same.";
child.HorizontalOptions = LayoutOptions.FillAndExpand;
var theLabel = new Label();
theLabel.SetBinding(Label.TextProperty, new Binding("ClassId", source: child));
inputs.Children.Add(theLabel);
inputs.Children.Add(child);
layout.Children.Add(inputs);
}
Button rotate = new Button()
{
Text = "Change Capitalization Settings. Ensure they update correctly",
AutomationId = "Rotation"
};
// This shifts everyones capitalization by one in order
// to test that updating the field works as expected
rotate.Clicked += (_, __) =>
{
var item1 = entryViews[0];
entryViews.Remove(item1);
entryViews.Add(item1);
var item2 = editorViews[0];
editorViews.Remove(item2);
editorViews.Add(item2);
for (int i = 0; i <= flags.Length; i++)
{
var editorView = editorViews[i] as EditorKeyboardFlags;
var entryView = entryViews[i] as EntryKeyboardFlags;
if (i == flags.Length)
{
entryView.FlagsToTestFor = null;
entryView.Keyboard = null;
entryView.ClassId = "EntryNoKeyboard";
editorView.FlagsToTestFor = null;
editorView.ClassId = "EntryNoKeyboard";
editorView.Keyboard = null;
}
else
{
entryView.FlagsToTestFor = flags[i];
entryView.Keyboard = Keyboard.Create(flags[i] | spellCheckForUwp);
entryView.ClassId = $"Entry{flags[i]}";
editorView.FlagsToTestFor = flags[i];
editorView.Keyboard = Keyboard.Create(flags[i] | spellCheckForUwp);
editorView.ClassId = $"Editor{flags[i]}";
}
}
};
StackLayout content = new StackLayout();
content.Children.Add(new ScrollView()
{
Content = layout
});
content.Children.Add(rotate);
Content = content;
}
public class EditorKeyboardFlags : Editor
{
public KeyboardFlags? FlagsToSet { get; set; }
public KeyboardFlags? FlagsToTestFor { get; set; }
}
public class EntryKeyboardFlags : Entry
{
public KeyboardFlags? FlagsToSet { get; set; }
public KeyboardFlags? FlagsToTestFor { get; set; }
}
#if UITEST
[Test]
public void Issue1683Test()
{
RunningApp.WaitForElement(q => q.Marked("Rotation"));
for (int i = 0; i < 6; i++)
{
RunningApp.Tap(q => q.Marked("Rotation"));
}
}
#endif
}
}