summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla36171.cs
blob: 6bcd16b7f2b32c22722518758f09fa7bb87ef0f2 (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
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
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 36171, "WinRT Entry UI not updating on TextChanged",
		PlatformAffected.WinPhone | PlatformAffected.WinRT)]
	public class Bugzilla36171 : TestContentPage // or TestMasterDetailPage, etc ...
	{
		protected override void Init ()
		{
			var entry = new Entry ();
			var editor = new Editor();
			var focuseEntryButton = new Button { Text = "Start Entry" };
			var focuseEditorButton = new Button { Text = "Start Editor" };

			focuseEntryButton.Clicked += (sender, args) => { entry.Focus (); };
			focuseEditorButton.Clicked += (sender, args) => { editor.Focus (); };

			var entryLabel = new Label { Text = "Type 123A into the Entry below; the entry should display '123'. If the 'A' is displayed, the test has failed. If the cursor resets to the beginning of the Entry after typing 'A', the test has failed." };
			var editorLabel = new Label { Text = "Type 123A into the Editor below; the entry should display '123'. If the 'A' is displayed, the test has failed. If the cursor resets to the beginning of the Editor after typing 'A', the test has failed." };

			entry.TextChanged += (sender, args) => {
				var e = sender as Entry;

				int val;

				if(string.IsNullOrEmpty (args.NewTextValue?.Trim ())) {
					return;
				}

				// check if this is numeric
				if(!int.TryParse (args.NewTextValue, out val)) {
					// put the old value back.
					e.Text = args.OldTextValue;
				}
			};

			editor.TextChanged += (sender, args) => {
				var e = sender as Editor;

				int val;

				if(string.IsNullOrEmpty (args.NewTextValue?.Trim ())) {
					return;
				}

				// check if this is numeric
				if(!int.TryParse (args.NewTextValue, out val)) {
					// put the old value back.
					e.Text = args.OldTextValue;
				}
			};

			// Initialize ui here instead of ctor
			Content = new StackLayout {
				Children = { focuseEntryButton, entryLabel, entry, focuseEditorButton, editorLabel, editor }
			};
		}

#if UITEST
		[Test]
		public void EntryTextDoesNotDisplayNonnumericInput ()
		{
			RunningApp.WaitForElement ("Start Entry");
			RunningApp.Tap ("Start Entry");

			RunningApp.EnterText ("123A");

			var entry = RunningApp.Query (q => q.Text("123"));
			Assert.That(entry.Length >= 1);

			var failedEntry = RunningApp.Query (q => q.Text("123A"));
			Assert.That(failedEntry.Length == 0);
				
			RunningApp.EnterText ("4");

			var entry2 = RunningApp.Query (q => q.Text("1234"));
			Assert.That(entry2.Length >= 1);

			RunningApp.ClearText();

			RunningApp.WaitForElement ("Start Editor");
			RunningApp.Tap ("Start Editor");

			RunningApp.EnterText ("123A");

			var editor = RunningApp.Query (q => q.Text("123"));
			Assert.That(editor.Length >= 1);

			var failedEditor = RunningApp.Query (q => q.Text("123A"));
			Assert.That(failedEditor.Length == 0);

			RunningApp.EnterText ("4");

			var editor2 = RunningApp.Query (q => q.Text("1234"));
			Assert.That(editor2.Length >= 1);
		}
#endif
	}
}