summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1461.cs
blob: 69c181a4ccf97c10e6b1d9d637a8bcf6fb220cee (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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

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

namespace Xamarin.Forms.Controls
{

#if UITEST
	public static class Issue1461Helpers
	{
		public static bool ShouldRunTest (IApp app)
		{
			var appAs = app as iOSApp;
			return (appAs != null && appAs.Device.IsTablet);
		}
	}
#endif

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1461, "1461 - (Popover in Portrait and Landscape)", PlatformAffected.iOS)]
	public class Issue1461 : TestContentPage
	{
		protected override async void Init ()
		{
			await Navigation.PushModalAsync (new Issue1461Page (MasterBehavior.Popover, false));
		}

#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "IsPresented")]
		[UiTest (typeof (MasterDetailPage), "Master")]
		public void Test1 ()
		{
			if (Issue1461Helpers.ShouldRunTest (RunningApp)) {
				RunningApp.SetOrientationLandscape ();
				var query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (!query.Any (), "Master should not present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.SetOrientationPortrait ();
				query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (!query.Any (), "Master should not present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.Tap (q => q.Marked ("Go Back"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}
#endif
	}

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1461, "1461 - Default", PlatformAffected.iOS)]
	public class Issue1461A : TestContentPage
	{
		protected override async void Init ()
		{
			await Navigation.PushModalAsync (new Issue1461Page (MasterBehavior.Default, null));
		}

#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "IsPresented")]
		[UiTest (typeof (MasterDetailPage), "Master")]
		public void Test2 ()
		{
			if (Issue1461Helpers.ShouldRunTest(RunningApp)) {
				RunningApp.SetOrientationLandscape ();
				var query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (query.Any (), "Master should be present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.SetOrientationPortrait ();
				query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (!query.Any (), "Master should not present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.Tap (q => q.Marked ("Go Back"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}

		#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "Button")]
		public void TestButton ()
		{
			if (Issue1461Helpers.ShouldRunTest(RunningApp)) {
				RunningApp.SetOrientationLandscape ();
				RunningApp.WaitForNoElement (q => q.Marked ("bank"));
				RunningApp.SetOrientationPortrait ();
				RunningApp.WaitForElement (q => q.Marked ("bank"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}
		#endif
#endif
	}

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1461, "1461 - (Splitview in Landscape)", PlatformAffected.iOS)]
	public class Issue1461B : TestContentPage
	{
		protected override async void Init ()
		{
			await Navigation.PushModalAsync (new Issue1461Page (MasterBehavior.SplitOnLandscape, null));
		}

#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "IsPresented")]
		[UiTest (typeof (MasterDetailPage), "Master")]
		public void Test3 ()
		{
			if (Issue1461Helpers.ShouldRunTest(RunningApp)) {
				RunningApp.SetOrientationLandscape ();
				var query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (query.Any (), "Master should be present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.SetOrientationPortrait ();
				query = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (!query.Any (), "Master should not present");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.Tap (q => q.Marked ("Go Back"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}
#endif
	}

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1461, "1461 - (Splitview in Portrait)", PlatformAffected.iOS)]
	public class Issue1461C : TestContentPage
	{
		protected override async void Init ()
		{
			await Navigation.PushModalAsync (new Issue1461Page (MasterBehavior.SplitOnPortrait, null));
		}

#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "IsPresented")]
		[UiTest (typeof (MasterDetailPage), "Master")]
		public void Test4 ()
		{
			if (Issue1461Helpers.ShouldRunTest(RunningApp)) {
				RunningApp.SetOrientationPortrait ();
				var s = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (s.Any (), "Master should be present");
				RunningApp.Screenshot ("Master should  present");

				RunningApp.SetOrientationLandscape ();
				s = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (!s.Any (), "Master should not present on landscape");
				RunningApp.Screenshot ("Master should not present");
				RunningApp.Tap (q => q.Marked ("Go Back"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}
#endif
	}

	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1461, "1461 - (Splitview in Portrait and Landscape)", PlatformAffected.iOS)]
	public class Issue1461D : TestContentPage
	{
		protected override async void Init ()
		{
			await Navigation.PushModalAsync (new Issue1461Page (MasterBehavior.Split, null));
		}

#if UITEST
		[Test]
		[UiTest (typeof (MasterDetailPage), "IsPresented")]
		[UiTest (typeof (MasterDetailPage), "Master")]
		public void Test5 ()
		{
			if (Issue1461Helpers.ShouldRunTest(RunningApp)) {
				RunningApp.SetOrientationPortrait ();
				var s = RunningApp.Query (q => q.Marked ("Master_Label"));
				Assert.IsTrue (s.Any (), "Master should be present");
				RunningApp.Screenshot ("Master should be present");

				RunningApp.SetOrientationLandscape ();
				s = RunningApp.Query (q => q.Marked ("Master_Label"));

				Assert.IsTrue (s.Any (), "Master should  be present");
				RunningApp.Screenshot ("Master should be present");
				RunningApp.Tap (q => q.Marked ("Go Back"));
			} else {
				Assert.Inconclusive ("Only run on iOS Tablet");
			}
		}
#endif
	}

	internal sealed class Issue1461Page : MasterDetailPage
	{
		public Issue1461Page ()
			: this (MasterBehavior.Default,null)
		{ }

		bool? _showButton;
		public Issue1461Page (MasterBehavior state, bool? initState)
		{

			var btn = new Button { Text = "hide me" };
			btn.Clicked += bnToggle_Clicked;
			Master = new ContentPage {
				Title = string.Format ("Master sample for {0}", state),
				Icon = "bank.png",
				Padding = Device.OnPlatform (new Thickness (5, 60, 5, 5), 5, 5),
				Content = 
					new StackLayout { Children = {
						new Label {
							Text = "Master Label",
							AutomationId = "Master_Label",
							BackgroundColor = Color.Gray
						},
						btn
					}
				},
				//BackgroundColor = Color.Red
			};

			if(initState.HasValue)
				_showButton = initState.Value;

			var lbl = new Label {
				HorizontalOptions =   LayoutOptions.End, 
				BindingContext = this
			};
			lbl.SetBinding (Label.TextProperty, "IsPresented");

			var bnToggle = new Button {
				Text = "Toggle IsPresented",
			};

			var bnGoBack = new Button {
				Text = "Go Back",
			};

			bnGoBack.Clicked += bnGoBack_Clicked;
			bnToggle.Clicked += bnToggle_Clicked;

			Detail = new NavigationPage( new ContentPage {
				Title = "Detail Title",
				Content = new StackLayout{ Spacing=10, Children= { lbl, bnToggle, bnGoBack} }
			});

			MasterBehavior = state;
		}

		public override bool ShouldShowToolbarButton ()
		{
			if (_showButton.HasValue)
				return _showButton.Value;
			return base.ShouldShowToolbarButton ();
		}

		async void bnGoBack_Clicked (object sender, EventArgs e)
		{
			await Navigation.PopModalAsync ();
		}

		async void bnToggle_Clicked (object sender, EventArgs e)
		{
			try {
				IsPresented = !IsPresented;
			} catch (InvalidOperationException ex) {
				await DisplayAlert ("Error", ex.Message, "ok");
			}
		
		}
	}
}