summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue852.cs
blob: b65668d3e3612051902296eca6801b2b746ff07e (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
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
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

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

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

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 852, "Async loading of Content causes UI element to be unclickable", PlatformAffected.Android | PlatformAffected.iOS)]
	public class Issue852 : ContentPage
	{
#if APP
		StackLayout _loggingInStackLayout;
		Button _loginButton;
		ScrollView _loginScrollView;

		public Issue852 ()
		{
			var welcomeLabel = new Label()
			{
				Text = "Logging into the System",
				HorizontalOptions = LayoutOptions.Center
			};

			var activitySpinner = new ActivityIndicator
			{
				Color = new Color(0, 0, 1),
				IsRunning = true
			};

			_loggingInStackLayout = new StackLayout
			{
				Orientation = StackOrientation.Vertical,
				VerticalOptions = LayoutOptions.Center,
				Spacing = 15
			};

			_loggingInStackLayout.Children.Add(welcomeLabel);
			_loggingInStackLayout.Children.Add(activitySpinner);

			Content = _loggingInStackLayout;
		}

		protected override async void OnAppearing()
		{
			base.OnAppearing();

			if (!(await AttemptLogin())) //try to log in, if login fails show login screen
			{
				Device.BeginInvokeOnMainThread (() => BuildLogin ());
			}
			else
			{
				Navigation.PopModalAsync();
			}
			IsBusy = false;

		}

		void BuildLogin()
		{
			Title = "Login";
			var welcomeLabel = new Label()
			{
				Text = "Welcome to the System",
				HorizontalOptions = LayoutOptions.Center
			};

			var usernameEntry = new Entry
			{
				IsPassword = false,
				Placeholder = "Username",
			};
			usernameEntry.SetBinding(Entry.TextProperty, new Binding("Username"));
			usernameEntry.Focused += (s, e) => welcomeLabel.Text = "Clicked User";

			var passwordEntry = new Entry
			{
				IsPassword = true,
				Placeholder = "Password",
			};
			passwordEntry.SetBinding(Entry.TextProperty, new Binding("Password", BindingMode.TwoWay));
			passwordEntry.Focused += (s, e) => welcomeLabel.Text = "Clicked Password";

			_loginButton = new Button
			{
				ClassId = "loginButton",
				Text = "Login",
			};
			_loginButton.SetBinding(Button.CommandProperty, new Binding("LoginCommand"));

			var loginStackLayout = new StackLayout
			{
				Orientation = StackOrientation.Vertical,
				VerticalOptions = LayoutOptions.Center,
				Spacing = 15
			};

			loginStackLayout.Children.Add(welcomeLabel);
			loginStackLayout.Children.Add(usernameEntry);
			loginStackLayout.Children.Add(passwordEntry);
			loginStackLayout.Children.Add(_loginButton);


			_loginScrollView = new ScrollView
			{
				Orientation = ScrollOrientation.Vertical,
				Content = loginStackLayout
			};
			Content = _loginScrollView;
		}

		async Task<bool> AttemptLogin()
		{
			await Task.Delay(2000);
			return false; //for this test we are always going ot fail, want to show login screen and error
		}
#endif
#if UITEST
		[Test]
		[UiTest (typeof(ContentPage))]
		public void Issue852TestsEntriesClickable ()
		{
			// TODO: Fix ME

			//App.WaitForElement (q => q.Marked ("Welcome to the System"));
			//App.WaitForElement (PlatformQueries.EntryWithPlaceholder ("Username"));
			//App.WaitForElement (PlatformQueries.EntryWithPlaceholder ("Password"));
			//App.WaitForElement (q => q.Button ("Login"));
			//App.Screenshot ("All elements present");

			//App.Tap (PlatformQueries.EntryWithPlaceholder ("Username"));
			//App.WaitForElement (q => q.Marked ("Clicked User"));
			//App.EnterText (PlatformQueries.EntryWithPlaceholder ("Username"), "Usertest");
			//App.Screenshot ("User entered");

			//App.Tap (PlatformQueries.EntryWithPlaceholder ("Password"));
			//App.WaitForElement (q => q.Marked ("Clicked Password"));
			//App.EnterText (PlatformQueries.EntryWithPlaceholder ("Password"), "Userpass");
			//App.Screenshot ("Password entered");

			//App.Screenshot ("Enties clickable");
			Assert.Inconclusive ("Fix Test");
		}
#endif
	}
}