-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Issue2339.cs
102 lines (92 loc) · 2.47 KB
/
Issue2339.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
using System.Diagnostics;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.Github5000)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 2339, "Picker not shown when .Focus() is called")]
public class Issue2339 : TestContentPage
{
protected override void Init()
{
var picker = new Picker { Items = { "One", "Two", "Three" } };
var pickerBtn = new Button
{
Text = "Click me to call .Focus on Picker",
AutomationId = "btnFocus"
};
pickerBtn.Clicked += (sender, args) =>
{
picker.Focus();
};
var pickerBtn2 = new Button
{
Text = "Click me to call .Unfocus on Picker",
AutomationId = "btnUnFocus"
};
pickerBtn2.Clicked += (sender, args) =>
{
picker.Unfocus();
};
var pickerBtn3 = new Button
{
Text = "Click me to .Focus () picker, wait 2 seconds, and .Unfocus () picker",
Command = new Command(async () =>
{
picker.Focus();
await Task.Delay(2000);
picker.Unfocus();
}),
AutomationId = "btnFocusThenUnFocus"
};
var focusFiredCount = 0;
var unfocusFiredCount = 0;
var focusFiredLabel = new Label { Text = "Picker Focused: " + focusFiredCount };
var unfocusedFiredLabel = new Label { Text = "Picker UnFocused: " + unfocusFiredCount };
picker.Focused += (s, e) =>
{
focusFiredCount++;
focusFiredLabel.Text = "Picker Focused: " + focusFiredCount;
};
picker.Unfocused += (s, e) =>
{
unfocusFiredCount++;
unfocusedFiredLabel.Text = "Picker UnFocused: " + unfocusFiredCount;
};
Content = new StackLayout
{
Children = {
focusFiredLabel,
unfocusedFiredLabel,
pickerBtn,
pickerBtn2,
pickerBtn3,
picker
}
};
}
#if UITEST
[Test]
#if __WINDOWS__
[Ignore("Focus Behavior is different on UWP")]
#endif
public void FocusAndUnFocusMultipleTimes()
{
RunningApp.WaitForElement("btnFocusThenUnFocus");
RunningApp.Tap(c => c.Marked("btnFocusThenUnFocus"));
RunningApp.WaitForElement(cw => cw.Marked("Picker Focused: 1"));
RunningApp.WaitForElement(cw => cw.Marked("Picker UnFocused: 1"));
RunningApp.Tap(c => c.Marked("btnFocusThenUnFocus"));
RunningApp.WaitForElement(cw => cw.Marked("Picker Focused: 2"));
RunningApp.WaitForElement(cw => cw.Marked("Picker UnFocused: 2"));
}
#endif
}
}