summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue892.cs
blob: 33402eeb35b581b6285e7a824b8b0374065167a2 (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
using System.Diagnostics;

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

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

namespace Xamarin.Forms.Controls.Issues
{

	public class NavPageNameObject
	{
		public string PageName { get; private set; }

		public NavPageNameObject (string pageName)
		{
			PageName = pageName;
		}
	}

	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 892, "NavigationPages as details in MasterDetailPage don't work as expected", PlatformAffected.Android)]
	public class Issue892 : TestMasterDetailPage
	{
		protected override void Init ()
		{
			var cells = new [] {
				new NavPageNameObject ("Close Master"),
				new NavPageNameObject ("Page 1"),
				new NavPageNameObject ("Page 3"),
				new NavPageNameObject ("Page 4"),
				new NavPageNameObject ("Page 5"),
				new NavPageNameObject ("Page 6"),
				new NavPageNameObject ("Page 7"),
				new NavPageNameObject ("Page 8"),
			};

			var template = new DataTemplate (typeof (TextCell));
			template.SetBinding (TextCell.TextProperty, "PageName");

			var listView = new ListView { 
				ItemTemplate = template,
				ItemsSource = cells
			};

			listView.BindingContext = cells;

			listView.ItemTapped += (sender, e) => {
				var cellName = ((NavPageNameObject)e.Item).PageName;
				if (cellName == "Close Master") {
					IsPresented = false;
				} else {
					Detail = new CustomNavDetailPage (cellName);
				}
			};

			var master = new ContentPage {
				Padding = new Thickness(0, 20, 0, 0),
				Title = "Master",
				Content = listView
			};
				
			Master = master;
			Detail = new CustomNavDetailPage ("Initial Page");

			MessagingCenter.Subscribe<NestedNavPageRootView> (this, "PresentMaster", (sender) => {
				IsPresented = true;
			});
		}

		// Issue892
		// NavigationPage nested in MasterDetail not working as expected Android

#if UITEST
		[Test]
		[Description ("Change pages in the Master ListView, and navigate to the end and back")]
		[UiTest (typeof(MasterDetailPage))]
		[UiTest (typeof(NavigationPage))]
		public void Issue892TestsNavigateChangePagesNavigate ()
		{
			NavigateToEndAndBack ();

			RunningApp.Tap (q => q.Marked ("Present Master"));
			
			RunningApp.Tap (q => q.Marked ("Page 5"));

			RunningApp.Tap (q => q.Marked ("Close Master"));

			RunningApp.Screenshot ("Select new detail navigation");

			NavigateToEndAndBack ();
		}

		void NavigateToEndAndBack ()
		{
			RunningApp.WaitForElement (q => q.Button ("Push next page")); // still required on iOS
			RunningApp.Tap (q => q.Marked ("Push next page"));
			RunningApp.Screenshot ("Pushed first page");

			RunningApp.WaitForElement (q => q.Button ("Push next next page")); // still required on iOS
			RunningApp.Tap (q => q.Marked ("Push next next page"));
			RunningApp.Screenshot ("Pushed second page");

			RunningApp.WaitForElement (q => q.Marked ("You are at the end of the line"));
			RunningApp.Screenshot ("Pushed last page");

			RunningApp.Tap (q => q.Marked ("Check back one"));
			RunningApp.WaitForElement (q => q.Marked ("Pop one"));
			RunningApp.Back ();
			RunningApp.Screenshot ("Navigate Back");

			RunningApp.Tap (q => q.Marked ("Check back two"));
			RunningApp.WaitForElement (q => q.Marked ("Pop two"));
			RunningApp.Back ();
			RunningApp.Screenshot ("Navigate Back");

			RunningApp.Tap (q => q.Marked ("Check back three"));
			RunningApp.WaitForElement (q => q.Marked ("At root"));
			RunningApp.Screenshot ("At root");
		}
#endif

	}

	public class CustomNavDetailPage : NavigationPage
	{
		public CustomNavDetailPage (string pageName)
		{
			PushAsync (new NestedNavPageRootView (pageName));
		}
	}

	public class NestedNavPageRootView : ContentPage
	{
		public NestedNavPageRootView (string pageTitle)
		{
			Title = pageTitle;
			BackgroundColor = Color.FromHex("#666");

			var label = new Label {
				Text = "Not Tapped"
			};

			Content = new StackLayout {
				Children = {
					label,
					new Button {
						Text = "Check back three",
						Command = new Command (() => { label.Text = "At root"; })
					},
					new Button {
						Text = "Push next page",
						Command = new Command (() => Navigation.PushAsync (new NestedNavPageOneLevel ()))
					},
					new Button {
						Text = "Present Master",
						Command = new Command (() => {
							MessagingCenter.Send<NestedNavPageRootView> (this, "PresentMaster");
						})
					}
				}
			};
		}
	}

	public class NestedNavPageOneLevel : ContentPage
	{
		public NestedNavPageOneLevel ()
		{
			Title = "One pushed";
			BackgroundColor = Color.FromHex("#999");

			var label = new Label {
				Text = "Not Tapped"
			};

			Content = new StackLayout {
				Children = {
					label,
					new Button {
						Text = "Check back two",
						Command = new Command (() => { label.Text = "Pop two"; })
					},
					new Button {
						Text = "Push next next page",
						Command = new Command (() => Navigation.PushAsync (new NestedNavPageTwoLevels ()))
					}
				}
			};
		}
	}

	public class NestedNavPageTwoLevels : ContentPage
	{
		public NestedNavPageTwoLevels ()
		{
			Title = "Two pushed";
			BackgroundColor = Color.FromHex("#BBB");

			var label = new Label {
				Text = "Not Tapped",
				TextColor = Color.Red
			};

			var label2 = new Label {
				Text = "You are at the end of the line",
				TextColor = Color.Red
			};

			Content = new StackLayout {
				Children = {
					label,
					label2,
					new Button {
						Text = "Check back one",
						Command = new Command (() => { label.Text = "Pop one"; })
					},
				}
			};
		}
	}
}