summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1691.cs
blob: 014bdae940bb3510d2624afdb7a1ca8ccdf7f199 (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
using System;
using System.Collections.ObjectModel;
using System.Linq;

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

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

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
	[Ignore("Temporarily ignoring until we can investigate intermittent failures")]
#endif
	[Preserve (AllMembers = true)]
	[Issue (IssueTracker.Github, 1691, "CarouselPage iOS CurrentPage bug")]
	public class Issue1691 : TestCarouselPage
	{
		int _currentIndex;
		int _page = 9;

		protected override void Init ()
		{
			_currentIndex = 10;
			ItemsSource = new ObservableCollection<int>() { _currentIndex };
			SelectedItem = ((ObservableCollection<int>)ItemsSource)[0];
		}

		protected override ContentPage CreateDefault (object item)
		{
			var currentInt = item as int?;

			var label = new Label {
				Text = "Page " + currentInt,
			}; 

			return new ContentPage {
				Content = new StackLayout {
					Children = {
						label, 
						new Button {
							AutomationId = "CreatePreviousPage" + currentInt,
							Text = "Create previous page",
							Command = new Command (() => {
								((ObservableCollection<int>)ItemsSource).Insert (0, _page);
								_page--;
								label.Text = "Page Created";
							})
						},
						new Button {
							AutomationId = "GoToPreviousPage" + currentInt,
							Text = "Go to previous page",
							Command = new Command (() => {
								CurrentPage = Children[0];
							})
						}
					}
				}
			};
		}

#if UITEST
		[Test]
		public void Issue1691Test ()
		{
			RunningApp.Screenshot ("I am at Issue 1691");
			RunningApp.Tap (q => q.Marked ("CreatePreviousPage10"));
			RunningApp.WaitForElement (q => q.Marked ("Page Created"));
			RunningApp.Screenshot ("I should be on the same page with a new page created to the left");
			RunningApp.Tap (q => q.Marked ("GoToPreviousPage10"));
			RunningApp.WaitForNoElement (q => q.Marked ("GoToPreviousPage10"));
			RunningApp.Screenshot ("I should be on page 9");
			RunningApp.WaitForElement (q => q.Marked ("GoToPreviousPage9"));
		}
#endif
	}
}