summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue417.cs
blob: 32391f400af1241138acabca628f0f70d87b1df6 (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
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.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 417, "Navigation.PopToRootAsync does nothing", PlatformAffected.Android)]
	public class Issue417 : TestNavigationPage
	{
		public static NavigationPage NavRoot;

		protected override void Init ()
		{
			Navigation.PushAsync (new FirstPage ());
			NavRoot = this;
		}

		public class FirstPage : ContentPage
		{
			public FirstPage ()
			{
				Title = "First Page";
				BackgroundColor = Color.Black;

				var nextPageBtn = new Button {
					Text = "Next Page"
				};

				nextPageBtn.Clicked += (s, e) => NavRoot.Navigation.PushAsync (new NextPage ());

				Content = nextPageBtn;
			}
		
		}

		public class NextPage : ContentPage
		{
			public NextPage ()
			{
				Title = "Second Page";

				var nextPage2Btn = new Button {
					Text = "Next Page 2"
				};

				nextPage2Btn.Clicked += (s, e) => NavRoot.Navigation.PushAsync (new NextPage2 ());
				BackgroundColor = Color.Black;
				Content = nextPage2Btn;

			}
		}

		public class NextPage2 : ContentPage
		{
			public NextPage2 ()
			{
				Title = "Third Page";

				var popToRootButton = new Button {
					Text = "Pop to root"
				};

				popToRootButton.Clicked += (s, e) => NavRoot.PopToRootAsync ();
				BackgroundColor = Color.Black;
				Content = popToRootButton;
			}
		}


#if UITEST
		[Test]
		[UiTest (typeof(NavigationPage), "PopToRootAsync")]
		public void Issue417TestsNavigateAndPopToRoot ()
		{
			RunningApp.WaitForElement (q => q.Marked ("First Page"));
			RunningApp.WaitForElement (q => q.Button ("Next Page"));
			RunningApp.Screenshot ("All elements present");

			RunningApp.Tap (q => q.Button ("Next Page"));

			RunningApp.WaitForElement (q => q.Marked ("Second Page"));
			RunningApp.WaitForElement (q => q.Button ("Next Page 2"));
			RunningApp.Screenshot ("At second page");
			RunningApp.Tap (q => q.Button ("Next Page 2"));

			RunningApp.WaitForElement (q => q.Marked ("Third Page"));
			RunningApp.WaitForElement (q => q.Button ("Pop to root"));
			RunningApp.Screenshot ("At third page");
			RunningApp.Tap (q => q.Button ("Pop to root"));

			RunningApp.WaitForElement (q => q.Marked ("First Page"));
			RunningApp.WaitForElement (q => q.Button ("Next Page"));
			RunningApp.Screenshot ("All elements present");

			RunningApp.Screenshot ("Popped to root");
		}
#endif
	}


}