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

using Xamarin.Forms.CustomAttributes;
using System.Collections.Generic;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Bugzilla, 29257, "CarouselPage.CurrentPage Does Not Work Properly When Used Inside a NavigationPage ")]
	public class Bugzilla29257 : TestContentPage 
	{
		List<string> _menuItems = new List<string> {
			"Page 1", "Page 2", "Page 3", "Page 4", "Page 5"
		};

		ListView _menu;

		protected override void Init ()
		{
			_menu = new ListView { ItemsSource = _menuItems };

			_menu.ItemSelected += PageSelected;

			Content = _menu;
		}

		async void PageSelected(object sender, SelectedItemChangedEventArgs e)
		{
			var selection = e.SelectedItem as string;

			switch (selection)
			{
			case "Page 1":
				await Navigation.PushAsync(new TestPage(0));
				break;

			case "Page 2":
				await Navigation.PushAsync(new TestPage(1));
				break;

			case "Page 3":
				await Navigation.PushAsync(new TestPage(2));
				break;

			case "Page 4":
				await Navigation.PushAsync(new TestPage(3));
				break;

			case "Page 5":
				await Navigation.PushAsync(new TestPage(4));
				break;
			}
			_menu.SelectedItem = null;
		}

		public class TestPage : CarouselPage
		{
			public TestPage()
			{
				Children.Add(new ContentPage { Content = new Label { Text = "This is page 1" , BackgroundColor = Color.Red} });
				Children.Add(new ContentPage { Content = new Label { Text = "This is page 2" , BackgroundColor = Color.Green} });
				Children.Add(new ContentPage { Content = new Label { Text = "This is page 3" , BackgroundColor = Color.Blue} });
				Children.Add(new ContentPage { Content = new Label { Text = "This is page 4" , BackgroundColor = Color.Pink} });
				Children.Add(new ContentPage { Content = new Label { Text = "This is page 5" , BackgroundColor = Color.Yellow } });

			}

			public TestPage(int page) : this()
			{
				CurrentPage = Children[page];
			}
		}

#if UITEST
		[Test]
		public void Bugzilla29257Test ()
		{
			RunningApp.Tap (q => q.Marked ("Page 1"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.WaitForElement (q => q.Marked ("This is page 1"));
			RunningApp.Back ();
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.Tap (q => q.Marked ("Page 2"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.WaitForElement (q => q.Marked ("This is page 2"));
			RunningApp.Back ();
			RunningApp.Tap (q => q.Marked ("Page 3"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.WaitForElement (q => q.Marked ("This is page 3"));
			RunningApp.Back ();
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.Tap (q => q.Marked ("Page 4"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.WaitForElement (q => q.Marked ("This is page 4"));
			RunningApp.Back ();
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.Tap (q => q.Marked ("Page 5"));
#if __MACOS__
			System.Threading.Thread.Sleep(2000);
#endif
			RunningApp.WaitForElement (q => q.Marked ("This is page 5"));
		}
#endif
	}
}