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

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

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

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 2965, "CarouselPage Disappearing event does not fire on Android")]
	public class Issue2965 : TestMasterDetailPage
	{
		static MasterDetailPage s_mdp;

		int _countAppearing;

		protected override void Init ()
		{
			s_mdp = this;
			
			var lblCount = new Label { AutomationId = "lblCount" };

			var myCarouselPage = new CarouselPage () {

				Children = {
					new ContentPage { 
						BackgroundColor = Color.Green,
						Content = new StackLayout {
							Children = {
								new Button { 
									AutomationId = "ShowMasterBtnPage1", 
									Text = "ShowMaster",
									Command = new Command(()=> s_mdp.IsPresented = true)
								},
								lblCount
							}
						}
					},
					new ContentPage { 
						BackgroundColor = Color.Red
					},
					new ContentPage { 
						BackgroundColor = Color.Lime,
					},
					new ContentPage { 
						BackgroundColor = Color.Purple,
					},
				}
			};

			var myCarouselDetailPage = new NavigationPage (myCarouselPage);

			var myPushButton = new Button () {
				Text = "Push Page", 
				HorizontalOptions = LayoutOptions.Start
			}; 

			myCarouselPage.Appearing += (sender, e) => {
				_countAppearing++;
				lblCount.Text = _countAppearing.ToString ();
			};
			myCarouselPage.Disappearing += (sender, e) => {
				_countAppearing--;
			};


			var mySecondDetailPage = new NavigationPage (new ContentPage () { 
				Title = "My Second Page", 

				Content = new StackLayout () {
					Orientation = StackOrientation.Vertical,
					Children = {
						new Button { 
							AutomationId = "ShowMasterBtnPage2", 
							Text = "ShowMaster",
							Command = new Command(()=> s_mdp.IsPresented = true)
						},
						myPushButton
					}
				}
			});

			myPushButton.Command = new Command (() => mySecondDetailPage.Navigation.PushAsync (new ContentPage () { Title = "My Pushed Page" }));

			var myMasterPage = new ContentPage () {
				Padding = new Thickness (0, 60, 0, 0),
				Title = "Menu",
				Content = new StackLayout () {
					Orientation = StackOrientation.Vertical,
					Children = {
						new Button () {
							Text = "Detail 1",
							AutomationId = "btnDetail1",
							Command = new Command (() => {
								Detail = myCarouselDetailPage;
								IsPresented = false;
							}),
							HorizontalOptions = LayoutOptions.Start
						},

						new Button () {
							Text = "Detail 2",
							AutomationId = "btnDetail2",
							Command = new Command (() => {
								Detail = mySecondDetailPage;
								IsPresented = false;
							}),
							HorizontalOptions = LayoutOptions.Start
						}

					}
				}
			};

			Master = myMasterPage;
			Detail = myCarouselDetailPage;
		}

#if UITEST
		[Test]
		[Ignore("Fails intermittently on TestCloud")]
		public void Issue2965Test ()
		{
			RunningApp.Screenshot ("I am at Issue 2965");
			var element = RunningApp.WaitForElement (q => q.Marked ("lblCount"))[0];
			Assert.That (element.Text, Is.EqualTo ("1"));

#if __IOS__
			RunningApp.Tap (q => q.Marked("Menu"));
#else
			RunningApp.Tap ("ShowMasterBtnPage1");
#endif
			RunningApp.Tap (q => q.Marked("btnDetail2"));

#if __IOS__
			RunningApp.Tap (q => q.Marked("Menu"));
#else
			RunningApp.Tap ("ShowMasterBtnPage2");
#endif
			RunningApp.Tap (q => q.Marked("btnDetail1"));
			element = RunningApp.WaitForElement (q => q.Marked ("lblCount"))[0];
			Assert.That (element.Text, Is.EqualTo ("1"));
		}
#endif
		}
	}