summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2272.cs
blob: d084de9cb68372e759316edc830337af1adcc9b4 (plain)
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
´╗┐using System;

using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

#if UITEST
using NUnit.Framework;
using Xamarin.UITest.Android;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 2272, "Entry text updating set focus on the beginning of text not the end of it", PlatformAffected.Android)]
	public class Issue2272 : TestContentPage
	{
		protected override void Init ()
		{
			var userNameEditor = new Entry () { Text = "userNameEditorEmptyString" };
			userNameEditor.Focused += (sender, args) => {
				userNameEditor.Text = "focused";
			};

			Content = new StackLayout {
				Spacing = 10,
				VerticalOptions = LayoutOptions.Start,
				Children = { userNameEditor }
			};
		}

#if UITEST
		[Test]
		public void TestFocusIsOnTheEndAfterSettingText ()
		{
			RunningApp.Tap (c => c.Marked ("userNameEditorEmptyString"));
			RunningApp.EnterText ("1");
			PressEnter ();
			Assert.Greater (RunningApp.Query (c => c.Marked ("focused1")).Length, 0);
		}

		void PressEnter ()
		{
			var androidApp = RunningApp as AndroidApp;
			if (androidApp != null) {
				androidApp.PressUserAction (UserAction.Done);
			}
			else {
				RunningApp.PressEnter ();
			}
		}
#endif
	}
}