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

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

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

namespace Xamarin.Forms.Controls.Issues
{
	internal class PageNameObject
	{
		public string PageName { get; private set; }

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

	[Preserve (AllMembers=true)]
	[Issue (IssueTracker.Github, 973, "ActionBar doesn't immediately update when nested TabbedPage is changed", PlatformAffected.Android)]
	public class Issue973 : TestMasterDetailPage
	{
		protected override void Init ()
		{
			var cells = new [] {
				new PageNameObject ("Close Master"),
				new PageNameObject ("Page 1"),
				new PageNameObject ("Page 2"),
				new PageNameObject ("Page 3"),
				new PageNameObject ("Page 4"),
				new PageNameObject ("Page 5"),
				new PageNameObject ("Page 6"),
				new PageNameObject ("Page 7"),
				new PageNameObject ("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 = ((PageNameObject)e.Item).PageName;

				if (cellName == "Close Master") {
					IsPresented = false;
				} else {
					var d = new CustomDetailPage (cellName) {
						Title = "Detail"
					};

					d.PresentMaster += (s, args) => {
						IsPresented = true;
					};

					Detail = d;
				}
			};

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

			Master = master;

			var detail = new CustomDetailPage ("Initial Page") {
				Title = "Detail"
			};

			detail.PresentMaster += (sender, e) => {
				IsPresented = true;
			};

			Detail = detail;
		}

#if UITEST
		[Test]
		[Description ("Test tab reset when swapping out detail")]
		[UiTest (typeof(NavigationPage))]
		[UiTest (typeof(TabbedPage))]
		public void Issue973TestsTabResetAfterDetailSwap ()
		{
			RunningApp.WaitForElement (q => q.Marked ("Initial Page Left aligned"));
			RunningApp.WaitForElement (q => q.Marked ("Tab 1"));

			RunningApp.Tap (q => q.Marked ("Tab 2"));
			RunningApp.WaitForElement (q => q.Marked ("Initial Page Right aligned"));
			RunningApp.Screenshot ("Tab 2 showing");

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

			RunningApp.Tap (q => q.Marked ("Page 4"));
			RunningApp.Screenshot ("Change detail page");

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

			RunningApp.WaitForElement (q => q.Marked ("Page 4 Left aligned"));
			RunningApp.Screenshot ("Tab 1 Showing and tab 1 should be selected");

			RunningApp.Tap (q => q.Marked ("Tab 2"));
			RunningApp.WaitForElement (q => q.Marked ("Page 4 Right aligned"));
			RunningApp.Screenshot ("Tab 2 showing");
		}
#endif

	}

	internal class CustomDetailPage : TabbedPage
	{
		public event EventHandler PresentMaster;

		public CustomDetailPage (string pageName)
		{
			Title = pageName;

			Children.Add (new ContentPage {
				Title = "Tab 1",
				Content = new StackLayout {
					Children = {
						new Label {
							VerticalOptions = LayoutOptions.Center,
							HorizontalOptions = LayoutOptions.Start,
							Text = pageName + " Left aligned"
						}
					}
				}
			});

			Children.Add (new ContentPage {
				Title = "Tab 2",
				Content = new StackLayout {
					Children = {
						new Label {
							VerticalOptions = LayoutOptions.Center,
							HorizontalOptions = LayoutOptions.End,
							Text = pageName + " Right aligned"
						},
						new Button {
							Text = "Present Master",
							Command = new Command (() => {
								var handler = PresentMaster;
								if (handler != null)
									handler(this, EventArgs.Empty);
							})
						}
					}
				}
			});
		}
	}
}